Skip to content

Commit 04b5b33

Browse files
committed
Add more tests
1 parent 73311b0 commit 04b5b33

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

programs/system/CreateAccountWithSeed_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ import (
1919
"strconv"
2020
"testing"
2121

22+
bin "github.com/gagliardetto/binary"
2223
ag_gofuzz "github.com/gagliardetto/gofuzz"
24+
"github.com/gagliardetto/solana-go"
2325
ag_require "github.com/stretchr/testify/require"
2426
)
2527

@@ -44,3 +46,51 @@ func TestEncodeDecode_CreateAccountWithSeed(t *testing.T) {
4446
})
4547
}
4648
}
49+
50+
func TestEncDec(t *testing.T) {
51+
instr := []byte{204, 95, 77, 127, 148, 25, 135, 127, 89, 146, 22, 90, 233, 80, 113, 3, 70, 176, 165, 222, 81, 200, 100, 223, 117, 165, 155, 44, 53, 225, 124, 20, 5, 0, 0, 0, 0, 0, 0, 0, 104, 101, 108, 108, 111, 192, 4, 14, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 57, 111, 59, 111, 183, 248, 249, 251, 128, 174, 206, 0, 81, 22, 3, 173, 244, 104, 15, 249, 239, 112, 33, 255, 66, 169, 29, 66, 7, 106, 231, 230}
52+
53+
{
54+
payerPrivateKey := solana.MustPrivateKeyFromBase58("5LRLfrUP22VtiNaPGAEgHPucoJmG8ejmomMVmpn4fkXjexYsT7RQGfGuMePG5PKvecZxMGrqa6EP2RmYcm7TYQvX")
55+
payerAccount, _ := solana.WalletFromPrivateKeyBase58(payerPrivateKey.String())
56+
programID := "4sCcZNQR8vfWckyi5L9KdptdaiLxdiMjVgKQay7HxzmK"
57+
programPubKey := solana.MustPublicKeyFromBase58(programID)
58+
59+
newSubAccount, err := solana.CreateWithSeed(
60+
payerAccount.PublicKey(),
61+
"hello",
62+
programPubKey,
63+
)
64+
ag_require.NoError(t, err)
65+
66+
instruction := NewCreateAccountWithSeedInstruction(
67+
payerAccount.PublicKey(),
68+
"hello",
69+
918720,
70+
4,
71+
programPubKey,
72+
payerAccount.PublicKey(),
73+
newSubAccount,
74+
payerAccount.PublicKey(),
75+
)
76+
77+
{
78+
buffer := new(bytes.Buffer)
79+
err = bin.NewBinEncoder(buffer).Encode(instruction)
80+
ag_require.NoError(t, err)
81+
ag_require.Equal(t, instr, buffer.Bytes())
82+
}
83+
84+
{
85+
got := new(CreateAccountWithSeed)
86+
err = decodeT(got, instr)
87+
got.AccountMetaSlice = solana.AccountMetaSlice{
88+
solana.Meta(payerAccount.PublicKey()).WRITE().SIGNER(),
89+
solana.Meta(newSubAccount).WRITE(),
90+
solana.Meta(payerAccount.PublicKey()).SIGNER(),
91+
}
92+
ag_require.NoError(t, err)
93+
ag_require.Equal(t, instruction, got)
94+
}
95+
}
96+
}

0 commit comments

Comments
 (0)