mod common;
use anyhow::Result;
use common::{
assert_success, decode_onchain_metadata, mint_test_nft, parse_mint_from_output,
strip_debug_quotes, TestContext,
};
fn mint_collection_nft(ctx: &TestContext, temp_dir: &std::path::Path) -> Result<String> {
let nft_json = temp_dir.join("collection_nft.json");
ctx.create_test_nft_json(&nft_json)?;
let nft_json_str = nft_json.to_string_lossy().to_string();
let output = ctx.run_metaboss(&[
"mint",
"one",
"-d",
&nft_json_str,
"-k",
&ctx.keypair_path,
"--sized",
"--max-editions",
"0",
]);
assert_success(&output);
let raw_mint = parse_mint_from_output(&output.stdout);
Ok(strip_debug_quotes(&raw_mint))
}
#[test]
#[ignore = "requires solana-test-validator (run with --ignored)"]
fn test_collections_set_and_verify() -> Result<()> {
let mut ctx = TestContext::new()?;
let temp_dir = ctx.create_temp_dir("set-and-verify");
let collection_mint = mint_collection_nft(&ctx, &temp_dir)?;
let child_mint = mint_test_nft(&ctx, &temp_dir)?;
let metadata = decode_onchain_metadata(&ctx, &child_mint)?;
assert!(
metadata.collection.is_none(),
"child NFT should have no collection before set-and-verify"
);
let output = ctx.run_metaboss(&[
"collections",
"set-and-verify",
"-k",
&ctx.keypair_path,
"--collection-mint",
&collection_mint,
"--nft-mint",
&child_mint,
]);
assert_success(&output);
let metadata = decode_onchain_metadata(&ctx, &child_mint)?;
let collection = metadata
.collection
.expect("child NFT should have a collection after set-and-verify");
assert_eq!(
collection.key.to_string(),
collection_mint,
"collection key should match the collection mint"
);
assert!(
collection.verified,
"collection should be verified after set-and-verify"
);
Ok(())
}
#[test]
#[ignore = "requires solana-test-validator (run with --ignored)"]
fn test_collections_verify_and_unverify() -> Result<()> {
let mut ctx = TestContext::new()?;
let temp_dir = ctx.create_temp_dir("verify-unverify");
let collection_mint = mint_collection_nft(&ctx, &temp_dir)?;
let child_mint = mint_test_nft(&ctx, &temp_dir)?;
let output = ctx.run_metaboss(&[
"collections",
"set-and-verify",
"-k",
&ctx.keypair_path,
"--collection-mint",
&collection_mint,
"--nft-mint",
&child_mint,
]);
assert_success(&output);
let metadata = decode_onchain_metadata(&ctx, &child_mint)?;
let collection = metadata
.collection
.expect("child should have collection after set-and-verify");
assert!(
collection.verified,
"collection should be verified initially"
);
let output = ctx.run_metaboss(&[
"collections",
"unverify",
"-k",
&ctx.keypair_path,
"--collection-mint",
&collection_mint,
"--nft-mint",
&child_mint,
]);
assert_success(&output);
let metadata = decode_onchain_metadata(&ctx, &child_mint)?;
let collection = metadata
.collection
.expect("child should still have collection after unverify");
assert_eq!(
collection.key.to_string(),
collection_mint,
"collection key should still match after unverify"
);
assert!(
!collection.verified,
"collection should be unverified after unverify"
);
let output = ctx.run_metaboss(&[
"collections",
"verify",
"-k",
&ctx.keypair_path,
"--collection-mint",
&collection_mint,
"--nft-mint",
&child_mint,
]);
assert_success(&output);
let metadata = decode_onchain_metadata(&ctx, &child_mint)?;
let collection = metadata
.collection
.expect("child should still have collection after re-verify");
assert!(
collection.verified,
"collection should be verified after re-verify"
);
Ok(())
}
#[test]
#[ignore = "requires solana-test-validator (run with --ignored)"]
fn test_collections_set_size() -> Result<()> {
let mut ctx = TestContext::new()?;
let temp_dir = ctx.create_temp_dir("set-size");
let nft_json = temp_dir.join("collection_nft.json");
ctx.create_test_nft_json(&nft_json)?;
let nft_json_str = nft_json.to_string_lossy().to_string();
let output = ctx.run_metaboss(&[
"mint",
"one",
"-d",
&nft_json_str,
"-k",
&ctx.keypair_path,
"--max-editions",
"0",
]);
assert_success(&output);
let collection_mint = strip_debug_quotes(&parse_mint_from_output(&output.stdout));
let metadata = decode_onchain_metadata(&ctx, &collection_mint)?;
assert!(
metadata.collection_details.is_none(),
"unsized collection should have no collection_details"
);
let output = ctx.run_metaboss(&[
"collections",
"set-size",
"-k",
&ctx.keypair_path,
"--collection-mint",
&collection_mint,
"--size",
"100",
]);
assert_success(&output);
let metadata = decode_onchain_metadata(&ctx, &collection_mint)?;
match &metadata.collection_details {
Some(mpl_token_metadata::types::CollectionDetails::V1 { size }) => {
assert_eq!(*size, 100, "collection size should be 100 after set-size");
}
other => {
panic!(
"expected CollectionDetails::V1 with size 100, got {:?}",
other
);
}
}
Ok(())
}