** The code is functional. The issue was with the test framework. See solution **.
I'm trying to create a group mint with token-2022.
I've followed the steps in:
Being an interface, i've used the spl-token-2022 program id with all of the instructions. Have not provided my own implementations.
The instructions in order (full code at the end of the question):
- create mint account (with enough lamports to cover group pointer)
- initialise the group pointer extension on the mint created in (1)
- initialise the mint
- initialize_group
Instructions 1-3 execute correctly. However at step (4) I'm hit with "Invalid Instruction".
[2024-01-07T19:33:59.051326000Z DEBUG solana_runtime::message_processor::stable_log] Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb invoke [2]
[2024-01-07T19:33:59.051718000Z DEBUG solana_runtime::message_processor::stable_log] Program log: Error: Invalid instruction
Full code:
pub fn create_group_mint_combined( payer: &Signer, group_mint: &Signer, authority: &AccountInfo, authority_seeds: &[&[u8]], max_group_size: u32, ) -> Result { let rent = Rent::get()?; let mint_space = ExtensionType::try_calculate_account_len::(&[ExtensionType::GroupPointer])?; let mint_rent_lamports = rent.minimum_balance(mint_space); invoke( &system_instruction::create_account( &payer.key(), &group_mint.key(), mint_rent_lamports, mint_space.try_into().unwrap(), &spl_token_2022::ID, ), &[payer.to_account_info(), group_mint.to_account_info()], )?; let initialize_extension = spl_token_2022::extension::group_pointer::instruction::initialize( &spl_token_2022::ID, &group_mint.key(), Some(authority.key()), Some(group_mint.key()), ) .unwrap(); invoke_signed( &initialize_extension, &[ group_mint.to_account_info(), authority.to_account_info(), group_mint.to_account_info(), ], &[authority_seeds], )?; let initialize_ix = initialize_mint2( &spl_token_2022::ID, &group_mint.key(), &authority.key(), Some(&authority.key()), 0, ) .unwrap(); msg!("Invoke initialise mint2"); invoke_signed( &initialize_ix, &[group_mint.to_account_info()], &[authority_seeds], )?; msg!("Initialize group"); invoke_signed( &initialize_group( &spl_token_2022::ID, &group_mint.key(), &group_mint.key(), &authority.key(), // Pubkey::new_unique().into(), Some(authority.key()), max_group_size, ), &[ group_mint.to_account_info(), authority.to_account_info(), ], &[authority_seeds], )?; msg!("Invoked"); Ok(()) }