diff --git a/examples/non-fungible-token/nft/src/lib.rs b/examples/non-fungible-token/nft/src/lib.rs index 14de726b4..d929e8aa2 100644 --- a/examples/non-fungible-token/nft/src/lib.rs +++ b/examples/non-fungible-token/nft/src/lib.rs @@ -360,6 +360,84 @@ mod tests { } } + #[test] + fn test_transfer_payout() { + let mut context = get_context(accounts(0)); + testing_env!(context.build()); + let mut contract = Contract::new_default_meta(accounts(0).into()); + + testing_env!(context + .storage_usage(env::storage_usage()) + .attached_deposit(MINT_STORAGE_COST) + .predecessor_account_id(accounts(0)) + .build()); + let token_id = "0".to_string(); + contract.nft_mint(token_id.clone(), accounts(0), sample_token_metadata()); + + testing_env!(context + .storage_usage(env::storage_usage()) + .attached_deposit(1) + .predecessor_account_id(accounts(0)) + .build()); + + let payout = contract.nft_transfer_payout( + accounts(1), + token_id.clone(), + None, + None, + U128::from(1), + None, + ); + + let mut expected_payout = HashMap::new(); + expected_payout.insert(accounts(0), U128::from(1)); + + assert_eq!(payout.payout, expected_payout); + + testing_env!(context + .storage_usage(env::storage_usage()) + .account_balance(env::account_balance()) + .is_view(true) + .attached_deposit(0) + .build()); + + if let Some(token) = contract.nft_token(token_id.clone()) { + assert_eq!(token.token_id, token_id); + assert_eq!(token.owner_id, accounts(1)); + assert_eq!(token.metadata.unwrap(), sample_token_metadata()); + assert_eq!(token.approved_account_ids.unwrap(), HashMap::new()); + } else { + panic!("token not correctly created, or not found by nft_token"); + } + } + + #[test] + fn test_payout() { + let mut context = get_context(accounts(0)); + testing_env!(context.build()); + let mut contract = Contract::new_default_meta(accounts(0).into()); + + testing_env!(context + .storage_usage(env::storage_usage()) + .attached_deposit(MINT_STORAGE_COST) + .predecessor_account_id(accounts(0)) + .build()); + let token_id = "0".to_string(); + contract.nft_mint(token_id.clone(), accounts(0), sample_token_metadata()); + + testing_env!(context + .storage_usage(env::storage_usage()) + .predecessor_account_id(accounts(0)) + .build()); + + let payout = contract.nft_payout(token_id, U128::from(1), None); + + let mut expected_payout = HashMap::new(); + expected_payout.insert(accounts(0), U128::from(1)); + + assert_eq!(payout.payout, expected_payout); + } + #[test] fn test_approve() { let mut context = get_context(accounts(0));