-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
88 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod test_approval; | ||
mod test_core; | ||
mod test_enumeration; | ||
mod test_payout; | ||
mod utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
examples/non-fungible-token/tests/workspaces/test_payout.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use crate::utils::{init, TOKEN_ID}; | ||
use near_contract_standards::non_fungible_token::Token; | ||
use near_sdk::json_types::U128; | ||
use near_sdk::ONE_YOCTO; | ||
|
||
#[tokio::test] | ||
async fn simulate_payout() -> anyhow::Result<()> { | ||
let worker = workspaces::sandbox().await?; | ||
let (nft_contract, alice, _, _) = init(&worker).await?; | ||
|
||
let res = nft_contract | ||
.call("nft_payout") | ||
.args_json((TOKEN_ID, U128::from(1), Option::<u32>::None)) | ||
.max_gas() | ||
.transact() | ||
.await?; | ||
assert!(res.is_success()); | ||
|
||
// A single NFT transfer event should have been logged: | ||
assert_eq!(res.logs().len(), 0); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn nft_transfer_payout() -> anyhow::Result<()> { | ||
let worker = workspaces::sandbox().await?; | ||
let (nft_contract, alice, _, _) = init(&worker).await?; | ||
|
||
let token = | ||
nft_contract.call("nft_token").args_json((TOKEN_ID,)).view().await?.json::<Token>()?; | ||
assert_eq!(token.owner_id.to_string(), nft_contract.id().to_string()); | ||
|
||
let res = nft_contract | ||
.call("nft_transfer_payout") | ||
.args_json(( | ||
alice.id(), | ||
TOKEN_ID, | ||
Option::<u64>::None, | ||
Some("simple transfer".to_string()), | ||
U128::from(1), | ||
Option::<u32>::None, | ||
)) | ||
.max_gas() | ||
.deposit(ONE_YOCTO) | ||
.transact() | ||
.await?; | ||
|
||
assert!(res.is_success()); | ||
|
||
// A single NFT transfer event should have been logged: | ||
assert_eq!(res.logs().len(), 1); | ||
|
||
let token = | ||
nft_contract.call("nft_token").args_json((TOKEN_ID,)).view().await?.json::<Token>()?; | ||
assert_eq!(token.owner_id.to_string(), alice.id().to_string()); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters