Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

token 2022: add a test for mint with group and member pointer #5927

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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