From 683c6db4959e386a909aac0eb37e34cc69aa22b1 Mon Sep 17 00:00:00 2001 From: Tristan Date: Wed, 15 May 2024 18:31:03 +0800 Subject: [PATCH] add test case for verify ins --- .../metaplex/token_metadata/instruction.go | 75 +------------------ .../token_metadata/instruction_test.go | 41 ++++++++++ 2 files changed, 43 insertions(+), 73 deletions(-) diff --git a/program/metaplex/token_metadata/instruction.go b/program/metaplex/token_metadata/instruction.go index 66957ad0..9d9ca58c 100644 --- a/program/metaplex/token_metadata/instruction.go +++ b/program/metaplex/token_metadata/instruction.go @@ -644,7 +644,7 @@ func CreateMetadataAccountV3(param CreateMetadataAccountV3Param) types.Instructi type VerifyCollectionParams struct { Metadata common.PublicKey - CollectionAuthority common.PublicKey + CollectionUpdateAuthority common.PublicKey Payer common.PublicKey CollectionMint common.PublicKey Collection common.PublicKey @@ -667,7 +667,7 @@ func CreateVerifyCollection(param VerifyCollectionParams) types.Instruction { IsSigner: false, }, { - PubKey: param.CollectionAuthority, + PubKey: param.CollectionUpdateAuthority, IsWritable: true, IsSigner: true, }, @@ -698,74 +698,3 @@ func CreateVerifyCollection(param VerifyCollectionParams) types.Instruction { Data: data, } } - -type SetAndVerifyCollectionParams struct { - Metadata common.PublicKey - CollectionAuthority common.PublicKey - Payer common.PublicKey - UpdateAuthority common.PublicKey - CollectionMint common.PublicKey - Collection common.PublicKey - CollectionMasterEditionAccount common.PublicKey - CollectionAuthorityRecord *common.PublicKey -} - -func CreateSetAndVerifyCollection(param SetAndVerifyCollectionParams) types.Instruction { - data, err := borsh.Serialize(struct { - Instruction Instruction - }{ - Instruction: InstructionSetAndVerifyCollection, - }) - if err != nil { - panic(err) - } - accounts := []types.AccountMeta{ - { - PubKey: param.Metadata, - IsWritable: true, - IsSigner: false, - }, - { - PubKey: param.CollectionAuthority, - IsWritable: true, - IsSigner: true, - }, - { - PubKey: param.Payer, - IsWritable: true, - IsSigner: true, - }, - { - PubKey: param.UpdateAuthority, - IsWritable: false, - IsSigner: false, - }, - { - PubKey: param.CollectionMint, - IsWritable: false, - IsSigner: false, - }, - { - PubKey: param.Collection, - IsWritable: false, - IsSigner: false, - }, - { - PubKey: param.CollectionMasterEditionAccount, - IsWritable: false, - IsSigner: false, - }, - } - if param.CollectionAuthorityRecord != nil { - accounts = append(accounts, types.AccountMeta{ - PubKey: *param.CollectionAuthorityRecord, - IsWritable: false, - IsSigner: false, - }) - } - return types.Instruction{ - ProgramID: common.MetaplexTokenMetaProgramID, - Accounts: accounts, - Data: data, - } -} diff --git a/program/metaplex/token_metadata/instruction_test.go b/program/metaplex/token_metadata/instruction_test.go index 1d696202..f159c89b 100644 --- a/program/metaplex/token_metadata/instruction_test.go +++ b/program/metaplex/token_metadata/instruction_test.go @@ -455,3 +455,44 @@ func TestCreateMetadataAccountV2(t *testing.T) { }) } } + +func TestCreateVerifyCollection(t *testing.T) { + type args struct { + param VerifyCollectionParams + } + tests := []struct { + name string + args args + want types.Instruction + }{ + { + args: args{ + param: VerifyCollectionParams{ + Metadata: common.PublicKeyFromString("MetaData11111111111111111111111111111111111"), + CollectionUpdateAuthority: common.PublicKeyFromString("CollectionUpdateAuthority111111111111111111"), + Payer: common.PublicKeyFromString("payer11111111111111111111111111111111111111"), + CollectionMint: common.PublicKeyFromString("CollectionMint11111111111111111111111111111"), + Collection: common.PublicKeyFromString("Collection111111111111111111111111111111111"), + CollectionMasterEditionAccount: common.PublicKeyFromString("CollectionMasterEditionAccount1111111111111"), + }, + }, + want: types.Instruction{ + ProgramID: common.MetaplexTokenMetaProgramID, + Accounts: []types.AccountMeta{ + {PubKey: common.PublicKeyFromString("MetaData11111111111111111111111111111111111"), IsSigner: false, IsWritable: true}, + {PubKey: common.PublicKeyFromString("CollectionUpdateAuthority111111111111111111"), IsSigner: true, IsWritable: true}, + {PubKey: common.PublicKeyFromString("payer11111111111111111111111111111111111111"), IsSigner: true, IsWritable: true}, + {PubKey: common.PublicKeyFromString("CollectionMint11111111111111111111111111111"), IsSigner: false, IsWritable: false}, + {PubKey: common.PublicKeyFromString("Collection111111111111111111111111111111111"), IsSigner: false, IsWritable: false}, + {PubKey: common.PublicKeyFromString("CollectionMasterEditionAccount1111111111111"), IsSigner: false, IsWritable: false}, + }, + Data: []byte{18}, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.Equalf(t, tt.want, CreateVerifyCollection(tt.args.param), "CreateVerifyCollection(%v)", tt.args.param) + }) + } +}