From 8766eb9cdd0edb3a26d1c980a9add130f83cc6df Mon Sep 17 00:00:00 2001 From: Joe C Date: Sat, 24 Feb 2024 09:29:30 -0600 Subject: [PATCH] token-js: add `GroupPointer` and `GroupMemberPointer` to `setAuthority` Add the newly added `GroupPointer` and `GroupMemberPointer` to the `setAuthority` instruction. --- token/js/src/instructions/setAuthority.ts | 2 + .../test/e2e-2022/groupMemberPointer.test.ts | 47 +++++++++++++++++++ token/js/test/e2e-2022/groupPointer.test.ts | 47 +++++++++++++++++++ 3 files changed, 96 insertions(+) diff --git a/token/js/src/instructions/setAuthority.ts b/token/js/src/instructions/setAuthority.ts index 545955cc1a3..58ef8e271f7 100644 --- a/token/js/src/instructions/setAuthority.ts +++ b/token/js/src/instructions/setAuthority.ts @@ -28,6 +28,8 @@ export enum AuthorityType { TransferHookProgramId = 10, ConfidentialTransferFeeConfig = 11, MetadataPointer = 12, + GroupPointer = 13, + GroupMemberPointer = 14, } /** TODO: docs */ diff --git a/token/js/test/e2e-2022/groupMemberPointer.test.ts b/token/js/test/e2e-2022/groupMemberPointer.test.ts index bf5d664ffc5..7111787e115 100644 --- a/token/js/test/e2e-2022/groupMemberPointer.test.ts +++ b/token/js/test/e2e-2022/groupMemberPointer.test.ts @@ -4,9 +4,11 @@ import { PublicKey } from '@solana/web3.js'; import { sendAndConfirmTransaction, Keypair, SystemProgram, Transaction } from '@solana/web3.js'; import { + AuthorityType, ExtensionType, createInitializeGroupMemberPointerInstruction, createInitializeMintInstruction, + createSetAuthorityInstruction, createUpdateGroupMemberPointerInstruction, getGroupMemberPointerState, getMint, @@ -94,4 +96,49 @@ describe('GroupMember pointer', () => { memberAddress: newGroupMemberAddress, }); }); + + it('can update authority', async () => { + const newAuthority = PublicKey.unique(); + const transaction = new Transaction().add( + createSetAuthorityInstruction( + mint.publicKey, + mintAuthority.publicKey, + AuthorityType.GroupMemberPointer, + newAuthority, + [], + TEST_PROGRAM_ID + ) + ); + await sendAndConfirmTransaction(connection, transaction, [payer, mintAuthority], undefined); + + const mintInfo = await getMint(connection, mint.publicKey, undefined, TEST_PROGRAM_ID); + const groupMemberPointer = getGroupMemberPointerState(mintInfo); + + expect(groupMemberPointer).to.deep.equal({ + authority: newAuthority, + memberAddress, + }); + }); + + it('can update authority to null', async () => { + const transaction = new Transaction().add( + createSetAuthorityInstruction( + mint.publicKey, + mintAuthority.publicKey, + AuthorityType.GroupMemberPointer, + null, + [], + TEST_PROGRAM_ID + ) + ); + await sendAndConfirmTransaction(connection, transaction, [payer, mintAuthority], undefined); + + const mintInfo = await getMint(connection, mint.publicKey, undefined, TEST_PROGRAM_ID); + const groupMemberPointer = getGroupMemberPointerState(mintInfo); + + expect(groupMemberPointer).to.deep.equal({ + authority: null, + memberAddress, + }); + }); }); diff --git a/token/js/test/e2e-2022/groupPointer.test.ts b/token/js/test/e2e-2022/groupPointer.test.ts index 0f2322dfe4c..5375031d4fa 100644 --- a/token/js/test/e2e-2022/groupPointer.test.ts +++ b/token/js/test/e2e-2022/groupPointer.test.ts @@ -4,9 +4,11 @@ import { PublicKey } from '@solana/web3.js'; import { sendAndConfirmTransaction, Keypair, SystemProgram, Transaction } from '@solana/web3.js'; import { + AuthorityType, ExtensionType, createInitializeGroupPointerInstruction, createInitializeMintInstruction, + createSetAuthorityInstruction, createUpdateGroupPointerInstruction, getGroupPointerState, getMint, @@ -94,4 +96,49 @@ describe('Group pointer', () => { groupAddress: newGroupAddress, }); }); + + it('can update authority', async () => { + const newAuthority = PublicKey.unique(); + const transaction = new Transaction().add( + createSetAuthorityInstruction( + mint.publicKey, + mintAuthority.publicKey, + AuthorityType.GroupPointer, + newAuthority, + [], + TEST_PROGRAM_ID + ) + ); + await sendAndConfirmTransaction(connection, transaction, [payer, mintAuthority], undefined); + + const mintInfo = await getMint(connection, mint.publicKey, undefined, TEST_PROGRAM_ID); + const groupPointer = getGroupPointerState(mintInfo); + + expect(groupPointer).to.deep.equal({ + authority: newAuthority, + groupAddress, + }); + }); + + it('can update authority to null', async () => { + const transaction = new Transaction().add( + createSetAuthorityInstruction( + mint.publicKey, + mintAuthority.publicKey, + AuthorityType.GroupPointer, + null, + [], + TEST_PROGRAM_ID + ) + ); + await sendAndConfirmTransaction(connection, transaction, [payer, mintAuthority], undefined); + + const mintInfo = await getMint(connection, mint.publicKey, undefined, TEST_PROGRAM_ID); + const groupPointer = getGroupPointerState(mintInfo); + + expect(groupPointer).to.deep.equal({ + authority: null, + groupAddress, + }); + }); });