diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml new file mode 100644 index 00000000..c9d779b8 --- /dev/null +++ b/integration-tests/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "non-fungible-token-integration-tests" +version = "1.0.0" +publish = false +edition = "2018" + +[dev-dependencies] +near-sdk = "5.5.0" +anyhow = "1.0" +tokio = { version = "1.18.1", features = ["full"] } +near-workspaces = "0.14" +serde_json = "1.0.128" + +[[example]] +name = "integration-tests" +path = "src/tests.rs" + diff --git a/integration-tests/rs/Cargo.toml b/integration-tests/rs/Cargo.toml deleted file mode 100644 index abe55819..00000000 --- a/integration-tests/rs/Cargo.toml +++ /dev/null @@ -1,23 +0,0 @@ -[package] -name = "non-fungible-token-integration-tests" -version = "1.0.0" -publish = false -edition = "2018" - -[dev-dependencies] -near-sdk = "4.1.1" -anyhow = "1.0" -borsh = "0.9" -maplit = "1.0" -near-units = "0.2.0" -# arbitrary_precision enabled for u128 types that workspaces requires for Balance types -serde_json = { version = "1.0", features = ["arbitrary_precision"] } -tokio = { version = "1.18.1", features = ["full"] } -tracing = "0.1" -tracing-subscriber = { version = "0.3.11", features = ["env-filter"] } -workspaces = "0.7.0" -pkg-config = "0.3.1" - -[[example]] -name = "integration-tests" -path = "src/tests.rs" diff --git a/integration-tests/rs/src/tests.rs b/integration-tests/src/tests.rs similarity index 90% rename from integration-tests/rs/src/tests.rs rename to integration-tests/src/tests.rs index 832148fc..3df30049 100644 --- a/integration-tests/rs/src/tests.rs +++ b/integration-tests/src/tests.rs @@ -1,16 +1,16 @@ -use near_units::{parse_gas, parse_near}; use serde_json::json; -use workspaces::prelude::*; -use workspaces::{network::Sandbox, Account, Contract, Worker}; +use near_workspaces::{Account, Contract, types::NearToken}; const NFT_WASM_FILEPATH: &str = "../../res/non_fungible_token.wasm"; const TR_WASM_FILEPATH: &str = "../../res/token_receiver.wasm"; const AR_WASM_FILEPATH: &str = "../../res/approval_receiver.wasm"; +const ONE_YOCTO: NearToken = NearToken::from_yoctonear(1); + #[tokio::main] async fn main() -> anyhow::Result<()> { // initiate environemnt - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; // deploy contracts let nft_wasm = std::fs::read(NFT_WASM_FILEPATH)?; @@ -24,27 +24,27 @@ async fn main() -> anyhow::Result<()> { let owner = worker.root_account().unwrap(); let alice = owner .create_subaccount("alice") - .initial_balance(parse_near!("30 N")) + .initial_balance(NearToken::from_near(30)) .transact() .await? .into_result()?; // Initialize contracts - nft_contract + let _ = nft_contract .call("new_default_meta") .args_json(serde_json::json!({ "owner_id": owner.id() })) .transact() .await?; - tr_contract + let _ = tr_contract .call("new") .args_json(serde_json::json!({ "non_fungible_token_account_id": nft_contract.id() })) .transact() .await?; - ar_contract + let _ = ar_contract .call("new") .args_json(serde_json::json!({ "non_fungible_token_account_id": nft_contract.id() @@ -76,7 +76,7 @@ async fn test_simple_approve( user: &Account, nft_contract: &Contract ) -> anyhow::Result<()> { - owner + let _ = owner .call(nft_contract.id(), "nft_mint") .args_json(json!({ "token_id": "0", @@ -87,18 +87,18 @@ async fn test_simple_approve( "copies": 10000, } })) - .deposit(parse_gas!("5950000000000000000000")) + .deposit(NearToken::from_yoctonear(5950000000000000000000)) .transact() .await; // root approves alice - owner + let _ = owner .call(nft_contract.id(), "nft_approve") .args_json(json!({ "token_id": "0", "account_id": user.id(), })) - .deposit(parse_gas!("5950000000000000000000")) + .deposit(NearToken::from_yoctonear(5950000000000000000000)) .transact() .await; @@ -148,7 +148,7 @@ async fn test_approval_simple_call( nft_contract: &Contract, approval_receiver: &Contract ) -> anyhow::Result<()> { - owner + let _ = owner .call(nft_contract.id(), "nft_mint") .args_json(json!({ "token_id": "1", @@ -159,7 +159,7 @@ async fn test_approval_simple_call( "copies": 1, } })) - .deposit(parse_gas!("5950000000000000000000")) + .deposit(NearToken::from_yoctonear(5950000000000000000000)) .transact() .await; @@ -170,8 +170,8 @@ async fn test_approval_simple_call( "account_id": approval_receiver.id(), "msg": "return-now" })) - .gas(parse_gas!("150 Tgas") as u64) - .deposit(parse_gas!("450000000000000000000")) + .max_gas() + .deposit(NearToken::from_yoctonear(450000000000000000000)) .transact() .await? .json()?; @@ -183,10 +183,10 @@ async fn test_approval_simple_call( .args_json(json!({ "token_id": "1", "account_id": approval_receiver.id(), - "msg": msg.clone(), + "msg": msg, })) - .gas(parse_gas!("150 Tgas") as u64) - .deposit(parse_gas!("450000000000000000000")) + .max_gas() + .deposit(NearToken::from_yoctonear(450000000000000000000)) .transact() .await? .json()?; @@ -202,7 +202,7 @@ async fn test_approved_account_transfers_token( nft_contract: &Contract ) -> anyhow::Result<()> { use serde_json::Value::String; - owner + let _ = owner .call(nft_contract.id(), "nft_transfer") .args_json(json!({ "receiver_id": user.id(), @@ -210,7 +210,7 @@ async fn test_approved_account_transfers_token( "approval_id": 1, "memo": "message for test 3", })) - .deposit(1) + .deposit(NearToken::from_yoctonear(1)) .transact() .await; @@ -232,37 +232,37 @@ async fn test_revoke( nft_contract: &Contract, token_receiver: &Contract ) -> anyhow::Result<()> { - owner + let _ = owner .call(nft_contract.id(), "nft_approve") .args_json(json!({ "token_id": "1", "account_id": user.id(), })) - .gas(parse_gas!("150 Tgas") as u64) - .deposit(parse_gas!("450000000000000000000")) + .max_gas() + .deposit(NearToken::from_yoctonear(450000000000000000000)) .transact() .await; // root approves token_receiver - owner + let _ = owner .call(nft_contract.id(), "nft_approve") .args_json(json!({ "token_id": "1", "account_id": token_receiver.id(), })) - .gas(parse_gas!("150 Tgas") as u64) - .deposit(parse_gas!("450000000000000000000")) + .max_gas() + .deposit(NearToken::from_yoctonear(450000000000000000000)) .transact() .await; // root revokes user - owner + let _ = owner .call(nft_contract.id(), "nft_revoke") .args_json(json!({ "token_id": "1", "account_id": user.id(), })) - .deposit(1) + .deposit(ONE_YOCTO) .transact() .await; @@ -291,13 +291,13 @@ async fn test_revoke( assert_eq!(revoke_bool, true); // root revokes token_receiver - owner + let _ = owner .call(nft_contract.id(), "nft_revoke") .args_json(json!({ "token_id": "1", "account_id": token_receiver.id(), })) - .deposit(1) + .deposit(NearToken::from_yoctonear(1)) .transact() .await; @@ -336,26 +336,26 @@ async fn test_revoke_all( token_receiver: &Contract ) -> anyhow::Result<()> { // root approves alice - owner + let _ = owner .call(nft_contract.id(), "nft_approve") .args_json(json!({ "token_id": "1", "account_id": user.id(), })) - .gas(parse_gas!("150 Tgas") as u64) - .deposit(parse_gas!("450000000000000000000")) + .max_gas() + .deposit(NearToken::from_yoctonear(450000000000000000000)) .transact() .await; // root approves token_receiver - owner + let _ = owner .call(nft_contract.id(), "nft_approve") .args_json(json!({ "token_id": "1", "account_id": token_receiver.id(), })) - .gas(parse_gas!("150 Tgas") as u64) - .deposit(parse_gas!("450000000000000000000")) + .max_gas() + .deposit(NearToken::from_yoctonear(450000000000000000000)) .transact() .await; @@ -400,13 +400,13 @@ async fn test_simple_transfer( .json()?; assert_eq!(token.get("owner_id"), Some(&String(owner.id().to_string()))); - owner + let _ = owner .call(nft_contract.id(), "nft_transfer") .args_json(json!({ "token_id": "1", "receiver_id": user.id(), })) - .deposit(1) + .deposit(ONE_YOCTO) .transact() .await; @@ -428,7 +428,7 @@ async fn test_transfer_call_fast_return_to_sender( nft_contract: &Contract ) -> anyhow::Result<()> { use serde_json::Value::String; - owner + let _ = owner .call(nft_contract.id(), "nft_mint") .args_json(json!({ "token_id": "2", @@ -439,11 +439,11 @@ async fn test_transfer_call_fast_return_to_sender( "copies": 1, } })) - .deposit(parse_gas!("6050000000000000000000")) + .deposit(NearToken::from_yoctonear(6050000000000000000000)) .transact() .await; - owner + let _ = owner .call(nft_contract.id(), "nft_transfer_call") .args_json(json!({ "token_id": "2", @@ -451,8 +451,8 @@ async fn test_transfer_call_fast_return_to_sender( "memo": "transfer & call", "msg": "return-it-now", })) - .deposit(1) - .gas(parse_gas!("150 Tgas") as u64) + .max_gas() + .deposit(ONE_YOCTO) .transact() .await; @@ -474,7 +474,7 @@ async fn test_transfer_call_slow_return_to_sender( nft_contract: &Contract ) -> anyhow::Result<()> { use serde_json::Value::String; - owner + let _ = owner .call(nft_contract.id(), "nft_transfer_call") .args_json(json!({ "token_id": "2", @@ -482,8 +482,8 @@ async fn test_transfer_call_slow_return_to_sender( "memo": "transfer & call", "msg": "return-it-later", })) - .deposit(1) - .gas(parse_gas!("150 Tgas") as u64) + .max_gas() + .deposit(ONE_YOCTO) .transact() .await; @@ -505,7 +505,7 @@ async fn test_transfer_call_fast_keep_with_sender( nft_contract: &Contract ) -> anyhow::Result<()> { use serde_json::Value::String; - owner + let _ = owner .call(nft_contract.id(), "nft_transfer_call") .args_json(json!({ "token_id": "2", @@ -513,8 +513,8 @@ async fn test_transfer_call_fast_keep_with_sender( "memo": "transfer & call", "msg": "keep-it-now", })) - .deposit(1) - .gas(parse_gas!("150 Tgas") as u64) + .max_gas() + .deposit(ONE_YOCTO) .transact() .await; @@ -539,7 +539,7 @@ async fn test_transfer_call_slow_keep_with_sender( nft_contract: &Contract ) -> anyhow::Result<()> { use serde_json::Value::String; - owner + let _ = owner .call(nft_contract.id(), "nft_mint") .args_json(json!({ "token_id": "3", @@ -550,11 +550,11 @@ async fn test_transfer_call_slow_keep_with_sender( "copies": 1, } })) - .deposit(parse_gas!("6050000000000000000000")) + .deposit(NearToken::from_yoctonear(6050000000000000000000)) .transact() .await; - owner + let _ = owner .call(nft_contract.id(), "nft_transfer_call") .args_json(json!({ "token_id": "3", @@ -562,8 +562,8 @@ async fn test_transfer_call_slow_keep_with_sender( "memo": "transfer & call", "msg": "keep-it-later", })) - .deposit(1) - .gas(parse_gas!("150 Tgas") as u64) + .max_gas() + .deposit(ONE_YOCTO) .transact() .await; @@ -588,7 +588,7 @@ async fn test_transfer_call_receiver_panics( nft_contract: &Contract ) -> anyhow::Result<()> { use serde_json::Value::String; - owner + let _ = owner .call(nft_contract.id(), "nft_mint") .args_json(json!({ "token_id": "4", @@ -599,12 +599,12 @@ async fn test_transfer_call_receiver_panics( "copies": 1, } })) - .deposit(parse_gas!("6050000000000000000000")) - .gas(parse_gas!("150 Tgas") as u64) + .max_gas() + .deposit(NearToken::from_yoctonear(6050000000000000000000)) .transact() .await; - owner + let _ = owner .call(nft_contract.id(), "nft_transfer_call") .args_json(json!({ "token_id": "4", @@ -612,8 +612,8 @@ async fn test_transfer_call_receiver_panics( "memo": "transfer & call", "msg": "incorrect message", })) - .deposit(1) - .gas(parse_gas!("150 Tgas") as u64) + .max_gas() + .deposit(ONE_YOCTO) .transact() .await; diff --git a/integration-tests/ts/ava.config.cjs b/integration-tests/ts/ava.config.cjs deleted file mode 100644 index c488d9de..00000000 --- a/integration-tests/ts/ava.config.cjs +++ /dev/null @@ -1,9 +0,0 @@ -require("util").inspect.defaultOptions.depth = 5; // Increase AVA's printing depth - -module.exports = { - timeout: "300000", - files: ["**/*.ava.ts"], - failWithoutAssertions: false, - extensions: ["ts"], - require: ["ts-node/register"], -}; diff --git a/integration-tests/ts/package.json b/integration-tests/ts/package.json deleted file mode 100644 index 38388f8f..00000000 --- a/integration-tests/ts/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "non-fungible-token-integration-tests-ts", - "version": "1.0.0", - "license": "(MIT AND Apache-2.0)", - "scripts": { - "test": "ava --verbose" - }, - "devDependencies": { - "ava": "^5.3.1", - "near-workspaces": "^3.3.0", - "typescript": "^4.6.4", - "ts-node": "^10.8.0", - "@types/bn.js": "^5.1.0" - }, - "dependencies": {} -} diff --git a/integration-tests/ts/src/main.ava.ts b/integration-tests/ts/src/main.ava.ts deleted file mode 100644 index 9528d5ab..00000000 --- a/integration-tests/ts/src/main.ava.ts +++ /dev/null @@ -1,498 +0,0 @@ -import { Worker, NearAccount, tGas, NEAR, BN } from 'near-workspaces'; -import anyTest, { TestFn } from 'ava'; -import { mint_more, nft_total_supply } from './utils'; - -const test = anyTest as TestFn<{ - worker: Worker; - accounts: Record; -}>; - -test.beforeEach(async t => { - const worker = await Worker.init(); - const root = worker.rootAccount; - - const nft = await root.createSubAccount('nft', { initialBalance: NEAR.parse('100 N').toJSON() }); - await nft.deploy('../../res/non_fungible_token.wasm'); - await nft.call(nft, 'new_default_meta', { owner_id: root.accountId }); - - await root.call( - nft, - "nft_mint", - { - token_id: "0", - receiver_id: root, - token_metadata: { - title: "Olympus Mons", - description: "The tallest mountain in the charted solar system", - media: null, - media_hash: null, - copies: 10000, - issued_at: null, - expires_at: null, - starts_at: null, - updated_at: null, - extra: null, - reference: null, - reference_hash: null, - } - }, - { attachedDeposit: '7000000000000000000000' } - ); - - const alice = await root.createSubAccount('alice', { initialBalance: NEAR.parse('100 N').toJSON() }); - - const tokenReceiver = await root.createSubAccount('token_receiver', { initialBalance: NEAR.parse('100 N').toJSON() }); - await tokenReceiver.deploy('../../res/token_receiver.wasm'); - await tokenReceiver.call(tokenReceiver, 'new', { non_fungible_token_account_id: nft.accountId }); - - const approvalReceiver = await root.createSubAccount('approval_receiver', { initialBalance: NEAR.parse('100 N').toJSON() }); - await approvalReceiver.deploy('../../res/approval_receiver.wasm'); - await approvalReceiver.call(approvalReceiver, 'new', { non_fungible_token_account_id: nft.accountId }); - - t.context.worker = worker; - t.context.accounts = { root, alice, nft, tokenReceiver, approvalReceiver }; -}); - -test.afterEach(async t => { - await t.context.worker.tearDown().catch(error => { - console.log('Failed to tear down the worker:', error); - }); -}); - -test('Simple approve', async test => { - const { root, alice, nft, tokenReceiver } = test.context.accounts; - // root approves alice - await root.call( - nft, - 'nft_approve', - { - token_id: '0', - account_id: alice, - }, - { - attachedDeposit: new BN('270000000000000000000'), // need more deposit than the sim-tests, cause names are longer - gas: tGas('150') - }, - ); - - // check nft_is_approved, don't provide approval_id - test.assert( - await nft.view( - 'nft_is_approved', - { - token_id: '0', - approved_account_id: alice, - }) - ); - - // check nft_is_approved, with approval_id=1 - test.assert( - await nft.view( - 'nft_is_approved', - { - token_id: '0', - approved_account_id: alice, - approval_id: 1, - }) - ); - - // check nft_is_approved, with approval_id=2 - test.false( - await nft.view( - 'nft_is_approved', - { - token_id: '0', - approved_account_id: alice, - approval_id: 2, - }) - ); - - // alternatively, one could check the data returned by nft_token - const token: any = await nft.view('nft_token', { token_id: '0', }); - test.deepEqual(token.approved_account_ids, { [alice.accountId]: 1 }) - - // root approves alice again, which changes the approval_id and doesn't require as much deposit - await root.call( - nft, - 'nft_approve', - { - token_id: '0', - account_id: alice, - }, - { attachedDeposit: '1', gas: tGas('150') } - ); - - test.true( - await nft.view( - 'nft_is_approved', - { - token_id: '0', - approved_account_id: alice, - approval_id: 2, - }, - ) - ); - - // approving another account gives different approval_id - await root.call( - nft, - 'nft_approve', - { - token_id: '0', - account_id: tokenReceiver, - }, - // note that token_receiver's account name is longer, and so takes more bytes to store and - // therefore requires a larger deposit! - { attachedDeposit: new BN('360000000000000000000'), gas: tGas('150') } - ); - - test.true( - await nft.view( - 'nft_is_approved', - { - token_id: '0', - approved_account_id: tokenReceiver, - approval_id: 3, - }) - ); -}); - -test('Approval with call', async test => { - const { root, nft, approvalReceiver } = test.context.accounts; - let outcome: string = await root.call( - nft, - 'nft_approve', - { - token_id: '0', - account_id: approvalReceiver, - msg: 'return-now', - }, - { attachedDeposit: new BN('390000000000000000000'), gas: tGas('150') }, - ); - - test.is(outcome, 'cool'); - - const msg = 'hahaha'; - outcome = await root.call( - nft, - 'nft_approve', - { - token_id: '0', - account_id: approvalReceiver, - msg: msg, - }, - { attachedDeposit: new BN('390000000000000000000'), gas: tGas('150') }, - ); - test.is(outcome, msg); -}); - -test('Approved account transfers token', async test => { - const { root, alice, nft } = test.context.accounts; - await root.call( - nft, - 'nft_approve', - { - token_id: '0', - account_id: alice, - - }, - { attachedDeposit: new BN('270000000000000000000'), gas: tGas('150') }, - ); - - await alice.call( - nft, - 'nft_transfer', - { - receiver_id: alice, - token_id: '0', - approval_id: 1, - memo: 'gotcha! bahahaha', - }, - { attachedDeposit: '1', gas: tGas('150') } - ); - - const token: any = await nft.view('nft_token', { token_id: '0' }); - test.is(token.owner_id, alice.accountId); -}); - -test('Revoke', async test => { - const { root, alice, nft, tokenReceiver } = test.context.accounts; - - // root approves alice - await root.call( - nft, - 'nft_approve', - { - token_id: '0', - account_id: alice, - }, - { attachedDeposit: new BN('270000000000000000000'), gas: tGas('150') }, - ); - - // root approves token_receiver - await root.call( - nft, - 'nft_approve', - { - token_id: '0', - account_id: tokenReceiver, - }, - { attachedDeposit: new BN('360000000000000000000'), gas: tGas('150') } - ); - - // root revokes alice - await root.call(nft, 'nft_revoke', { token_id: '0', account_id: alice }, { attachedDeposit: new BN('1') }); - - // alice is revoked... - test.false( - await nft.view('nft_is_approved', { token_id: '0', approved_account_id: alice }) - ); - - // but token_receiver is still approved - test.true( - await nft.view('nft_is_approved', { token_id: '0', approved_account_id: tokenReceiver }) - ); - - // root revokes token_receiver - await root.call(nft, 'nft_revoke', { token_id: '0', account_id: tokenReceiver }, { attachedDeposit: '1' }); - - // alice is still revoked... - test.false( - await nft.view('nft_is_approved', { token_id: '0', approved_account_id: alice }) - ); - - // ...and now so is token_receiver - test.false( - await nft.view('nft_is_approved', { token_id: '0', approved_account_id: tokenReceiver }) - ); -}) - -test('Revoke all', async test => { - const { root, alice, tokenReceiver, nft } = test.context.accounts; - // root approves alice - await root.call( - nft, - 'nft_approve', - { - token_id: '0', - account_id: alice, - - }, - { attachedDeposit: new BN('270000000000000000000'), gas: tGas('150') }, - ); - - // root approves token_receiver - await root.call( - nft, - 'nft_approve', - { - token_id: '0', - account_id: tokenReceiver, - }, - { attachedDeposit: new BN('360000000000000000000'), gas: tGas('150') } - ); - - await root.call(nft, 'nft_revoke_all', { token_id: '0' }, { attachedDeposit: '1' }); - - // everyone revoked... - test.false( - await nft.view('nft_is_approved', { token_id: '0', approved_account_id: alice }) - ); - test.false( - await nft.view('nft_is_approved', { token_id: '0', approved_account_id: tokenReceiver }) - ); -}) - -test('Simple transfer', async test => { - const { root, alice, nft } = test.context.accounts; - let token: any = await nft.view('nft_token', { token_id: '0' }); - test.is(token.owner_id, root.accountId); - - const result = await root.callRaw( - nft, - 'nft_transfer', - { - receiver_id: alice, - token_id: '0', - memo: "simple transfer", - }, - { attachedDeposit: '1' }, - ); - test.assert(result.succeeded); - token = await nft.view('nft_token', { token_id: '0' }); - test.is(token.owner_id, alice.accountId); -}); - -test('Transfer call fast return to sender', async test => { - const { root, tokenReceiver, nft } = test.context.accounts; - await root.call( - nft, - 'nft_transfer_call', - { - receiver_id: tokenReceiver, - token_id: '0', - memo: 'transfer & call', - msg: 'return-it-now', - }, - { attachedDeposit: '1', gas: tGas(150) }, - ); - - const token: any = await nft.view('nft_token', { token_id: '0' }); - test.is(token.owner_id, root.accountId); -}); - -test('Transfer call slow return to sender', async test => { - const { root, tokenReceiver, nft } = test.context.accounts; - await root.call( - nft, - 'nft_transfer_call', - { - receiver_id: tokenReceiver, - token_id: '0', - memo: 'transfer & call', - msg: 'return-it-later', - }, - { attachedDeposit: '1', gas: tGas(150) }, - ); - - const token: any = await nft.view('nft_token', { token_id: '0' }); - test.is(token.owner_id, root.accountId); -}); - -test('Transfer call fast keep with sender', async test => { - const { root, tokenReceiver, nft } = test.context.accounts; - await root.call( - nft, - 'nft_transfer_call', - { - receiver_id: tokenReceiver, - token_id: '0', - memo: 'transfer & call', - msg: 'keep-it-now', - }, - { attachedDeposit: '1', gas: tGas(150) }, - ); - const token: any = await nft.view('nft_token', { token_id: '0' }); - test.is(token.owner_id, tokenReceiver.accountId); -}); - -test('Transfer call slow keep with sender', async test => { - const { root, tokenReceiver, nft } = test.context.accounts; - await root.call( - nft, - 'nft_transfer_call', - { - receiver_id: tokenReceiver, - token_id: '0', - approval_id: null, - memo: 'transfer & call', - msg: 'keep-it-later', - }, - { attachedDeposit: '1', gas: tGas(150) }, - ); - const token: any = await nft.view('nft_token', { token_id: '0' }); - test.is(token.owner_id, tokenReceiver.accountId); -}); - -// test('Transfer call receiver panics', async test => { -// const { root, tokenReceiver, nft } = test.context.accounts; - -// await test.throwsAsync( -// root.call( -// nft.accountId, -// 'nft_transfer_call', -// { -// receiver_id: tokenReceiver, -// token_id: '0', -// approval_id: null, -// memo: 'transfer & call', -// msg: 'incorrect message' -// }, -// { attachedDeposit: '1', gas: tGas(150) } -// ) -// ); - -// const token: any = await nft.view('nft_token', { token_id: '0' }); -// test.is(token.owner_id, root.accountId); -// }); - -test('Enum total supply', async test => { - const { root, alice, nft } = test.context.accounts; - await mint_more(root, nft); - - const total_supply = await nft_total_supply(nft, alice); - test.deepEqual(total_supply, new BN(4)); -}); - -test('Enum nft tokens', async test => { - const { root, nft } = test.context.accounts; - await mint_more(root, nft); - - // No optional args should return all - let tokens: any[] = await nft.view('nft_tokens'); - test.is(tokens.length, 4); - - // Start at "1", with no limit arg - tokens = await nft.view('nft_tokens', { from_index: '1' }); - test.is(tokens.length, 3); - test.is(tokens[0].token_id, '1'); - test.is(tokens[1].token_id, '2'); - test.is(tokens[2].token_id, '3'); - - // Start at "2", with limit 1 - tokens = await nft.view('nft_tokens', { from_index: '2', limit: 1 }); - test.is(tokens.length, 1); - test.is(tokens[0].token_id, '2'); - - // Don't specify from_index, but limit 2 - tokens = await nft.view('nft_tokens', { limit: 2 }); - test.is(tokens.length, 2); - test.is(tokens[0].token_id, '0'); - test.is(tokens[1].token_id, '1'); -}); - -test('Enum nft supply for owner', async test => { - const { root, alice, nft } = test.context.accounts; - // Get number from account with no NFTs - let ownerNumTokens: BN = new BN(await nft.view('nft_supply_for_owner', { account_id: alice })); - test.deepEqual(ownerNumTokens, new BN(0)); - - ownerNumTokens = new BN(await nft.view('nft_supply_for_owner', { account_id: root })); - test.deepEqual(ownerNumTokens, new BN(1)); - - await mint_more(root, nft); - - ownerNumTokens = new BN(await nft.view('nft_supply_for_owner', { account_id: root })); - test.deepEqual(ownerNumTokens, new BN(4)); -}); - -test('Enum nft tokens for owner', async test => { - const { root, alice, nft } = test.context.accounts; - await mint_more(root, nft); - - // Get tokens from account with no NFTs - let ownerTokens: any[] = await nft.view('nft_tokens_for_owner', { account_id: alice }); - test.deepEqual(ownerTokens.length, 0); - - // Get tokens with no optional args - ownerTokens = await nft.view('nft_tokens_for_owner', { account_id: root }); - test.deepEqual(ownerTokens.length, 4); - - // With from_index and no limit - ownerTokens = await nft.view('nft_tokens_for_owner', { account_id: root, from_index: new BN(2) }); - test.deepEqual(ownerTokens.length, 2); - test.is(ownerTokens[0].token_id, '2'); - test.is(ownerTokens[1].token_id, '3'); - - // With from_index and limit 1 - ownerTokens = await nft.view('nft_tokens_for_owner', { account_id: root, from_index: new BN(1), limit: 1 }); - test.deepEqual(ownerTokens.length, 1); - test.is(ownerTokens[0].token_id, '1'); - - // No from_index but limit 3 - ownerTokens = await nft.view('nft_tokens_for_owner', { account_id: root, limit: 3 }); - test.deepEqual(ownerTokens.length, 3); - test.is(ownerTokens[0].token_id, '0'); - test.is(ownerTokens[1].token_id, '1'); - test.is(ownerTokens[2].token_id, '2'); -}); \ No newline at end of file diff --git a/integration-tests/ts/src/utils.ts b/integration-tests/ts/src/utils.ts deleted file mode 100644 index 7ce12c25..00000000 --- a/integration-tests/ts/src/utils.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { NearAccount, BN } from 'near-workspaces'; - -export async function helper_mint( - token_id: string, - root: NearAccount, - nft: NearAccount, - title: String, - desc: String) { - await root.call( - nft, - "nft_mint", - { - token_id: token_id, - receiver_id: root, - token_metadata: { - title: title, - description: desc, - media: null, - media_hash: null, - copies: 1, - issued_at: null, - expires_at: null, - starts_at: null, - updated_at: null, - extra: null, - reference: null, - reference_hash: null, - } - }, - { attachedDeposit: '7000000000000000000000' } - ) -} -export async function mint_more(root: NearAccount, nft: NearAccount) { - await helper_mint( - "1", - root, - nft, - "Black as the Night", - "In charcoal" - ); - await helper_mint( - "2", - root, - nft, - "Hamakua", - "Vintage recording" - ); - await helper_mint( - "3", - root, - nft, - "Aloha ke akua", - "Original with piano" - ); -} - -export async function nft_total_supply(nft: NearAccount, user: NearAccount): Promise { - return new BN(await nft.view('nft_total_supply')); -} -