From 2d39f9cd4be7da3751e38a65f5d6f3dff3d10beb Mon Sep 17 00:00:00 2001 From: Joe Date: Mon, 27 Nov 2023 20:05:22 -0500 Subject: [PATCH] address feedback --- .../tests/token_group_initialize_member.rs | 45 ++++++++++++------- .../src/extension/token_group/processor.rs | 10 ++--- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/token/program-2022-test/tests/token_group_initialize_member.rs b/token/program-2022-test/tests/token_group_initialize_member.rs index 1801d36231a..d6df05f51cf 100644 --- a/token/program-2022-test/tests/token_group_initialize_member.rs +++ b/token/program-2022-test/tests/token_group_initialize_member.rs @@ -1,4 +1,4 @@ -#![cfg(feature = "test-sbf")] +// #![cfg(feature = "test-sbf")] mod program_test; use { @@ -81,7 +81,7 @@ async fn setup(group: SetupConfig, members: Vec) -> (TestContext, V &payer_pubkey, &group_token_context.mint_authority.pubkey(), &group_authority, - 5, + 2, &[&group_token_context.mint_authority], ) .await @@ -136,10 +136,21 @@ async fn success_initialize() { ) .await .unwrap_err(); + let member_index = if group_mint_keypair + .pubkey() + .cmp(&member1_mint_keypair.pubkey()) + .is_le() + { + 4 + } else { + 3 + }; assert_eq!( error, TokenClientError::Client(Box::new(TransportError::TransactionError( - TransactionError::InsufficientFundsForRent { account_index: 4 } + TransactionError::InsufficientFundsForRent { + account_index: member_index + } ))) ); @@ -241,6 +252,11 @@ async fn success_initialize() { ); // fail double-init + { + let mut context = member_contexts[0].context.lock().await; + context.get_new_latest_blockhash().await.unwrap(); + context.get_new_latest_blockhash().await.unwrap(); + } let error = member1_token_context .token .token_group_initialize_member( @@ -261,7 +277,7 @@ async fn success_initialize() { ))) ); - // Now the others + // Now the second let member2_token_context = member_contexts[1].token_context.take().unwrap(); member2_token_context .token @@ -286,8 +302,9 @@ async fn success_initialize() { } ); + // Third should fail on max size let member3_token_context = member_contexts[2].token_context.take().unwrap(); - member3_token_context + let error = member3_token_context .token .token_group_initialize_member_with_rent_transfer( &payer_pubkey, @@ -297,17 +314,15 @@ async fn success_initialize() { &[&member3_token_context.mint_authority, &group_authority], ) .await - .unwrap(); - let mint_info = member3_token_context.token.get_mint_info().await.unwrap(); - let member_bytes = mint_info.get_extension_bytes::().unwrap(); - let fetched_member = pod_from_bytes::(member_bytes).unwrap(); + .unwrap_err(); assert_eq!( - fetched_member, - &TokenGroupMember { - mint: member3_mint_keypair.pubkey(), - group: group_mint_keypair.pubkey(), - member_number: 3.try_into().unwrap(), - } + error, + TokenClientError::Client(Box::new(TransportError::TransactionError( + TransactionError::InstructionError( + 1, + InstructionError::Custom(TokenGroupError::SizeExceedsMaxSize as u32) + ) + ))) ); } diff --git a/token/program-2022/src/extension/token_group/processor.rs b/token/program-2022/src/extension/token_group/processor.rs index e374eb6fec4..56d632426ef 100644 --- a/token/program-2022/src/extension/token_group/processor.rs +++ b/token/program-2022/src/extension/token_group/processor.rs @@ -96,7 +96,7 @@ pub fn process_initialize_group( } /// Processes an -/// [UpdateGroupMaxSize](enum.GroupInterfaceInstruction.html) +/// [UpdateGroupMaxSize](enum.TokenGroupInstruction.html) /// instruction pub fn process_update_group_max_size( _program_id: &Pubkey, @@ -120,7 +120,7 @@ pub fn process_update_group_max_size( } /// Processes an -/// [UpdateGroupAuthority](enum.GroupInterfaceInstruction.html) +/// [UpdateGroupAuthority](enum.TokenGroupInstruction.html) /// instruction pub fn process_update_group_authority( _program_id: &Pubkey, @@ -143,9 +143,9 @@ pub fn process_update_group_authority( Ok(()) } -/// Processes an [InitializeMember](enum.GroupInterfaceInstruction.html) +/// Processes an [InitializeMember](enum.TokenGroupInstruction.html) /// instruction -pub fn process_initialize_group_member( +pub fn process_initialize_member( _program_id: &Pubkey, accounts: &[AccountInfo], ) -> ProgramResult { @@ -230,7 +230,7 @@ pub fn process_instruction( } TokenGroupInstruction::InitializeMember(_) => { msg!("TokenGroupInstruction: InitializeMember"); - process_initialize_group_member(program_id, accounts) + process_initialize_member(program_id, accounts) } } }