Skip to content

Commit

Permalink
token 2022: add a test for mint with group and member pointer
Browse files Browse the repository at this point in the history
This PR adds a test to ensure a mint can successfully be initialized with _both_
a `GroupPointer` and a `GroupMemberPointer`.

A mint may be both a member of a group, but also a group itself (or sub-group).
  • Loading branch information
Joe C authored Nov 29, 2023
1 parent 3c82062 commit 8c0270f
Showing 1 changed file with 58 additions and 13 deletions.
71 changes: 58 additions & 13 deletions token/program-2022-test/tests/group_member_pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use {
},
spl_token_2022::{
error::TokenError,
extension::{group_member_pointer::GroupMemberPointer, BaseStateWithExtensions},
extension::{
group_member_pointer::GroupMemberPointer, group_pointer::GroupPointer,
BaseStateWithExtensions,
},
instruction,
processor::Processor,
},
Expand All @@ -29,7 +32,12 @@ fn setup_program_test() -> ProgramTest {
program_test
}

async fn setup(mint: Keypair, member_address: &Pubkey, authority: &Pubkey) -> TestContext {
async fn setup(
mint: Keypair,
member_address: &Pubkey,
authority: &Pubkey,
maybe_group_address: Option<Pubkey>,
) -> TestContext {
let program_test = setup_program_test();

let context = program_test.start_with_context().await;
Expand All @@ -38,15 +46,18 @@ async fn setup(mint: Keypair, member_address: &Pubkey, authority: &Pubkey) -> Te
context,
token_context: None,
};
let mut extension_init_params = vec![ExtensionInitializationParams::GroupMemberPointer {
authority: Some(*authority),
member_address: Some(*member_address),
}];
if let Some(group_address) = maybe_group_address {
extension_init_params.push(ExtensionInitializationParams::GroupPointer {
authority: Some(*authority),
group_address: Some(group_address),
});
}
context
.init_token_with_mint_keypair_and_freeze_authority(
mint,
vec![ExtensionInitializationParams::GroupMemberPointer {
authority: Some(*authority),
member_address: Some(*member_address),
}],
None,
)
.init_token_with_mint_keypair_and_freeze_authority(mint, extension_init_params, None)
.await
.unwrap();
context
Expand All @@ -57,7 +68,7 @@ async fn success_init() {
let authority = Pubkey::new_unique();
let member_address = Pubkey::new_unique();
let mint_keypair = Keypair::new();
let token = setup(mint_keypair, &member_address, &authority)
let token = setup(mint_keypair, &member_address, &authority, None)
.await
.token_context
.take()
Expand All @@ -74,6 +85,40 @@ async fn success_init() {
);
}

#[tokio::test]
async fn success_init_with_group() {
let authority = Pubkey::new_unique();
let group_address = Pubkey::new_unique();
let member_address = Pubkey::new_unique();
let mint_keypair = Keypair::new();
let token = setup(
mint_keypair,
&member_address,
&authority,
Some(group_address),
)
.await
.token_context
.take()
.unwrap()
.token;

let state = token.get_mint_info().await.unwrap();
assert!(state.base.is_initialized);
let extension = state.get_extension::<GroupMemberPointer>().unwrap();
assert_eq!(extension.authority, Some(authority).try_into().unwrap());
assert_eq!(
extension.member_address,
Some(member_address).try_into().unwrap()
);
let extension = state.get_extension::<GroupPointer>().unwrap();
assert_eq!(extension.authority, Some(authority).try_into().unwrap());
assert_eq!(
extension.group_address,
Some(group_address).try_into().unwrap()
);
}

#[tokio::test]
async fn fail_init_all_none() {
let mut program_test = ProgramTest::default();
Expand Down Expand Up @@ -112,7 +157,7 @@ async fn set_authority() {
let authority = Keypair::new();
let member_address = Pubkey::new_unique();
let mint_keypair = Keypair::new();
let token = setup(mint_keypair, &member_address, &authority.pubkey())
let token = setup(mint_keypair, &member_address, &authority.pubkey(), None)
.await
.token_context
.take()
Expand Down Expand Up @@ -202,7 +247,7 @@ async fn update_member_address() {
let authority = Keypair::new();
let member_address = Pubkey::new_unique();
let mint_keypair = Keypair::new();
let token = setup(mint_keypair, &member_address, &authority.pubkey())
let token = setup(mint_keypair, &member_address, &authority.pubkey(), None)
.await
.token_context
.take()
Expand Down

0 comments on commit 8c0270f

Please sign in to comment.