github.com/gagliardetto/solana-go@v1.11.0/programs/token/accounts_test.go (about) 1 package token 2 3 import ( 4 "bytes" 5 "testing" 6 7 "github.com/davecgh/go-spew/spew" 8 bin "github.com/gagliardetto/binary" 9 "github.com/gagliardetto/solana-go" 10 "github.com/stretchr/testify/require" 11 ) 12 13 func TestMint(t *testing.T) { 14 accountBytes := []byte{ 15 1, 0, 0, 0, 16 5, 234, 156, 241, 108, 228, 17, 152, 241, 164, 153, 55, 200, 140, 55, 10, 148, 212, 175, 255, 137, 181, 186, 203, 142, 244, 94, 99, 36, 187, 120, 247, 17 9, 169, 49, 235, 241, 182, 6, 0, 18 6, 19 1, 20 1, 0, 0, 0, 21 5, 234, 156, 241, 108, 228, 17, 152, 241, 164, 153, 55, 200, 140, 55, 10, 148, 212, 175, 255, 137, 181, 186, 203, 142, 244, 94, 99, 36, 187, 120, 247, 22 } 23 { 24 dec := bin.NewBinDecoder(accountBytes) 25 mint := Mint{} 26 27 err := dec.Decode(&mint) 28 require.NoError(t, err, spew.Sdump(mint)) 29 30 require.Equal(t, 31 &Mint{ 32 MintAuthority: solana.MustPublicKeyFromBase58("Q6XprfkF8RQQKoQVG33xT88H7wi8Uk1B1CC7YAs69Gi").ToPointer(), 33 Supply: 1890000009537801, 34 Decimals: 6, 35 IsInitialized: true, 36 FreezeAuthority: solana.MustPublicKeyFromBase58("Q6XprfkF8RQQKoQVG33xT88H7wi8Uk1B1CC7YAs69Gi").ToPointer(), 37 }, 38 &mint, 39 ) 40 41 { 42 buf := new(bytes.Buffer) 43 err := bin.NewBinEncoder(buf).Encode(mint) 44 require.NoError(t, err) 45 require.Equal(t, accountBytes, buf.Bytes(), bin.FormatByteSlice(buf.Bytes())) 46 } 47 } 48 } 49 50 func TestAccount(t *testing.T) { 51 accountBytes := []byte{ 52 6, 155, 136, 87, 254, 171, 129, 132, 251, 104, 127, 99, 70, 24, 192, 53, 218, 196, 57, 220, 26, 235, 59, 85, 152, 160, 240, 0, 0, 0, 0, 1, 53 93, 100, 62, 133, 31, 102, 235, 161, 170, 152, 161, 7, 39, 223, 9, 180, 1, 224, 134, 204, 54, 241, 9, 195, 240, 147, 219, 146, 35, 92, 26, 224, 54 42, 34, 176, 1, 0, 0, 0, 0, 55 56 0, 0, 0, 0, 57 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 58 59 1, 60 1, 0, 0, 0, 61 240, 29, 31, 0, 0, 0, 0, 0, 62 0, 0, 0, 0, 0, 0, 0, 0, 63 64 0, 0, 0, 0, 65 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66 } 67 { 68 dec := bin.NewBinDecoder(accountBytes) 69 account := Account{} 70 71 err := dec.Decode(&account) 72 require.NoError(t, err, spew.Sdump(account)) 73 74 balance := uint64(2039280) 75 require.Equal(t, 76 &Account{ 77 Mint: solana.MustPublicKeyFromBase58("So11111111111111111111111111111111111111112"), 78 Owner: solana.MustPublicKeyFromBase58("7HZaCWazgTuuFuajxaaxGYbGnyVKwxvsJKue1W4Nvyro"), 79 Amount: (uint64)(28320298), 80 Delegate: (*solana.PublicKey)(nil), 81 State: (AccountState)(1), 82 IsNative: (*uint64)(&balance), 83 DelegatedAmount: (uint64)(0), 84 CloseAuthority: (*solana.PublicKey)(nil), 85 }, 86 &account, 87 ) 88 89 { 90 buf := bin.NewWriteByWrite("") 91 err := bin.NewBinEncoder(buf).Encode(account) 92 require.NoError(t, err) 93 require.Equal(t, accountBytes, buf.Bytes(), bin.FormatByteSlice(buf.Bytes())) 94 } 95 } 96 }