@@ -361,6 +361,54 @@ describe('Token-2022 Transfer Hook — Counter (Pinocchio)', () => {
361361 assert . equal ( counterValue ( ) , 2n , 'the counter advanced to two' ) ;
362362 } ) ;
363363
364+ it ( 'Configures a second mint against the existing counter' , async ( ) => {
365+ // The counter is global, not per-mint, so setting up a second mint must
366+ // reuse it. Creating it again would fail and roll the whole setup back,
367+ // leaving every mint after the first unable to use this hook.
368+ const secondMint = await generateKeyPairSigner ( ) ;
369+ const initIx = {
370+ programAddress : programId ,
371+ accounts : [
372+ { address : payer . address , role : AccountRole . WRITABLE_SIGNER , signer : payer } ,
373+ { address : secondMint . address , role : AccountRole . WRITABLE_SIGNER , signer : secondMint } ,
374+ { address : TOKEN_2022_PROGRAM_ADDRESS , role : AccountRole . READONLY } ,
375+ { address : SYSTEM_PROGRAM_ADDRESS , role : AccountRole . READONLY } ,
376+ ] ,
377+ data : Uint8Array . of ( INITIALIZE_DISCRIMINATOR , DECIMALS ) ,
378+ } ;
379+ send ( await tx ( [ initIx ] ) , 'initialize second mint' ) ;
380+
381+ const [ secondMetaList ] = await getProgramDerivedAddress ( {
382+ programAddress : programId ,
383+ seeds : [ 'extra-account-metas' , addressEncoder . encode ( secondMint . address ) ] ,
384+ } ) ;
385+ const countBefore = counterValue ( ) ;
386+
387+ const metasIx = {
388+ programAddress : programId ,
389+ accounts : [
390+ { address : payer . address , role : AccountRole . WRITABLE_SIGNER , signer : payer } ,
391+ { address : secondMetaList , role : AccountRole . WRITABLE } ,
392+ { address : secondMint . address , role : AccountRole . READONLY } ,
393+ { address : counter , role : AccountRole . WRITABLE } ,
394+ { address : TOKEN_2022_PROGRAM_ADDRESS , role : AccountRole . READONLY } ,
395+ { address : ASSOCIATED_TOKEN_PROGRAM_ADDRESS , role : AccountRole . READONLY } ,
396+ { address : SYSTEM_PROGRAM_ADDRESS , role : AccountRole . READONLY } ,
397+ ] ,
398+ data : INITIALIZE_EXTRA_ACCOUNT_META_LIST_DISCRIMINATOR ,
399+ } ;
400+ send ( await tx ( [ metasIx ] ) , 'initialize second extra account meta list' ) ;
401+
402+ const account = svm . getAccount ( secondMetaList ) ;
403+ if ( ! account ?. exists ) throw new Error ( 'second extra account meta list not found' ) ;
404+ assert . deepEqual (
405+ Array . from ( account . data ) ,
406+ Array . from ( EXPECTED_EXTRA_ACCOUNT_METAS ) ,
407+ 'the second mint got its own list' ,
408+ ) ;
409+ assert . equal ( counterValue ( ) , countBefore , 'the shared counter kept its value' ) ;
410+ } ) ;
411+
364412 it ( 'Rejects calling the hook outside a transfer' , async ( ) => {
365413 // Same accounts Token-2022 would pass, but invoked directly. The source
366414 // account's `transferring` flag is only set mid-transfer, so this fails.
0 commit comments