diff --git a/tokenprog/instruction.go b/tokenprog/instruction.go index 6961908c..5103b435 100644 --- a/tokenprog/instruction.go +++ b/tokenprog/instruction.go @@ -309,6 +309,25 @@ func BurnChecked(accountPubkey, mintPubkey, authPubkey common.PublicKey, signerP } } -func InitializeAccount2() types.Instruction { - panic("not implement yet") +func InitializeAccount2(accountPubkey, mintPubkey, ownerPubkey common.PublicKey) types.Instruction { + data, err := common.SerializeData(struct { + Instruction Instruction + Owner common.PublicKey + }{ + Instruction: InstructionInitializeAccount2, + Owner: ownerPubkey, + }) + if err != nil { + panic(err) + } + + return types.Instruction{ + ProgramID: common.TokenProgramID, + Accounts: []types.AccountMeta{ + {PubKey: accountPubkey, IsSigner: false, IsWritable: true}, + {PubKey: mintPubkey, IsSigner: false, IsWritable: false}, + {PubKey: common.SysVarRentPubkey, IsSigner: false, IsWritable: false}, + }, + Data: data, + } } diff --git a/tokenprog/instruction_test.go b/tokenprog/instruction_test.go index 9b3bec48..63521d9a 100644 --- a/tokenprog/instruction_test.go +++ b/tokenprog/instruction_test.go @@ -301,3 +301,40 @@ func TestCloseAccount(t *testing.T) { }) } } + +func TestInitializeAccount2(t *testing.T) { + type args struct { + accountPubkey common.PublicKey + mintPubkey common.PublicKey + ownerPubkey common.PublicKey + } + tests := []struct { + name string + args args + want types.Instruction + }{ + { + args: args{ + accountPubkey: common.PublicKeyFromString("FtvD2ymcAFh59DGGmJkANyJzEpLDR1GLgqDrUxfe2dPm"), + mintPubkey: common.PublicKeyFromString("BkXBQ9ThbQffhmG39c2TbXW94pEmVGJAvxWk6hfxRvUJ"), + ownerPubkey: common.PublicKeyFromString("EvN4kgKmCmYzdbd5kL8Q8YgkUW5RoqMTpBczrfLExtx7"), + }, + want: types.Instruction{ + ProgramID: common.TokenProgramID, + Accounts: []types.AccountMeta{ + {PubKey: common.PublicKeyFromString("FtvD2ymcAFh59DGGmJkANyJzEpLDR1GLgqDrUxfe2dPm"), IsSigner: false, IsWritable: true}, + {PubKey: common.PublicKeyFromString("BkXBQ9ThbQffhmG39c2TbXW94pEmVGJAvxWk6hfxRvUJ"), IsSigner: false, IsWritable: false}, + {PubKey: common.SysVarRentPubkey, IsSigner: false, IsWritable: false}, + }, + Data: []byte{16, 206, 211, 135, 230, 195, 111, 87, 254, 147, 239, 143, 81, 110, 159, 49, 140, 109, 137, 224, 197, 24, 49, 223, 61, 123, 8, 78, 109, 110, 136, 228, 240}, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := InitializeAccount2(tt.args.accountPubkey, tt.args.mintPubkey, tt.args.ownerPubkey); !reflect.DeepEqual(got, tt.want) { + t.Errorf("InitializeAccount2() = %v, want %v", got, tt.want) + } + }) + } +}