Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ruseinov committed Sep 26, 2023
1 parent 562b284 commit 933c029
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions examples/non-fungible-token/nft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 933c029

Please sign in to comment.