From e28468673b743d63f3a7efbb2678471e03228675 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 18 Oct 2023 23:16:24 +0200 Subject: [PATCH] return to group nomenclature --- token-group/example/src/lib.rs | 2 +- token-group/example/src/processor.rs | 106 ++++++++------- ...lize_collection.rs => initialize_group.rs} | 68 +++++----- ...lection_member.rs => initialize_member.rs} | 61 +++++---- ...authority.rs => update_group_authority.rs} | 70 +++++----- ...n_max_size.rs => update_group_max_size.rs} | 121 +++++++++--------- 6 files changed, 206 insertions(+), 222 deletions(-) rename token-group/example/tests/{initialize_collection.rs => initialize_group.rs} (65%) rename token-group/example/tests/{initialize_collection_member.rs => initialize_member.rs} (78%) rename token-group/example/tests/{update_collection_authority.rs => update_group_authority.rs} (69%) rename token-group/example/tests/{update_collection_max_size.rs => update_group_max_size.rs} (65%) diff --git a/token-group/example/src/lib.rs b/token-group/example/src/lib.rs index d476bbbab83..749eb07e34a 100644 --- a/token-group/example/src/lib.rs +++ b/token-group/example/src/lib.rs @@ -1,4 +1,4 @@ -//! Crate defining an example program for creating SPL token collections +//! Crate defining an example program for creating SPL token groups //! using the SPL Token Group interface. #![deny(missing_docs)] diff --git a/token-group/example/src/processor.rs b/token-group/example/src/processor.rs index 31c9ae22e39..b0f9e8e0959 100644 --- a/token-group/example/src/processor.rs +++ b/token-group/example/src/processor.rs @@ -37,21 +37,21 @@ fn check_update_authority( } /// Processes an [InitializeGroup](enum.GroupInterfaceInstruction.html) -/// instruction for a `Collection` -pub fn process_initialize_collection( +/// instruction +pub fn process_initialize_group( _program_id: &Pubkey, accounts: &[AccountInfo], data: InitializeGroup, ) -> ProgramResult { - // Assumes one has already created a mint for the collection. + // Assumes one has already created a mint for the group. let account_info_iter = &mut accounts.iter(); // Accounts expected by this instruction: // - // 0. `[w]` Collection (Group) + // 0. `[w]` Group // 1. `[]` Mint // 2. `[s]` Mint authority - let collection_info = next_account_info(account_info_iter)?; + let group_info = next_account_info(account_info_iter)?; let mint_info = next_account_info(account_info_iter)?; let mint_authority_info = next_account_info(account_info_iter)?; @@ -71,18 +71,18 @@ pub fn process_initialize_collection( } // Allocate a TLV entry for the space and write it in - let mut buffer = collection_info.try_borrow_mut_data()?; + let mut buffer = group_info.try_borrow_mut_data()?; let mut state = TlvStateMut::unpack(&mut buffer)?; - let (collection, _) = state.init_value::(false)?; - *collection = TokenGroup::new(mint_info.key, data.update_authority, data.max_size.into()); + let (group, _) = state.init_value::(false)?; + *group = TokenGroup::new(mint_info.key, data.update_authority, data.max_size.into()); Ok(()) } /// Processes an /// [UpdateGroupMaxSize](enum.GroupInterfaceInstruction.html) -/// instruction for a `Collection` -pub fn process_update_collection_max_size( +/// instruction +pub fn process_update_group_max_size( _program_id: &Pubkey, accounts: &[AccountInfo], data: UpdateGroupMaxSize, @@ -91,27 +91,27 @@ pub fn process_update_collection_max_size( // Accounts expected by this instruction: // - // 0. `[w]` Collection (Group) + // 0. `[w]` Group // 1. `[s]` Update authority - let collection_info = next_account_info(account_info_iter)?; + let group_info = next_account_info(account_info_iter)?; let update_authority_info = next_account_info(account_info_iter)?; - let mut buffer = collection_info.try_borrow_mut_data()?; + let mut buffer = group_info.try_borrow_mut_data()?; let mut state = TlvStateMut::unpack(&mut buffer)?; - let collection = state.get_first_value_mut::()?; + let group = state.get_first_value_mut::()?; - check_update_authority(update_authority_info, &collection.update_authority)?; + check_update_authority(update_authority_info, &group.update_authority)?; // Update the max size (zero-copy) - collection.update_max_size(data.max_size.into())?; + group.update_max_size(data.max_size.into())?; Ok(()) } /// Processes an /// [UpdateGroupAuthority](enum.GroupInterfaceInstruction.html) -/// instruction for a `Collection` -pub fn process_update_collection_authority( +/// instruction +pub fn process_update_group_authority( _program_id: &Pubkey, accounts: &[AccountInfo], data: UpdateGroupAuthority, @@ -120,49 +120,46 @@ pub fn process_update_collection_authority( // Accounts expected by this instruction: // - // 0. `[w]` Collection (Group) + // 0. `[w]` Group // 1. `[s]` Current update authority - let collection_info = next_account_info(account_info_iter)?; + let group_info = next_account_info(account_info_iter)?; let update_authority_info = next_account_info(account_info_iter)?; - let mut buffer = collection_info.try_borrow_mut_data()?; + let mut buffer = group_info.try_borrow_mut_data()?; let mut state = TlvStateMut::unpack(&mut buffer)?; - let collection = state.get_first_value_mut::()?; + let group = state.get_first_value_mut::()?; - check_update_authority(update_authority_info, &collection.update_authority)?; + check_update_authority(update_authority_info, &group.update_authority)?; // Update the authority (zero-copy) - collection.update_authority = data.new_authority; + group.update_authority = data.new_authority; Ok(()) } /// Processes an [InitializeMember](enum.GroupInterfaceInstruction.html) -/// instruction for a `Collection` -pub fn process_initialize_collection_member( - _program_id: &Pubkey, - accounts: &[AccountInfo], -) -> ProgramResult { - // For this group, we are going to assume the collection has been +/// instruction +pub fn process_initialize_member(_program_id: &Pubkey, accounts: &[AccountInfo]) -> ProgramResult { + // For this group, we are going to assume the group has been // initialized, and we're also assuming a mint has been created for the // member. - // Collection members in this example can have their own separate - // metadata that differs from the metadata of the collection, since + // Group members in this example can have their own separate + // metadata that differs from the metadata of the group, since // metadata is not involved here. let account_info_iter = &mut accounts.iter(); // Accounts expected by this instruction: // - // 0. `[w]` Collection Member (Member) - // 1. `[]` Collection Member (Member) Mint - // 2. `[s]` Collection Member (Member) Mint authority - // 3. `[w]` Collection (Group) - // 4. `[s]` Collection (Group) update authority + // 0. `[w]` Member + // 1. `[]` Member Mint + // 2. `[s]` Member Mint authority + // 3. `[w]` Group + // 4. `[s]` Group update authority let member_info = next_account_info(account_info_iter)?; let member_mint_info = next_account_info(account_info_iter)?; let member_mint_authority_info = next_account_info(account_info_iter)?; - let collection_info = next_account_info(account_info_iter)?; - let collection_update_authority_info = next_account_info(account_info_iter)?; + let group_info = next_account_info(account_info_iter)?; + let group_update_authority_info = next_account_info(account_info_iter)?; // Mint checks on the member { @@ -181,22 +178,19 @@ pub fn process_initialize_collection_member( } } - // Increment the size of the collection - let mut buffer = collection_info.try_borrow_mut_data()?; + // Increment the size of the group + let mut buffer = group_info.try_borrow_mut_data()?; let mut state = TlvStateMut::unpack(&mut buffer)?; - let collection = state.get_first_value_mut::()?; + let group = state.get_first_value_mut::()?; - check_update_authority( - collection_update_authority_info, - &collection.update_authority, - )?; - let member_number = collection.increment_size()?; + check_update_authority(group_update_authority_info, &group.update_authority)?; + let member_number = group.increment_size()?; // Allocate a TLV entry for the space and write it in let mut buffer = member_info.try_borrow_mut_data()?; let mut state = TlvStateMut::unpack(&mut buffer)?; let (member, _) = state.init_value::(false)?; - *member = TokenGroupMember::new(member_mint_info.key, collection_info.key, member_number); + *member = TokenGroupMember::new(member_mint_info.key, group_info.key, member_number); Ok(()) } @@ -206,20 +200,20 @@ pub fn process(program_id: &Pubkey, accounts: &[AccountInfo], input: &[u8]) -> P let instruction = TokenGroupInstruction::unpack(input)?; match instruction { TokenGroupInstruction::InitializeGroup(data) => { - msg!("Instruction: InitializeCollection"); - process_initialize_collection(program_id, accounts, data) + msg!("Instruction: InitializeGroup"); + process_initialize_group(program_id, accounts, data) } TokenGroupInstruction::UpdateGroupMaxSize(data) => { - msg!("Instruction: UpdateCollectionMaxSize"); - process_update_collection_max_size(program_id, accounts, data) + msg!("Instruction: UpdateGroupMaxSize"); + process_update_group_max_size(program_id, accounts, data) } TokenGroupInstruction::UpdateGroupAuthority(data) => { - msg!("Instruction: UpdateCollectionAuthority"); - process_update_collection_authority(program_id, accounts, data) + msg!("Instruction: UpdateGroupAuthority"); + process_update_group_authority(program_id, accounts, data) } TokenGroupInstruction::InitializeMember(_) => { - msg!("Instruction: InitializeCollectionMember"); - process_initialize_collection_member(program_id, accounts) + msg!("Instruction: InitializeMember"); + process_initialize_member(program_id, accounts) } } } diff --git a/token-group/example/tests/initialize_collection.rs b/token-group/example/tests/initialize_group.rs similarity index 65% rename from token-group/example/tests/initialize_collection.rs rename to token-group/example/tests/initialize_group.rs index 0e4d162c7d6..585335d8f96 100644 --- a/token-group/example/tests/initialize_collection.rs +++ b/token-group/example/tests/initialize_group.rs @@ -20,15 +20,15 @@ use { }; #[tokio::test] -async fn test_initialize_collection() { +async fn test_initialize_group() { let program_id = Pubkey::new_unique(); - let collection = Keypair::new(); - let collection_mint = Keypair::new(); - let collection_mint_authority = Keypair::new(); + let group = Keypair::new(); + let group_mint = Keypair::new(); + let group_mint_authority = Keypair::new(); - let collection_group_state = TokenGroup { + let group_state = TokenGroup { update_authority: None.try_into().unwrap(), - mint: collection_mint.pubkey(), + mint: group_mint.pubkey(), size: 0.into(), max_size: 50.into(), }; @@ -38,11 +38,11 @@ async fn test_initialize_collection() { let token_client = Token::new( client, &spl_token_2022::id(), - &collection_mint.pubkey(), + &group_mint.pubkey(), Some(0), payer.clone(), ); - setup_mint(&token_client, &collection_mint, &collection_mint_authority).await; + setup_mint(&token_client, &group_mint, &group_mint_authority).await; let mut context = context.lock().await; @@ -53,18 +53,18 @@ async fn test_initialize_collection() { // Fail: mint authority not signer let mut init_group_ix = initialize_group( &program_id, - &collection.pubkey(), - &collection_mint.pubkey(), - &collection_mint_authority.pubkey(), - collection_group_state.update_authority.try_into().unwrap(), - collection_group_state.max_size.into(), + &group.pubkey(), + &group_mint.pubkey(), + &group_mint_authority.pubkey(), + group_state.update_authority.try_into().unwrap(), + group_state.max_size.into(), ); init_group_ix.accounts[2].is_signer = false; let transaction = Transaction::new_signed_with_payer( &[ system_instruction::create_account( &context.payer.pubkey(), - &collection.pubkey(), + &group.pubkey(), rent_lamports, space.try_into().unwrap(), &program_id, @@ -72,7 +72,7 @@ async fn test_initialize_collection() { init_group_ix, ], Some(&context.payer.pubkey()), - &[&context.payer, &collection], + &[&context.payer, &group], context.last_blockhash, ); assert_eq!( @@ -85,27 +85,27 @@ async fn test_initialize_collection() { TransactionError::InstructionError(1, InstructionError::MissingRequiredSignature) ); - // Success: create the collection + // Success: create the group let transaction = Transaction::new_signed_with_payer( &[ system_instruction::create_account( &context.payer.pubkey(), - &collection.pubkey(), + &group.pubkey(), rent_lamports, space.try_into().unwrap(), &program_id, ), initialize_group( &program_id, - &collection.pubkey(), - &collection_mint.pubkey(), - &collection_mint_authority.pubkey(), - collection_group_state.update_authority.try_into().unwrap(), - collection_group_state.max_size.into(), + &group.pubkey(), + &group_mint.pubkey(), + &group_mint_authority.pubkey(), + group_state.update_authority.try_into().unwrap(), + group_state.max_size.into(), ), ], Some(&context.payer.pubkey()), - &[&context.payer, &collection_mint_authority, &collection], + &[&context.payer, &group_mint_authority, &group], context.last_blockhash, ); context @@ -114,29 +114,29 @@ async fn test_initialize_collection() { .await .unwrap(); - // Fetch the collection account and ensure it matches our state - let fetched_collection_account = context + // Fetch the group account and ensure it matches our state + let fetched_group_account = context .banks_client - .get_account(collection.pubkey()) + .get_account(group.pubkey()) .await .unwrap() .unwrap(); - let fetched_meta = TlvStateBorrowed::unpack(&fetched_collection_account.data).unwrap(); - let fetched_collection_group_state = fetched_meta.get_first_value::().unwrap(); - assert_eq!(fetched_collection_group_state, &collection_group_state); + let fetched_meta = TlvStateBorrowed::unpack(&fetched_group_account.data).unwrap(); + let fetched_group_state = fetched_meta.get_first_value::().unwrap(); + assert_eq!(fetched_group_state, &group_state); // Fail: can't initialize twice let transaction = Transaction::new_signed_with_payer( &[initialize_group( &program_id, - &collection.pubkey(), - &collection_mint.pubkey(), - &collection_mint_authority.pubkey(), + &group.pubkey(), + &group_mint.pubkey(), + &group_mint_authority.pubkey(), Pubkey::new_unique().into(), // Intentionally changed - collection_group_state.max_size.into(), + group_state.max_size.into(), )], Some(&context.payer.pubkey()), - &[&context.payer, &collection_mint_authority], + &[&context.payer, &group_mint_authority], context.last_blockhash, ); assert_eq!( diff --git a/token-group/example/tests/initialize_collection_member.rs b/token-group/example/tests/initialize_member.rs similarity index 78% rename from token-group/example/tests/initialize_collection_member.rs rename to token-group/example/tests/initialize_member.rs index 89fe52a7ea5..c32a75571bd 100644 --- a/token-group/example/tests/initialize_collection_member.rs +++ b/token-group/example/tests/initialize_member.rs @@ -20,21 +20,19 @@ use { }; #[tokio::test] -async fn test_initialize_collection_member() { +async fn test_initialize_group_member() { let program_id = Pubkey::new_unique(); - let collection = Keypair::new(); - let collection_mint = Keypair::new(); - let collection_mint_authority = Keypair::new(); - let collection_update_authority = Keypair::new(); + let group = Keypair::new(); + let group_mint = Keypair::new(); + let group_mint_authority = Keypair::new(); + let group_update_authority = Keypair::new(); let member = Keypair::new(); let member_mint = Keypair::new(); let member_mint_authority = Keypair::new(); - let collection_group_state = TokenGroup { - update_authority: Some(collection_update_authority.pubkey()) - .try_into() - .unwrap(), - mint: collection_mint.pubkey(), + let group_state = TokenGroup { + update_authority: Some(group_update_authority.pubkey()).try_into().unwrap(), + mint: group_mint.pubkey(), size: 30.into(), max_size: 50.into(), }; @@ -45,12 +43,12 @@ async fn test_initialize_collection_member() { &Token::new( client.clone(), &spl_token_2022::id(), - &collection_mint.pubkey(), + &group_mint.pubkey(), Some(0), payer.clone(), ), - &collection_mint, - &collection_mint_authority, + &group_mint, + &group_mint_authority, ) .await; setup_mint( @@ -76,22 +74,22 @@ async fn test_initialize_collection_member() { &[ system_instruction::create_account( &context.payer.pubkey(), - &collection.pubkey(), + &group.pubkey(), rent_lamports, space.try_into().unwrap(), &program_id, ), initialize_group( &program_id, - &collection.pubkey(), - &collection_mint.pubkey(), - &collection_mint_authority.pubkey(), - collection_group_state.update_authority.try_into().unwrap(), - collection_group_state.max_size.into(), + &group.pubkey(), + &group_mint.pubkey(), + &group_mint_authority.pubkey(), + group_state.update_authority.try_into().unwrap(), + group_state.max_size.into(), ), ], Some(&context.payer.pubkey()), - &[&context.payer, &collection_mint_authority, &collection], + &[&context.payer, &group_mint_authority, &group], context.last_blockhash, ); context @@ -109,8 +107,8 @@ async fn test_initialize_collection_member() { &member.pubkey(), &member_mint.pubkey(), &member_mint_authority.pubkey(), - &collection.pubkey(), - &collection_update_authority.pubkey(), + &group.pubkey(), + &group_update_authority.pubkey(), ); init_member_ix.accounts[2].is_signer = false; let transaction = Transaction::new_signed_with_payer( @@ -125,7 +123,7 @@ async fn test_initialize_collection_member() { init_member_ix, ], Some(&context.payer.pubkey()), - &[&context.payer, &member, &collection_update_authority], + &[&context.payer, &member, &group_update_authority], context.last_blockhash, ); assert_eq!( @@ -144,8 +142,8 @@ async fn test_initialize_collection_member() { &member.pubkey(), &member_mint.pubkey(), &member_mint_authority.pubkey(), - &collection.pubkey(), - &collection_update_authority.pubkey(), + &group.pubkey(), + &group_update_authority.pubkey(), ); init_member_ix.accounts[4].is_signer = false; let transaction = Transaction::new_signed_with_payer( @@ -188,8 +186,8 @@ async fn test_initialize_collection_member() { &member.pubkey(), &member_mint.pubkey(), &member_mint_authority.pubkey(), - &collection.pubkey(), - &collection_update_authority.pubkey(), + &group.pubkey(), + &group_update_authority.pubkey(), ), ], Some(&context.payer.pubkey()), @@ -197,7 +195,7 @@ async fn test_initialize_collection_member() { &context.payer, &member, &member_mint_authority, - &collection_update_authority, + &group_update_authority, ], context.last_blockhash, ); @@ -215,8 +213,7 @@ async fn test_initialize_collection_member() { .unwrap() .unwrap(); let fetched_meta = TlvStateBorrowed::unpack(&member_account.data).unwrap(); - let fetched_collection_member_state = - fetched_meta.get_first_value::().unwrap(); - assert_eq!(fetched_collection_member_state.group, collection.pubkey()); - assert_eq!(u32::from(fetched_collection_member_state.member_number), 1); + let fetched_group_member_state = fetched_meta.get_first_value::().unwrap(); + assert_eq!(fetched_group_member_state.group, group.pubkey()); + assert_eq!(u32::from(fetched_group_member_state.member_number), 1); } diff --git a/token-group/example/tests/update_collection_authority.rs b/token-group/example/tests/update_group_authority.rs similarity index 69% rename from token-group/example/tests/update_collection_authority.rs rename to token-group/example/tests/update_group_authority.rs index 703c3d08878..adf2f00c209 100644 --- a/token-group/example/tests/update_collection_authority.rs +++ b/token-group/example/tests/update_group_authority.rs @@ -21,18 +21,16 @@ use { }; #[tokio::test] -async fn test_update_collection_authority() { +async fn test_update_group_authority() { let program_id = Pubkey::new_unique(); - let collection = Keypair::new(); - let collection_mint = Keypair::new(); - let collection_mint_authority = Keypair::new(); - let collection_update_authority = Keypair::new(); + let group = Keypair::new(); + let group_mint = Keypair::new(); + let group_mint_authority = Keypair::new(); + let group_update_authority = Keypair::new(); - let collection_group_state = TokenGroup { - update_authority: Some(collection_update_authority.pubkey()) - .try_into() - .unwrap(), - mint: collection_mint.pubkey(), + let group_state = TokenGroup { + update_authority: Some(group_update_authority.pubkey()).try_into().unwrap(), + mint: group_mint.pubkey(), size: 30.into(), max_size: 50.into(), }; @@ -42,11 +40,11 @@ async fn test_update_collection_authority() { let token_client = Token::new( client, &spl_token_2022::id(), - &collection_mint.pubkey(), + &group_mint.pubkey(), Some(0), payer.clone(), ); - setup_mint(&token_client, &collection_mint, &collection_mint_authority).await; + setup_mint(&token_client, &group_mint, &group_mint_authority).await; let mut context = context.lock().await; @@ -58,22 +56,22 @@ async fn test_update_collection_authority() { &[ system_instruction::create_account( &context.payer.pubkey(), - &collection.pubkey(), + &group.pubkey(), rent_lamports, space.try_into().unwrap(), &program_id, ), initialize_group( &program_id, - &collection.pubkey(), - &collection_mint.pubkey(), - &collection_mint_authority.pubkey(), - collection_group_state.update_authority.try_into().unwrap(), - collection_group_state.max_size.into(), + &group.pubkey(), + &group_mint.pubkey(), + &group_mint_authority.pubkey(), + group_state.update_authority.try_into().unwrap(), + group_state.max_size.into(), ), ], Some(&context.payer.pubkey()), - &[&context.payer, &collection_mint_authority, &collection], + &[&context.payer, &group_mint_authority, &group], context.last_blockhash, ); context @@ -85,8 +83,8 @@ async fn test_update_collection_authority() { // Fail: update authority not signer let mut update_ix = update_group_authority( &program_id, - &collection.pubkey(), - &collection_update_authority.pubkey(), + &group.pubkey(), + &group_update_authority.pubkey(), None, ); update_ix.accounts[1].is_signer = false; @@ -110,12 +108,12 @@ async fn test_update_collection_authority() { let transaction = Transaction::new_signed_with_payer( &[update_group_authority( &program_id, - &collection.pubkey(), - &collection.pubkey(), + &group.pubkey(), + &group.pubkey(), None, )], Some(&context.payer.pubkey()), - &[&context.payer, &collection], + &[&context.payer, &group], context.last_blockhash, ); assert_eq!( @@ -135,12 +133,12 @@ async fn test_update_collection_authority() { let transaction = Transaction::new_signed_with_payer( &[update_group_authority( &program_id, - &collection.pubkey(), - &collection_update_authority.pubkey(), + &group.pubkey(), + &group_update_authority.pubkey(), None, )], Some(&context.payer.pubkey()), - &[&context.payer, &collection_update_authority], + &[&context.payer, &group_update_authority], context.last_blockhash, ); context @@ -150,16 +148,16 @@ async fn test_update_collection_authority() { .unwrap(); // Fetch the account and assert the new authority - let fetched_collection_account = context + let fetched_group_account = context .banks_client - .get_account(collection.pubkey()) + .get_account(group.pubkey()) .await .unwrap() .unwrap(); - let fetched_meta = TlvStateBorrowed::unpack(&fetched_collection_account.data).unwrap(); - let fetched_collection_group_state = fetched_meta.get_first_value::().unwrap(); + let fetched_meta = TlvStateBorrowed::unpack(&fetched_group_account.data).unwrap(); + let fetched_group_state = fetched_meta.get_first_value::().unwrap(); assert_eq!( - fetched_collection_group_state.update_authority, + fetched_group_state.update_authority, None.try_into().unwrap(), ); @@ -167,12 +165,12 @@ async fn test_update_collection_authority() { let transaction = Transaction::new_signed_with_payer( &[update_group_authority( &program_id, - &collection.pubkey(), - &collection_update_authority.pubkey(), - Some(collection_update_authority.pubkey()), + &group.pubkey(), + &group_update_authority.pubkey(), + Some(group_update_authority.pubkey()), )], Some(&context.payer.pubkey()), - &[&context.payer, &collection_update_authority], + &[&context.payer, &group_update_authority], context.last_blockhash, ); assert_eq!( diff --git a/token-group/example/tests/update_collection_max_size.rs b/token-group/example/tests/update_group_max_size.rs similarity index 65% rename from token-group/example/tests/update_collection_max_size.rs rename to token-group/example/tests/update_group_max_size.rs index 96b9cfaeb80..af30d53f7a9 100644 --- a/token-group/example/tests/update_collection_max_size.rs +++ b/token-group/example/tests/update_group_max_size.rs @@ -22,18 +22,16 @@ use { }; #[tokio::test] -async fn test_update_collection_max_size() { +async fn test_update_group_max_size() { let program_id = Pubkey::new_unique(); - let collection = Keypair::new(); - let collection_mint = Keypair::new(); - let collection_mint_authority = Keypair::new(); - let collection_update_authority = Keypair::new(); + let group = Keypair::new(); + let group_mint = Keypair::new(); + let group_mint_authority = Keypair::new(); + let group_update_authority = Keypair::new(); - let collection_group_state = TokenGroup { - update_authority: Some(collection_update_authority.pubkey()) - .try_into() - .unwrap(), - mint: collection_mint.pubkey(), + let group_state = TokenGroup { + update_authority: Some(group_update_authority.pubkey()).try_into().unwrap(), + mint: group_mint.pubkey(), size: 30.into(), max_size: 50.into(), }; @@ -43,11 +41,11 @@ async fn test_update_collection_max_size() { let token_client = Token::new( client, &spl_token_2022::id(), - &collection_mint.pubkey(), + &group_mint.pubkey(), Some(0), payer.clone(), ); - setup_mint(&token_client, &collection_mint, &collection_mint_authority).await; + setup_mint(&token_client, &group_mint, &group_mint_authority).await; let mut context = context.lock().await; @@ -59,22 +57,22 @@ async fn test_update_collection_max_size() { &[ system_instruction::create_account( &context.payer.pubkey(), - &collection.pubkey(), + &group.pubkey(), rent_lamports, space.try_into().unwrap(), &program_id, ), initialize_group( &program_id, - &collection.pubkey(), - &collection_mint.pubkey(), - &collection_mint_authority.pubkey(), - collection_group_state.update_authority.try_into().unwrap(), - collection_group_state.max_size.into(), + &group.pubkey(), + &group_mint.pubkey(), + &group_mint_authority.pubkey(), + group_state.update_authority.try_into().unwrap(), + group_state.max_size.into(), ), ], Some(&context.payer.pubkey()), - &[&context.payer, &collection_mint_authority, &collection], + &[&context.payer, &group_mint_authority, &group], context.last_blockhash, ); context @@ -84,8 +82,7 @@ async fn test_update_collection_max_size() { .unwrap(); // Fail: update authority not signer - let mut update_ix = - update_group_max_size(&program_id, &collection.pubkey(), &collection.pubkey(), 100); + let mut update_ix = update_group_max_size(&program_id, &group.pubkey(), &group.pubkey(), 100); update_ix.accounts[1].is_signer = false; let transaction = Transaction::new_signed_with_payer( &[update_ix], @@ -107,12 +104,12 @@ async fn test_update_collection_max_size() { let transaction = Transaction::new_signed_with_payer( &[update_group_max_size( &program_id, - &collection.pubkey(), - &collection.pubkey(), + &group.pubkey(), + &group.pubkey(), 100, )], Some(&context.payer.pubkey()), - &[&context.payer, &collection], + &[&context.payer, &group], context.last_blockhash, ); assert_eq!( @@ -129,33 +126,33 @@ async fn test_update_collection_max_size() { ); // Fail: size exceeds new max size - let fetched_collection_account = context + let fetched_group_account = context .banks_client - .get_account(collection.pubkey()) + .get_account(group.pubkey()) .await .unwrap() .unwrap(); - let mut data = fetched_collection_account.data; + let mut data = fetched_group_account.data; let mut state = TlvStateMut::unpack(&mut data).unwrap(); - let collection_data = state.get_first_value_mut::().unwrap(); - collection_data.size = 30.into(); + let group_data = state.get_first_value_mut::().unwrap(); + group_data.size = 30.into(); context.set_account( - &collection.pubkey(), + &group.pubkey(), &SolanaAccount { data, - ..fetched_collection_account + ..fetched_group_account } .into(), ); let transaction = Transaction::new_signed_with_payer( &[update_group_max_size( &program_id, - &collection.pubkey(), - &collection_update_authority.pubkey(), + &group.pubkey(), + &group_update_authority.pubkey(), 20, )], Some(&context.payer.pubkey()), - &[&context.payer, &collection_update_authority], + &[&context.payer, &group_update_authority], context.last_blockhash, ); assert_eq!( @@ -175,12 +172,12 @@ async fn test_update_collection_max_size() { let transaction = Transaction::new_signed_with_payer( &[update_group_max_size( &program_id, - &collection.pubkey(), - &collection_update_authority.pubkey(), + &group.pubkey(), + &group_update_authority.pubkey(), 100, )], Some(&context.payer.pubkey()), - &[&context.payer, &collection_update_authority], + &[&context.payer, &group_update_authority], context.last_blockhash, ); context @@ -190,31 +187,29 @@ async fn test_update_collection_max_size() { .unwrap(); // Fetch the account and assert the new max size - let fetched_collection_account = context + let fetched_group_account = context .banks_client - .get_account(collection.pubkey()) + .get_account(group.pubkey()) .await .unwrap() .unwrap(); - let fetched_meta = TlvStateBorrowed::unpack(&fetched_collection_account.data).unwrap(); - let fetched_collection_group_state = fetched_meta.get_first_value::().unwrap(); - assert_eq!(fetched_collection_group_state.max_size, 100.into()); + let fetched_meta = TlvStateBorrowed::unpack(&fetched_group_account.data).unwrap(); + let fetched_group_state = fetched_meta.get_first_value::().unwrap(); + assert_eq!(fetched_group_state.max_size, 100.into()); } // Fail: immutable group #[tokio::test] -async fn test_update_collection_max_size_fail_immutable_group() { +async fn test_update_group_max_size_fail_immutable_group() { let program_id = Pubkey::new_unique(); - let collection = Keypair::new(); - let collection_mint = Keypair::new(); - let collection_mint_authority = Keypair::new(); - let collection_update_authority = Keypair::new(); + let group = Keypair::new(); + let group_mint = Keypair::new(); + let group_mint_authority = Keypair::new(); + let group_update_authority = Keypair::new(); - let collection_group_state = TokenGroup { - update_authority: Some(collection_update_authority.pubkey()) - .try_into() - .unwrap(), - mint: collection_mint.pubkey(), + let group_state = TokenGroup { + update_authority: Some(group_update_authority.pubkey()).try_into().unwrap(), + mint: group_mint.pubkey(), size: 30.into(), max_size: 50.into(), }; @@ -224,11 +219,11 @@ async fn test_update_collection_max_size_fail_immutable_group() { let token_client = Token::new( client, &spl_token_2022::id(), - &collection_mint.pubkey(), + &group_mint.pubkey(), Some(0), payer.clone(), ); - setup_mint(&token_client, &collection_mint, &collection_mint_authority).await; + setup_mint(&token_client, &group_mint, &group_mint_authority).await; let mut context = context.lock().await; @@ -240,22 +235,22 @@ async fn test_update_collection_max_size_fail_immutable_group() { &[ system_instruction::create_account( &context.payer.pubkey(), - &collection.pubkey(), + &group.pubkey(), rent_lamports, space.try_into().unwrap(), &program_id, ), initialize_group( &program_id, - &collection.pubkey(), - &collection_mint.pubkey(), - &collection_mint_authority.pubkey(), + &group.pubkey(), + &group_mint.pubkey(), + &group_mint_authority.pubkey(), None, - collection_group_state.max_size.into(), + group_state.max_size.into(), ), ], Some(&context.payer.pubkey()), - &[&context.payer, &collection_mint_authority, &collection], + &[&context.payer, &group_mint_authority, &group], context.last_blockhash, ); context @@ -267,12 +262,12 @@ async fn test_update_collection_max_size_fail_immutable_group() { let transaction = Transaction::new_signed_with_payer( &[update_group_max_size( &program_id, - &collection.pubkey(), - &collection_update_authority.pubkey(), + &group.pubkey(), + &group_update_authority.pubkey(), 100, )], Some(&context.payer.pubkey()), - &[&context.payer, &collection_update_authority], + &[&context.payer, &group_update_authority], context.last_blockhash, ); assert_eq!(