Skip to content

Commit

Permalink
implement tokenprog init account2
Browse files Browse the repository at this point in the history
  • Loading branch information
yihau committed Mar 25, 2021
1 parent 5c7f734 commit 77e8790
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
23 changes: 21 additions & 2 deletions tokenprog/instruction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
37 changes: 37 additions & 0 deletions tokenprog/instruction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
}

0 comments on commit 77e8790

Please sign in to comment.