Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Nov 28, 2023
1 parent d8d5faa commit 2d39f9c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
45 changes: 30 additions & 15 deletions token/program-2022-test/tests/token_group_initialize_member.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg(feature = "test-sbf")]
// #![cfg(feature = "test-sbf")]

mod program_test;
use {
Expand Down Expand Up @@ -81,7 +81,7 @@ async fn setup(group: SetupConfig, members: Vec<SetupConfig>) -> (TestContext, V
&payer_pubkey,
&group_token_context.mint_authority.pubkey(),
&group_authority,
5,
2,
&[&group_token_context.mint_authority],
)
.await
Expand Down Expand Up @@ -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
}
)))
);

Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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::<TokenGroupMember>().unwrap();
let fetched_member = pod_from_bytes::<TokenGroupMember>(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)
)
)))
);
}

Expand Down
10 changes: 5 additions & 5 deletions token/program-2022/src/extension/token_group/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
}
}

0 comments on commit 2d39f9c

Please sign in to comment.