Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kstepanovdev committed Feb 15, 2024
1 parent cd7066f commit dca5db8
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 1 deletion.
45 changes: 44 additions & 1 deletion clients/js/test/mintV1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import {
generateSigner,
none,
publicKey,
some,
} from '@metaplex-foundation/umi';
import test from 'ava';
import { MetadataArgsArgs, fetchMerkleTree, hashLeaf, mintV1 } from '../src';
import { MetadataArgsArgs, TokenStandard, fetchMerkleTree, hashLeaf, mintV1 } from '../src';
import { createTree, createUmi } from './_setup';

test('it can mint an NFT from a Bubblegum tree', async (t) => {
Expand Down Expand Up @@ -46,3 +47,45 @@ test('it can mint an NFT from a Bubblegum tree', async (t) => {
});
t.is(merkleTreeAccount.tree.rightMostPath.leaf, publicKey(leaf));
});

test('it cannot mint an NFT from a Bubblegum tree because token standard is empty', async (t) => {
// Given an empty Bubblegum tree.
const umi = await createUmi();
const merkleTree = await createTree(umi);
const leafOwner = generateSigner(umi).publicKey;

// When we mint a new NFT from the tree using the following metadata.
const metadata: MetadataArgsArgs = {
name: 'My NFT',
uri: 'https://example.com/my-nft.json',
sellerFeeBasisPoints: 500, // 5%
collection: none(),
creators: [],
tokenStandard: none()
};
const promise = mintV1(umi, { leafOwner, merkleTree, metadata }).sendAndConfirm(umi);
// Then we expect a program error because metadata's token standard is empty.
await t.throwsAsync(promise, { name: 'InvalidTokenStandard' });
});


test('it cannot mint an NFT from a Bubblegum tree because token standard is wrong', async (t) => {
// Given an empty Bubblegum tree.
const umi = await createUmi();
const merkleTree = await createTree(umi);
const leafOwner = generateSigner(umi).publicKey;

// When we mint a new NFT from the tree using the following metadata.
const metadata: MetadataArgsArgs = {
name: 'My NFT',
uri: 'https://example.com/my-nft.json',
sellerFeeBasisPoints: 500, // 5%
collection: none(),
creators: [],
tokenStandard: some(TokenStandard.FungibleAsset)
};
const promise = mintV1(umi, { leafOwner, merkleTree, metadata }).sendAndConfirm(umi);
// Then we expect a program error because metadata's token standard is FungibleAsset which is wrong.
await t.throwsAsync(promise, { name: 'InvalidTokenStandard' });
});

90 changes: 90 additions & 0 deletions clients/rust/tests/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,94 @@ mod mint {

tree_manager.assert_root(&mut context).await;
}

#[tokio::test]
async fn mint_empty_token_standard() {
let mut program_test = create_program_test();
program_test.set_compute_max_units(400_000);
let mut context = program_test.start_with_context().await;

// Given a new merkle tree.

let mut tree_manager = TreeManager::<5, 8>::default();
tree_manager.create(&mut context).await.unwrap();

assert!(find_account(&mut context, &tree_manager.tree.pubkey())
.await
.is_some());

// When minting a new cNFT.
let owner = Keypair::new();

let metadata = MetadataArgs {
name: String::from("cNFT"),
uri: String::from("https://c.nft"),
symbol: String::from("cNFT"),
creators: vec![Creator {
address: context.payer.pubkey(),
share: 100,
verified: false,
}],
edition_nonce: None,
is_mutable: true,
primary_sale_happened: true,
seller_fee_basis_points: 500,
token_program_version: TokenProgramVersion::Original,
token_standard: None,
collection: None,
uses: None,
};

let minting_result = tree_manager
.mint(&mut context, owner.pubkey(), metadata)
.await;

// Minting must fail because the token standard hasn't been provided.
assert!(minting_result.is_err());
}

#[tokio::test]
async fn mint_wrong_token_standard() {
let mut program_test = create_program_test();
program_test.set_compute_max_units(400_000);
let mut context = program_test.start_with_context().await;

// Given a new merkle tree.

let mut tree_manager = TreeManager::<5, 8>::default();
tree_manager.create(&mut context).await.unwrap();

assert!(find_account(&mut context, &tree_manager.tree.pubkey())
.await
.is_some());

// When minting a new cNFT.
let owner = Keypair::new();

let metadata = MetadataArgs {
name: String::from("cNFT"),
uri: String::from("https://c.nft"),
symbol: String::from("cNFT"),
creators: vec![Creator {
address: context.payer.pubkey(),
share: 100,
verified: false,
}],
edition_nonce: None,
is_mutable: true,
primary_sale_happened: true,
seller_fee_basis_points: 500,
token_program_version: TokenProgramVersion::Original,
token_standard: Some(TokenStandard::FungibleAsset),
collection: None,
uses: None,
};

let minting_result = tree_manager
.mint(&mut context, owner.pubkey(), metadata)
.await;

// Minting must fail because the provided token standard is Fungible.
assert!(minting_result.is_err());
}
}

0 comments on commit dca5db8

Please sign in to comment.