Skip to content

Commit

Permalink
cut metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Oct 18, 2023
1 parent fc35055 commit 773d3a3
Showing 5 changed files with 25 additions and 142 deletions.
25 changes: 2 additions & 23 deletions token-group/example/tests/initialize_collection.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
mod setup;

use {
setup::{setup_mint_and_metadata, setup_program_test},
setup::{setup_mint, setup_program_test},
solana_program::{instruction::InstructionError, pubkey::Pubkey, system_instruction},
solana_program_test::tokio,
solana_sdk::{
@@ -13,7 +13,6 @@ use {
},
spl_token_client::token::Token,
spl_token_group_interface::{instruction::initialize_group, state::Group},
spl_token_metadata_interface::state::TokenMetadata,
spl_type_length_value::{
error::TlvError,
state::{TlvState, TlvStateBorrowed},
@@ -26,17 +25,7 @@ async fn test_initialize_collection() {
let collection = Keypair::new();
let collection_mint = Keypair::new();
let collection_mint_authority = Keypair::new();
let collection_metadata = Keypair::new();
let collection_metadata_update_authority = Keypair::new();

let collection_metadata_state = TokenMetadata {
update_authority: None.try_into().unwrap(),
mint: collection_mint.pubkey(),
name: "The Coolest Collection".to_string(),
symbol: "COOL".to_string(),
uri: "https://cool.com".to_string(),
additional_metadata: vec![],
};
let collection_group_state = Group {
update_authority: None.try_into().unwrap(),
size: 0.into(),
@@ -52,17 +41,7 @@ async fn test_initialize_collection() {
Some(0),
payer.clone(),
);

setup_mint_and_metadata(
&token_client,
&collection_mint,
&collection_mint_authority,
&collection_metadata.pubkey(),
&collection_metadata_update_authority.pubkey(),
&collection_metadata_state,
payer,
)
.await;
setup_mint(&token_client, &collection_mint, &collection_mint_authority).await;

let mut context = context.lock().await;

43 changes: 13 additions & 30 deletions token-group/example/tests/initialize_collection_member.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
mod setup;

use {
setup::{setup_mint_and_metadata, setup_program_test},
setup::{setup_mint, setup_program_test},
solana_program::{instruction::InstructionError, pubkey::Pubkey, system_instruction},
solana_program_test::tokio,
solana_sdk::{
@@ -16,7 +16,6 @@ use {
instruction::{initialize_group, initialize_member},
state::{Group, Member},
},
spl_token_metadata_interface::state::TokenMetadata,
spl_type_length_value::state::{TlvState, TlvStateBorrowed},
};

@@ -26,20 +25,11 @@ async fn test_initialize_collection_member() {
let collection = Keypair::new();
let collection_mint = Keypair::new();
let collection_mint_authority = Keypair::new();
let collection_metadata = Keypair::new();
let collection_update_authority = Keypair::new();
let member = Keypair::new();
let member_mint = Keypair::new();
let member_mint_authority = Keypair::new();

let collection_metadata_state = TokenMetadata {
update_authority: None.try_into().unwrap(),
mint: collection_mint.pubkey(),
name: "The Coolest Collection".to_string(),
symbol: "COOL".to_string(),
uri: "https://cool.com".to_string(),
additional_metadata: vec![],
};
let collection_group_state = Group {
update_authority: Some(collection_update_authority.pubkey())
.try_into()
@@ -50,7 +40,7 @@ async fn test_initialize_collection_member() {

let (context, client, payer) = setup_program_test(&program_id).await;

setup_mint_and_metadata(
setup_mint(
&Token::new(
client.clone(),
&spl_token_2022::id(),
@@ -60,27 +50,20 @@ async fn test_initialize_collection_member() {
),
&collection_mint,
&collection_mint_authority,
&collection_metadata.pubkey(),
&collection_update_authority.pubkey(),
&collection_metadata_state,
payer.clone(),
)
.await;
Token::new(
client,
&spl_token_2022::id(),
&member_mint.pubkey(),
Some(0),
payer.clone(),
)
.create_mint(
&member_mint_authority.pubkey(),
None,
vec![],
&[&member_mint],
setup_mint(
&Token::new(
client.clone(),
&spl_token_2022::id(),
&member_mint.pubkey(),
Some(0),
payer.clone(),
),
&member_mint,
&member_mint_authority,
)
.await
.unwrap();
.await;

let mut context = context.lock().await;

28 changes: 4 additions & 24 deletions token-group/example/tests/setup.rs
Original file line number Diff line number Diff line change
@@ -8,9 +8,8 @@ use {
ProgramBanksClient, ProgramBanksClientProcessTransaction, ProgramClient,
SendTransaction, SimulateTransaction,
},
token::{ExtensionInitializationParams, Token},
token::Token,
},
spl_token_metadata_interface::state::TokenMetadata,
std::sync::Arc,
};

@@ -44,38 +43,19 @@ pub async fn setup_program_test(
(context, client, payer)
}

/// Set up a Token-2022 mint and metadata
pub async fn setup_mint_and_metadata<T: SendTransaction + SimulateTransaction>(
/// Set up a Token-2022 mint
pub async fn setup_mint<T: SendTransaction + SimulateTransaction>(
token_client: &Token<T>,
mint_keypair: &Keypair,
mint_authority_keypair: &Keypair,
metadata_pubkey: &Pubkey,
metadata_update_authority_pubkey: &Pubkey,
token_metadata: &TokenMetadata,
payer: Arc<Keypair>,
) {
token_client
.create_mint(
&mint_authority_keypair.pubkey(),
None,
vec![ExtensionInitializationParams::MetadataPointer {
authority: Some(*metadata_update_authority_pubkey),
metadata_address: Some(*metadata_pubkey),
}],
vec![],
&[mint_keypair],
)
.await
.unwrap();
token_client
.token_metadata_initialize_with_rent_transfer(
&payer.pubkey(),
metadata_update_authority_pubkey,
&mint_authority_keypair.pubkey(),
token_metadata.name.clone(),
token_metadata.symbol.clone(),
token_metadata.uri.clone(),
&[&payer, mint_authority_keypair],
)
.await
.unwrap();
}
24 changes: 2 additions & 22 deletions token-group/example/tests/update_collection_authority.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
mod setup;

use {
setup::{setup_mint_and_metadata, setup_program_test},
setup::{setup_mint, setup_program_test},
solana_program::{instruction::InstructionError, pubkey::Pubkey, system_instruction},
solana_program_test::tokio,
solana_sdk::{
@@ -17,7 +17,6 @@ use {
instruction::{initialize_group, update_group_authority},
state::Group,
},
spl_token_metadata_interface::state::TokenMetadata,
spl_type_length_value::state::{TlvState, TlvStateBorrowed},
};

@@ -27,17 +26,8 @@ async fn test_update_collection_authority() {
let collection = Keypair::new();
let collection_mint = Keypair::new();
let collection_mint_authority = Keypair::new();
let collection_metadata = Keypair::new();
let collection_update_authority = Keypair::new();

let collection_metadata_state = TokenMetadata {
update_authority: None.try_into().unwrap(),
mint: collection_mint.pubkey(),
name: "The Coolest Collection".to_string(),
symbol: "COOL".to_string(),
uri: "https://cool.com".to_string(),
additional_metadata: vec![],
};
let collection_group_state = Group {
update_authority: Some(collection_update_authority.pubkey())
.try_into()
@@ -55,17 +45,7 @@ async fn test_update_collection_authority() {
Some(0),
payer.clone(),
);

setup_mint_and_metadata(
&token_client,
&collection_mint,
&collection_mint_authority,
&collection_metadata.pubkey(),
&collection_update_authority.pubkey(),
&collection_metadata_state,
payer,
)
.await;
setup_mint(&token_client, &collection_mint, &collection_mint_authority).await;

let mut context = context.lock().await;

47 changes: 4 additions & 43 deletions token-group/example/tests/update_collection_max_size.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
mod setup;

use {
setup::{setup_mint_and_metadata, setup_program_test},
setup::{setup_mint, setup_program_test},
solana_program::{instruction::InstructionError, pubkey::Pubkey, system_instruction},
solana_program_test::tokio,
solana_sdk::{
@@ -18,7 +18,6 @@ use {
instruction::{initialize_group, update_group_max_size},
state::Group,
},
spl_token_metadata_interface::state::TokenMetadata,
spl_type_length_value::state::{TlvState, TlvStateBorrowed, TlvStateMut},
};

@@ -28,17 +27,8 @@ async fn test_update_collection_max_size() {
let collection = Keypair::new();
let collection_mint = Keypair::new();
let collection_mint_authority = Keypair::new();
let collection_metadata = Keypair::new();
let collection_update_authority = Keypair::new();

let collection_metadata_state = TokenMetadata {
update_authority: None.try_into().unwrap(),
mint: collection_mint.pubkey(),
name: "The Coolest Collection".to_string(),
symbol: "COOL".to_string(),
uri: "https://cool.com".to_string(),
additional_metadata: vec![],
};
let collection_group_state = Group {
update_authority: Some(collection_update_authority.pubkey())
.try_into()
@@ -56,17 +46,7 @@ async fn test_update_collection_max_size() {
Some(0),
payer.clone(),
);

setup_mint_and_metadata(
&token_client,
&collection_mint,
&collection_mint_authority,
&collection_metadata.pubkey(),
&collection_update_authority.pubkey(),
&collection_metadata_state,
payer,
)
.await;
setup_mint(&token_client, &collection_mint, &collection_mint_authority).await;

let mut context = context.lock().await;

@@ -227,17 +207,8 @@ async fn test_update_collection_max_size_fail_immutable_group() {
let collection = Keypair::new();
let collection_mint = Keypair::new();
let collection_mint_authority = Keypair::new();
let collection_metadata = Keypair::new();
let collection_update_authority = Keypair::new();

let collection_metadata_state = TokenMetadata {
update_authority: None.try_into().unwrap(),
mint: collection_mint.pubkey(),
name: "The Coolest Collection".to_string(),
symbol: "COOL".to_string(),
uri: "https://cool.com".to_string(),
additional_metadata: vec![],
};
let collection_group_state = Group {
update_authority: Some(collection_update_authority.pubkey())
.try_into()
@@ -255,17 +226,7 @@ async fn test_update_collection_max_size_fail_immutable_group() {
Some(0),
payer.clone(),
);

setup_mint_and_metadata(
&token_client,
&collection_mint,
&collection_mint_authority,
&collection_metadata.pubkey(),
&collection_update_authority.pubkey(),
&collection_metadata_state,
payer,
)
.await;
setup_mint(&token_client, &collection_mint, &collection_mint_authority).await;

let mut context = context.lock().await;

@@ -287,7 +248,7 @@ async fn test_update_collection_max_size_fail_immutable_group() {
&collection.pubkey(),
&collection_mint.pubkey(),
&collection_mint_authority.pubkey(),
None.try_into().unwrap(),
None,
collection_group_state.max_size.into(),
),
],

0 comments on commit 773d3a3

Please sign in to comment.