Skip to content

Commit

Permalink
Implement mint fee collection deduct correctly from protocol and coll…
Browse files Browse the repository at this point in the history
…ection owner
  • Loading branch information
justinphamnz committed Oct 28, 2023
1 parent c7f00be commit 2fa8e65
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions pallets/nft/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,3 +1090,43 @@ fn pre_signed_mint_should_work_with_only_account() {
assert_eq!(OrmlNft::tokens_by_owner((account(2), 0, 0)), ());
})
}

#[test]
fn pre_signed_mint_should_collect_fee_with_mint_price() {
ExtBuilder::default().build().execute_with(|| {
let alice = account(1);
let user_1_pair = sp_core::sr25519::Pair::from_string("//Alice", None).unwrap();
let user_1_signer = MultiSigner::Sr25519(user_1_pair.public());
let user_1 = user_1_signer.clone().into_account();
let mint_data: PreSignedMint<ClassId, TokenId, AccountId, Balance> = PreSignedMint {
class_id: 0,
attributes: test_attributes(1),
metadata: vec![],
only_account: None,
mint_price: Some(50),
token_id: None,
};
let message = Encode::encode(&mint_data);
let signature = MultiSignature::Sr25519(user_1_pair.sign(&message));
assert_ok!(Balances::transfer(
RuntimeOrigin::signed(alice.clone()),
user_1.clone(),
100
));
assert_eq!(Balances::free_balance(user_1.clone()), 100);
assert_eq!(Balances::free_balance(alice.clone()), 99900);

init_test_nft(RuntimeOrigin::signed(user_1.clone()));
assert_eq!(Balances::free_balance(user_1.clone()), 96); // Deduct fee

assert_ok!(Nft::mint_pre_signed(
RuntimeOrigin::signed(alice.clone()),
Box::new(mint_data.clone()),
signature.clone(),
user_1.clone(),
));
assert_eq!(Balances::free_balance(user_1.clone()), 146); // Get 50 mint fees from NFT
assert_eq!(Balances::free_balance(alice.clone()), 99849); // Pay 1 mint fee for protocol and 50 mint price = 99900 - 51
assert_eq!(OrmlNft::tokens_by_owner((account(2), 0, 0)), ());
})
}

0 comments on commit 2fa8e65

Please sign in to comment.