diff --git a/.github/workflows/pr-integration-test-runner.yml b/.github/workflows/pr-integration-test-runner.yml index 65c1970..37663f7 100644 --- a/.github/workflows/pr-integration-test-runner.yml +++ b/.github/workflows/pr-integration-test-runner.yml @@ -16,7 +16,7 @@ jobs: env: CI: 1 DEBUG: 0 - DFX_VERSION: 0.9.3 + DFX_VERSION: 0.11.1 DFX_WARNING: -version_check NODE_ENV: ci DFX_CANDID_RELEASE: 2022-01-06 @@ -48,9 +48,9 @@ jobs: override: true target: wasm32-unknown-unknown - - name: Install ic-cdk-optimizer - if: steps.cache-rust.outputs.cache-hit != 'true' - run: cargo install ic-cdk-optimizer + # - name: Install ic-cdk-optimizer + # if: steps.cache-rust.outputs.cache-hit != 'true' + # run: cargo install ic-cdk-optimizer - name: Cache Dfx id: cache-dfx diff --git a/Makefile b/Makefile index deb29fe..9b5fa85 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,10 @@ LOCAL_CUSTODIAN_PRINCIPAL = $(shell dfx identity get-principal) TEST_CUSTODIAN_PRINCIPAL = $(shell cat test/custodian-test-principal) -CAP_ID ?= $(shell cd cap && dfx canister id ic-history-router) +CAP_ID ?= $(shell dfx canister id cap-router) cap-local: - # Verifying cap... $(shell [ -z "$(CAP_ID)" ] && cd cap && dfx deploy ic-history-router) + # Verifying cap... $(shell [ -z "$(CAP_ID)" ] && dfx deploy cap-router) @echo "cap local canister id: $(CAP_ID)" init: @@ -52,4 +52,4 @@ clean: clean-dfx npm --prefix test run clean clean-dfx: stop-replica - rm -rf .dfx cap/.dfx \ No newline at end of file + rm -rf .dfx cap/.dfx diff --git a/README.md b/README.md index 1111582..3b6b9ae 100644 --- a/README.md +++ b/README.md @@ -6,19 +6,23 @@ [DIP-721](spec.md) is an ERC-721 style non-fungible token standard built mirroring its Ethereum counterpart and adapting it to the Internet Computer, maintaining the same interface. This standard aims to adopt the EIP-721 to the Internet Computer; providing a -simple, non-ambiguous, extendable API for the transfer and tracking ownership of NFTs and expanding/building upon the EXT standard with partial compatibility. +simple, non-ambiguous, extendable API for the transfer and tracking ownership of NFTs ## ๐Ÿ“’ Table of Contents -- [Specification](#-specification) -- [Community](#-community) -- [NFT Implementation example](#-nft-implementation-example) -- [Contribution guideline](#-contributing) +- [๐Ÿ’Ž DIP-721](#-dip-721) + - [๐Ÿ“’ Table of Contents](#-table-of-contents) + - [๐ŸŽ“ Specification](#-specification) + - [๐Ÿ‘‹ Community](#-community) + - [๐Ÿ‘ฉ NFT Implementation example](#-nft-implementation-example) + - [๐Ÿ™ Contributing](#-contributing) ## ๐ŸŽ“ Specification The document for the [DIP-721](spec.md) is available [here](spec.md). +There are 2 versions of the v2 spec. One with namespace and snakecase, and one non namespaced and camel case. The legacy.rs provides the initial v2 spec without namespace, but the final version that should be used and integrated against has the namespace. + โš ๏ธ This is an an in-development standard, consider it a work in progress as we finalize details in its design and gather feedback from the community. ## ๐Ÿ‘‹ Community diff --git a/cap b/cap index a97dd7f..521ff43 160000 --- a/cap +++ b/cap @@ -1 +1 @@ -Subproject commit a97dd7f5bcbf0af45d58f0a36a3ed39f4a5d7b6e +Subproject commit 521ff43cdaf1ec4e8bab58902ad26995b5cfd9ee diff --git a/dfx.json b/dfx.json index a3e6992..dc3de9a 100644 --- a/dfx.json +++ b/dfx.json @@ -1,11 +1,16 @@ { "version": 1, - "dfx": "0.9.3", + "dfx": "0.11.1", "canisters": { "nft": { "package": "nft", "candid": "nft.did", "type": "rust" + }, + "cap-router": { + "type": "custom", + "wasm": "cap/wasm/cap_router.wasm", + "candid": "cap/candid/router.did" } }, "defaults": { diff --git a/nft.did b/nft.did index d2081d2..f5af872 100644 --- a/nft.did +++ b/nft.did @@ -96,8 +96,38 @@ service : (opt InitArgs) -> { burn : (nat) -> (Result); custodians : () -> (vec principal) query; cycles : () -> (nat) query; - dfxInfo : () -> (text) query; - gitCommitHash : () -> (text) query; + dfx_info : () -> (text) query; + dip721_approve : (principal, nat) -> (Result); + dip721_balance_of : (principal) -> (Result) query; + dip721_burn : (nat) -> (Result); + dip721_custodians : () -> (vec principal) query; + dip721_cycles : () -> (nat) query; + dip721_is_approved_for_all : (principal, principal) -> (Result_1) query; + dip721_logo : () -> (opt text) query; + dip721_metadata : () -> (ManualReply) query; + dip721_mint : (principal, nat, vec record { text; GenericValue }) -> (Result); + dip721_name : () -> (opt text) query; + dip721_operator_of : (nat) -> (Result_2) query; + dip721_operator_token_identifiers : (principal) -> (ManualReply_1) query; + dip721_operator_token_metadata : (principal) -> (ManualReply_2) query; + dip721_owner_of : (nat) -> (Result_2) query; + dip721_owner_token_identifiers : (principal) -> (ManualReply_1) query; + dip721_owner_token_metadata : (principal) -> (ManualReply_2) query; + dip721_set_approval_for_all : (principal, bool) -> (Result); + dip721_set_custodians : (vec principal) -> (); + dip721_set_logo : (text) -> (); + dip721_set_name : (text) -> (); + dip721_set_symbol : (text) -> (); + dip721_stats : () -> (Stats) query; + dip721_supported_interfaces : () -> (vec SupportedInterface) query; + dip721_symbol : () -> (opt text) query; + dip721_token_metadata : (nat) -> (ManualReply_3) query; + dip721_total_supply : () -> (nat) query; + dip721_total_transactions : () -> (nat) query; + dip721_total_unique_holders : () -> (nat) query; + dip721_transfer : (principal, nat) -> (Result); + dip721_transfer_from : (principal, principal, nat) -> (Result); + git_commit_hash : () -> (text) query; isApprovedForAll : (principal, principal) -> (Result_1) query; logo : () -> (opt text) query; metadata : () -> (ManualReply) query; @@ -109,7 +139,7 @@ service : (opt InitArgs) -> { ownerOf : (nat) -> (Result_2) query; ownerTokenIdentifiers : (principal) -> (ManualReply_1) query; ownerTokenMetadata : (principal) -> (ManualReply_2) query; - rustToolchainInfo : () -> (text) query; + rust_toolchain_info : () -> (text) query; setApprovalForAll : (principal, bool) -> (Result); setCustodians : (vec principal) -> (); setLogo : (text) -> (); diff --git a/src/legacy.rs b/src/legacy.rs new file mode 100644 index 0000000..b7c772e --- /dev/null +++ b/src/legacy.rs @@ -0,0 +1,204 @@ +use crate::*; + +// ====================== +// QUERY CALLS +// ====================== + +#[query(manual_reply = true)] +#[candid_method(query)] +fn name() -> ManualReply> { + dip721_name() +} + +#[query(manual_reply = true)] +#[candid_method(query)] +fn logo() -> ManualReply> { + dip721_logo() +} + +#[query(manual_reply = true)] +#[candid_method(query)] +fn symbol() -> ManualReply> { + dip721_symbol() +} + +#[query(manual_reply = true)] +#[candid_method(query)] +fn custodians() -> ManualReply> { + dip721_custodians() +} + +#[query(manual_reply = true)] +#[candid_method(query)] +fn metadata() -> ManualReply { + dip721_metadata() +} + +#[update(name = "setName", guard = "is_canister_custodian")] +#[candid_method(update, rename = "setName")] +fn set_name(name: String) { + dip721_set_name(name) +} + +#[update(name = "setLogo", guard = "is_canister_custodian")] +#[candid_method(update, rename = "setLogo")] +fn set_logo(logo: String) { + dip721_set_logo(logo) +} + +#[update(name = "setSymbol", guard = "is_canister_custodian")] +#[candid_method(update, rename = "setSymbol")] +fn set_symbol(symbol: String) { + dip721_set_symbol(symbol) +} +#[update(name = "setCustodians", guard = "is_canister_custodian")] +#[candid_method(update, rename = "setCustodians")] +fn set_custodians(custodians: HashSet) { + dip721_set_custodians(custodians) +} + +#[query(name = "totalSupply")] +#[candid_method(query, rename = "totalSupply")] +fn total_supply() -> Nat { + dip721_total_supply() +} + +#[query(name = "totalTransactions")] +#[candid_method(query, rename = "totalTransactions")] +fn total_transactions() -> Nat { + dip721_total_transactions() +} + +#[query()] +#[candid_method(query)] +fn cycles() -> Nat { + dip721_cycles() +} + +#[query(name = "totalUniqueHolders")] +#[candid_method(query, rename = "totalUniqueHolders")] +fn total_unique_holders() -> Nat { + dip721_total_unique_holders() +} + +#[query()] +#[candid_method(query)] +fn stats() -> Stats { + dip721_stats() +} + +#[query(name = "supportedInterfaces")] +#[candid_method(query, rename = "supportedInterfaces")] +fn supported_interfaces() -> Vec { + dip721_supported_interfaces() +} + +#[query(name = "balanceOf")] +#[candid_method(query, rename = "balanceOf")] +fn balance_of(owner: Principal) -> Result { + dip721_balance_of(owner) +} + +#[query(name = "ownerOf")] +#[candid_method(query, rename = "ownerOf")] +fn owner_of(token_identifier: TokenIdentifier) -> Result, NftError> { + dip721_owner_of(token_identifier) +} + +#[query(name = "operatorOf")] +#[candid_method(query, rename = "operatorOf")] +fn operator_of(token_identifier: TokenIdentifier) -> Result, NftError> { + dip721_operator_of(token_identifier) +} + +#[query(name = "ownerTokenMetadata", manual_reply = true)] +#[candid_method(query, rename = "ownerTokenMetadata")] +fn owner_token_metadata(owner: Principal) -> ManualReply, NftError>> { + dip721_owner_token_metadata(owner) +} + +#[query(name = "operatorTokenMetadata", manual_reply = true)] +#[candid_method(query, rename = "operatorTokenMetadata")] +fn operator_token_metadata( + operator: Principal, +) -> ManualReply, NftError>> { + dip721_operator_token_metadata(operator) +} + +#[query(name = "ownerTokenIdentifiers", manual_reply = true)] +#[candid_method(query, rename = "ownerTokenIdentifiers")] +fn owner_token_identifiers( + owner: Principal, +) -> ManualReply, NftError>> { + dip721_owner_token_identifiers(owner) +} + +#[query(name = "operatorTokenIdentifiers", manual_reply = true)] +#[candid_method(query, rename = "operatorTokenIdentifiers")] +fn operator_token_identifiers( + operator: Principal, +) -> ManualReply, NftError>> { + dip721_operator_token_identifiers(operator) +} + +#[query(name = "tokenMetadata", manual_reply = true)] +#[candid_method(query, rename = "tokenMetadata")] +fn token_metadata( + token_identifier: TokenIdentifier, +) -> ManualReply> { + dip721_token_metadata(token_identifier) +} + +#[query(name = "isApprovedForAll")] +#[candid_method(query, rename = "isApprovedForAll")] +fn is_approved_for_all(owner: Principal, operator: Principal) -> Result { + dip721_is_approved_for_all(owner, operator) +} + +// ====================== +// UPDATE CALLS +// ====================== + +#[update(name = "approve")] +#[candid_method(update, rename = "approve")] +fn approve(operator: Principal, token_identifier: TokenIdentifier) -> Result { + dip721_approve(operator, token_identifier) +} + +#[update(name = "setApprovalForAll")] +#[candid_method(update, rename = "setApprovalForAll")] +fn set_approval_for_all(operator: Principal, is_approved: bool) -> Result { + dip721_set_approval_for_all(operator, is_approved) +} + +#[update(name = "transfer")] +#[candid_method(update, rename = "transfer")] +fn transfer(to: Principal, token_identifier: TokenIdentifier) -> Result { + dip721_transfer(to, token_identifier) +} + +#[update(name = "transferFrom")] +#[candid_method(update, rename = "transferFrom")] +fn transfer_from( + owner: Principal, + to: Principal, + token_identifier: TokenIdentifier, +) -> Result { + dip721_transfer_from(owner, to, token_identifier) +} + +#[update(name = "mint", guard = "is_canister_custodian")] +#[candid_method(update, rename = "mint")] +fn mint( + to: Principal, + token_identifier: TokenIdentifier, + properties: Vec<(String, GenericValue)>, +) -> Result { + dip721_mint(to, token_identifier, properties) +} + +#[update(name = "burn")] +#[candid_method(update, rename = "burn")] +fn burn(token_identifier: TokenIdentifier) -> Result { + dip721_burn(token_identifier) +} diff --git a/src/main.rs b/src/main.rs index 056799f..98a2596 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,9 @@ use std::cell::RefCell; use std::collections::{HashMap, HashSet}; use std::ops::Not; use types::*; + +mod legacy; + mod types { use super::*; #[derive(CandidType, Deserialize)] @@ -339,13 +342,13 @@ fn init(args: Option) { ledger::with_mut(|ledger| ledger.init_metadata(caller(), args)); } -fn is_canister_custodian() -> Result<(), String> { +pub fn is_canister_custodian() -> Result<(), String> { ledger::with(|ledger| { ledger .metadata() .custodians .contains(&caller()) - .then(|| ()) + .then_some(()) .ok_or_else(|| "Caller is not an custodian of canister".into()) }) } @@ -353,20 +356,20 @@ fn is_canister_custodian() -> Result<(), String> { // ================================================================================================== // cover metadata // ================================================================================================== -#[query(name = "gitCommitHash")] -#[candid_method(query, rename = "gitCommitHash")] +#[query()] +#[candid_method(query)] fn git_commit_hash() -> &'static str { run_command_str!("git", "rev-parse", "HEAD") } -#[query(name = "rustToolchainInfo")] -#[candid_method(query, rename = "rustToolchainInfo")] +#[query()] +#[candid_method(query)] fn rust_toolchain_info() -> &'static str { run_command_str!("rustup", "show") } -#[query(name = "dfxInfo")] -#[candid_method(query, rename = "dfxInfo")] +#[query()] +#[candid_method(query)] fn dfx_info() -> &'static str { run_command_str!("dfx", "--version") } @@ -374,57 +377,57 @@ fn dfx_info() -> &'static str { // ================================================================================================== // metadata // ================================================================================================== -#[query(name = "name", manual_reply = true)] -#[candid_method(query, rename = "name")] -fn name() -> ManualReply> { +#[query(manual_reply = true)] +#[candid_method(query)] +fn dip721_name() -> ManualReply> { ledger::with(|ledger| ManualReply::one(ledger.metadata().name.as_ref())) } -#[query(name = "logo", manual_reply = true)] -#[candid_method(query, rename = "logo")] -fn logo() -> ManualReply> { +#[query(manual_reply = true)] +#[candid_method(query)] +fn dip721_logo() -> ManualReply> { ledger::with(|ledger| ManualReply::one(ledger.metadata().logo.as_ref())) } -#[query(name = "symbol", manual_reply = true)] -#[candid_method(query, rename = "symbol")] -fn symbol() -> ManualReply> { +#[query(manual_reply = true)] +#[candid_method(query)] +fn dip721_symbol() -> ManualReply> { ledger::with(|ledger| ManualReply::one(ledger.metadata().symbol.as_ref())) } -#[query(name = "custodians", manual_reply = true)] -#[candid_method(query, rename = "custodians")] -fn custodians() -> ManualReply> { +#[query(manual_reply = true)] +#[candid_method(query)] +fn dip721_custodians() -> ManualReply> { ledger::with(|ledger| ManualReply::one(&ledger.metadata().custodians)) } -#[query(name = "metadata", manual_reply = true)] -#[candid_method(query, rename = "metadata")] -fn metadata() -> ManualReply { +#[query(manual_reply = true)] +#[candid_method(query)] +fn dip721_metadata() -> ManualReply { ledger::with(|ledger| ManualReply::one(ledger.metadata())) } -#[update(name = "setName", guard = "is_canister_custodian")] -#[candid_method(update, rename = "setName")] -fn set_name(name: String) { +#[update(guard = "is_canister_custodian")] +#[candid_method(update)] +fn dip721_set_name(name: String) { ledger::with_mut(|ledger| ledger.metadata_mut().name = Some(name)); } -#[update(name = "setLogo", guard = "is_canister_custodian")] -#[candid_method(update, rename = "setLogo")] -fn set_logo(logo: String) { +#[update(guard = "is_canister_custodian")] +#[candid_method(update)] +fn dip721_set_logo(logo: String) { ledger::with_mut(|ledger| ledger.metadata_mut().logo = Some(logo)); } -#[update(name = "setSymbol", guard = "is_canister_custodian")] -#[candid_method(update, rename = "setSymbol")] -fn set_symbol(symbol: String) { +#[update(guard = "is_canister_custodian")] +#[candid_method(update)] +fn dip721_set_symbol(symbol: String) { ledger::with_mut(|ledger| ledger.metadata_mut().symbol = Some(symbol)); } -#[update(name = "setCustodians", guard = "is_canister_custodian")] -#[candid_method(update, rename = "setCustodians")] -fn set_custodians(custodians: HashSet) { +#[update(guard = "is_canister_custodian")] +#[candid_method(update)] +fn dip721_set_custodians(custodians: HashSet) { ledger::with_mut(|ledger| ledger.metadata_mut().custodians = custodians); } @@ -433,47 +436,47 @@ fn set_custodians(custodians: HashSet) { // ================================================================================================== /// Returns the total current supply of NFT tokens. /// NFTs that are minted and later burned explicitly or sent to the zero address should also count towards totalSupply. -#[query(name = "totalSupply")] -#[candid_method(query, rename = "totalSupply")] -fn total_supply() -> Nat { +#[query()] +#[candid_method(query)] +fn dip721_total_supply() -> Nat { ledger::with(|ledger| Nat::from(ledger.tokens_count())) } -#[query(name = "totalTransactions")] -#[candid_method(query, rename = "totalTransactions")] -fn total_transactions() -> Nat { +#[query()] +#[candid_method(query)] +fn dip721_total_transactions() -> Nat { ledger::with(|ledger| ledger.tx_count()) } -#[query(name = "cycles")] -#[candid_method(query, rename = "cycles")] -fn cycles() -> Nat { +#[query()] +#[candid_method(query)] +fn dip721_cycles() -> Nat { Nat::from(canister_balance128()) } -#[query(name = "totalUniqueHolders")] -#[candid_method(query, rename = "totalUniqueHolders")] -fn total_unique_holders() -> Nat { +#[query()] +#[candid_method(query)] +fn dip721_total_unique_holders() -> Nat { ledger::with(|ledger| Nat::from(ledger.owners_count())) } -#[query(name = "stats")] -#[candid_method(query, rename = "stats")] -fn stats() -> Stats { +#[query()] +#[candid_method(query)] +fn dip721_stats() -> Stats { Stats { - total_transactions: total_transactions(), - total_supply: total_supply(), - cycles: cycles(), - total_unique_holders: total_unique_holders(), + total_transactions: dip721_total_transactions(), + total_supply: dip721_total_supply(), + cycles: dip721_cycles(), + total_unique_holders: dip721_total_unique_holders(), } } // ================================================================================================== // supported interfaces // ================================================================================================== -#[query(name = "supportedInterfaces")] -#[candid_method(query, rename = "supportedInterfaces")] -fn supported_interfaces() -> Vec { +#[query()] +#[candid_method(query)] +fn dip721_supported_interfaces() -> Vec { vec![ SupportedInterface::Approval, SupportedInterface::Mint, @@ -484,9 +487,9 @@ fn supported_interfaces() -> Vec { // ================================================================================================== // balance // ================================================================================================== -#[query(name = "balanceOf")] -#[candid_method(query, rename = "balanceOf")] -fn balance_of(owner: Principal) -> Result { +#[query()] +#[candid_method(query)] +fn dip721_balance_of(owner: Principal) -> Result { ledger::with(|ledger| { ledger .owner_token_identifiers(&owner) @@ -497,43 +500,45 @@ fn balance_of(owner: Principal) -> Result { // ================================================================================================== // token ownership // ================================================================================================== -#[query(name = "ownerOf")] -#[candid_method(query, rename = "ownerOf")] -fn owner_of(token_identifier: TokenIdentifier) -> Result, NftError> { +#[query()] +#[candid_method(query)] +fn dip721_owner_of(token_identifier: TokenIdentifier) -> Result, NftError> { ledger::with(|ledger| ledger.owner_of(&token_identifier)) } -#[query(name = "operatorOf")] -#[candid_method(query, rename = "operatorOf")] -fn operator_of(token_identifier: TokenIdentifier) -> Result, NftError> { +#[query()] +#[candid_method(query)] +fn dip721_operator_of(token_identifier: TokenIdentifier) -> Result, NftError> { ledger::with(|ledger| ledger.operator_of(&token_identifier)) } -#[query(name = "ownerTokenMetadata", manual_reply = true)] -#[candid_method(query, rename = "ownerTokenMetadata")] -fn owner_token_metadata(owner: Principal) -> ManualReply, NftError>> { +#[query(manual_reply = true)] +#[candid_method(query)] +fn dip721_owner_token_metadata( + owner: Principal, +) -> ManualReply, NftError>> { ledger::with(|ledger| ManualReply::one(ledger.owner_token_metadata(&owner))) } -#[query(name = "operatorTokenMetadata", manual_reply = true)] -#[candid_method(query, rename = "operatorTokenMetadata")] -fn operator_token_metadata( +#[query(manual_reply = true)] +#[candid_method(query)] +fn dip721_operator_token_metadata( operator: Principal, ) -> ManualReply, NftError>> { ledger::with(|ledger| ManualReply::one(ledger.operator_token_metadata(&operator))) } -#[query(name = "ownerTokenIdentifiers", manual_reply = true)] -#[candid_method(query, rename = "ownerTokenIdentifiers")] -fn owner_token_identifiers( +#[query(manual_reply = true)] +#[candid_method(query)] +fn dip721_owner_token_identifiers( owner: Principal, ) -> ManualReply, NftError>> { ledger::with(|ledger| ManualReply::one(ledger.owner_token_identifiers(&owner))) } -#[query(name = "operatorTokenIdentifiers", manual_reply = true)] -#[candid_method(query, rename = "operatorTokenIdentifiers")] -fn operator_token_identifiers( +#[query(manual_reply = true)] +#[candid_method(query)] +fn dip721_operator_token_identifiers( operator: Principal, ) -> ManualReply, NftError>> { ledger::with(|ledger| ManualReply::one(ledger.operator_token_identifiers(&operator))) @@ -542,9 +547,9 @@ fn operator_token_identifiers( // ================================================================================================== // token metadata // ================================================================================================== -#[query(name = "tokenMetadata", manual_reply = true)] -#[candid_method(query, rename = "tokenMetadata")] -fn token_metadata( +#[query(manual_reply = true)] +#[candid_method(query)] +fn dip721_token_metadata( token_identifier: TokenIdentifier, ) -> ManualReply> { ledger::with(|ledger| ManualReply::one(ledger.token_metadata(&token_identifier))) @@ -553,9 +558,9 @@ fn token_metadata( // ================================================================================================== // approved for all // ================================================================================================== -#[query(name = "isApprovedForAll")] -#[candid_method(query, rename = "isApprovedForAll")] -fn is_approved_for_all(owner: Principal, operator: Principal) -> Result { +#[query()] +#[candid_method(query)] +fn dip721_is_approved_for_all(owner: Principal, operator: Principal) -> Result { ledger::with(|ledger| { ledger .owner_token_metadata(&owner) @@ -570,19 +575,19 @@ fn is_approved_for_all(owner: Principal, operator: Principal) -> Result Result { +#[update] +#[candid_method(update)] +fn dip721_approve(operator: Principal, token_identifier: TokenIdentifier) -> Result { ledger::with_mut(|ledger| { let caller = caller(); operator .ne(&caller) - .then(|| ()) + .then_some(()) .ok_or(NftError::SelfApprove)?; ledger .owner_of(&token_identifier)? .eq(&Some(caller)) - .then(|| ()) + .then_some(()) .ok_or(NftError::UnauthorizedOwner)?; ledger.update_operator_cache( &token_identifier, @@ -610,14 +615,14 @@ fn approve(operator: Principal, token_identifier: TokenIdentifier) -> Result Result { +#[update] +#[candid_method(update)] +fn dip721_set_approval_for_all(operator: Principal, is_approved: bool) -> Result { ledger::with_mut(|ledger| { let caller = caller(); operator .ne(&caller) - .then(|| ()) + .then_some(()) .ok_or(NftError::SelfApprove)?; let owner_token_identifiers = ledger.owner_token_identifiers(&caller)?.clone(); for token_identifier in owner_token_identifiers { @@ -647,17 +652,17 @@ fn set_approval_for_all(operator: Principal, is_approved: bool) -> Result Result { +#[update] +#[candid_method(update)] +fn dip721_transfer(to: Principal, token_identifier: TokenIdentifier) -> Result { ledger::with_mut(|ledger| { let caller = caller(); - to.ne(&caller).then(|| ()).ok_or(NftError::SelfTransfer)?; + to.ne(&caller).then_some(()).ok_or(NftError::SelfTransfer)?; let old_owner = ledger.owner_of(&token_identifier)?; let old_operator = ledger.operator_of(&token_identifier)?; old_owner .eq(&Some(caller)) - .then(|| ()) + .then_some(()) .ok_or(NftError::UnauthorizedOwner)?; ledger.update_owner_cache(&token_identifier, old_owner, Some(to)); ledger.update_operator_cache(&token_identifier, old_operator, None); @@ -680,25 +685,25 @@ fn transfer(to: Principal, token_identifier: TokenIdentifier) -> Result Result { ledger::with_mut(|ledger| { let caller = caller(); - owner.ne(&to).then(|| ()).ok_or(NftError::SelfTransfer)?; + owner.ne(&to).then_some(()).ok_or(NftError::SelfTransfer)?; let old_owner = ledger.owner_of(&token_identifier)?; let old_operator = ledger.operator_of(&token_identifier)?; old_owner .eq(&Some(owner)) - .then(|| ()) + .then_some(()) .ok_or(NftError::UnauthorizedOwner)?; old_operator .eq(&Some(caller)) - .then(|| ()) + .then_some(()) .ok_or(NftError::UnauthorizedOperator)?; ledger.update_owner_cache(&token_identifier, old_owner, Some(to)); ledger.update_operator_cache(&token_identifier, old_operator, None); @@ -721,9 +726,9 @@ fn transfer_from( }) } -#[update(name = "mint", guard = "is_canister_custodian")] -#[candid_method(update, rename = "mint")] -fn mint( +#[update(guard = "is_canister_custodian")] +#[candid_method(update)] +fn dip721_mint( to: Principal, token_identifier: TokenIdentifier, properties: Vec<(String, GenericValue)>, @@ -733,7 +738,7 @@ fn mint( ledger .is_token_existed(&token_identifier) .not() - .then(|| ()) + .then_some(()) .ok_or(NftError::ExistedNFT)?; ledger.add_token_metadata( token_identifier.clone(), @@ -771,15 +776,15 @@ fn mint( }) } -#[update(name = "burn")] -#[candid_method(update, rename = "burn")] -fn burn(token_identifier: TokenIdentifier) -> Result { +#[update] +#[candid_method(update)] +fn dip721_burn(token_identifier: TokenIdentifier) -> Result { ledger::with_mut(|ledger| { let caller = caller(); let old_owner = ledger.owner_of(&token_identifier)?; old_owner .eq(&Some(caller)) - .then(|| ()) + .then_some(()) .ok_or(NftError::UnauthorizedOwner)?; let old_operator = ledger.operator_of(&token_identifier)?; ledger.update_owner_cache(&token_identifier, old_owner, None); @@ -847,7 +852,7 @@ fn main() { std::print!("{}", export_candid()); } -#[query(name = "__get_candid_interface_tmp_hack")] +#[query()] fn export_candid() -> String { ic_cdk::export::candid::export_service!(); __export_service() diff --git a/test/factory/idl.d.ts b/test/factory/idl.d.ts index 21a290f..ec8aa3e 100644 --- a/test/factory/idl.d.ts +++ b/test/factory/idl.d.ts @@ -103,8 +103,41 @@ export interface _SERVICE { 'burn' : ActorMethod<[bigint], Result>, 'custodians' : ActorMethod<[], Array>, 'cycles' : ActorMethod<[], bigint>, - 'dfxInfo' : ActorMethod<[], string>, - 'gitCommitHash' : ActorMethod<[], string>, + 'dfx_info' : ActorMethod<[], string>, + 'dip721_approve' : ActorMethod<[Principal, bigint], Result>, + 'dip721_balance_of' : ActorMethod<[Principal], Result>, + 'dip721_burn' : ActorMethod<[bigint], Result>, + 'dip721_custodians' : ActorMethod<[], Array>, + 'dip721_cycles' : ActorMethod<[], bigint>, + 'dip721_is_approved_for_all' : ActorMethod<[Principal, Principal], Result_1>, + 'dip721_logo' : ActorMethod<[], [] | [string]>, + 'dip721_metadata' : ActorMethod<[], ManualReply>, + 'dip721_mint' : ActorMethod< + [Principal, bigint, Array<[string, GenericValue]>], + Result, + >, + 'dip721_name' : ActorMethod<[], [] | [string]>, + 'dip721_operator_of' : ActorMethod<[bigint], Result_2>, + 'dip721_operator_token_identifiers' : ActorMethod<[Principal], ManualReply_1>, + 'dip721_operator_token_metadata' : ActorMethod<[Principal], ManualReply_2>, + 'dip721_owner_of' : ActorMethod<[bigint], Result_2>, + 'dip721_owner_token_identifiers' : ActorMethod<[Principal], ManualReply_1>, + 'dip721_owner_token_metadata' : ActorMethod<[Principal], ManualReply_2>, + 'dip721_set_approval_for_all' : ActorMethod<[Principal, boolean], Result>, + 'dip721_set_custodians' : ActorMethod<[Array], undefined>, + 'dip721_set_logo' : ActorMethod<[string], undefined>, + 'dip721_set_name' : ActorMethod<[string], undefined>, + 'dip721_set_symbol' : ActorMethod<[string], undefined>, + 'dip721_stats' : ActorMethod<[], Stats>, + 'dip721_supported_interfaces' : ActorMethod<[], Array>, + 'dip721_symbol' : ActorMethod<[], [] | [string]>, + 'dip721_token_metadata' : ActorMethod<[bigint], ManualReply_3>, + 'dip721_total_supply' : ActorMethod<[], bigint>, + 'dip721_total_transactions' : ActorMethod<[], bigint>, + 'dip721_total_unique_holders' : ActorMethod<[], bigint>, + 'dip721_transfer' : ActorMethod<[Principal, bigint], Result>, + 'dip721_transfer_from' : ActorMethod<[Principal, Principal, bigint], Result>, + 'git_commit_hash' : ActorMethod<[], string>, 'isApprovedForAll' : ActorMethod<[Principal, Principal], Result_1>, 'logo' : ActorMethod<[], [] | [string]>, 'metadata' : ActorMethod<[], ManualReply>, @@ -119,7 +152,7 @@ export interface _SERVICE { 'ownerOf' : ActorMethod<[bigint], Result_2>, 'ownerTokenIdentifiers' : ActorMethod<[Principal], ManualReply_1>, 'ownerTokenMetadata' : ActorMethod<[Principal], ManualReply_2>, - 'rustToolchainInfo' : ActorMethod<[], string>, + 'rust_toolchain_info' : ActorMethod<[], string>, 'setApprovalForAll' : ActorMethod<[Principal, boolean], Result>, 'setCustodians' : ActorMethod<[Array], undefined>, 'setLogo' : ActorMethod<[string], undefined>, diff --git a/test/factory/idl.ts b/test/factory/idl.ts index 149fdca..4e17192 100644 --- a/test/factory/idl.ts +++ b/test/factory/idl.ts @@ -116,8 +116,74 @@ export const idlFactory = ({ IDL }) => { 'burn' : IDL.Func([IDL.Nat], [Result], []), 'custodians' : IDL.Func([], [IDL.Vec(IDL.Principal)], ['query']), 'cycles' : IDL.Func([], [IDL.Nat], ['query']), - 'dfxInfo' : IDL.Func([], [IDL.Text], ['query']), - 'gitCommitHash' : IDL.Func([], [IDL.Text], ['query']), + 'dfx_info' : IDL.Func([], [IDL.Text], ['query']), + 'dip721_approve' : IDL.Func([IDL.Principal, IDL.Nat], [Result], []), + 'dip721_balance_of' : IDL.Func([IDL.Principal], [Result], ['query']), + 'dip721_burn' : IDL.Func([IDL.Nat], [Result], []), + 'dip721_custodians' : IDL.Func([], [IDL.Vec(IDL.Principal)], ['query']), + 'dip721_cycles' : IDL.Func([], [IDL.Nat], ['query']), + 'dip721_is_approved_for_all' : IDL.Func( + [IDL.Principal, IDL.Principal], + [Result_1], + ['query'], + ), + 'dip721_logo' : IDL.Func([], [IDL.Opt(IDL.Text)], ['query']), + 'dip721_metadata' : IDL.Func([], [ManualReply], ['query']), + 'dip721_mint' : IDL.Func( + [IDL.Principal, IDL.Nat, IDL.Vec(IDL.Tuple(IDL.Text, GenericValue))], + [Result], + [], + ), + 'dip721_name' : IDL.Func([], [IDL.Opt(IDL.Text)], ['query']), + 'dip721_operator_of' : IDL.Func([IDL.Nat], [Result_2], ['query']), + 'dip721_operator_token_identifiers' : IDL.Func( + [IDL.Principal], + [ManualReply_1], + ['query'], + ), + 'dip721_operator_token_metadata' : IDL.Func( + [IDL.Principal], + [ManualReply_2], + ['query'], + ), + 'dip721_owner_of' : IDL.Func([IDL.Nat], [Result_2], ['query']), + 'dip721_owner_token_identifiers' : IDL.Func( + [IDL.Principal], + [ManualReply_1], + ['query'], + ), + 'dip721_owner_token_metadata' : IDL.Func( + [IDL.Principal], + [ManualReply_2], + ['query'], + ), + 'dip721_set_approval_for_all' : IDL.Func( + [IDL.Principal, IDL.Bool], + [Result], + [], + ), + 'dip721_set_custodians' : IDL.Func([IDL.Vec(IDL.Principal)], [], []), + 'dip721_set_logo' : IDL.Func([IDL.Text], [], []), + 'dip721_set_name' : IDL.Func([IDL.Text], [], []), + 'dip721_set_symbol' : IDL.Func([IDL.Text], [], []), + 'dip721_stats' : IDL.Func([], [Stats], ['query']), + 'dip721_supported_interfaces' : IDL.Func( + [], + [IDL.Vec(SupportedInterface)], + ['query'], + ), + 'dip721_symbol' : IDL.Func([], [IDL.Opt(IDL.Text)], ['query']), + 'dip721_token_metadata' : IDL.Func([IDL.Nat], [ManualReply_3], ['query']), + 'dip721_total_supply' : IDL.Func([], [IDL.Nat], ['query']), + 'dip721_total_transactions' : IDL.Func([], [IDL.Nat], ['query']), + 'dip721_total_unique_holders' : IDL.Func([], [IDL.Nat], ['query']), + 'dip721_transfer' : IDL.Func([IDL.Principal, IDL.Nat], [Result], []), + 'dip721_transfer_from' : IDL.Func( + [IDL.Principal, IDL.Principal, IDL.Nat], + [Result], + [], + ), + 'git_commit_hash' : IDL.Func([], [IDL.Text], ['query']), 'isApprovedForAll' : IDL.Func( [IDL.Principal, IDL.Principal], [Result_1], @@ -153,7 +219,7 @@ export const idlFactory = ({ IDL }) => { [ManualReply_2], ['query'], ), - 'rustToolchainInfo' : IDL.Func([], [IDL.Text], ['query']), + 'rust_toolchain_info' : IDL.Func([], [IDL.Text], ['query']), 'setApprovalForAll' : IDL.Func([IDL.Principal, IDL.Bool], [Result], []), 'setCustodians' : IDL.Func([IDL.Vec(IDL.Principal)], [], []), 'setLogo' : IDL.Func([IDL.Text], [], []), diff --git a/test/integration/coverMetadata.test.ts b/test/integration/coverMetadata.test.ts index 19b126e..320dc39 100644 --- a/test/integration/coverMetadata.test.ts +++ b/test/integration/coverMetadata.test.ts @@ -6,13 +6,13 @@ const normalActors = [aliceActor, bobActor, johnActor]; const allActors = [...normalActors, custodianActor]; test("Cover metadata.", async t => { - (await Promise.all(allActors.map(actor => actor.gitCommitHash()))).forEach(result => + (await Promise.all(allActors.map(actor => actor.git_commit_hash()))).forEach(result => t.true(typeof result === "string" && result !== "") ); - (await Promise.all(allActors.map(actor => actor.rustToolchainInfo()))).forEach(result => + (await Promise.all(allActors.map(actor => actor.rust_toolchain_info()))).forEach(result => t.true(typeof result === "string" && result !== "") ); - (await Promise.all(allActors.map(actor => actor.dfxInfo()))).forEach(result => + (await Promise.all(allActors.map(actor => actor.dfx_info()))).forEach(result => t.true(typeof result === "string" && result !== "") ); }); diff --git a/test/integration/ledger.test.ts b/test/integration/ledger.test.ts index 06270cb..e2a7a61 100644 --- a/test/integration/ledger.test.ts +++ b/test/integration/ledger.test.ts @@ -50,12 +50,12 @@ const testTxns = async (transactions: any[]): Promise => { test.serial("simple mint NFT and verify information.", async t => { // mint t.deepEqual( - await custodianActor.mint(aliceIdentity.getPrincipal(), BigInt(1), [["A", {Nat64Content: BigInt(9999)}]]), + await custodianActor.dip721_mint(aliceIdentity.getPrincipal(), BigInt(1), [["A", {Nat64Content: BigInt(9999)}]]), {Ok: BigInt(0)} ); // verify token - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(1))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(1))))).forEach(result => { t.like(result, { Ok: { transferred_at: [], @@ -74,25 +74,25 @@ test.serial("simple mint NFT and verify information.", async t => { }); }); - // verify balanceOf - (await Promise.all(allActors.map(actor => actor.balanceOf(aliceIdentity.getPrincipal())))).forEach(result => { + // verify balance_of + (await Promise.all(allActors.map(actor => actor.dip721_balance_of(aliceIdentity.getPrincipal())))).forEach(result => { t.deepEqual(result, {Ok: BigInt(1)}); }); - // verify ownerOf - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(1))))).forEach(result => { + // verify owner_of + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(1))))).forEach(result => { t.deepEqual(result, {Ok: [aliceIdentity.getPrincipal()]}); }); - // verify ownerTokenIdentifiers - (await Promise.all(allActors.map(actor => actor.ownerTokenIdentifiers(aliceIdentity.getPrincipal())))).forEach( - result => { - t.deepEqual(result, {Ok: [BigInt(1)]}); - } - ); + // verify owner_token_identifiers + ( + await Promise.all(allActors.map(actor => actor.dip721_owner_token_identifiers(aliceIdentity.getPrincipal()))) + ).forEach(result => { + t.deepEqual(result, {Ok: [BigInt(1)]}); + }); - // verify ownerTokenMetadata - (await Promise.all(allActors.map(actor => actor.ownerTokenMetadata(aliceIdentity.getPrincipal())))).forEach( + // verify owner_token_metadata + (await Promise.all(allActors.map(actor => actor.dip721_owner_token_metadata(aliceIdentity.getPrincipal())))).forEach( result => { t.true("Ok" in result); t.is((result as {Ok: Array}).Ok.length, 1); @@ -113,35 +113,35 @@ test.serial("simple mint NFT and verify information.", async t => { } ); - // verify operatorOf - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(1))))).forEach(result => { + // verify operator_of + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(1))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); }); test.serial("verify stats after simple mint.", async t => { - // verify totalTransactions - (await Promise.all(allActors.map(actor => actor.totalTransactions()))).forEach(result => { + // verify total_transactions + (await Promise.all(allActors.map(actor => actor.dip721_total_transactions()))).forEach(result => { t.is(result, BigInt(1)); }); - // verify totalSupply - (await Promise.all(allActors.map(actor => actor.totalSupply()))).forEach(result => { + // verify total_supply + (await Promise.all(allActors.map(actor => actor.dip721_total_supply()))).forEach(result => { t.is(result, BigInt(1)); }); // verify cycles - (await Promise.all(allActors.map(actor => actor.cycles()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_cycles()))).forEach(result => { t.truthy(result); }); // verify totalUniqueHolders - (await Promise.all(allActors.map(actor => actor.totalUniqueHolders()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_total_unique_holders()))).forEach(result => { t.is(result, BigInt(1)); }); // verify stats - (await Promise.all(allActors.map(actor => actor.stats()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_stats()))).forEach(result => { t.truthy(result.cycles); t.is(result.total_transactions, BigInt(1)); t.is(result.total_supply, BigInt(1)); @@ -154,20 +154,23 @@ test.serial("error on query non-existed information.", async t => { ( await Promise.allSettled( normalActors.map(actor => - actor.mint(aliceIdentity.getPrincipal(), BigInt(1), [["A", {Nat64Content: BigInt(9999)}]]) + actor.dip721_mint(aliceIdentity.getPrincipal(), BigInt(1), [["A", {Nat64Content: BigInt(9999)}]]) ) ) ).forEach(promise => t.is(promise.status, "rejected")); // mint error when existed nft - t.deepEqual(await custodianActor.mint(bobIdentity.getPrincipal(), BigInt(1), [["Z", {Int64Content: BigInt(-1)}]]), { - Err: { - ExistedNFT: null + t.deepEqual( + await custodianActor.dip721_mint(bobIdentity.getPrincipal(), BigInt(1), [["Z", {Int64Content: BigInt(-1)}]]), + { + Err: { + ExistedNFT: null + } } - }); + ); - // tokenMetadata error when non-exist token - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(2))))).forEach(result => { + // token_metadata error when non-exist token + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(2))))).forEach(result => { t.deepEqual(result, { Err: { TokenNotFound: null @@ -175,32 +178,32 @@ test.serial("error on query non-existed information.", async t => { }); }); - // balanceOf error when non-exist owner - (await Promise.all(allActors.map(actor => actor.balanceOf(johnIdentity.getPrincipal())))).forEach(result => { + // balance_of error when non-exist owner + (await Promise.all(allActors.map(actor => actor.dip721_balance_of(johnIdentity.getPrincipal())))).forEach(result => { t.deepEqual(result, {Err: {OwnerNotFound: null}}); }); - // ownerOf error when non-exist token - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(2))))).forEach(result => { + // owner_of error when non-exist token + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(2))))).forEach(result => { t.deepEqual(result, {Err: {TokenNotFound: null}}); }); - // ownerTokenIdentifiers error when non-exist owner - (await Promise.all(allActors.map(actor => actor.ownerTokenIdentifiers(bobIdentity.getPrincipal())))).forEach( + // owner_token_identifiers error when non-exist owner + (await Promise.all(allActors.map(actor => actor.dip721_owner_token_identifiers(bobIdentity.getPrincipal())))).forEach( result => { t.deepEqual(result, {Err: {OwnerNotFound: null}}); } ); - // ownerTokenMetadata error when non-exist owner - (await Promise.all(allActors.map(actor => actor.ownerTokenMetadata(custodianIdentity.getPrincipal())))).forEach( - result => { - t.deepEqual(result, {Err: {OwnerNotFound: null}}); - } - ); + // owner_token_metadata error when non-exist owner + ( + await Promise.all(allActors.map(actor => actor.dip721_owner_token_metadata(custodianIdentity.getPrincipal()))) + ).forEach(result => { + t.deepEqual(result, {Err: {OwnerNotFound: null}}); + }); - // operatorOf error when non-exist token - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(2))))).forEach(result => { + // operator_of error when non-exist token + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(2))))).forEach(result => { t.deepEqual(result, {Err: {TokenNotFound: null}}); }); }); @@ -237,15 +240,18 @@ test.serial("verify basic mint transaction.", async t => { test.serial("mint NFTs.", async t => { t.deepEqual( - await custodianActor.mint(aliceIdentity.getPrincipal(), BigInt(2), [["B", {Int64Content: BigInt(1234)}]]), + await custodianActor.dip721_mint(aliceIdentity.getPrincipal(), BigInt(2), [["B", {Int64Content: BigInt(1234)}]]), {Ok: BigInt(1)} ); - t.deepEqual(await custodianActor.mint(bobIdentity.getPrincipal(), BigInt(3), [["C", {Int32Content: 5678}]]), { + t.deepEqual(await custodianActor.dip721_mint(bobIdentity.getPrincipal(), BigInt(3), [["C", {Int32Content: 5678}]]), { Ok: BigInt(2) }); - t.deepEqual(await custodianActor.mint(johnIdentity.getPrincipal(), BigInt(4), [["D", {TextContent: "โˆ†โ‰ˆรงโˆšโˆซ"}]]), { - Ok: BigInt(3) - }); + t.deepEqual( + await custodianActor.dip721_mint(johnIdentity.getPrincipal(), BigInt(4), [["D", {TextContent: "โˆ†โ‰ˆรงโˆšโˆซ"}]]), + { + Ok: BigInt(3) + } + ); }); test.serial("verify transactions after mints", async t => { @@ -291,28 +297,28 @@ test.serial("verify transactions after mints", async t => { }); test.serial("verify stats after mint.", async t => { - // verify totalTransactions - (await Promise.all(allActors.map(actor => actor.totalTransactions()))).forEach(result => { + // verify total_transactions + (await Promise.all(allActors.map(actor => actor.dip721_total_transactions()))).forEach(result => { t.is(result, BigInt(4)); }); - // verify totalSupply - (await Promise.all(allActors.map(actor => actor.totalSupply()))).forEach(result => { + // verify total_supply + (await Promise.all(allActors.map(actor => actor.dip721_total_supply()))).forEach(result => { t.is(result, BigInt(4)); }); // verify cycles - (await Promise.all(allActors.map(actor => actor.cycles()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_cycles()))).forEach(result => { t.truthy(result); }); // verify totalUniqueHolders - (await Promise.all(allActors.map(actor => actor.totalUniqueHolders()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_total_unique_holders()))).forEach(result => { t.is(result, BigInt(3)); }); // verify stats - (await Promise.all(allActors.map(actor => actor.stats()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_stats()))).forEach(result => { t.truthy(result.cycles); t.is(result.total_transactions, BigInt(4)); t.is(result.total_supply, BigInt(4)); @@ -322,7 +328,7 @@ test.serial("verify stats after mint.", async t => { test.serial("verify mint information.", async t => { // verify token - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(2))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(2))))).forEach(result => { t.like(result, { Ok: { transferred_at: [], @@ -340,7 +346,7 @@ test.serial("verify mint information.", async t => { } }); }); - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(3))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(3))))).forEach(result => { t.like(result, { Ok: { transferred_at: [], @@ -358,7 +364,7 @@ test.serial("verify mint information.", async t => { } }); }); - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(4))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(4))))).forEach(result => { t.like(result, { Ok: { transferred_at: [], @@ -377,53 +383,53 @@ test.serial("verify mint information.", async t => { }); }); - // verify balanceOf - (await Promise.all(allActors.map(actor => actor.balanceOf(aliceIdentity.getPrincipal())))).forEach(result => { + // verify balance_of + (await Promise.all(allActors.map(actor => actor.dip721_balance_of(aliceIdentity.getPrincipal())))).forEach(result => { t.deepEqual(result, {Ok: BigInt(2)}); }); - (await Promise.all(allActors.map(actor => actor.balanceOf(bobIdentity.getPrincipal())))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_balance_of(bobIdentity.getPrincipal())))).forEach(result => { t.deepEqual(result, {Ok: BigInt(1)}); }); - (await Promise.all(allActors.map(actor => actor.balanceOf(johnIdentity.getPrincipal())))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_balance_of(johnIdentity.getPrincipal())))).forEach(result => { t.deepEqual(result, {Ok: BigInt(1)}); }); - // verify ownerOf - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(2))))).forEach(result => { + // verify owner_of + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(2))))).forEach(result => { t.deepEqual(result, {Ok: [aliceIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(3))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(3))))).forEach(result => { t.deepEqual(result, {Ok: [bobIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(4))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(4))))).forEach(result => { t.deepEqual(result, {Ok: [johnIdentity.getPrincipal()]}); }); - // verify ownerTokenIdentifiers - (await Promise.all(allActors.map(actor => actor.ownerTokenIdentifiers(aliceIdentity.getPrincipal())))).forEach( - result => { - t.true((result as {Ok: Array}).Ok.includes(BigInt(1))); - t.true((result as {Ok: Array}).Ok.includes(BigInt(2))); - } - ); - (await Promise.all(allActors.map(actor => actor.ownerTokenIdentifiers(bobIdentity.getPrincipal())))).forEach( + // verify owner_token_identifiers + ( + await Promise.all(allActors.map(actor => actor.dip721_owner_token_identifiers(aliceIdentity.getPrincipal()))) + ).forEach(result => { + t.true((result as {Ok: Array}).Ok.includes(BigInt(1))); + t.true((result as {Ok: Array}).Ok.includes(BigInt(2))); + }); + (await Promise.all(allActors.map(actor => actor.dip721_owner_token_identifiers(bobIdentity.getPrincipal())))).forEach( result => { t.deepEqual(result, {Ok: [BigInt(3)]}); } ); - (await Promise.all(allActors.map(actor => actor.ownerTokenIdentifiers(johnIdentity.getPrincipal())))).forEach( - result => { - t.deepEqual(result, {Ok: [BigInt(4)]}); - } - ); + ( + await Promise.all(allActors.map(actor => actor.dip721_owner_token_identifiers(johnIdentity.getPrincipal()))) + ).forEach(result => { + t.deepEqual(result, {Ok: [BigInt(4)]}); + }); - // verify ownerTokenMetadata - (await Promise.all(allActors.map(actor => actor.ownerTokenMetadata(aliceIdentity.getPrincipal())))).forEach( + // verify owner_token_metadata + (await Promise.all(allActors.map(actor => actor.dip721_owner_token_metadata(aliceIdentity.getPrincipal())))).forEach( result => { t.true("Ok" in result); t.is((result as {Ok: Array}).Ok.length, 2); t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(1)), + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(1)), { transferred_at: [], transferred_by: [], @@ -440,7 +446,7 @@ test.serial("verify mint information.", async t => { } ); t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(2)), + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(2)), { transferred_at: [], transferred_by: [], @@ -458,75 +464,87 @@ test.serial("verify mint information.", async t => { ); } ); - (await Promise.all(allActors.map(actor => actor.ownerTokenMetadata(bobIdentity.getPrincipal())))).forEach(result => { - t.true("Ok" in result); - t.is((result as {Ok: Array}).Ok.length, 1); - t.like((result as {Ok: Array}).Ok[0], { - transferred_at: [], - transferred_by: [], - owner: [bobIdentity.getPrincipal()], - operator: [], - properties: [["C", {Int32Content: 5678}]], - is_burned: false, - approved_at: [], - approved_by: [], - burned_by: [], - burned_at: [], - token_identifier: BigInt(3), - minted_by: custodianIdentity.getPrincipal() - }); - }); - (await Promise.all(allActors.map(actor => actor.ownerTokenMetadata(johnIdentity.getPrincipal())))).forEach(result => { - t.true("Ok" in result); - t.is((result as {Ok: Array}).Ok.length, 1); - t.like((result as {Ok: Array}).Ok[0], { - transferred_at: [], - transferred_by: [], - owner: [johnIdentity.getPrincipal()], - operator: [], - properties: [["D", {TextContent: "โˆ†โ‰ˆรงโˆšโˆซ"}]], - is_burned: false, - approved_at: [], - approved_by: [], - burned_by: [], - burned_at: [], - token_identifier: BigInt(4), - minted_by: custodianIdentity.getPrincipal() - }); - }); + (await Promise.all(allActors.map(actor => actor.dip721_owner_token_metadata(bobIdentity.getPrincipal())))).forEach( + result => { + t.true("Ok" in result); + t.is((result as {Ok: Array}).Ok.length, 1); + t.like((result as {Ok: Array}).Ok[0], { + transferred_at: [], + transferred_by: [], + owner: [bobIdentity.getPrincipal()], + operator: [], + properties: [["C", {Int32Content: 5678}]], + is_burned: false, + approved_at: [], + approved_by: [], + burned_by: [], + burned_at: [], + token_identifier: BigInt(3), + minted_by: custodianIdentity.getPrincipal() + }); + } + ); + (await Promise.all(allActors.map(actor => actor.dip721_owner_token_metadata(johnIdentity.getPrincipal())))).forEach( + result => { + t.true("Ok" in result); + t.is((result as {Ok: Array}).Ok.length, 1); + t.like((result as {Ok: Array}).Ok[0], { + transferred_at: [], + transferred_by: [], + owner: [johnIdentity.getPrincipal()], + operator: [], + properties: [["D", {TextContent: "โˆ†โ‰ˆรงโˆšโˆซ"}]], + is_burned: false, + approved_at: [], + approved_by: [], + burned_by: [], + burned_at: [], + token_identifier: BigInt(4), + minted_by: custodianIdentity.getPrincipal() + }); + } + ); - // verify operatorOf - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(1))))).forEach(result => { + // verify operator_of + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(1))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(2))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(2))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(3))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(3))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(4))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(4))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); }); test.serial("approve NFTs.", async t => { - t.deepEqual(await bobActor.approve(aliceIdentity.getPrincipal(), BigInt(3)), {Ok: BigInt(4)}); - t.deepEqual(await johnActor.approve(aliceIdentity.getPrincipal(), BigInt(4)), {Ok: BigInt(5)}); - t.deepEqual(await aliceActor.approve(bobIdentity.getPrincipal(), BigInt(1)), {Ok: BigInt(6)}); - t.deepEqual(await aliceActor.approve(johnIdentity.getPrincipal(), BigInt(2)), {Ok: BigInt(7)}); + t.deepEqual(await bobActor.dip721_approve(aliceIdentity.getPrincipal(), BigInt(3)), {Ok: BigInt(4)}); + t.deepEqual(await johnActor.dip721_approve(aliceIdentity.getPrincipal(), BigInt(4)), {Ok: BigInt(5)}); + t.deepEqual(await aliceActor.dip721_approve(bobIdentity.getPrincipal(), BigInt(1)), {Ok: BigInt(6)}); + t.deepEqual(await aliceActor.dip721_approve(johnIdentity.getPrincipal(), BigInt(2)), {Ok: BigInt(7)}); - // verify isApprovedForAll + // verify is_approved_for_all ( await Promise.all([ - ...allActors.map(actor => actor.isApprovedForAll(bobIdentity.getPrincipal(), aliceIdentity.getPrincipal())), - ...allActors.map(actor => actor.isApprovedForAll(johnIdentity.getPrincipal(), aliceIdentity.getPrincipal())) + ...allActors.map(actor => + actor.dip721_is_approved_for_all(bobIdentity.getPrincipal(), aliceIdentity.getPrincipal()) + ), + ...allActors.map(actor => + actor.dip721_is_approved_for_all(johnIdentity.getPrincipal(), aliceIdentity.getPrincipal()) + ) ]) ).forEach(result => t.deepEqual(result, {Ok: true})); ( await Promise.all([ - ...allActors.map(actor => actor.isApprovedForAll(aliceIdentity.getPrincipal(), bobIdentity.getPrincipal())), - ...allActors.map(actor => actor.isApprovedForAll(aliceIdentity.getPrincipal(), johnIdentity.getPrincipal())) + ...allActors.map(actor => + actor.dip721_is_approved_for_all(aliceIdentity.getPrincipal(), bobIdentity.getPrincipal()) + ), + ...allActors.map(actor => + actor.dip721_is_approved_for_all(aliceIdentity.getPrincipal(), johnIdentity.getPrincipal()) + ) ]) ).forEach(result => t.deepEqual(result, {Ok: false})); }); @@ -585,28 +603,28 @@ test.serial("verify transactions after approval.", async t => { }); test.serial("verify stats after approve.", async t => { - // verify totalTransactions - (await Promise.all(allActors.map(actor => actor.totalTransactions()))).forEach(result => { + // verify total_transactions + (await Promise.all(allActors.map(actor => actor.dip721_total_transactions()))).forEach(result => { t.is(result, BigInt(8)); }); - // verify totalSupply - (await Promise.all(allActors.map(actor => actor.totalSupply()))).forEach(result => { + // verify total_supply + (await Promise.all(allActors.map(actor => actor.dip721_total_supply()))).forEach(result => { t.is(result, BigInt(4)); }); // verify cycles - (await Promise.all(allActors.map(actor => actor.cycles()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_cycles()))).forEach(result => { t.truthy(result); }); // verify totalUniqueHolders - (await Promise.all(allActors.map(actor => actor.totalUniqueHolders()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_total_unique_holders()))).forEach(result => { t.is(result, BigInt(3)); }); // verify stats - (await Promise.all(allActors.map(actor => actor.stats()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_stats()))).forEach(result => { t.truthy(result.cycles); t.is(result.total_transactions, BigInt(8)); t.is(result.total_supply, BigInt(4)); @@ -615,47 +633,47 @@ test.serial("verify stats after approve.", async t => { }); test.serial("verify approve information.", async t => { - // verify balanceOf - (await Promise.all(allActors.map(actor => actor.balanceOf(aliceIdentity.getPrincipal())))).forEach(result => { + // verify balance_of + (await Promise.all(allActors.map(actor => actor.dip721_balance_of(aliceIdentity.getPrincipal())))).forEach(result => { t.deepEqual(result, {Ok: BigInt(2)}); }); - (await Promise.all(allActors.map(actor => actor.balanceOf(bobIdentity.getPrincipal())))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_balance_of(bobIdentity.getPrincipal())))).forEach(result => { t.deepEqual(result, {Ok: BigInt(1)}); }); - (await Promise.all(allActors.map(actor => actor.balanceOf(johnIdentity.getPrincipal())))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_balance_of(johnIdentity.getPrincipal())))).forEach(result => { t.deepEqual(result, {Ok: BigInt(1)}); }); - // verify ownerOf - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(1))))).forEach(result => { + // verify owner_of + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(1))))).forEach(result => { t.deepEqual(result, {Ok: [aliceIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(2))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(2))))).forEach(result => { t.deepEqual(result, {Ok: [aliceIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(3))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(3))))).forEach(result => { t.deepEqual(result, {Ok: [bobIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(4))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(4))))).forEach(result => { t.deepEqual(result, {Ok: [johnIdentity.getPrincipal()]}); }); - // verify operatorOf - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(1))))).forEach(result => { + // verify operator_of + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(1))))).forEach(result => { t.deepEqual(result, {Ok: [bobIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(2))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(2))))).forEach(result => { t.deepEqual(result, {Ok: [johnIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(3))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(3))))).forEach(result => { t.deepEqual(result, {Ok: [aliceIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(4))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(4))))).forEach(result => { t.deepEqual(result, {Ok: [aliceIdentity.getPrincipal()]}); }); // verify token - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(1))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(1))))).forEach(result => { t.like(result, { Ok: { transferred_at: [], @@ -672,7 +690,7 @@ test.serial("verify approve information.", async t => { } }); }); - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(2))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(2))))).forEach(result => { t.like(result, { Ok: { transferred_at: [], @@ -689,7 +707,7 @@ test.serial("verify approve information.", async t => { } }); }); - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(3))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(3))))).forEach(result => { t.like(result, { Ok: { transferred_at: [], @@ -706,7 +724,7 @@ test.serial("verify approve information.", async t => { } }); }); - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(4))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(4))))).forEach(result => { t.like(result, { Ok: { transferred_at: [], @@ -724,13 +742,13 @@ test.serial("verify approve information.", async t => { }); }); - // verify ownerTokenMetadata - (await Promise.all(allActors.map(actor => actor.ownerTokenMetadata(aliceIdentity.getPrincipal())))).forEach( + // verify owner_token_metadata + (await Promise.all(allActors.map(actor => actor.dip721_owner_token_metadata(aliceIdentity.getPrincipal())))).forEach( result => { t.true("Ok" in result); t.is((result as {Ok: Array}).Ok.length, 2); t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(1)), + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(1)), { transferred_at: [], transferred_by: [], @@ -746,7 +764,7 @@ test.serial("verify approve information.", async t => { } ); t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(2)), + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(2)), { transferred_at: [], transferred_by: [], @@ -763,100 +781,85 @@ test.serial("verify approve information.", async t => { ); } ); - (await Promise.all(allActors.map(actor => actor.ownerTokenMetadata(bobIdentity.getPrincipal())))).forEach(result => { - t.true("Ok" in result); - t.is((result as {Ok: Array}).Ok.length, 1); - t.like((result as {Ok: Array}).Ok[0], { - transferred_at: [], - transferred_by: [], - owner: [bobIdentity.getPrincipal()], - operator: [aliceIdentity.getPrincipal()], - properties: [["C", {Int32Content: 5678}]], - is_burned: false, - approved_by: [bobIdentity.getPrincipal()], - burned_by: [], - burned_at: [], - token_identifier: BigInt(3), - minted_by: custodianIdentity.getPrincipal() - }); - }); - (await Promise.all(allActors.map(actor => actor.ownerTokenMetadata(johnIdentity.getPrincipal())))).forEach(result => { - t.true("Ok" in result); - t.is((result as {Ok: Array}).Ok.length, 1); - t.like((result as {Ok: Array}).Ok[0], { - transferred_at: [], - transferred_by: [], - owner: [johnIdentity.getPrincipal()], - operator: [aliceIdentity.getPrincipal()], - properties: [["D", {TextContent: "โˆ†โ‰ˆรงโˆšโˆซ"}]], - is_burned: false, - approved_by: [johnIdentity.getPrincipal()], - burned_by: [], - burned_at: [], - token_identifier: BigInt(4), - minted_by: custodianIdentity.getPrincipal() - }); - }); - - // verify operatorTokenMetadata - (await Promise.all(allActors.map(actor => actor.operatorTokenMetadata(aliceIdentity.getPrincipal())))).forEach( + (await Promise.all(allActors.map(actor => actor.dip721_owner_token_metadata(bobIdentity.getPrincipal())))).forEach( result => { t.true("Ok" in result); - t.is((result as {Ok: Array}).Ok.length, 2); - t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(3)), - { - transferred_at: [], - transferred_by: [], - owner: [bobIdentity.getPrincipal()], - operator: [aliceIdentity.getPrincipal()], - properties: [["C", {Int32Content: 5678}]], - is_burned: false, - approved_by: [bobIdentity.getPrincipal()], - burned_by: [], - burned_at: [], - token_identifier: BigInt(3), - minted_by: custodianIdentity.getPrincipal() - } - ); - t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(4)), - { - transferred_at: [], - transferred_by: [], - owner: [johnIdentity.getPrincipal()], - operator: [aliceIdentity.getPrincipal()], - properties: [["D", {TextContent: "โˆ†โ‰ˆรงโˆšโˆซ"}]], - is_burned: false, - approved_by: [johnIdentity.getPrincipal()], - burned_by: [], - burned_at: [], - token_identifier: BigInt(4), - minted_by: custodianIdentity.getPrincipal() - } - ); + t.is((result as {Ok: Array}).Ok.length, 1); + t.like((result as {Ok: Array}).Ok[0], { + transferred_at: [], + transferred_by: [], + owner: [bobIdentity.getPrincipal()], + operator: [aliceIdentity.getPrincipal()], + properties: [["C", {Int32Content: 5678}]], + is_burned: false, + approved_by: [bobIdentity.getPrincipal()], + burned_by: [], + burned_at: [], + token_identifier: BigInt(3), + minted_by: custodianIdentity.getPrincipal() + }); } ); - (await Promise.all(allActors.map(actor => actor.operatorTokenMetadata(bobIdentity.getPrincipal())))).forEach( + (await Promise.all(allActors.map(actor => actor.dip721_owner_token_metadata(johnIdentity.getPrincipal())))).forEach( result => { t.true("Ok" in result); t.is((result as {Ok: Array}).Ok.length, 1); t.like((result as {Ok: Array}).Ok[0], { transferred_at: [], transferred_by: [], - owner: [aliceIdentity.getPrincipal()], - operator: [bobIdentity.getPrincipal()], - properties: [["A", {Nat64Content: BigInt(9999)}]], + owner: [johnIdentity.getPrincipal()], + operator: [aliceIdentity.getPrincipal()], + properties: [["D", {TextContent: "โˆ†โ‰ˆรงโˆšโˆซ"}]], is_burned: false, - approved_by: [aliceIdentity.getPrincipal()], + approved_by: [johnIdentity.getPrincipal()], burned_by: [], burned_at: [], - token_identifier: BigInt(1), + token_identifier: BigInt(4), minted_by: custodianIdentity.getPrincipal() }); } ); - (await Promise.all(allActors.map(actor => actor.operatorTokenMetadata(johnIdentity.getPrincipal())))).forEach( + + // verify operator_token_metadata + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_metadata(aliceIdentity.getPrincipal()))) + ).forEach(result => { + t.true("Ok" in result); + t.is((result as {Ok: Array}).Ok.length, 2); + t.like( + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(3)), + { + transferred_at: [], + transferred_by: [], + owner: [bobIdentity.getPrincipal()], + operator: [aliceIdentity.getPrincipal()], + properties: [["C", {Int32Content: 5678}]], + is_burned: false, + approved_by: [bobIdentity.getPrincipal()], + burned_by: [], + burned_at: [], + token_identifier: BigInt(3), + minted_by: custodianIdentity.getPrincipal() + } + ); + t.like( + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(4)), + { + transferred_at: [], + transferred_by: [], + owner: [johnIdentity.getPrincipal()], + operator: [aliceIdentity.getPrincipal()], + properties: [["D", {TextContent: "โˆ†โ‰ˆรงโˆšโˆซ"}]], + is_burned: false, + approved_by: [johnIdentity.getPrincipal()], + burned_by: [], + burned_at: [], + token_identifier: BigInt(4), + minted_by: custodianIdentity.getPrincipal() + } + ); + }); + (await Promise.all(allActors.map(actor => actor.dip721_operator_token_metadata(bobIdentity.getPrincipal())))).forEach( result => { t.true("Ok" in result); t.is((result as {Ok: Array}).Ok.length, 1); @@ -864,95 +867,122 @@ test.serial("verify approve information.", async t => { transferred_at: [], transferred_by: [], owner: [aliceIdentity.getPrincipal()], - operator: [johnIdentity.getPrincipal()], - properties: [["B", {Int64Content: BigInt(1234)}]], + operator: [bobIdentity.getPrincipal()], + properties: [["A", {Nat64Content: BigInt(9999)}]], is_burned: false, approved_by: [aliceIdentity.getPrincipal()], burned_by: [], burned_at: [], - token_identifier: BigInt(2), + token_identifier: BigInt(1), minted_by: custodianIdentity.getPrincipal() }); } ); + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_metadata(johnIdentity.getPrincipal()))) + ).forEach(result => { + t.true("Ok" in result); + t.is((result as {Ok: Array}).Ok.length, 1); + t.like((result as {Ok: Array}).Ok[0], { + transferred_at: [], + transferred_by: [], + owner: [aliceIdentity.getPrincipal()], + operator: [johnIdentity.getPrincipal()], + properties: [["B", {Int64Content: BigInt(1234)}]], + is_burned: false, + approved_by: [aliceIdentity.getPrincipal()], + burned_by: [], + burned_at: [], + token_identifier: BigInt(2), + minted_by: custodianIdentity.getPrincipal() + }); + }); - // verify operatorTokenIdentifiers - (await Promise.all(allActors.map(actor => actor.operatorTokenIdentifiers(aliceIdentity.getPrincipal())))).forEach( - result => { - t.true((result as {Ok: Array}).Ok.includes(BigInt(3))); - t.true((result as {Ok: Array}).Ok.includes(BigInt(4))); - } - ); - (await Promise.all(allActors.map(actor => actor.operatorTokenIdentifiers(bobIdentity.getPrincipal())))).forEach( - result => { - t.deepEqual(result, {Ok: [BigInt(1)]}); - } - ); - (await Promise.all(allActors.map(actor => actor.operatorTokenIdentifiers(johnIdentity.getPrincipal())))).forEach( - result => { - t.deepEqual(result, {Ok: [BigInt(2)]}); - } - ); + // verify operator_token_identifiers + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_identifiers(aliceIdentity.getPrincipal()))) + ).forEach(result => { + t.true((result as {Ok: Array}).Ok.includes(BigInt(3))); + t.true((result as {Ok: Array}).Ok.includes(BigInt(4))); + }); + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_identifiers(bobIdentity.getPrincipal()))) + ).forEach(result => { + t.deepEqual(result, {Ok: [BigInt(1)]}); + }); + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_identifiers(johnIdentity.getPrincipal()))) + ).forEach(result => { + t.deepEqual(result, {Ok: [BigInt(2)]}); + }); }); test.serial("error on self approve or approve non-existed operator.", async t => { - t.deepEqual(await aliceActor.approve(aliceIdentity.getPrincipal(), BigInt(1)), {Err: {SelfApprove: null}}); - t.deepEqual(await aliceActor.approve(aliceIdentity.getPrincipal(), BigInt(2)), {Err: {SelfApprove: null}}); - t.deepEqual(await bobActor.approve(bobIdentity.getPrincipal(), BigInt(3)), {Err: {SelfApprove: null}}); - t.deepEqual(await johnActor.approve(johnIdentity.getPrincipal(), BigInt(4)), {Err: {SelfApprove: null}}); + t.deepEqual(await aliceActor.dip721_approve(aliceIdentity.getPrincipal(), BigInt(1)), {Err: {SelfApprove: null}}); + t.deepEqual(await aliceActor.dip721_approve(aliceIdentity.getPrincipal(), BigInt(2)), {Err: {SelfApprove: null}}); + t.deepEqual(await bobActor.dip721_approve(bobIdentity.getPrincipal(), BigInt(3)), {Err: {SelfApprove: null}}); + t.deepEqual(await johnActor.dip721_approve(johnIdentity.getPrincipal(), BigInt(4)), {Err: {SelfApprove: null}}); - // operatorTokenMetadata error when non-existed operator - (await Promise.all(allActors.map(actor => actor.operatorTokenMetadata(custodianIdentity.getPrincipal())))).forEach( - result => { - t.deepEqual(result, {Err: {OperatorNotFound: null}}); - } - ); + // operator_token_metadata error when non-existed operator + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_metadata(custodianIdentity.getPrincipal()))) + ).forEach(result => { + t.deepEqual(result, {Err: {OperatorNotFound: null}}); + }); - // operatorTokenIdentifiers error when non-existed operator - (await Promise.all(allActors.map(actor => actor.operatorTokenIdentifiers(custodianIdentity.getPrincipal())))).forEach( - result => { - t.deepEqual(result, {Err: {OperatorNotFound: null}}); - } - ); + // operator_token_identifiers error when non-existed operator + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_identifiers(custodianIdentity.getPrincipal()))) + ).forEach(result => { + t.deepEqual(result, {Err: {OperatorNotFound: null}}); + }); }); test.serial("error on unauthorize owner when approve.", async t => { - t.deepEqual(await custodianActor.approve(aliceIdentity.getPrincipal(), BigInt(1)), {Err: {UnauthorizedOwner: null}}); - t.deepEqual(await custodianActor.approve(aliceIdentity.getPrincipal(), BigInt(2)), {Err: {UnauthorizedOwner: null}}); - t.deepEqual(await custodianActor.approve(aliceIdentity.getPrincipal(), BigInt(3)), {Err: {UnauthorizedOwner: null}}); - t.deepEqual(await custodianActor.approve(aliceIdentity.getPrincipal(), BigInt(4)), {Err: {UnauthorizedOwner: null}}); -}); - + t.deepEqual(await custodianActor.dip721_approve(aliceIdentity.getPrincipal(), BigInt(1)), { + Err: {UnauthorizedOwner: null} + }); + t.deepEqual(await custodianActor.dip721_approve(aliceIdentity.getPrincipal(), BigInt(2)), { + Err: {UnauthorizedOwner: null} + }); + t.deepEqual(await custodianActor.dip721_approve(aliceIdentity.getPrincipal(), BigInt(3)), { + Err: {UnauthorizedOwner: null} + }); + t.deepEqual(await custodianActor.dip721_approve(aliceIdentity.getPrincipal(), BigInt(4)), { + Err: {UnauthorizedOwner: null} + }); +}); + test.serial("approve NFTs (new operator).", async t => { - t.deepEqual(await aliceActor.approve(custodianIdentity.getPrincipal(), BigInt(1)), {Ok: BigInt(8)}); - t.deepEqual(await aliceActor.approve(custodianIdentity.getPrincipal(), BigInt(2)), {Ok: BigInt(9)}); - t.deepEqual(await bobActor.approve(custodianIdentity.getPrincipal(), BigInt(3)), {Ok: BigInt(10)}); - t.deepEqual(await johnActor.approve(custodianIdentity.getPrincipal(), BigInt(4)), {Ok: BigInt(11)}); + t.deepEqual(await aliceActor.dip721_approve(custodianIdentity.getPrincipal(), BigInt(1)), {Ok: BigInt(8)}); + t.deepEqual(await aliceActor.dip721_approve(custodianIdentity.getPrincipal(), BigInt(2)), {Ok: BigInt(9)}); + t.deepEqual(await bobActor.dip721_approve(custodianIdentity.getPrincipal(), BigInt(3)), {Ok: BigInt(10)}); + t.deepEqual(await johnActor.dip721_approve(custodianIdentity.getPrincipal(), BigInt(4)), {Ok: BigInt(11)}); }); test.serial("verify stats after approve (new operator).", async t => { - // verify totalTransactions - (await Promise.all(allActors.map(actor => actor.totalTransactions()))).forEach(result => { + // verify total_transactions + (await Promise.all(allActors.map(actor => actor.dip721_total_transactions()))).forEach(result => { t.is(result, BigInt(12)); }); - // verify totalSupply - (await Promise.all(allActors.map(actor => actor.totalSupply()))).forEach(result => { + // verify total_supply + (await Promise.all(allActors.map(actor => actor.dip721_total_supply()))).forEach(result => { t.is(result, BigInt(4)); }); // verify cycles - (await Promise.all(allActors.map(actor => actor.cycles()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_cycles()))).forEach(result => { t.truthy(result); }); // verify totalUniqueHolders - (await Promise.all(allActors.map(actor => actor.totalUniqueHolders()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_total_unique_holders()))).forEach(result => { t.is(result, BigInt(3)); }); // verify stats - (await Promise.all(allActors.map(actor => actor.stats()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_stats()))).forEach(result => { t.truthy(result.cycles); t.is(result.total_transactions, BigInt(12)); t.is(result.total_supply, BigInt(4)); @@ -961,22 +991,22 @@ test.serial("verify stats after approve (new operator).", async t => { }); test.serial("verify approve information after updated to new operator.", async t => { - // verify operatorOf - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(1))))).forEach(result => { + // verify operator_of + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(1))))).forEach(result => { t.deepEqual(result, {Ok: [custodianIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(2))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(2))))).forEach(result => { t.deepEqual(result, {Ok: [custodianIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(3))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(3))))).forEach(result => { t.deepEqual(result, {Ok: [custodianIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(4))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(4))))).forEach(result => { t.deepEqual(result, {Ok: [custodianIdentity.getPrincipal()]}); }); // verify token - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(1))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(1))))).forEach(result => { t.like(result, { Ok: { transferred_at: [], @@ -993,7 +1023,7 @@ test.serial("verify approve information after updated to new operator.", async t } }); }); - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(2))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(2))))).forEach(result => { t.like(result, { Ok: { transferred_at: [], @@ -1010,7 +1040,7 @@ test.serial("verify approve information after updated to new operator.", async t } }); }); - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(3))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(3))))).forEach(result => { t.like(result, { Ok: { transferred_at: [], @@ -1027,7 +1057,7 @@ test.serial("verify approve information after updated to new operator.", async t } }); }); - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(4))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(4))))).forEach(result => { t.like(result, { Ok: { transferred_at: [], @@ -1045,13 +1075,13 @@ test.serial("verify approve information after updated to new operator.", async t }); }); - // verify ownerTokenMetadata - (await Promise.all(allActors.map(actor => actor.ownerTokenMetadata(aliceIdentity.getPrincipal())))).forEach( + // verify owner_token_metadata + (await Promise.all(allActors.map(actor => actor.dip721_owner_token_metadata(aliceIdentity.getPrincipal())))).forEach( result => { t.true("Ok" in result); t.is((result as {Ok: Array}).Ok.length, 2); t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(1)), + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(1)), { transferred_at: [], transferred_by: [], @@ -1067,7 +1097,7 @@ test.serial("verify approve information after updated to new operator.", async t } ); t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(2)), + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(2)), { transferred_at: [], transferred_by: [], @@ -1084,241 +1114,288 @@ test.serial("verify approve information after updated to new operator.", async t ); } ); - (await Promise.all(allActors.map(actor => actor.ownerTokenMetadata(bobIdentity.getPrincipal())))).forEach(result => { - t.true("Ok" in result); - t.is((result as {Ok: Array}).Ok.length, 1); - t.like((result as {Ok: Array}).Ok[0], { - transferred_at: [], - transferred_by: [], - owner: [bobIdentity.getPrincipal()], - operator: [custodianIdentity.getPrincipal()], - properties: [["C", {Int32Content: 5678}]], - is_burned: false, - approved_by: [bobIdentity.getPrincipal()], - burned_by: [], - burned_at: [], - token_identifier: BigInt(3), - minted_by: custodianIdentity.getPrincipal() - }); - }); - (await Promise.all(allActors.map(actor => actor.ownerTokenMetadata(johnIdentity.getPrincipal())))).forEach(result => { - t.true("Ok" in result); - t.is((result as {Ok: Array}).Ok.length, 1); - t.like((result as {Ok: Array}).Ok[0], { - transferred_at: [], - transferred_by: [], - owner: [johnIdentity.getPrincipal()], - operator: [custodianIdentity.getPrincipal()], - properties: [["D", {TextContent: "โˆ†โ‰ˆรงโˆšโˆซ"}]], - is_burned: false, - approved_by: [johnIdentity.getPrincipal()], - burned_by: [], - burned_at: [], - token_identifier: BigInt(4), - minted_by: custodianIdentity.getPrincipal() - }); - }); - - // verify operatorTokenMetadata - (await Promise.all(allActors.map(actor => actor.operatorTokenMetadata(custodianIdentity.getPrincipal())))).forEach( + (await Promise.all(allActors.map(actor => actor.dip721_owner_token_metadata(bobIdentity.getPrincipal())))).forEach( result => { t.true("Ok" in result); - t.is((result as {Ok: Array}).Ok.length, 4); - t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(1)), - { - transferred_at: [], - transferred_by: [], - owner: [aliceIdentity.getPrincipal()], - operator: [custodianIdentity.getPrincipal()], - properties: [["A", {Nat64Content: BigInt(9999)}]], - is_burned: false, - approved_by: [aliceIdentity.getPrincipal()], - burned_by: [], - burned_at: [], - token_identifier: BigInt(1), - minted_by: custodianIdentity.getPrincipal() - } - ); - t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(2)), - { - transferred_at: [], - transferred_by: [], - owner: [aliceIdentity.getPrincipal()], - operator: [custodianIdentity.getPrincipal()], - properties: [["B", {Int64Content: BigInt(1234)}]], - is_burned: false, - approved_by: [aliceIdentity.getPrincipal()], - burned_by: [], - burned_at: [], - token_identifier: BigInt(2), - minted_by: custodianIdentity.getPrincipal() - } - ); - t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(3)), - { - transferred_at: [], - transferred_by: [], - owner: [bobIdentity.getPrincipal()], - operator: [custodianIdentity.getPrincipal()], - properties: [["C", {Int32Content: 5678}]], - is_burned: false, - approved_by: [bobIdentity.getPrincipal()], - burned_by: [], - burned_at: [], - token_identifier: BigInt(3), - minted_by: custodianIdentity.getPrincipal() - } - ); - t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(4)), - { - transferred_at: [], - transferred_by: [], - owner: [johnIdentity.getPrincipal()], - operator: [custodianIdentity.getPrincipal()], - properties: [["D", {TextContent: "โˆ†โ‰ˆรงโˆšโˆซ"}]], - is_burned: false, - approved_by: [johnIdentity.getPrincipal()], - burned_by: [], - burned_at: [], - token_identifier: BigInt(4), - minted_by: custodianIdentity.getPrincipal() - } - ); + t.is((result as {Ok: Array}).Ok.length, 1); + t.like((result as {Ok: Array}).Ok[0], { + transferred_at: [], + transferred_by: [], + owner: [bobIdentity.getPrincipal()], + operator: [custodianIdentity.getPrincipal()], + properties: [["C", {Int32Content: 5678}]], + is_burned: false, + approved_by: [bobIdentity.getPrincipal()], + burned_by: [], + burned_at: [], + token_identifier: BigInt(3), + minted_by: custodianIdentity.getPrincipal() + }); } ); - - // verify operatorTokenIdentifiers - (await Promise.all(allActors.map(actor => actor.operatorTokenIdentifiers(custodianIdentity.getPrincipal())))).forEach( + (await Promise.all(allActors.map(actor => actor.dip721_owner_token_metadata(johnIdentity.getPrincipal())))).forEach( result => { - t.true((result as {Ok: Array}).Ok.includes(BigInt(1))); - t.true((result as {Ok: Array}).Ok.includes(BigInt(2))); - t.true((result as {Ok: Array}).Ok.includes(BigInt(3))); - t.true((result as {Ok: Array}).Ok.includes(BigInt(4))); + t.true("Ok" in result); + t.is((result as {Ok: Array}).Ok.length, 1); + t.like((result as {Ok: Array}).Ok[0], { + transferred_at: [], + transferred_by: [], + owner: [johnIdentity.getPrincipal()], + operator: [custodianIdentity.getPrincipal()], + properties: [["D", {TextContent: "โˆ†โ‰ˆรงโˆšโˆซ"}]], + is_burned: false, + approved_by: [johnIdentity.getPrincipal()], + burned_by: [], + burned_at: [], + token_identifier: BigInt(4), + minted_by: custodianIdentity.getPrincipal() + }); } ); + + // verify operator_token_metadata + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_metadata(custodianIdentity.getPrincipal()))) + ).forEach(result => { + t.true("Ok" in result); + t.is((result as {Ok: Array}).Ok.length, 4); + t.like( + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(1)), + { + transferred_at: [], + transferred_by: [], + owner: [aliceIdentity.getPrincipal()], + operator: [custodianIdentity.getPrincipal()], + properties: [["A", {Nat64Content: BigInt(9999)}]], + is_burned: false, + approved_by: [aliceIdentity.getPrincipal()], + burned_by: [], + burned_at: [], + token_identifier: BigInt(1), + minted_by: custodianIdentity.getPrincipal() + } + ); + t.like( + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(2)), + { + transferred_at: [], + transferred_by: [], + owner: [aliceIdentity.getPrincipal()], + operator: [custodianIdentity.getPrincipal()], + properties: [["B", {Int64Content: BigInt(1234)}]], + is_burned: false, + approved_by: [aliceIdentity.getPrincipal()], + burned_by: [], + burned_at: [], + token_identifier: BigInt(2), + minted_by: custodianIdentity.getPrincipal() + } + ); + t.like( + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(3)), + { + transferred_at: [], + transferred_by: [], + owner: [bobIdentity.getPrincipal()], + operator: [custodianIdentity.getPrincipal()], + properties: [["C", {Int32Content: 5678}]], + is_burned: false, + approved_by: [bobIdentity.getPrincipal()], + burned_by: [], + burned_at: [], + token_identifier: BigInt(3), + minted_by: custodianIdentity.getPrincipal() + } + ); + t.like( + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(4)), + { + transferred_at: [], + transferred_by: [], + owner: [johnIdentity.getPrincipal()], + operator: [custodianIdentity.getPrincipal()], + properties: [["D", {TextContent: "โˆ†โ‰ˆรงโˆšโˆซ"}]], + is_burned: false, + approved_by: [johnIdentity.getPrincipal()], + burned_by: [], + burned_at: [], + token_identifier: BigInt(4), + minted_by: custodianIdentity.getPrincipal() + } + ); + }); + + // verify operator_token_identifiers + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_identifiers(custodianIdentity.getPrincipal()))) + ).forEach(result => { + t.true((result as {Ok: Array}).Ok.includes(BigInt(1))); + t.true((result as {Ok: Array}).Ok.includes(BigInt(2))); + t.true((result as {Ok: Array}).Ok.includes(BigInt(3))); + t.true((result as {Ok: Array}).Ok.includes(BigInt(4))); + }); }); test.serial("error on querying old operator information.", async t => { - // operatorTokenMetadata error when non-existed operator - (await Promise.all(allActors.map(actor => actor.operatorTokenMetadata(aliceIdentity.getPrincipal())))).forEach( - result => { - t.deepEqual(result, {Err: {OperatorNotFound: null}}); - } - ); - (await Promise.all(allActors.map(actor => actor.operatorTokenMetadata(bobIdentity.getPrincipal())))).forEach( - result => { - t.deepEqual(result, {Err: {OperatorNotFound: null}}); - } - ); - (await Promise.all(allActors.map(actor => actor.operatorTokenMetadata(johnIdentity.getPrincipal())))).forEach( + // operator_token_metadata error when non-existed operator + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_metadata(aliceIdentity.getPrincipal()))) + ).forEach(result => { + t.deepEqual(result, {Err: {OperatorNotFound: null}}); + }); + (await Promise.all(allActors.map(actor => actor.dip721_operator_token_metadata(bobIdentity.getPrincipal())))).forEach( result => { t.deepEqual(result, {Err: {OperatorNotFound: null}}); } ); + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_metadata(johnIdentity.getPrincipal()))) + ).forEach(result => { + t.deepEqual(result, {Err: {OperatorNotFound: null}}); + }); - // operatorTokenIdentifiers error when non-existed operator - (await Promise.all(allActors.map(actor => actor.operatorTokenIdentifiers(aliceIdentity.getPrincipal())))).forEach( - result => { - t.deepEqual(result, {Err: {OperatorNotFound: null}}); - } - ); - (await Promise.all(allActors.map(actor => actor.operatorTokenIdentifiers(bobIdentity.getPrincipal())))).forEach( - result => { - t.deepEqual(result, {Err: {OperatorNotFound: null}}); - } - ); - (await Promise.all(allActors.map(actor => actor.operatorTokenIdentifiers(johnIdentity.getPrincipal())))).forEach( - result => { - t.deepEqual(result, {Err: {OperatorNotFound: null}}); - } - ); + // operator_token_identifiers error when non-existed operator + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_identifiers(aliceIdentity.getPrincipal()))) + ).forEach(result => { + t.deepEqual(result, {Err: {OperatorNotFound: null}}); + }); + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_identifiers(bobIdentity.getPrincipal()))) + ).forEach(result => { + t.deepEqual(result, {Err: {OperatorNotFound: null}}); + }); + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_identifiers(johnIdentity.getPrincipal()))) + ).forEach(result => { + t.deepEqual(result, {Err: {OperatorNotFound: null}}); + }); }); -test.serial("error on self transferFrom.", async t => { +test.serial("error on self transfer_from.", async t => { t.deepEqual( - await custodianActor.transferFrom(custodianIdentity.getPrincipal(), custodianIdentity.getPrincipal(), BigInt(1)), + await custodianActor.dip721_transfer_from( + custodianIdentity.getPrincipal(), + custodianIdentity.getPrincipal(), + BigInt(1) + ), { Err: {SelfTransfer: null} } ); - t.deepEqual(await aliceActor.transferFrom(aliceIdentity.getPrincipal(), aliceIdentity.getPrincipal(), BigInt(2)), { - Err: {SelfTransfer: null} - }); - t.deepEqual(await bobActor.transferFrom(bobIdentity.getPrincipal(), bobIdentity.getPrincipal(), BigInt(3)), { - Err: {SelfTransfer: null} - }); - t.deepEqual(await johnActor.transferFrom(johnIdentity.getPrincipal(), johnIdentity.getPrincipal(), BigInt(4)), { + t.deepEqual( + await aliceActor.dip721_transfer_from(aliceIdentity.getPrincipal(), aliceIdentity.getPrincipal(), BigInt(2)), + { + Err: {SelfTransfer: null} + } + ); + t.deepEqual(await bobActor.dip721_transfer_from(bobIdentity.getPrincipal(), bobIdentity.getPrincipal(), BigInt(3)), { Err: {SelfTransfer: null} }); + t.deepEqual( + await johnActor.dip721_transfer_from(johnIdentity.getPrincipal(), johnIdentity.getPrincipal(), BigInt(4)), + { + Err: {SelfTransfer: null} + } + ); }); // invalid owner -test.serial("error on unauthorized owner when calling transferFrom.", async t => { +test.serial("error on unauthorized owner when calling transfer_from.", async t => { t.deepEqual( - await custodianActor.transferFrom(custodianIdentity.getPrincipal(), aliceIdentity.getPrincipal(), BigInt(1)), + await custodianActor.dip721_transfer_from( + custodianIdentity.getPrincipal(), + aliceIdentity.getPrincipal(), + BigInt(1) + ), { Err: {UnauthorizedOwner: null} } ); t.deepEqual( - await aliceActor.transferFrom(custodianIdentity.getPrincipal(), aliceIdentity.getPrincipal(), BigInt(2)), + await aliceActor.dip721_transfer_from(custodianIdentity.getPrincipal(), aliceIdentity.getPrincipal(), BigInt(2)), + { + Err: {UnauthorizedOwner: null} + } + ); + t.deepEqual( + await bobActor.dip721_transfer_from(custodianIdentity.getPrincipal(), bobIdentity.getPrincipal(), BigInt(3)), + { + Err: {UnauthorizedOwner: null} + } + ); + t.deepEqual( + await johnActor.dip721_transfer_from(custodianIdentity.getPrincipal(), johnIdentity.getPrincipal(), BigInt(4)), { Err: {UnauthorizedOwner: null} } ); - t.deepEqual(await bobActor.transferFrom(custodianIdentity.getPrincipal(), bobIdentity.getPrincipal(), BigInt(3)), { - Err: {UnauthorizedOwner: null} - }); - t.deepEqual(await johnActor.transferFrom(custodianIdentity.getPrincipal(), johnIdentity.getPrincipal(), BigInt(4)), { - Err: {UnauthorizedOwner: null} - }); }); // invalid operator -test.serial("error on unauthorized operator when calling transferFrom.", async t => { - t.deepEqual(await bobActor.transferFrom(aliceIdentity.getPrincipal(), custodianIdentity.getPrincipal(), BigInt(1)), { - Err: {UnauthorizedOperator: null} - }); - t.deepEqual(await bobActor.transferFrom(aliceIdentity.getPrincipal(), custodianIdentity.getPrincipal(), BigInt(2)), { - Err: {UnauthorizedOperator: null} - }); - t.deepEqual(await johnActor.transferFrom(bobIdentity.getPrincipal(), custodianIdentity.getPrincipal(), BigInt(3)), { - Err: {UnauthorizedOperator: null} - }); - t.deepEqual(await aliceActor.transferFrom(johnIdentity.getPrincipal(), custodianIdentity.getPrincipal(), BigInt(4)), { - Err: {UnauthorizedOperator: null} - }); +test.serial("error on unauthorized operator when calling transfer_from.", async t => { + t.deepEqual( + await bobActor.dip721_transfer_from(aliceIdentity.getPrincipal(), custodianIdentity.getPrincipal(), BigInt(1)), + { + Err: {UnauthorizedOperator: null} + } + ); + t.deepEqual( + await bobActor.dip721_transfer_from(aliceIdentity.getPrincipal(), custodianIdentity.getPrincipal(), BigInt(2)), + { + Err: {UnauthorizedOperator: null} + } + ); + t.deepEqual( + await johnActor.dip721_transfer_from(bobIdentity.getPrincipal(), custodianIdentity.getPrincipal(), BigInt(3)), + { + Err: {UnauthorizedOperator: null} + } + ); + t.deepEqual( + await aliceActor.dip721_transfer_from(johnIdentity.getPrincipal(), custodianIdentity.getPrincipal(), BigInt(4)), + { + Err: {UnauthorizedOperator: null} + } + ); }); -test.serial("transferFrom.", async t => { +test.serial("transfer_from.", async t => { t.deepEqual( - await custodianActor.transferFrom(aliceIdentity.getPrincipal(), custodianIdentity.getPrincipal(), BigInt(1)), + await custodianActor.dip721_transfer_from( + aliceIdentity.getPrincipal(), + custodianIdentity.getPrincipal(), + BigInt(1) + ), { Ok: BigInt(12) } ); t.deepEqual( - await custodianActor.transferFrom(aliceIdentity.getPrincipal(), custodianIdentity.getPrincipal(), BigInt(2)), + await custodianActor.dip721_transfer_from( + aliceIdentity.getPrincipal(), + custodianIdentity.getPrincipal(), + BigInt(2) + ), { Ok: BigInt(13) } ); t.deepEqual( - await custodianActor.transferFrom(bobIdentity.getPrincipal(), custodianIdentity.getPrincipal(), BigInt(3)), + await custodianActor.dip721_transfer_from(bobIdentity.getPrincipal(), custodianIdentity.getPrincipal(), BigInt(3)), { Ok: BigInt(14) } ); - t.deepEqual(await custodianActor.transferFrom(johnIdentity.getPrincipal(), aliceIdentity.getPrincipal(), BigInt(4)), { - Ok: BigInt(15) - }); + t.deepEqual( + await custodianActor.dip721_transfer_from(johnIdentity.getPrincipal(), aliceIdentity.getPrincipal(), BigInt(4)), + { + Ok: BigInt(15) + } + ); }); -test.serial("verify transactions after transferFrom.", async t => { +test.serial("verify transactions after transfer_from.", async t => { const txns = await testTxns([ { id: "12", @@ -1375,29 +1452,29 @@ test.serial("verify transactions after transferFrom.", async t => { }); }); -test.serial("verify stats after transferFrom.", async t => { - // verify totalTransactions - (await Promise.all(allActors.map(actor => actor.totalTransactions()))).forEach(result => { +test.serial("verify stats after transfer_from.", async t => { + // verify total_transactions + (await Promise.all(allActors.map(actor => actor.dip721_total_transactions()))).forEach(result => { t.is(result, BigInt(16)); }); - // verify totalSupply - (await Promise.all(allActors.map(actor => actor.totalSupply()))).forEach(result => { + // verify total_supply + (await Promise.all(allActors.map(actor => actor.dip721_total_supply()))).forEach(result => { t.is(result, BigInt(4)); }); // verify cycles - (await Promise.all(allActors.map(actor => actor.cycles()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_cycles()))).forEach(result => { t.truthy(result); }); // verify totalUniqueHolders - (await Promise.all(allActors.map(actor => actor.totalUniqueHolders()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_total_unique_holders()))).forEach(result => { t.is(result, BigInt(2)); }); // verify stats - (await Promise.all(allActors.map(actor => actor.stats()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_stats()))).forEach(result => { t.truthy(result.cycles); t.is(result.total_transactions, BigInt(16)); t.is(result.total_supply, BigInt(4)); @@ -1405,45 +1482,47 @@ test.serial("verify stats after transferFrom.", async t => { }); }); -test.serial("verify transferFrom information.", async t => { - // verify balanceOf - (await Promise.all(allActors.map(actor => actor.balanceOf(aliceIdentity.getPrincipal())))).forEach(result => { +test.serial("verify transfer_from information.", async t => { + // verify balance_of + (await Promise.all(allActors.map(actor => actor.dip721_balance_of(aliceIdentity.getPrincipal())))).forEach(result => { t.deepEqual(result, {Ok: BigInt(1)}); }); - (await Promise.all(allActors.map(actor => actor.balanceOf(custodianIdentity.getPrincipal())))).forEach(result => { - t.deepEqual(result, {Ok: BigInt(3)}); - }); + (await Promise.all(allActors.map(actor => actor.dip721_balance_of(custodianIdentity.getPrincipal())))).forEach( + result => { + t.deepEqual(result, {Ok: BigInt(3)}); + } + ); - // verify ownerOf - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(1))))).forEach(result => { + // verify owner_of + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(1))))).forEach(result => { t.deepEqual(result, {Ok: [custodianIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(2))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(2))))).forEach(result => { t.deepEqual(result, {Ok: [custodianIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(3))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(3))))).forEach(result => { t.deepEqual(result, {Ok: [custodianIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(4))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(4))))).forEach(result => { t.deepEqual(result, {Ok: [aliceIdentity.getPrincipal()]}); }); - // verify operatorOf - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(1))))).forEach(result => { + // verify operator_of + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(1))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(2))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(2))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(3))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(3))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(4))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(4))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); // verify token - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(1))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(1))))).forEach(result => { t.like(result, { Ok: { owner: [custodianIdentity.getPrincipal()], @@ -1459,7 +1538,7 @@ test.serial("verify transferFrom information.", async t => { } }); }); - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(2))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(2))))).forEach(result => { t.like(result, { Ok: { owner: [custodianIdentity.getPrincipal()], @@ -1475,7 +1554,7 @@ test.serial("verify transferFrom information.", async t => { } }); }); - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(3))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(3))))).forEach(result => { t.like(result, { Ok: { owner: [custodianIdentity.getPrincipal()], @@ -1491,7 +1570,7 @@ test.serial("verify transferFrom information.", async t => { } }); }); - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(4))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(4))))).forEach(result => { t.like(result, { Ok: { owner: [aliceIdentity.getPrincipal()], @@ -1508,8 +1587,8 @@ test.serial("verify transferFrom information.", async t => { }); }); - // verify ownerTokenMetadata - (await Promise.all(allActors.map(actor => actor.ownerTokenMetadata(aliceIdentity.getPrincipal())))).forEach( + // verify owner_token_metadata + (await Promise.all(allActors.map(actor => actor.dip721_owner_token_metadata(aliceIdentity.getPrincipal())))).forEach( result => { t.true("Ok" in result); t.is((result as {Ok: Array}).Ok.length, 1); @@ -1520,122 +1599,122 @@ test.serial("verify transferFrom information.", async t => { is_burned: false, approved_by: [johnIdentity.getPrincipal()], burned_by: [], - burned_at: [], - token_identifier: BigInt(4), - minted_by: custodianIdentity.getPrincipal(), - transferred_by: [custodianIdentity.getPrincipal()] - }); - } - ); - (await Promise.all(allActors.map(actor => actor.ownerTokenMetadata(custodianIdentity.getPrincipal())))).forEach( - result => { - t.true("Ok" in result); - t.is((result as {Ok: Array}).Ok.length, 3); - t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(1)), - { - owner: [custodianIdentity.getPrincipal()], - operator: [], - properties: [["A", {Nat64Content: BigInt(9999)}]], - is_burned: false, - approved_by: [aliceIdentity.getPrincipal()], - burned_by: [], - burned_at: [], - token_identifier: BigInt(1), - minted_by: custodianIdentity.getPrincipal(), - transferred_by: [custodianIdentity.getPrincipal()] - } - ); - t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(2)), - { - owner: [custodianIdentity.getPrincipal()], - operator: [], - properties: [["B", {Int64Content: BigInt(1234)}]], - is_burned: false, - approved_by: [aliceIdentity.getPrincipal()], - burned_by: [], - burned_at: [], - token_identifier: BigInt(2), - minted_by: custodianIdentity.getPrincipal(), - transferred_by: [custodianIdentity.getPrincipal()] - } - ); - t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(3)), - { - owner: [custodianIdentity.getPrincipal()], - operator: [], - properties: [["C", {Int32Content: 5678}]], - is_burned: false, - approved_by: [bobIdentity.getPrincipal()], - burned_by: [], - burned_at: [], - token_identifier: BigInt(3), - minted_by: custodianIdentity.getPrincipal(), - transferred_by: [custodianIdentity.getPrincipal()] - } - ); + burned_at: [], + token_identifier: BigInt(4), + minted_by: custodianIdentity.getPrincipal(), + transferred_by: [custodianIdentity.getPrincipal()] + }); } ); + ( + await Promise.all(allActors.map(actor => actor.dip721_owner_token_metadata(custodianIdentity.getPrincipal()))) + ).forEach(result => { + t.true("Ok" in result); + t.is((result as {Ok: Array}).Ok.length, 3); + t.like( + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(1)), + { + owner: [custodianIdentity.getPrincipal()], + operator: [], + properties: [["A", {Nat64Content: BigInt(9999)}]], + is_burned: false, + approved_by: [aliceIdentity.getPrincipal()], + burned_by: [], + burned_at: [], + token_identifier: BigInt(1), + minted_by: custodianIdentity.getPrincipal(), + transferred_by: [custodianIdentity.getPrincipal()] + } + ); + t.like( + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(2)), + { + owner: [custodianIdentity.getPrincipal()], + operator: [], + properties: [["B", {Int64Content: BigInt(1234)}]], + is_burned: false, + approved_by: [aliceIdentity.getPrincipal()], + burned_by: [], + burned_at: [], + token_identifier: BigInt(2), + minted_by: custodianIdentity.getPrincipal(), + transferred_by: [custodianIdentity.getPrincipal()] + } + ); + t.like( + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(3)), + { + owner: [custodianIdentity.getPrincipal()], + operator: [], + properties: [["C", {Int32Content: 5678}]], + is_burned: false, + approved_by: [bobIdentity.getPrincipal()], + burned_by: [], + burned_at: [], + token_identifier: BigInt(3), + minted_by: custodianIdentity.getPrincipal(), + transferred_by: [custodianIdentity.getPrincipal()] + } + ); + }); - // verify ownerTokenIdentifiers - (await Promise.all(allActors.map(actor => actor.ownerTokenIdentifiers(aliceIdentity.getPrincipal())))).forEach( - result => { - t.deepEqual(result, {Ok: [BigInt(4)]}); - } - ); - (await Promise.all(allActors.map(actor => actor.ownerTokenIdentifiers(custodianIdentity.getPrincipal())))).forEach( - result => { - t.true((result as {Ok: Array}).Ok.includes(BigInt(1))); - t.true((result as {Ok: Array}).Ok.includes(BigInt(2))); - t.true((result as {Ok: Array}).Ok.includes(BigInt(3))); - } - ); + // verify owner_token_identifiers + ( + await Promise.all(allActors.map(actor => actor.dip721_owner_token_identifiers(aliceIdentity.getPrincipal()))) + ).forEach(result => { + t.deepEqual(result, {Ok: [BigInt(4)]}); + }); + ( + await Promise.all(allActors.map(actor => actor.dip721_owner_token_identifiers(custodianIdentity.getPrincipal()))) + ).forEach(result => { + t.true((result as {Ok: Array}).Ok.includes(BigInt(1))); + t.true((result as {Ok: Array}).Ok.includes(BigInt(2))); + t.true((result as {Ok: Array}).Ok.includes(BigInt(3))); + }); }); test.serial("error on self transfer.", async t => { - t.deepEqual(await custodianActor.transfer(custodianIdentity.getPrincipal(), BigInt(1)), { + t.deepEqual(await custodianActor.dip721_transfer(custodianIdentity.getPrincipal(), BigInt(1)), { Err: {SelfTransfer: null} }); - t.deepEqual(await aliceActor.transfer(aliceIdentity.getPrincipal(), BigInt(2)), { + t.deepEqual(await aliceActor.dip721_transfer(aliceIdentity.getPrincipal(), BigInt(2)), { Err: {SelfTransfer: null} }); - t.deepEqual(await bobActor.transfer(bobIdentity.getPrincipal(), BigInt(3)), { + t.deepEqual(await bobActor.dip721_transfer(bobIdentity.getPrincipal(), BigInt(3)), { Err: {SelfTransfer: null} }); - t.deepEqual(await johnActor.transfer(johnIdentity.getPrincipal(), BigInt(4)), { + t.deepEqual(await johnActor.dip721_transfer(johnIdentity.getPrincipal(), BigInt(4)), { Err: {SelfTransfer: null} }); }); // invalid owner test.serial("error on unauthorized owner when calling transfer.", async t => { - t.deepEqual(await aliceActor.transfer(custodianIdentity.getPrincipal(), BigInt(1)), { + t.deepEqual(await aliceActor.dip721_transfer(custodianIdentity.getPrincipal(), BigInt(1)), { Err: {UnauthorizedOwner: null} }); - t.deepEqual(await aliceActor.transfer(custodianIdentity.getPrincipal(), BigInt(2)), { + t.deepEqual(await aliceActor.dip721_transfer(custodianIdentity.getPrincipal(), BigInt(2)), { Err: {UnauthorizedOwner: null} }); - t.deepEqual(await bobActor.transfer(custodianIdentity.getPrincipal(), BigInt(3)), { + t.deepEqual(await bobActor.dip721_transfer(custodianIdentity.getPrincipal(), BigInt(3)), { Err: {UnauthorizedOwner: null} }); - t.deepEqual(await johnActor.transfer(custodianIdentity.getPrincipal(), BigInt(4)), { + t.deepEqual(await johnActor.dip721_transfer(custodianIdentity.getPrincipal(), BigInt(4)), { Err: {UnauthorizedOwner: null} }); }); test.serial("transfer.", async t => { - t.deepEqual(await custodianActor.transfer(johnIdentity.getPrincipal(), BigInt(1)), { + t.deepEqual(await custodianActor.dip721_transfer(johnIdentity.getPrincipal(), BigInt(1)), { Ok: BigInt(16) }); - t.deepEqual(await custodianActor.transfer(johnIdentity.getPrincipal(), BigInt(2)), { + t.deepEqual(await custodianActor.dip721_transfer(johnIdentity.getPrincipal(), BigInt(2)), { Ok: BigInt(17) }); - t.deepEqual(await custodianActor.transfer(bobIdentity.getPrincipal(), BigInt(3)), { + t.deepEqual(await custodianActor.dip721_transfer(bobIdentity.getPrincipal(), BigInt(3)), { Ok: BigInt(18) }); - t.deepEqual(await aliceActor.transfer(bobIdentity.getPrincipal(), BigInt(4)), { + t.deepEqual(await aliceActor.dip721_transfer(bobIdentity.getPrincipal(), BigInt(4)), { Ok: BigInt(19) }); }); @@ -1694,28 +1773,28 @@ test.serial("verify transactions after transfer.", async t => { }); test.serial("verify stats after transfer.", async t => { - // verify totalTransactions - (await Promise.all(allActors.map(actor => actor.totalTransactions()))).forEach(result => { + // verify total_transactions + (await Promise.all(allActors.map(actor => actor.dip721_total_transactions()))).forEach(result => { t.is(result, BigInt(20)); }); - // verify totalSupply - (await Promise.all(allActors.map(actor => actor.totalSupply()))).forEach(result => { + // verify total_supply + (await Promise.all(allActors.map(actor => actor.dip721_total_supply()))).forEach(result => { t.is(result, BigInt(4)); }); // verify cycles - (await Promise.all(allActors.map(actor => actor.cycles()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_cycles()))).forEach(result => { t.truthy(result); }); // verify totalUniqueHolders - (await Promise.all(allActors.map(actor => actor.totalUniqueHolders()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_total_unique_holders()))).forEach(result => { t.is(result, BigInt(2)); }); // verify stats - (await Promise.all(allActors.map(actor => actor.stats()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_stats()))).forEach(result => { t.truthy(result.cycles); t.is(result.total_transactions, BigInt(20)); t.is(result.total_supply, BigInt(4)); @@ -1724,44 +1803,44 @@ test.serial("verify stats after transfer.", async t => { }); test.serial("verify transfer information.", async t => { - // verify balanceOf - (await Promise.all(allActors.map(actor => actor.balanceOf(bobIdentity.getPrincipal())))).forEach(result => { + // verify balance_of + (await Promise.all(allActors.map(actor => actor.dip721_balance_of(bobIdentity.getPrincipal())))).forEach(result => { t.deepEqual(result, {Ok: BigInt(2)}); }); - (await Promise.all(allActors.map(actor => actor.balanceOf(johnIdentity.getPrincipal())))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_balance_of(johnIdentity.getPrincipal())))).forEach(result => { t.deepEqual(result, {Ok: BigInt(2)}); }); - // verify ownerOf - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(1))))).forEach(result => { + // verify owner_of + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(1))))).forEach(result => { t.deepEqual(result, {Ok: [johnIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(2))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(2))))).forEach(result => { t.deepEqual(result, {Ok: [johnIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(3))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(3))))).forEach(result => { t.deepEqual(result, {Ok: [bobIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(4))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(4))))).forEach(result => { t.deepEqual(result, {Ok: [bobIdentity.getPrincipal()]}); }); - // verify operatorOf - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(1))))).forEach(result => { + // verify operator_of + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(1))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(2))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(2))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(3))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(3))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(4))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(4))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); // verify token - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(1))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(1))))).forEach(result => { t.like(result, { Ok: { owner: [johnIdentity.getPrincipal()], @@ -1777,7 +1856,7 @@ test.serial("verify transfer information.", async t => { } }); }); - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(2))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(2))))).forEach(result => { t.like(result, { Ok: { owner: [johnIdentity.getPrincipal()], @@ -1793,7 +1872,7 @@ test.serial("verify transfer information.", async t => { } }); }); - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(3))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(3))))).forEach(result => { t.like(result, { Ok: { owner: [bobIdentity.getPrincipal()], @@ -1809,7 +1888,7 @@ test.serial("verify transfer information.", async t => { } }); }); - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(4))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(4))))).forEach(result => { t.like(result, { Ok: { owner: [bobIdentity.getPrincipal()], @@ -1826,84 +1905,88 @@ test.serial("verify transfer information.", async t => { }); }); - // verify ownerTokenMetadata - (await Promise.all(allActors.map(actor => actor.ownerTokenMetadata(johnIdentity.getPrincipal())))).forEach(result => { - t.true("Ok" in result); - t.is((result as {Ok: Array}).Ok.length, 2); - t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(1)), - { - owner: [johnIdentity.getPrincipal()], - operator: [], - properties: [["A", {Nat64Content: BigInt(9999)}]], - is_burned: false, - approved_by: [aliceIdentity.getPrincipal()], - burned_by: [], - burned_at: [], - token_identifier: BigInt(1), - minted_by: custodianIdentity.getPrincipal(), - transferred_by: [custodianIdentity.getPrincipal()] - } - ); - t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(2)), - { - owner: [johnIdentity.getPrincipal()], - operator: [], - properties: [["B", {Int64Content: BigInt(1234)}]], - is_burned: false, - approved_by: [aliceIdentity.getPrincipal()], - burned_by: [], - burned_at: [], - token_identifier: BigInt(2), - minted_by: custodianIdentity.getPrincipal(), - transferred_by: [custodianIdentity.getPrincipal()] - } - ); - }); - (await Promise.all(allActors.map(actor => actor.ownerTokenMetadata(bobIdentity.getPrincipal())))).forEach(result => { - t.true("Ok" in result); - t.is((result as {Ok: Array}).Ok.length, 2); - t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(3)), - { - owner: [bobIdentity.getPrincipal()], - operator: [], - properties: [["C", {Int32Content: 5678}]], - is_burned: false, - approved_by: [bobIdentity.getPrincipal()], - burned_by: [], - burned_at: [], - token_identifier: BigInt(3), - minted_by: custodianIdentity.getPrincipal(), - transferred_by: [custodianIdentity.getPrincipal()] - } - ); - t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(4)), - { - owner: [bobIdentity.getPrincipal()], - operator: [], - properties: [["D", {TextContent: "โˆ†โ‰ˆรงโˆšโˆซ"}]], - is_burned: false, - approved_by: [johnIdentity.getPrincipal()], - burned_by: [], - burned_at: [], - token_identifier: BigInt(4), - minted_by: custodianIdentity.getPrincipal(), - transferred_by: [aliceIdentity.getPrincipal()] - } - ); - }); - - // verify ownerTokenIdentifiers - (await Promise.all(allActors.map(actor => actor.ownerTokenIdentifiers(johnIdentity.getPrincipal())))).forEach( + // verify owner_token_metadata + (await Promise.all(allActors.map(actor => actor.dip721_owner_token_metadata(johnIdentity.getPrincipal())))).forEach( + result => { + t.true("Ok" in result); + t.is((result as {Ok: Array}).Ok.length, 2); + t.like( + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(1)), + { + owner: [johnIdentity.getPrincipal()], + operator: [], + properties: [["A", {Nat64Content: BigInt(9999)}]], + is_burned: false, + approved_by: [aliceIdentity.getPrincipal()], + burned_by: [], + burned_at: [], + token_identifier: BigInt(1), + minted_by: custodianIdentity.getPrincipal(), + transferred_by: [custodianIdentity.getPrincipal()] + } + ); + t.like( + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(2)), + { + owner: [johnIdentity.getPrincipal()], + operator: [], + properties: [["B", {Int64Content: BigInt(1234)}]], + is_burned: false, + approved_by: [aliceIdentity.getPrincipal()], + burned_by: [], + burned_at: [], + token_identifier: BigInt(2), + minted_by: custodianIdentity.getPrincipal(), + transferred_by: [custodianIdentity.getPrincipal()] + } + ); + } + ); + (await Promise.all(allActors.map(actor => actor.dip721_owner_token_metadata(bobIdentity.getPrincipal())))).forEach( result => { - t.true((result as {Ok: Array}).Ok.includes(BigInt(1))); - t.true((result as {Ok: Array}).Ok.includes(BigInt(2))); + t.true("Ok" in result); + t.is((result as {Ok: Array}).Ok.length, 2); + t.like( + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(3)), + { + owner: [bobIdentity.getPrincipal()], + operator: [], + properties: [["C", {Int32Content: 5678}]], + is_burned: false, + approved_by: [bobIdentity.getPrincipal()], + burned_by: [], + burned_at: [], + token_identifier: BigInt(3), + minted_by: custodianIdentity.getPrincipal(), + transferred_by: [custodianIdentity.getPrincipal()] + } + ); + t.like( + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(4)), + { + owner: [bobIdentity.getPrincipal()], + operator: [], + properties: [["D", {TextContent: "โˆ†โ‰ˆรงโˆšโˆซ"}]], + is_burned: false, + approved_by: [johnIdentity.getPrincipal()], + burned_by: [], + burned_at: [], + token_identifier: BigInt(4), + minted_by: custodianIdentity.getPrincipal(), + transferred_by: [aliceIdentity.getPrincipal()] + } + ); } ); - (await Promise.all(allActors.map(actor => actor.ownerTokenIdentifiers(bobIdentity.getPrincipal())))).forEach( + + // verify owner_token_identifiers + ( + await Promise.all(allActors.map(actor => actor.dip721_owner_token_identifiers(johnIdentity.getPrincipal()))) + ).forEach(result => { + t.true((result as {Ok: Array}).Ok.includes(BigInt(1))); + t.true((result as {Ok: Array}).Ok.includes(BigInt(2))); + }); + (await Promise.all(allActors.map(actor => actor.dip721_owner_token_identifiers(bobIdentity.getPrincipal())))).forEach( result => { t.true((result as {Ok: Array}).Ok.includes(BigInt(3))); t.true((result as {Ok: Array}).Ok.includes(BigInt(4))); @@ -1911,20 +1994,24 @@ test.serial("verify transfer information.", async t => { ); }); -test.serial("setApprovalForAll(true).", async t => { - t.deepEqual(await bobActor.setApprovalForAll(johnIdentity.getPrincipal(), true), {Ok: BigInt(20)}); - t.deepEqual(await johnActor.setApprovalForAll(bobIdentity.getPrincipal(), true), {Ok: BigInt(21)}); +test.serial("set_approval_for_all(true).", async t => { + t.deepEqual(await bobActor.dip721_set_approval_for_all(johnIdentity.getPrincipal(), true), {Ok: BigInt(20)}); + t.deepEqual(await johnActor.dip721_set_approval_for_all(bobIdentity.getPrincipal(), true), {Ok: BigInt(21)}); - // verify isApprovedForAll + // verify is_approved_for_all ( await Promise.all([ - ...allActors.map(actor => actor.isApprovedForAll(bobIdentity.getPrincipal(), johnIdentity.getPrincipal())), - ...allActors.map(actor => actor.isApprovedForAll(johnIdentity.getPrincipal(), bobIdentity.getPrincipal())) + ...allActors.map(actor => + actor.dip721_is_approved_for_all(bobIdentity.getPrincipal(), johnIdentity.getPrincipal()) + ), + ...allActors.map(actor => + actor.dip721_is_approved_for_all(johnIdentity.getPrincipal(), bobIdentity.getPrincipal()) + ) ]) ).forEach(result => t.deepEqual(result, {Ok: true})); }); -test.serial("verify transactions after SetApprovalForAll(true).", async t => { +test.serial("verify transactions after Set_approval_for_all(true).", async t => { const txns = await testTxns([ { id: "20", @@ -1955,29 +2042,29 @@ test.serial("verify transactions after SetApprovalForAll(true).", async t => { }); }); -test.serial("verify stats after setApprovalForAll(true).", async t => { - // verify totalTransactions - (await Promise.all(allActors.map(actor => actor.totalTransactions()))).forEach(result => { +test.serial("verify stats after set_approval_for_all(true).", async t => { + // verify total_transactions + (await Promise.all(allActors.map(actor => actor.dip721_total_transactions()))).forEach(result => { t.is(result, BigInt(22)); }); - // verify totalSupply - (await Promise.all(allActors.map(actor => actor.totalSupply()))).forEach(result => { + // verify total_supply + (await Promise.all(allActors.map(actor => actor.dip721_total_supply()))).forEach(result => { t.is(result, BigInt(4)); }); // verify cycles - (await Promise.all(allActors.map(actor => actor.cycles()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_cycles()))).forEach(result => { t.truthy(result); }); // verify totalUniqueHolders - (await Promise.all(allActors.map(actor => actor.totalUniqueHolders()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_total_unique_holders()))).forEach(result => { t.is(result, BigInt(2)); }); // verify stats - (await Promise.all(allActors.map(actor => actor.stats()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_stats()))).forEach(result => { t.truthy(result.cycles); t.is(result.total_transactions, BigInt(22)); t.is(result.total_supply, BigInt(4)); @@ -1985,45 +2072,45 @@ test.serial("verify stats after setApprovalForAll(true).", async t => { }); }); -test.serial("verify setApprovalForAll(true) information.", async t => { - // verify balanceOf - (await Promise.all(allActors.map(actor => actor.balanceOf(bobIdentity.getPrincipal())))).forEach(result => { +test.serial("verify set_approval_for_all(true) information.", async t => { + // verify balance_of + (await Promise.all(allActors.map(actor => actor.dip721_balance_of(bobIdentity.getPrincipal())))).forEach(result => { t.deepEqual(result, {Ok: BigInt(2)}); }); - (await Promise.all(allActors.map(actor => actor.balanceOf(johnIdentity.getPrincipal())))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_balance_of(johnIdentity.getPrincipal())))).forEach(result => { t.deepEqual(result, {Ok: BigInt(2)}); }); - // verify ownerOf - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(1))))).forEach(result => { + // verify owner_of + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(1))))).forEach(result => { t.deepEqual(result, {Ok: [johnIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(2))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(2))))).forEach(result => { t.deepEqual(result, {Ok: [johnIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(3))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(3))))).forEach(result => { t.deepEqual(result, {Ok: [bobIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(4))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(4))))).forEach(result => { t.deepEqual(result, {Ok: [bobIdentity.getPrincipal()]}); }); - // verify operatorOf - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(1))))).forEach(result => { + // verify operator_of + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(1))))).forEach(result => { t.deepEqual(result, {Ok: [bobIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(2))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(2))))).forEach(result => { t.deepEqual(result, {Ok: [bobIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(3))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(3))))).forEach(result => { t.deepEqual(result, {Ok: [johnIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(4))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(4))))).forEach(result => { t.deepEqual(result, {Ok: [johnIdentity.getPrincipal()]}); }); // verify token - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(1))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(1))))).forEach(result => { t.like(result, { Ok: { owner: [johnIdentity.getPrincipal()], @@ -2038,78 +2125,10 @@ test.serial("verify setApprovalForAll(true) information.", async t => { transferred_by: [custodianIdentity.getPrincipal()] } }); - }); - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(2))))).forEach(result => { - t.like(result, { - Ok: { - owner: [johnIdentity.getPrincipal()], - operator: [bobIdentity.getPrincipal()], - properties: [["B", {Int64Content: BigInt(1234)}]], - is_burned: false, - approved_by: [johnIdentity.getPrincipal()], - burned_by: [], - burned_at: [], - token_identifier: BigInt(2), - minted_by: custodianIdentity.getPrincipal(), - transferred_by: [custodianIdentity.getPrincipal()] - } - }); - }); - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(3))))).forEach(result => { - t.like(result, { - Ok: { - owner: [bobIdentity.getPrincipal()], - operator: [johnIdentity.getPrincipal()], - properties: [["C", {Int32Content: 5678}]], - is_burned: false, - approved_by: [bobIdentity.getPrincipal()], - burned_by: [], - burned_at: [], - token_identifier: BigInt(3), - minted_by: custodianIdentity.getPrincipal(), - transferred_by: [custodianIdentity.getPrincipal()] - } - }); - }); - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(4))))).forEach(result => { - t.like(result, { - Ok: { - owner: [bobIdentity.getPrincipal()], - operator: [johnIdentity.getPrincipal()], - properties: [["D", {TextContent: "โˆ†โ‰ˆรงโˆšโˆซ"}]], - is_burned: false, - approved_by: [bobIdentity.getPrincipal()], - burned_by: [], - burned_at: [], - token_identifier: BigInt(4), - minted_by: custodianIdentity.getPrincipal(), - transferred_by: [aliceIdentity.getPrincipal()] - } - }); - }); - - // verify ownerTokenMetadata - (await Promise.all(allActors.map(actor => actor.ownerTokenMetadata(johnIdentity.getPrincipal())))).forEach(result => { - t.true("Ok" in result); - t.is((result as {Ok: Array}).Ok.length, 2); - t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(1)), - { - owner: [johnIdentity.getPrincipal()], - operator: [bobIdentity.getPrincipal()], - properties: [["A", {Nat64Content: BigInt(9999)}]], - is_burned: false, - approved_by: [johnIdentity.getPrincipal()], - burned_by: [], - burned_at: [], - token_identifier: BigInt(1), - minted_by: custodianIdentity.getPrincipal(), - transferred_by: [custodianIdentity.getPrincipal()] - } - ); - t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(2)), - { + }); + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(2))))).forEach(result => { + t.like(result, { + Ok: { owner: [johnIdentity.getPrincipal()], operator: [bobIdentity.getPrincipal()], properties: [["B", {Int64Content: BigInt(1234)}]], @@ -2121,14 +2140,11 @@ test.serial("verify setApprovalForAll(true) information.", async t => { minted_by: custodianIdentity.getPrincipal(), transferred_by: [custodianIdentity.getPrincipal()] } - ); + }); }); - (await Promise.all(allActors.map(actor => actor.ownerTokenMetadata(bobIdentity.getPrincipal())))).forEach(result => { - t.true("Ok" in result); - t.is((result as {Ok: Array}).Ok.length, 2); - t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(3)), - { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(3))))).forEach(result => { + t.like(result, { + Ok: { owner: [bobIdentity.getPrincipal()], operator: [johnIdentity.getPrincipal()], properties: [["C", {Int32Content: 5678}]], @@ -2140,10 +2156,11 @@ test.serial("verify setApprovalForAll(true) information.", async t => { minted_by: custodianIdentity.getPrincipal(), transferred_by: [custodianIdentity.getPrincipal()] } - ); - t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(4)), - { + }); + }); + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(4))))).forEach(result => { + t.like(result, { + Ok: { owner: [bobIdentity.getPrincipal()], operator: [johnIdentity.getPrincipal()], properties: [["D", {TextContent: "โˆ†โ‰ˆรงโˆšโˆซ"}]], @@ -2155,66 +2172,140 @@ test.serial("verify setApprovalForAll(true) information.", async t => { minted_by: custodianIdentity.getPrincipal(), transferred_by: [aliceIdentity.getPrincipal()] } - ); + }); }); - // verify ownerTokenIdentifiers - (await Promise.all(allActors.map(actor => actor.ownerTokenIdentifiers(johnIdentity.getPrincipal())))).forEach( + // verify owner_token_metadata + (await Promise.all(allActors.map(actor => actor.dip721_owner_token_metadata(johnIdentity.getPrincipal())))).forEach( result => { - t.true((result as {Ok: Array}).Ok.includes(BigInt(1))); - t.true((result as {Ok: Array}).Ok.includes(BigInt(2))); - } - ); - (await Promise.all(allActors.map(actor => actor.ownerTokenIdentifiers(bobIdentity.getPrincipal())))).forEach( - result => { - t.true((result as {Ok: Array}).Ok.includes(BigInt(3))); - t.true((result as {Ok: Array}).Ok.includes(BigInt(4))); + t.true("Ok" in result); + t.is((result as {Ok: Array}).Ok.length, 2); + t.like( + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(1)), + { + owner: [johnIdentity.getPrincipal()], + operator: [bobIdentity.getPrincipal()], + properties: [["A", {Nat64Content: BigInt(9999)}]], + is_burned: false, + approved_by: [johnIdentity.getPrincipal()], + burned_by: [], + burned_at: [], + token_identifier: BigInt(1), + minted_by: custodianIdentity.getPrincipal(), + transferred_by: [custodianIdentity.getPrincipal()] + } + ); + t.like( + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(2)), + { + owner: [johnIdentity.getPrincipal()], + operator: [bobIdentity.getPrincipal()], + properties: [["B", {Int64Content: BigInt(1234)}]], + is_burned: false, + approved_by: [johnIdentity.getPrincipal()], + burned_by: [], + burned_at: [], + token_identifier: BigInt(2), + minted_by: custodianIdentity.getPrincipal(), + transferred_by: [custodianIdentity.getPrincipal()] + } + ); } ); - - // verify operatorTokenMetadata - (await Promise.all(allActors.map(actor => actor.operatorTokenMetadata(johnIdentity.getPrincipal())))).forEach( + (await Promise.all(allActors.map(actor => actor.dip721_owner_token_metadata(bobIdentity.getPrincipal())))).forEach( result => { t.true("Ok" in result); t.is((result as {Ok: Array}).Ok.length, 2); t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(4)), + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(3)), { owner: [bobIdentity.getPrincipal()], operator: [johnIdentity.getPrincipal()], - properties: [["D", {TextContent: "โˆ†โ‰ˆรงโˆšโˆซ"}]], + properties: [["C", {Int32Content: 5678}]], is_burned: false, approved_by: [bobIdentity.getPrincipal()], burned_by: [], burned_at: [], - token_identifier: BigInt(4), + token_identifier: BigInt(3), minted_by: custodianIdentity.getPrincipal(), - transferred_by: [aliceIdentity.getPrincipal()] + transferred_by: [custodianIdentity.getPrincipal()] } ); t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(3)), + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(4)), { owner: [bobIdentity.getPrincipal()], operator: [johnIdentity.getPrincipal()], - properties: [["C", {Int32Content: 5678}]], + properties: [["D", {TextContent: "โˆ†โ‰ˆรงโˆšโˆซ"}]], is_burned: false, approved_by: [bobIdentity.getPrincipal()], burned_by: [], burned_at: [], - token_identifier: BigInt(3), + token_identifier: BigInt(4), minted_by: custodianIdentity.getPrincipal(), - transferred_by: [custodianIdentity.getPrincipal()] + transferred_by: [aliceIdentity.getPrincipal()] } ); } ); - (await Promise.all(allActors.map(actor => actor.operatorTokenMetadata(bobIdentity.getPrincipal())))).forEach( + + // verify owner_token_identifiers + ( + await Promise.all(allActors.map(actor => actor.dip721_owner_token_identifiers(johnIdentity.getPrincipal()))) + ).forEach(result => { + t.true((result as {Ok: Array}).Ok.includes(BigInt(1))); + t.true((result as {Ok: Array}).Ok.includes(BigInt(2))); + }); + (await Promise.all(allActors.map(actor => actor.dip721_owner_token_identifiers(bobIdentity.getPrincipal())))).forEach( + result => { + t.true((result as {Ok: Array}).Ok.includes(BigInt(3))); + t.true((result as {Ok: Array}).Ok.includes(BigInt(4))); + } + ); + + // verify operator_token_metadata + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_metadata(johnIdentity.getPrincipal()))) + ).forEach(result => { + t.true("Ok" in result); + t.is((result as {Ok: Array}).Ok.length, 2); + t.like( + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(4)), + { + owner: [bobIdentity.getPrincipal()], + operator: [johnIdentity.getPrincipal()], + properties: [["D", {TextContent: "โˆ†โ‰ˆรงโˆšโˆซ"}]], + is_burned: false, + approved_by: [bobIdentity.getPrincipal()], + burned_by: [], + burned_at: [], + token_identifier: BigInt(4), + minted_by: custodianIdentity.getPrincipal(), + transferred_by: [aliceIdentity.getPrincipal()] + } + ); + t.like( + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(3)), + { + owner: [bobIdentity.getPrincipal()], + operator: [johnIdentity.getPrincipal()], + properties: [["C", {Int32Content: 5678}]], + is_burned: false, + approved_by: [bobIdentity.getPrincipal()], + burned_by: [], + burned_at: [], + token_identifier: BigInt(3), + minted_by: custodianIdentity.getPrincipal(), + transferred_by: [custodianIdentity.getPrincipal()] + } + ); + }); + (await Promise.all(allActors.map(actor => actor.dip721_operator_token_metadata(bobIdentity.getPrincipal())))).forEach( result => { t.true("Ok" in result); t.is((result as {Ok: Array}).Ok.length, 2); t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(2)), + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(2)), { owner: [johnIdentity.getPrincipal()], operator: [bobIdentity.getPrincipal()], @@ -2229,7 +2320,7 @@ test.serial("verify setApprovalForAll(true) information.", async t => { } ); t.like( - (result as {Ok: Array}).Ok.find(tokenMetadata => tokenMetadata.token_identifier === BigInt(1)), + (result as {Ok: Array}).Ok.find(token_metadata => token_metadata.token_identifier === BigInt(1)), { owner: [johnIdentity.getPrincipal()], operator: [bobIdentity.getPrincipal()], @@ -2246,42 +2337,52 @@ test.serial("verify setApprovalForAll(true) information.", async t => { } ); - // verify operatorTokenIdentifiers - (await Promise.all(allActors.map(actor => actor.operatorTokenIdentifiers(johnIdentity.getPrincipal())))).forEach( - result => { - t.true((result as {Ok: Array}).Ok.includes(BigInt(3))); - t.true((result as {Ok: Array}).Ok.includes(BigInt(4))); - } - ); - (await Promise.all(allActors.map(actor => actor.operatorTokenIdentifiers(bobIdentity.getPrincipal())))).forEach( - result => { - t.true((result as {Ok: Array}).Ok.includes(BigInt(1))); - t.true((result as {Ok: Array}).Ok.includes(BigInt(2))); - } - ); + // verify operator_token_identifiers + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_identifiers(johnIdentity.getPrincipal()))) + ).forEach(result => { + t.true((result as {Ok: Array}).Ok.includes(BigInt(3))); + t.true((result as {Ok: Array}).Ok.includes(BigInt(4))); + }); + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_identifiers(bobIdentity.getPrincipal()))) + ).forEach(result => { + t.true((result as {Ok: Array}).Ok.includes(BigInt(1))); + t.true((result as {Ok: Array}).Ok.includes(BigInt(2))); + }); }); -test.serial("error on self approve when setApprovalForAll.", async t => { - t.deepEqual(await johnActor.setApprovalForAll(johnIdentity.getPrincipal(), true), {Err: {SelfApprove: null}}); - t.deepEqual(await bobActor.setApprovalForAll(bobIdentity.getPrincipal(), true), {Err: {SelfApprove: null}}); - t.deepEqual(await johnActor.setApprovalForAll(johnIdentity.getPrincipal(), false), {Err: {SelfApprove: null}}); - t.deepEqual(await bobActor.setApprovalForAll(bobIdentity.getPrincipal(), false), {Err: {SelfApprove: null}}); +test.serial("error on self approve when set_approval_for_all.", async t => { + t.deepEqual(await johnActor.dip721_set_approval_for_all(johnIdentity.getPrincipal(), true), { + Err: {SelfApprove: null} + }); + t.deepEqual(await bobActor.dip721_set_approval_for_all(bobIdentity.getPrincipal(), true), {Err: {SelfApprove: null}}); + t.deepEqual(await johnActor.dip721_set_approval_for_all(johnIdentity.getPrincipal(), false), { + Err: {SelfApprove: null} + }); + t.deepEqual(await bobActor.dip721_set_approval_for_all(bobIdentity.getPrincipal(), false), { + Err: {SelfApprove: null} + }); }); -test.serial("setApprovalForAll(false).", async t => { - t.deepEqual(await bobActor.setApprovalForAll(johnIdentity.getPrincipal(), false), {Ok: BigInt(22)}); - t.deepEqual(await johnActor.setApprovalForAll(bobIdentity.getPrincipal(), false), {Ok: BigInt(23)}); +test.serial("set_approval_for_all(false).", async t => { + t.deepEqual(await bobActor.dip721_set_approval_for_all(johnIdentity.getPrincipal(), false), {Ok: BigInt(22)}); + t.deepEqual(await johnActor.dip721_set_approval_for_all(bobIdentity.getPrincipal(), false), {Ok: BigInt(23)}); - // verify isApprovedForAll + // verify is_approved_for_all ( await Promise.all([ - ...allActors.map(actor => actor.isApprovedForAll(bobIdentity.getPrincipal(), johnIdentity.getPrincipal())), - ...allActors.map(actor => actor.isApprovedForAll(johnIdentity.getPrincipal(), bobIdentity.getPrincipal())) + ...allActors.map(actor => + actor.dip721_is_approved_for_all(bobIdentity.getPrincipal(), johnIdentity.getPrincipal()) + ), + ...allActors.map(actor => + actor.dip721_is_approved_for_all(johnIdentity.getPrincipal(), bobIdentity.getPrincipal()) + ) ]) ).forEach(result => t.deepEqual(result, {Ok: false})); }); -test.serial("verify transactions after SetApprovalForAll(false).", async t => { +test.serial("verify transactions after Set_approval_for_all(false).", async t => { const txns = await testTxns([ { id: "22", @@ -2312,29 +2413,29 @@ test.serial("verify transactions after SetApprovalForAll(false).", async t => { }); }); -test.serial("verify stats after setApprovalForAll(false).", async t => { - // verify totalTransactions - (await Promise.all(allActors.map(actor => actor.totalTransactions()))).forEach(result => { +test.serial("verify stats after set_approval_for_all(false).", async t => { + // verify total_transactions + (await Promise.all(allActors.map(actor => actor.dip721_total_transactions()))).forEach(result => { t.is(result, BigInt(24)); }); - // verify totalSupply - (await Promise.all(allActors.map(actor => actor.totalSupply()))).forEach(result => { + // verify total_supply + (await Promise.all(allActors.map(actor => actor.dip721_total_supply()))).forEach(result => { t.is(result, BigInt(4)); }); // verify cycles - (await Promise.all(allActors.map(actor => actor.cycles()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_cycles()))).forEach(result => { t.truthy(result); }); // verify totalUniqueHolders - (await Promise.all(allActors.map(actor => actor.totalUniqueHolders()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_total_unique_holders()))).forEach(result => { t.is(result, BigInt(2)); }); // verify stats - (await Promise.all(allActors.map(actor => actor.stats()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_stats()))).forEach(result => { t.truthy(result.cycles); t.is(result.total_transactions, BigInt(24)); t.is(result.total_supply, BigInt(4)); @@ -2342,51 +2443,51 @@ test.serial("verify stats after setApprovalForAll(false).", async t => { }); }); -test.serial("verify setApprovalForAll(false) information.", async t => { - // verify balanceOf - (await Promise.all(allActors.map(actor => actor.balanceOf(bobIdentity.getPrincipal())))).forEach(result => { +test.serial("verify set_approval_for_all(false) information.", async t => { + // verify balance_of + (await Promise.all(allActors.map(actor => actor.dip721_balance_of(bobIdentity.getPrincipal())))).forEach(result => { t.deepEqual(result, {Ok: BigInt(2)}); }); - (await Promise.all(allActors.map(actor => actor.balanceOf(johnIdentity.getPrincipal())))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_balance_of(johnIdentity.getPrincipal())))).forEach(result => { t.deepEqual(result, {Ok: BigInt(2)}); }); - // verify ownerOf - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(1))))).forEach(result => { + // verify owner_of + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(1))))).forEach(result => { t.deepEqual(result, {Ok: [johnIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(2))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(2))))).forEach(result => { t.deepEqual(result, {Ok: [johnIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(3))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(3))))).forEach(result => { t.deepEqual(result, {Ok: [bobIdentity.getPrincipal()]}); }); - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(4))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(4))))).forEach(result => { t.deepEqual(result, {Ok: [bobIdentity.getPrincipal()]}); }); - // verify operatorOf - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(1))))).forEach(result => { + // verify operator_of + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(1))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(2))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(2))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(3))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(3))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(4))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(4))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); - // verify ownerTokenIdentifiers - (await Promise.all(allActors.map(actor => actor.ownerTokenIdentifiers(johnIdentity.getPrincipal())))).forEach( - result => { - t.true((result as {Ok: Array}).Ok.includes(BigInt(1))); - t.true((result as {Ok: Array}).Ok.includes(BigInt(2))); - } - ); - (await Promise.all(allActors.map(actor => actor.ownerTokenIdentifiers(bobIdentity.getPrincipal())))).forEach( + // verify owner_token_identifiers + ( + await Promise.all(allActors.map(actor => actor.dip721_owner_token_identifiers(johnIdentity.getPrincipal()))) + ).forEach(result => { + t.true((result as {Ok: Array}).Ok.includes(BigInt(1))); + t.true((result as {Ok: Array}).Ok.includes(BigInt(2))); + }); + (await Promise.all(allActors.map(actor => actor.dip721_owner_token_identifiers(bobIdentity.getPrincipal())))).forEach( result => { t.true((result as {Ok: Array}).Ok.includes(BigInt(3))); t.true((result as {Ok: Array}).Ok.includes(BigInt(4))); @@ -2394,29 +2495,29 @@ test.serial("verify setApprovalForAll(false) information.", async t => { ); }); -test.serial("error on query non-existed operator (operator removed from tokenMetadata).", async t => { - // verify operatorTokenMetadata - (await Promise.all(allActors.map(actor => actor.operatorTokenMetadata(johnIdentity.getPrincipal())))).forEach( +test.serial("error on query non-existed operator (operator removed from token_metadata).", async t => { + // verify operator_token_metadata + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_metadata(johnIdentity.getPrincipal()))) + ).forEach(result => t.deepEqual(result, {Err: {OperatorNotFound: null}})); + (await Promise.all(allActors.map(actor => actor.dip721_operator_token_metadata(bobIdentity.getPrincipal())))).forEach( result => t.deepEqual(result, {Err: {OperatorNotFound: null}}) ); - (await Promise.all(allActors.map(actor => actor.operatorTokenMetadata(bobIdentity.getPrincipal())))).forEach(result => - t.deepEqual(result, {Err: {OperatorNotFound: null}}) - ); - // verify operatorTokenIdentifiers - (await Promise.all(allActors.map(actor => actor.operatorTokenIdentifiers(johnIdentity.getPrincipal())))).forEach( - result => t.deepEqual(result, {Err: {OperatorNotFound: null}}) - ); - (await Promise.all(allActors.map(actor => actor.operatorTokenIdentifiers(bobIdentity.getPrincipal())))).forEach( - result => t.deepEqual(result, {Err: {OperatorNotFound: null}}) - ); + // verify operator_token_identifiers + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_identifiers(johnIdentity.getPrincipal()))) + ).forEach(result => t.deepEqual(result, {Err: {OperatorNotFound: null}})); + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_identifiers(bobIdentity.getPrincipal()))) + ).forEach(result => t.deepEqual(result, {Err: {OperatorNotFound: null}})); }); test.serial("burn NFTs.", async t => { - t.deepEqual(await johnActor.burn(BigInt(1)), {Ok: BigInt(24)}); - t.deepEqual(await bobActor.burn(BigInt(3)), {Ok: BigInt(25)}); - t.deepEqual(await johnActor.burn(BigInt(2)), {Ok: BigInt(26)}); - t.deepEqual(await bobActor.burn(BigInt(4)), {Ok: BigInt(27)}); + t.deepEqual(await johnActor.dip721_burn(BigInt(1)), {Ok: BigInt(24)}); + t.deepEqual(await bobActor.dip721_burn(BigInt(3)), {Ok: BigInt(25)}); + t.deepEqual(await johnActor.dip721_burn(BigInt(2)), {Ok: BigInt(26)}); + t.deepEqual(await bobActor.dip721_burn(BigInt(4)), {Ok: BigInt(27)}); }); test.serial("verify transactions after burn.", async t => { @@ -2469,28 +2570,28 @@ test.serial("verify transactions after burn.", async t => { }); test.serial("verify stats after burn.", async t => { - // verify totalTransactions - (await Promise.all(allActors.map(actor => actor.totalTransactions()))).forEach(result => { + // verify total_transactions + (await Promise.all(allActors.map(actor => actor.dip721_total_transactions()))).forEach(result => { t.is(result, BigInt(28)); }); - // verify totalSupply - (await Promise.all(allActors.map(actor => actor.totalSupply()))).forEach(result => { + // verify total_supply + (await Promise.all(allActors.map(actor => actor.dip721_total_supply()))).forEach(result => { t.is(result, BigInt(4)); }); // verify cycles - (await Promise.all(allActors.map(actor => actor.cycles()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_cycles()))).forEach(result => { t.truthy(result); }); // verify totalUniqueHolders - (await Promise.all(allActors.map(actor => actor.totalUniqueHolders()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_total_unique_holders()))).forEach(result => { t.is(result, BigInt(0)); }); // verify stats - (await Promise.all(allActors.map(actor => actor.stats()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_stats()))).forEach(result => { t.truthy(result.cycles); t.is(result.total_transactions, BigInt(28)); t.is(result.total_supply, BigInt(4)); @@ -2500,7 +2601,7 @@ test.serial("verify stats after burn.", async t => { test.serial("verify burn information.", async t => { // verify token - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(1))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(1))))).forEach(result => { t.like(result, { Ok: { owner: [], @@ -2515,7 +2616,7 @@ test.serial("verify burn information.", async t => { } }); }); - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(2))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(2))))).forEach(result => { t.like(result, { Ok: { owner: [], @@ -2530,7 +2631,7 @@ test.serial("verify burn information.", async t => { } }); }); - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(3))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(3))))).forEach(result => { t.like(result, { Ok: { owner: [], @@ -2545,7 +2646,7 @@ test.serial("verify burn information.", async t => { } }); }); - (await Promise.all(allActors.map(actor => actor.tokenMetadata(BigInt(4))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_token_metadata(BigInt(4))))).forEach(result => { t.like(result, { Ok: { owner: [], @@ -2563,140 +2664,151 @@ test.serial("verify burn information.", async t => { }); test.serial("error on query - burned NFTs.", async t => { - // verify balanceOf - (await Promise.all(allActors.map(actor => actor.balanceOf(aliceIdentity.getPrincipal())))).forEach(result => { - t.deepEqual(result, {Err: {OwnerNotFound: null}}); - }); - (await Promise.all(allActors.map(actor => actor.balanceOf(bobIdentity.getPrincipal())))).forEach(result => { + // verify balance_of + (await Promise.all(allActors.map(actor => actor.dip721_balance_of(aliceIdentity.getPrincipal())))).forEach(result => { t.deepEqual(result, {Err: {OwnerNotFound: null}}); }); - (await Promise.all(allActors.map(actor => actor.balanceOf(johnIdentity.getPrincipal())))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_balance_of(bobIdentity.getPrincipal())))).forEach(result => { t.deepEqual(result, {Err: {OwnerNotFound: null}}); }); - (await Promise.all(allActors.map(actor => actor.balanceOf(custodianIdentity.getPrincipal())))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_balance_of(johnIdentity.getPrincipal())))).forEach(result => { t.deepEqual(result, {Err: {OwnerNotFound: null}}); }); + (await Promise.all(allActors.map(actor => actor.dip721_balance_of(custodianIdentity.getPrincipal())))).forEach( + result => { + t.deepEqual(result, {Err: {OwnerNotFound: null}}); + } + ); - // verify ownerOf - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(1))))).forEach(result => { + // verify owner_of + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(1))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(2))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(2))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(3))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(3))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); - (await Promise.all(allActors.map(actor => actor.ownerOf(BigInt(4))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_owner_of(BigInt(4))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); - // verify operatorOf - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(1))))).forEach(result => { + // verify operator_of + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(1))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(2))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(2))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(3))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(3))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); - (await Promise.all(allActors.map(actor => actor.operatorOf(BigInt(4))))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_operator_of(BigInt(4))))).forEach(result => { t.deepEqual(result, {Ok: []}); }); - // verify ownerTokenMetadata - (await Promise.all(allActors.map(actor => actor.ownerTokenMetadata(aliceIdentity.getPrincipal())))).forEach(result => - t.deepEqual(result, {Err: {OwnerNotFound: null}}) - ); - (await Promise.all(allActors.map(actor => actor.ownerTokenMetadata(bobIdentity.getPrincipal())))).forEach(result => - t.deepEqual(result, {Err: {OwnerNotFound: null}}) + // verify owner_token_metadata + (await Promise.all(allActors.map(actor => actor.dip721_owner_token_metadata(aliceIdentity.getPrincipal())))).forEach( + result => t.deepEqual(result, {Err: {OwnerNotFound: null}}) ); - (await Promise.all(allActors.map(actor => actor.ownerTokenMetadata(johnIdentity.getPrincipal())))).forEach(result => - t.deepEqual(result, {Err: {OwnerNotFound: null}}) + (await Promise.all(allActors.map(actor => actor.dip721_owner_token_metadata(bobIdentity.getPrincipal())))).forEach( + result => t.deepEqual(result, {Err: {OwnerNotFound: null}}) ); - (await Promise.all(allActors.map(actor => actor.ownerTokenMetadata(custodianIdentity.getPrincipal())))).forEach( + (await Promise.all(allActors.map(actor => actor.dip721_owner_token_metadata(johnIdentity.getPrincipal())))).forEach( result => t.deepEqual(result, {Err: {OwnerNotFound: null}}) ); + ( + await Promise.all(allActors.map(actor => actor.dip721_owner_token_metadata(custodianIdentity.getPrincipal()))) + ).forEach(result => t.deepEqual(result, {Err: {OwnerNotFound: null}})); - // verify operatorTokenMetadata - (await Promise.all(allActors.map(actor => actor.operatorTokenMetadata(aliceIdentity.getPrincipal())))).forEach( - result => t.deepEqual(result, {Err: {OperatorNotFound: null}}) - ); - (await Promise.all(allActors.map(actor => actor.operatorTokenMetadata(bobIdentity.getPrincipal())))).forEach(result => - t.deepEqual(result, {Err: {OperatorNotFound: null}}) - ); - (await Promise.all(allActors.map(actor => actor.operatorTokenMetadata(johnIdentity.getPrincipal())))).forEach( - result => t.deepEqual(result, {Err: {OperatorNotFound: null}}) - ); - (await Promise.all(allActors.map(actor => actor.operatorTokenMetadata(custodianIdentity.getPrincipal())))).forEach( + // verify operator_token_metadata + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_metadata(aliceIdentity.getPrincipal()))) + ).forEach(result => t.deepEqual(result, {Err: {OperatorNotFound: null}})); + (await Promise.all(allActors.map(actor => actor.dip721_operator_token_metadata(bobIdentity.getPrincipal())))).forEach( result => t.deepEqual(result, {Err: {OperatorNotFound: null}}) ); + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_metadata(johnIdentity.getPrincipal()))) + ).forEach(result => t.deepEqual(result, {Err: {OperatorNotFound: null}})); + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_metadata(custodianIdentity.getPrincipal()))) + ).forEach(result => t.deepEqual(result, {Err: {OperatorNotFound: null}})); - // verify ownerTokenIdentifiers - (await Promise.all(allActors.map(actor => actor.ownerTokenIdentifiers(aliceIdentity.getPrincipal())))).forEach( - result => { - t.deepEqual(result, {Err: {OwnerNotFound: null}}); - } - ); - (await Promise.all(allActors.map(actor => actor.ownerTokenIdentifiers(bobIdentity.getPrincipal())))).forEach( - result => { - t.deepEqual(result, {Err: {OwnerNotFound: null}}); - } - ); - (await Promise.all(allActors.map(actor => actor.ownerTokenIdentifiers(johnIdentity.getPrincipal())))).forEach( - result => { - t.deepEqual(result, {Err: {OwnerNotFound: null}}); - } - ); - (await Promise.all(allActors.map(actor => actor.ownerTokenIdentifiers(custodianIdentity.getPrincipal())))).forEach( + // verify owner_token_identifiers + ( + await Promise.all(allActors.map(actor => actor.dip721_owner_token_identifiers(aliceIdentity.getPrincipal()))) + ).forEach(result => { + t.deepEqual(result, {Err: {OwnerNotFound: null}}); + }); + (await Promise.all(allActors.map(actor => actor.dip721_owner_token_identifiers(bobIdentity.getPrincipal())))).forEach( result => { t.deepEqual(result, {Err: {OwnerNotFound: null}}); } ); + ( + await Promise.all(allActors.map(actor => actor.dip721_owner_token_identifiers(johnIdentity.getPrincipal()))) + ).forEach(result => { + t.deepEqual(result, {Err: {OwnerNotFound: null}}); + }); + ( + await Promise.all(allActors.map(actor => actor.dip721_owner_token_identifiers(custodianIdentity.getPrincipal()))) + ).forEach(result => { + t.deepEqual(result, {Err: {OwnerNotFound: null}}); + }); - // verify operatorTokenIdentifiers - (await Promise.all(allActors.map(actor => actor.operatorTokenIdentifiers(aliceIdentity.getPrincipal())))).forEach( - result => { - t.deepEqual(result, {Err: {OperatorNotFound: null}}); - } - ); - (await Promise.all(allActors.map(actor => actor.operatorTokenIdentifiers(bobIdentity.getPrincipal())))).forEach( - result => { - t.deepEqual(result, {Err: {OperatorNotFound: null}}); - } - ); - (await Promise.all(allActors.map(actor => actor.operatorTokenIdentifiers(johnIdentity.getPrincipal())))).forEach( - result => { - t.deepEqual(result, {Err: {OperatorNotFound: null}}); - } - ); - (await Promise.all(allActors.map(actor => actor.operatorTokenIdentifiers(custodianIdentity.getPrincipal())))).forEach( - result => { - t.deepEqual(result, {Err: {OperatorNotFound: null}}); - } - ); + // verify operator_token_identifiers + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_identifiers(aliceIdentity.getPrincipal()))) + ).forEach(result => { + t.deepEqual(result, {Err: {OperatorNotFound: null}}); + }); + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_identifiers(bobIdentity.getPrincipal()))) + ).forEach(result => { + t.deepEqual(result, {Err: {OperatorNotFound: null}}); + }); + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_identifiers(johnIdentity.getPrincipal()))) + ).forEach(result => { + t.deepEqual(result, {Err: {OperatorNotFound: null}}); + }); + ( + await Promise.all(allActors.map(actor => actor.dip721_operator_token_identifiers(custodianIdentity.getPrincipal()))) + ).forEach(result => { + t.deepEqual(result, {Err: {OperatorNotFound: null}}); + }); }); test.serial("error on update(mint) - burned NFTs.", async t => { // mint - t.deepEqual(await custodianActor.mint(aliceIdentity.getPrincipal(), BigInt(1), [["X", {Int64Content: BigInt(-1)}]]), { - Err: { - ExistedNFT: null + t.deepEqual( + await custodianActor.dip721_mint(aliceIdentity.getPrincipal(), BigInt(1), [["X", {Int64Content: BigInt(-1)}]]), + { + Err: { + ExistedNFT: null + } } - }); - t.deepEqual(await custodianActor.mint(bobIdentity.getPrincipal(), BigInt(1), [["Y", {Int64Content: BigInt(-1)}]]), { - Err: { - ExistedNFT: null + ); + t.deepEqual( + await custodianActor.dip721_mint(bobIdentity.getPrincipal(), BigInt(1), [["Y", {Int64Content: BigInt(-1)}]]), + { + Err: { + ExistedNFT: null + } } - }); - t.deepEqual(await custodianActor.mint(johnIdentity.getPrincipal(), BigInt(1), [["Z", {Int64Content: BigInt(-1)}]]), { - Err: { - ExistedNFT: null + ); + t.deepEqual( + await custodianActor.dip721_mint(johnIdentity.getPrincipal(), BigInt(1), [["Z", {Int64Content: BigInt(-1)}]]), + { + Err: { + ExistedNFT: null + } } - }); + ); t.deepEqual( - await custodianActor.mint(custodianIdentity.getPrincipal(), BigInt(1), [[".", {Int64Content: BigInt(-1)}]]), + await custodianActor.dip721_mint(custodianIdentity.getPrincipal(), BigInt(1), [[".", {Int64Content: BigInt(-1)}]]), { Err: { ExistedNFT: null @@ -2707,52 +2819,78 @@ test.serial("error on update(mint) - burned NFTs.", async t => { test.serial("error on update(burn) - burned NFTs.", async t => { // burn - t.deepEqual(await aliceActor.burn(BigInt(1)), {Err: {UnauthorizedOwner: null}}); - t.deepEqual(await bobActor.burn(BigInt(3)), {Err: {UnauthorizedOwner: null}}); - t.deepEqual(await johnActor.burn(BigInt(2)), {Err: {UnauthorizedOwner: null}}); - t.deepEqual(await custodianActor.burn(BigInt(4)), {Err: {UnauthorizedOwner: null}}); + t.deepEqual(await aliceActor.dip721_burn(BigInt(1)), {Err: {UnauthorizedOwner: null}}); + t.deepEqual(await bobActor.dip721_burn(BigInt(3)), {Err: {UnauthorizedOwner: null}}); + t.deepEqual(await johnActor.dip721_burn(BigInt(2)), {Err: {UnauthorizedOwner: null}}); + t.deepEqual(await custodianActor.dip721_burn(BigInt(4)), {Err: {UnauthorizedOwner: null}}); }); test.serial("error on update(approve) - burned NFTs.", async t => { // approve - t.deepEqual(await aliceActor.approve(bobIdentity.getPrincipal(), BigInt(1)), {Err: {UnauthorizedOwner: null}}); - t.deepEqual(await bobActor.approve(johnIdentity.getPrincipal(), BigInt(2)), {Err: {UnauthorizedOwner: null}}); - t.deepEqual(await johnActor.approve(custodianIdentity.getPrincipal(), BigInt(3)), {Err: {UnauthorizedOwner: null}}); - t.deepEqual(await custodianActor.approve(aliceIdentity.getPrincipal(), BigInt(4)), {Err: {UnauthorizedOwner: null}}); + t.deepEqual(await aliceActor.dip721_approve(bobIdentity.getPrincipal(), BigInt(1)), {Err: {UnauthorizedOwner: null}}); + t.deepEqual(await bobActor.dip721_approve(johnIdentity.getPrincipal(), BigInt(2)), {Err: {UnauthorizedOwner: null}}); + t.deepEqual(await johnActor.dip721_approve(custodianIdentity.getPrincipal(), BigInt(3)), { + Err: {UnauthorizedOwner: null} + }); + t.deepEqual(await custodianActor.dip721_approve(aliceIdentity.getPrincipal(), BigInt(4)), { + Err: {UnauthorizedOwner: null} + }); }); test.serial("error on update(transfer) - burned NFTs.", async t => { // transfer - t.deepEqual(await aliceActor.transfer(bobIdentity.getPrincipal(), BigInt(1)), {Err: {UnauthorizedOwner: null}}); - t.deepEqual(await bobActor.transfer(johnIdentity.getPrincipal(), BigInt(2)), {Err: {UnauthorizedOwner: null}}); - t.deepEqual(await johnActor.transfer(custodianIdentity.getPrincipal(), BigInt(3)), {Err: {UnauthorizedOwner: null}}); - t.deepEqual(await custodianActor.transfer(aliceIdentity.getPrincipal(), BigInt(4)), {Err: {UnauthorizedOwner: null}}); -}); - -test.serial("error on update(transferFrom) - burned NFTs.", async t => { - // transferFrom - t.deepEqual(await aliceActor.transferFrom(bobIdentity.getPrincipal(), johnIdentity.getPrincipal(), BigInt(1)), { + t.deepEqual(await aliceActor.dip721_transfer(bobIdentity.getPrincipal(), BigInt(1)), { Err: {UnauthorizedOwner: null} }); - t.deepEqual(await bobActor.transferFrom(johnIdentity.getPrincipal(), custodianIdentity.getPrincipal(), BigInt(2)), { + t.deepEqual(await bobActor.dip721_transfer(johnIdentity.getPrincipal(), BigInt(2)), {Err: {UnauthorizedOwner: null}}); + t.deepEqual(await johnActor.dip721_transfer(custodianIdentity.getPrincipal(), BigInt(3)), { Err: {UnauthorizedOwner: null} }); - t.deepEqual(await johnActor.transferFrom(custodianIdentity.getPrincipal(), aliceIdentity.getPrincipal(), BigInt(3)), { - Err: {UnauthorizedOwner: null} - }); - t.deepEqual(await custodianActor.transferFrom(aliceIdentity.getPrincipal(), bobIdentity.getPrincipal(), BigInt(4)), { + t.deepEqual(await custodianActor.dip721_transfer(aliceIdentity.getPrincipal(), BigInt(4)), { Err: {UnauthorizedOwner: null} }); }); -test.serial("error on update(setApprovalForAll) - burned NFTs.", async t => { +test.serial("error on update(transfer_from) - burned NFTs.", async t => { + // transfer_from + t.deepEqual( + await aliceActor.dip721_transfer_from(bobIdentity.getPrincipal(), johnIdentity.getPrincipal(), BigInt(1)), + { + Err: {UnauthorizedOwner: null} + } + ); + t.deepEqual( + await bobActor.dip721_transfer_from(johnIdentity.getPrincipal(), custodianIdentity.getPrincipal(), BigInt(2)), + { + Err: {UnauthorizedOwner: null} + } + ); + t.deepEqual( + await johnActor.dip721_transfer_from(custodianIdentity.getPrincipal(), aliceIdentity.getPrincipal(), BigInt(3)), + { + Err: {UnauthorizedOwner: null} + } + ); + t.deepEqual( + await custodianActor.dip721_transfer_from(aliceIdentity.getPrincipal(), bobIdentity.getPrincipal(), BigInt(4)), + { + Err: {UnauthorizedOwner: null} + } + ); +}); + +test.serial("error on update(set_approval_for_all) - burned NFTs.", async t => { // set_approval_for_all - t.deepEqual(await aliceActor.setApprovalForAll(bobIdentity.getPrincipal(), true), {Err: {OwnerNotFound: null}}); - t.deepEqual(await bobActor.setApprovalForAll(johnIdentity.getPrincipal(), false), {Err: {OwnerNotFound: null}}); - t.deepEqual(await johnActor.setApprovalForAll(custodianIdentity.getPrincipal(), true), { + t.deepEqual(await aliceActor.dip721_set_approval_for_all(bobIdentity.getPrincipal(), true), { + Err: {OwnerNotFound: null} + }); + t.deepEqual(await bobActor.dip721_set_approval_for_all(johnIdentity.getPrincipal(), false), { + Err: {OwnerNotFound: null} + }); + t.deepEqual(await johnActor.dip721_set_approval_for_all(custodianIdentity.getPrincipal(), true), { Err: {OwnerNotFound: null} }); - t.deepEqual(await custodianActor.setApprovalForAll(aliceIdentity.getPrincipal(), false), { + t.deepEqual(await custodianActor.dip721_set_approval_for_all(aliceIdentity.getPrincipal(), false), { Err: {OwnerNotFound: null} }); }); diff --git a/test/integration/metadata.test.ts b/test/integration/metadata.test.ts index 3217a98..74e0097 100644 --- a/test/integration/metadata.test.ts +++ b/test/integration/metadata.test.ts @@ -6,43 +6,49 @@ const normalActors = [aliceActor, bobActor, johnActor]; const allActors = [...normalActors, custodianActor]; test("CRUD name", async (t: Assertions) => { - (await Promise.all(allActors.map(actor => actor.name()))).forEach(result => t.deepEqual(result, [])); - await t.notThrowsAsync(custodianActor.setName("nft")); - (await Promise.all(allActors.map(actor => actor.name()))).forEach(result => t.deepEqual(result, ["nft"])); + (await Promise.all(allActors.map(actor => actor.dip721_name()))).forEach(result => t.deepEqual(result, [])); + await t.notThrowsAsync(custodianActor.dip721_set_name("nft")); + (await Promise.all(allActors.map(actor => actor.dip721_name()))).forEach(result => t.deepEqual(result, ["nft"])); }); test("CRUD logo", async (t: Assertions) => { - (await Promise.all(allActors.map(actor => actor.logo()))).forEach(result => t.deepEqual(result, [])); - await t.notThrowsAsync(custodianActor.setLogo("nftLogo")); - (await Promise.all(allActors.map(actor => actor.logo()))).forEach(result => t.deepEqual(result, ["nftLogo"])); + (await Promise.all(allActors.map(actor => actor.dip721_logo()))).forEach(result => t.deepEqual(result, [])); + await t.notThrowsAsync(custodianActor.dip721_set_logo("nftLogo")); + (await Promise.all(allActors.map(actor => actor.dip721_logo()))).forEach(result => t.deepEqual(result, ["nftLogo"])); }); test("CRUD symbol", async (t: Assertions) => { - (await Promise.all(allActors.map(actor => actor.symbol()))).forEach(result => t.deepEqual(result, [])); - await t.notThrowsAsync(custodianActor.setSymbol("nftSymbol")); - (await Promise.all(allActors.map(actor => actor.symbol()))).forEach(result => t.deepEqual(result, ["nftSymbol"])); + (await Promise.all(allActors.map(actor => actor.dip721_symbol()))).forEach(result => t.deepEqual(result, [])); + await t.notThrowsAsync(custodianActor.dip721_set_symbol("nftSymbol")); + (await Promise.all(allActors.map(actor => actor.dip721_symbol()))).forEach(result => + t.deepEqual(result, ["nftSymbol"]) + ); }); test("CRUD custodians", async (t: Assertions) => { - (await Promise.all(allActors.map(actor => actor.custodians()))).forEach(result => - t.is(result.filter(custodians => custodians.toText() === custodianIdentity.getPrincipal().toText()).length, 1) + (await Promise.all(allActors.map(actor => actor.dip721_custodians()))).forEach(result => + t.is( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + result.filter((custodians: any) => custodians.toText() === custodianIdentity.getPrincipal().toText()).length, + 1 + ) ); await t.notThrowsAsync( - custodianActor.setCustodians([custodianIdentity.getPrincipal(), custodianIdentity.getPrincipal()]) + custodianActor.dip721_set_custodians([custodianIdentity.getPrincipal(), custodianIdentity.getPrincipal()]) ); - (await Promise.all(allActors.map(actor => actor.custodians()))).forEach(result => + (await Promise.all(allActors.map(actor => actor.dip721_custodians()))).forEach(result => t.deepEqual(result, [custodianIdentity.getPrincipal()]) ); }); test("interfaces", async (t: Assertions) => { - (await Promise.all(allActors.map(actor => actor.supportedInterfaces()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_supported_interfaces()))).forEach(result => { t.deepEqual(result, [{Approval: null}, {Mint: null}, {Burn: null}]); }); }); test("metadata", async t => { - (await Promise.all(allActors.map(actor => actor.metadata()))).forEach(result => { + (await Promise.all(allActors.map(actor => actor.dip721_metadata()))).forEach(result => { t.deepEqual(result.name, ["nft"]); t.deepEqual(result.logo, ["nftLogo"]); t.deepEqual(result.symbol, ["nftSymbol"]); @@ -52,19 +58,19 @@ test("metadata", async t => { test("error on unauthorized metadata update", async t => { // setName error when caller is not an custodian - (await Promise.allSettled(normalActors.map(actor => actor.setName("nft")))).forEach(promise => + (await Promise.allSettled(normalActors.map(actor => actor.dip721_set_name("nft")))).forEach(promise => t.is(promise.status, "rejected") ); // setLogo error when caller is not an custodian - (await Promise.allSettled(normalActors.map(actor => actor.setLogo("nftLogo")))).forEach(promise => + (await Promise.allSettled(normalActors.map(actor => actor.dip721_set_logo("nftLogo")))).forEach(promise => t.is(promise.status, "rejected") ); // setSymbol error when caller is not an custodian - (await Promise.allSettled(normalActors.map(actor => actor.setSymbol("nftSymbol")))).forEach(promise => + (await Promise.allSettled(normalActors.map(actor => actor.dip721_set_symbol("nftSymbol")))).forEach(promise => t.is(promise.status, "rejected") ); // setCustodians error when caller is not an custodian - (await Promise.allSettled(normalActors.map(actor => actor.setCustodians([])))).forEach(promise => + (await Promise.allSettled(normalActors.map(actor => actor.dip721_set_custodians([])))).forEach(promise => t.is(promise.status, "rejected") ); }); diff --git a/test/setup.ts b/test/setup.ts index 9fc3006..6070f7e 100644 --- a/test/setup.ts +++ b/test/setup.ts @@ -19,11 +19,10 @@ export const johnIdentity = Ed25519KeyIdentity.generate(); const secretKey = readFileSync("./custodian-test-secret", {encoding: "utf8"}); export const custodianIdentity = Ed25519KeyIdentity.fromSecretKey(Buffer.from(secretKey, "hex")); -export const nftCanisterId = JSON.parse(readFileSync("../.dfx/local/canister_ids.json", {encoding: "utf8"}))["nft"] - .local as string; -export const capCanisterId = JSON.parse(readFileSync("../cap/.dfx/local/canister_ids.json", {encoding: "utf8"}))[ - "ic-history-router" -].local as string; +const canister_ids = JSON.parse(readFileSync("../.dfx/local/canister_ids.json", {encoding: "utf8"})); + +export const nftCanisterId = canister_ids["nft"].local as string; +export const capCanisterId = canister_ids["cap-router"].local as string; const createActor = async (identity: Identity): Promise => { const agent = new HttpAgent({host, fetch, identity});