difftreelog
Merge pull request #986 from UniqueNetwork/feature/add_mint_bulk_cross
in: master
Add mintBulkCross to NFT and RFT collections
20 files changed
node/cli/src/command.rsdiffbeforeafterboth--- a/node/cli/src/command.rs
+++ b/node/cli/src/command.rs
@@ -425,7 +425,7 @@
.map(|cfg| &cfg.registry);
let task_manager =
sc_service::TaskManager::new(runner.config().tokio_handle.clone(), *registry)
- .map_err(|e| format!("Error: {:?}", e))?;
+ .map_err(|e| format!("Error: {e:?}"))?;
let info_provider = Some(timestamp_with_aura_info(12000));
runner.async_run(|config| -> Result<(Pin<Box<dyn Future<Output = _>>>, _)> {
pallets/common/src/eth.rsdiffbeforeafterboth--- a/pallets/common/src/eth.rs
+++ b/pallets/common/src/eth.rs
@@ -119,7 +119,7 @@
} else if self.sub == Default::default() {
Ok(Some(T::CrossAccountId::from_eth(self.eth)))
} else {
- Err(format!("All fields of cross account is non zeroed {:?}", self).into())
+ Err(format!("All fields of cross account is non zeroed {self:?}").into())
}
}
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -26,7 +26,7 @@
char::{REPLACEMENT_CHARACTER, decode_utf16},
convert::TryInto,
};
-use evm_coder::{abi::AbiType, ToLog, generate_stubgen, solidity_interface, types::*};
+use evm_coder::{abi::AbiType, AbiCoder, ToLog, generate_stubgen, solidity_interface, types::*};
use frame_support::BoundedVec;
use up_data_structs::{
TokenId, PropertyPermission, PropertyKeyPermission, Property, CollectionId, PropertyKey,
@@ -64,6 +64,15 @@
},
}
+/// Token minting parameters
+#[derive(AbiCoder, Default, Debug)]
+pub struct MintTokenData {
+ /// Minted token owner
+ pub owner: eth::CrossAddress,
+ /// Minted token properties
+ pub properties: Vec<eth::Property>,
+}
+
frontier_contract! {
macro_rules! NonfungibleHandle_result {...}
impl<T: Config> Contract for NonfungibleHandle<T> {...}
@@ -981,13 +990,41 @@
Ok(true)
}
+ /// @notice Function to mint a token.
+ /// @param data Array of pairs of token owner and token's properties for minted token
+ #[weight(<SelfWeightOf<T>>::create_multiple_items(data.len() as u32) + <SelfWeightOf<T>>::set_token_properties(data.len() as u32))]
+ fn mint_bulk_cross(&mut self, caller: Caller, data: Vec<MintTokenData>) -> Result<bool> {
+ let caller = T::CrossAccountId::from_eth(caller);
+ let budget = self
+ .recorder
+ .weight_calls_budget(<StructureWeight<T>>::find_parent());
+
+ let mut create_nft_data = Vec::with_capacity(data.len());
+ for MintTokenData { owner, properties } in data {
+ let owner = owner.into_sub_cross_account::<T>()?;
+ create_nft_data.push(CreateItemData::<T> {
+ properties: properties
+ .into_iter()
+ .map(|property| property.try_into())
+ .collect::<Result<Vec<_>>>()?
+ .try_into()
+ .map_err(|_| "too many properties")?,
+ owner,
+ });
+ }
+
+ <Pallet<T>>::create_multiple_items(self, &caller, create_nft_data, &budget)
+ .map_err(dispatch_to_evm::<T>)?;
+ Ok(true)
+ }
+
/// @notice Function to mint multiple tokens with the given tokenUris.
/// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive
/// numbers and first number should be obtained with `nextTokenId` method
/// @param to The new owner
/// @param tokens array of pairs of token ID and token URI for minted tokens
#[solidity(hide, rename_selector = "mintBulkWithTokenURI")]
- #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32) + <SelfWeightOf<T>>::set_token_properties(tokens.len() as u32))]
+ #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32) + <SelfWeightOf<T>>::set_token_properties(tokens.len() as u32))]
fn mint_bulk_with_token_uri(
&mut self,
caller: Caller,
pallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterbothbinary blob — no preview
pallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth--- a/pallets/nonfungible/src/stubs/UniqueNFT.sol
+++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol
@@ -800,7 +800,7 @@
}
/// @title Unique extensions for ERC721.
-/// @dev the ERC-165 identifier for this interface is 0x307b061a
+/// @dev the ERC-165 identifier for this interface is 0x9b397d16
contract ERC721UniqueExtensions is Dummy, ERC165 {
/// @notice A descriptive name for a collection of NFTs in this contract
/// @dev EVM selector for this function is: 0x06fdde03,
@@ -997,6 +997,17 @@
// return false;
// }
+ /// @notice Function to mint a token.
+ /// @param data Array of pairs of token owner and token's properties for minted token
+ /// @dev EVM selector for this function is: 0xab427b0c,
+ /// or in textual repr: mintBulkCross(((address,uint256),(string,bytes)[])[])
+ function mintBulkCross(MintTokenData[] memory data) public returns (bool) {
+ require(false, stub_error);
+ data;
+ dummy = 0;
+ return false;
+ }
+
// /// @notice Function to mint multiple tokens with the given tokenUris.
// /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive
// /// numbers and first number should be obtained with `nextTokenId` method
@@ -1044,6 +1055,14 @@
string uri;
}
+/// Token minting parameters
+struct MintTokenData {
+ /// Minted token owner
+ CrossAddress owner;
+ /// Minted token properties
+ Property[] properties;
+}
+
/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
/// @dev See https://eips.ethereum.org/EIPS/eip-721
/// @dev the ERC-165 identifier for this interface is 0x780e9d63
pallets/refungible/src/erc.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -26,7 +26,7 @@
char::{REPLACEMENT_CHARACTER, decode_utf16},
convert::TryInto,
};
-use evm_coder::{abi::AbiType, ToLog, generate_stubgen, solidity_interface, types::*};
+use evm_coder::{abi::AbiType, AbiCoder, ToLog, generate_stubgen, solidity_interface, types::*};
use frame_support::{BoundedBTreeMap, BoundedVec};
use pallet_common::{
CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,
@@ -71,6 +71,24 @@
},
}
+/// Token minting parameters
+#[derive(AbiCoder, Default, Debug)]
+pub struct OwnerPieces {
+ /// Minted token owner
+ pub owner: eth::CrossAddress,
+ /// Number of token pieces
+ pub pieces: u128,
+}
+
+/// Token minting parameters
+#[derive(AbiCoder, Default, Debug)]
+pub struct MintTokenData {
+ /// Minted token owner and number of pieces
+ pub owners: Vec<OwnerPieces>,
+ /// Minted token properties
+ pub properties: Vec<eth::Property>,
+}
+
/// @title A contract that allows to set and delete token properties and change token property permissions.
#[solidity_interface(name = TokenProperties, events(ERC721TokenEvent), enum(derive(PreDispatch)), enum_attr(weight))]
impl<T: Config> RefungibleHandle<T> {
@@ -1021,6 +1039,55 @@
Ok(true)
}
+ /// @notice Function to mint a token.
+ /// @param tokenProperties Properties of minted token
+ #[weight(if token_properties.len() == 1 {
+ <SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(token_properties.iter().next().unwrap().owners.len() as u32)
+ } else {
+ <SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(token_properties.len() as u32)
+ } + <SelfWeightOf<T>>::set_token_properties(token_properties.len() as u32))]
+ fn mint_bulk_cross(
+ &mut self,
+ caller: Caller,
+ token_properties: Vec<MintTokenData>,
+ ) -> Result<bool> {
+ let caller = T::CrossAccountId::from_eth(caller);
+ let budget = self
+ .recorder
+ .weight_calls_budget(<StructureWeight<T>>::find_parent());
+ let has_multiple_tokens = token_properties.len() > 1;
+
+ let mut create_rft_data = Vec::with_capacity(token_properties.len());
+ for MintTokenData { owners, properties } in token_properties {
+ let has_multiple_owners = owners.len() > 1;
+ if has_multiple_tokens & has_multiple_owners {
+ return Err(
+ "creation of multiple tokens supported only if they have single owner each"
+ .into(),
+ );
+ }
+ let users: BoundedBTreeMap<_, _, _> = owners
+ .into_iter()
+ .map(|data| Ok((data.owner.into_sub_cross_account::<T>()?, data.pieces)))
+ .collect::<Result<BTreeMap<_, _>>>()?
+ .try_into()
+ .map_err(|_| "too many users")?;
+ create_rft_data.push(CreateItemData::<T> {
+ properties: properties
+ .into_iter()
+ .map(|property| property.try_into())
+ .collect::<Result<Vec<_>>>()?
+ .try_into()
+ .map_err(|_| "too many properties")?,
+ users,
+ });
+ }
+
+ <Pallet<T>>::create_multiple_items(self, &caller, create_rft_data, &budget)
+ .map_err(dispatch_to_evm::<T>)?;
+ Ok(true)
+ }
+
/// @notice Function to mint multiple tokens with the given tokenUris.
/// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive
/// numbers and first number should be obtained with `nextTokenId` method
pallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterbothbinary blob — no preview
pallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth--- a/pallets/refungible/src/stubs/UniqueRefungible.sol
+++ b/pallets/refungible/src/stubs/UniqueRefungible.sol
@@ -800,7 +800,7 @@
}
/// @title Unique extensions for ERC721.
-/// @dev the ERC-165 identifier for this interface is 0x95c0f66c
+/// @dev the ERC-165 identifier for this interface is 0x4abaabdb
contract ERC721UniqueExtensions is Dummy, ERC165 {
/// @notice A descriptive name for a collection of NFTs in this contract
/// @dev EVM selector for this function is: 0x06fdde03,
@@ -986,6 +986,17 @@
// return false;
// }
+ /// @notice Function to mint a token.
+ /// @param tokenProperties Properties of minted token
+ /// @dev EVM selector for this function is: 0xdf7a5db7,
+ /// or in textual repr: mintBulkCross((((address,uint256),uint128)[],(string,bytes)[])[])
+ function mintBulkCross(MintTokenData[] memory tokenProperties) public returns (bool) {
+ require(false, stub_error);
+ tokenProperties;
+ dummy = 0;
+ return false;
+ }
+
// /// @notice Function to mint multiple tokens with the given tokenUris.
// /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive
// /// numbers and first number should be obtained with `nextTokenId` method
@@ -1045,6 +1056,22 @@
string uri;
}
+/// Token minting parameters
+struct MintTokenData {
+ /// Minted token owner and number of pieces
+ OwnerPieces[] owners;
+ /// Minted token properties
+ Property[] properties;
+}
+
+/// Token minting parameters
+struct OwnerPieces {
+ /// Minted token owner
+ CrossAddress owner;
+ /// Number of token pieces
+ uint128 pieces;
+}
+
/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
/// @dev See https://eips.ethereum.org/EIPS/eip-721
/// @dev the ERC-165 identifier for this interface is 0x780e9d63
pallets/scheduler-v2/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/scheduler-v2/src/benchmarking.rs
+++ b/pallets/scheduler-v2/src/benchmarking.rs
@@ -136,8 +136,10 @@
let bound = EncodedCall::bound() as u32;
let mut len = match maybe_lookup_len {
Some(len) => {
- len.min(<T::Preimages as PreimageRecipient<T::Hash>>::MaxSize::get() - 2)
- .max(bound) - 3
+ len.clamp(
+ bound,
+ <T::Preimages as PreimageRecipient<T::Hash>>::MaxSize::get() - 2,
+ ) - 3
}
None => bound.saturating_sub(4),
};
pallets/unique/src/eth/stubs/CollectionHelpers.rawdiffbeforeafterbothbinary blob — no preview
pallets/unique/src/eth/stubs/CollectionHelpers.soldiffbeforeafterboth--- a/pallets/unique/src/eth/stubs/CollectionHelpers.sol
+++ b/pallets/unique/src/eth/stubs/CollectionHelpers.sol
@@ -25,12 +25,12 @@
}
/// @title Contract, which allows users to operate with collections
-/// @dev the ERC-165 identifier for this interface is 0x4135fff1
+/// @dev the ERC-165 identifier for this interface is 0x94e5af0d
contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
/// Create a collection
/// @return address Address of the newly created collection
- /// @dev EVM selector for this function is: 0xa765ee5b,
- /// or in textual repr: createCollection(((address,uint256),string,string,string,uint8,uint8,(string,bytes)[],(string,(uint8,bool)[])[],(address,uint256)[],(bool,bool,address[]),(uint8,uint256)[],uint8))
+ /// @dev EVM selector for this function is: 0x72b5bea7,
+ /// or in textual repr: createCollection((string,string,string,uint8,uint8,(string,bytes)[],(string,(uint8,bool)[])[],(address,uint256)[],(bool,bool,address[]),(uint8,uint256)[],(address,uint256),uint8))
function createCollection(CreateCollectionData memory data) public payable returns (address) {
require(false, stub_error);
data;
@@ -170,8 +170,6 @@
/// Collection properties
struct CreateCollectionData {
- /// Collection sponsor
- CrossAddress pending_sponsor;
/// Collection name
string name;
/// Collection description
@@ -192,11 +190,12 @@
CollectionNestingAndPermission nesting_settings;
/// Collection limits
CollectionLimitValue[] limits;
+ /// Collection sponsor
+ CrossAddress pending_sponsor;
/// Extra collection flags
CollectionFlags flags;
}
-/// Cross account struct
type CollectionFlags is uint8;
library CollectionFlagsLib {
@@ -207,13 +206,19 @@
/// External collections can't be managed using `unique` api
CollectionFlags constant externalField = CollectionFlags.wrap(1);
- /// Reserved bits
+ /// Reserved flags
function reservedField(uint8 value) public pure returns (CollectionFlags) {
require(value < 1 << 5, "out of bound value");
return CollectionFlags.wrap(value << 1);
}
}
+/// Cross account struct
+struct CrossAddress {
+ address eth;
+ uint256 sub;
+}
+
/// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.
struct CollectionLimitValue {
CollectionLimitField field;
@@ -250,12 +255,6 @@
bool collection_admin;
/// If set - only tokens from specified collections can be nested.
address[] restricted;
-}
-
-/// Cross account struct
-struct CrossAddress {
- address eth;
- uint256 sub;
}
/// Ethereum representation of Token Property Permissions.
@@ -292,10 +291,10 @@
/// Type of tokens in collection
enum CollectionMode {
- /// Fungible
- Fungible,
/// Nonfungible
Nonfungible,
+ /// Fungible
+ Fungible,
/// Refungible
Refungible
}
runtime/common/ethereum/sponsoring/refungible.rsdiffbeforeafterboth--- a/runtime/common/ethereum/sponsoring/refungible.rs
+++ b/runtime/common/ethereum/sponsoring/refungible.rs
@@ -242,6 +242,7 @@
BurnFrom { .. }
| BurnFromCross { .. }
| MintBulk { .. }
+ | MintBulkCross { .. }
| MintBulkWithTokenUri { .. } => None,
MintCross { .. } => withdraw_create_item::<T>(
runtime/common/tests/mod.rsdiffbeforeafterboth--- a/runtime/common/tests/mod.rs
+++ b/runtime/common/tests/mod.rs
@@ -33,7 +33,7 @@
const PARA_ID: u32 = 2037;
fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
- TPublic::Pair::from_string(&format!("//{}", seed), None)
+ TPublic::Pair::from_string(&format!("//{seed}"), None)
.expect("static values are valid; qed")
.public()
}
tests/src/eth/abi/nonFungible.jsondiffbeforeafterboth--- a/tests/src/eth/abi/nonFungible.json
+++ b/tests/src/eth/abi/nonFungible.json
@@ -469,6 +469,39 @@
"inputs": [
{
"components": [
+ {
+ "components": [
+ { "internalType": "address", "name": "eth", "type": "address" },
+ { "internalType": "uint256", "name": "sub", "type": "uint256" }
+ ],
+ "internalType": "struct CrossAddress",
+ "name": "owner",
+ "type": "tuple"
+ },
+ {
+ "components": [
+ { "internalType": "string", "name": "key", "type": "string" },
+ { "internalType": "bytes", "name": "value", "type": "bytes" }
+ ],
+ "internalType": "struct Property[]",
+ "name": "properties",
+ "type": "tuple[]"
+ }
+ ],
+ "internalType": "struct MintTokenData[]",
+ "name": "data",
+ "type": "tuple[]"
+ }
+ ],
+ "name": "mintBulkCross",
+ "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "inputs": [
+ {
+ "components": [
{ "internalType": "address", "name": "eth", "type": "address" },
{ "internalType": "uint256", "name": "sub", "type": "uint256" }
],
tests/src/eth/abi/reFungible.jsondiffbeforeafterboth--- a/tests/src/eth/abi/reFungible.json
+++ b/tests/src/eth/abi/reFungible.json
@@ -451,6 +451,55 @@
"inputs": [
{
"components": [
+ {
+ "components": [
+ {
+ "components": [
+ {
+ "internalType": "address",
+ "name": "eth",
+ "type": "address"
+ },
+ {
+ "internalType": "uint256",
+ "name": "sub",
+ "type": "uint256"
+ }
+ ],
+ "internalType": "struct CrossAddress",
+ "name": "owner",
+ "type": "tuple"
+ },
+ { "internalType": "uint128", "name": "pieces", "type": "uint128" }
+ ],
+ "internalType": "struct OwnerPieces[]",
+ "name": "owners",
+ "type": "tuple[]"
+ },
+ {
+ "components": [
+ { "internalType": "string", "name": "key", "type": "string" },
+ { "internalType": "bytes", "name": "value", "type": "bytes" }
+ ],
+ "internalType": "struct Property[]",
+ "name": "properties",
+ "type": "tuple[]"
+ }
+ ],
+ "internalType": "struct MintTokenData[]",
+ "name": "tokenProperties",
+ "type": "tuple[]"
+ }
+ ],
+ "name": "mintBulkCross",
+ "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "inputs": [
+ {
+ "components": [
{ "internalType": "address", "name": "eth", "type": "address" },
{ "internalType": "uint256", "name": "sub", "type": "uint256" }
],
tests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth--- a/tests/src/eth/api/CollectionHelpers.sol
+++ b/tests/src/eth/api/CollectionHelpers.sol
@@ -20,12 +20,12 @@
}
/// @title Contract, which allows users to operate with collections
-/// @dev the ERC-165 identifier for this interface is 0x4135fff1
+/// @dev the ERC-165 identifier for this interface is 0x94e5af0d
interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
/// Create a collection
/// @return address Address of the newly created collection
- /// @dev EVM selector for this function is: 0xa765ee5b,
- /// or in textual repr: createCollection(((address,uint256),string,string,string,uint8,uint8,(string,bytes)[],(string,(uint8,bool)[])[],(address,uint256)[],(bool,bool,address[]),(uint8,uint256)[],uint8))
+ /// @dev EVM selector for this function is: 0x72b5bea7,
+ /// or in textual repr: createCollection((string,string,string,uint8,uint8,(string,bytes)[],(string,(uint8,bool)[])[],(address,uint256)[],(bool,bool,address[]),(uint8,uint256)[],(address,uint256),uint8))
function createCollection(CreateCollectionData memory data) external payable returns (address);
/// Create an NFT collection
@@ -103,8 +103,6 @@
/// Collection properties
struct CreateCollectionData {
- /// Collection sponsor
- CrossAddress pending_sponsor;
/// Collection name
string name;
/// Collection description
@@ -125,11 +123,12 @@
CollectionNestingAndPermission nesting_settings;
/// Collection limits
CollectionLimitValue[] limits;
+ /// Collection sponsor
+ CrossAddress pending_sponsor;
/// Extra collection flags
CollectionFlags flags;
}
-/// Cross account struct
type CollectionFlags is uint8;
library CollectionFlagsLib {
@@ -140,13 +139,19 @@
/// External collections can't be managed using `unique` api
CollectionFlags constant externalField = CollectionFlags.wrap(1);
- /// Reserved bits
+ /// Reserved flags
function reservedField(uint8 value) public pure returns (CollectionFlags) {
require(value < 1 << 5, "out of bound value");
return CollectionFlags.wrap(value << 1);
}
}
+/// Cross account struct
+struct CrossAddress {
+ address eth;
+ uint256 sub;
+}
+
/// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.
struct CollectionLimitValue {
CollectionLimitField field;
@@ -183,12 +188,6 @@
bool collection_admin;
/// If set - only tokens from specified collections can be nested.
address[] restricted;
-}
-
-/// Cross account struct
-struct CrossAddress {
- address eth;
- uint256 sub;
}
/// Ethereum representation of Token Property Permissions.
@@ -225,10 +224,10 @@
/// Type of tokens in collection
enum CollectionMode {
- /// Fungible
- Fungible,
/// Nonfungible
Nonfungible,
+ /// Fungible
+ Fungible,
/// Refungible
Refungible
}
tests/src/eth/api/UniqueNFT.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -551,7 +551,7 @@
}
/// @title Unique extensions for ERC721.
-/// @dev the ERC-165 identifier for this interface is 0x307b061a
+/// @dev the ERC-165 identifier for this interface is 0x9b397d16
interface ERC721UniqueExtensions is Dummy, ERC165 {
/// @notice A descriptive name for a collection of NFTs in this contract
/// @dev EVM selector for this function is: 0x06fdde03,
@@ -674,6 +674,12 @@
// /// or in textual repr: mintBulk(address,uint256[])
// function mintBulk(address to, uint256[] memory tokenIds) external returns (bool);
+ /// @notice Function to mint a token.
+ /// @param data Array of pairs of token owner and token's properties for minted token
+ /// @dev EVM selector for this function is: 0xab427b0c,
+ /// or in textual repr: mintBulkCross(((address,uint256),(string,bytes)[])[])
+ function mintBulkCross(MintTokenData[] memory data) external returns (bool);
+
// /// @notice Function to mint multiple tokens with the given tokenUris.
// /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive
// /// numbers and first number should be obtained with `nextTokenId` method
@@ -705,6 +711,14 @@
string uri;
}
+/// Token minting parameters
+struct MintTokenData {
+ /// Minted token owner
+ CrossAddress owner;
+ /// Minted token properties
+ Property[] properties;
+}
+
/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
/// @dev See https://eips.ethereum.org/EIPS/eip-721
/// @dev the ERC-165 identifier for this interface is 0x780e9d63
tests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueRefungible.sol
+++ b/tests/src/eth/api/UniqueRefungible.sol
@@ -551,7 +551,7 @@
}
/// @title Unique extensions for ERC721.
-/// @dev the ERC-165 identifier for this interface is 0x95c0f66c
+/// @dev the ERC-165 identifier for this interface is 0x4abaabdb
interface ERC721UniqueExtensions is Dummy, ERC165 {
/// @notice A descriptive name for a collection of NFTs in this contract
/// @dev EVM selector for this function is: 0x06fdde03,
@@ -668,6 +668,12 @@
// /// or in textual repr: mintBulk(address,uint256[])
// function mintBulk(address to, uint256[] memory tokenIds) external returns (bool);
+ /// @notice Function to mint a token.
+ /// @param tokenProperties Properties of minted token
+ /// @dev EVM selector for this function is: 0xdf7a5db7,
+ /// or in textual repr: mintBulkCross((((address,uint256),uint128)[],(string,bytes)[])[])
+ function mintBulkCross(MintTokenData[] memory tokenProperties) external returns (bool);
+
// /// @notice Function to mint multiple tokens with the given tokenUris.
// /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive
// /// numbers and first number should be obtained with `nextTokenId` method
@@ -706,6 +712,22 @@
string uri;
}
+/// Token minting parameters
+struct MintTokenData {
+ /// Minted token owner and number of pieces
+ OwnerPieces[] owners;
+ /// Minted token properties
+ Property[] properties;
+}
+
+/// Token minting parameters
+struct OwnerPieces {
+ /// Minted token owner
+ CrossAddress owner;
+ /// Number of token pieces
+ uint128 pieces;
+}
+
/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
/// @dev See https://eips.ethereum.org/EIPS/eip-721
/// @dev the ERC-165 identifier for this interface is 0x780e9d63
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';18import {IKeyringPair} from '@polkadot/types/types';19import {Contract} from 'web3-eth-contract';20import {ITokenPropertyPermission} from '../util/playgrounds/types';2122describe('Check ERC721 token URI for NFT', () => {23 let donor: IKeyringPair;2425 before(async function() {26 await usingEthPlaygrounds(async (_helper, privateKey) => {27 donor = await privateKey({url: import.meta.url});28 });29 });3031 async function setup(helper: EthUniqueHelper, baseUri: string, propertyKey?: string, propertyValue?: string): Promise<{contract: Contract, nextTokenId: string}> {32 const owner = await helper.eth.createAccountWithBalance(donor);33 const receiver = helper.eth.createAccount();3435 const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', 'a', 'b', baseUri);36 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);3738 const result = await contract.methods.mint(receiver).send();39 const tokenId = result.events.Transfer.returnValues.tokenId;40 expect(tokenId).to.be.equal('1');4142 if(propertyKey && propertyValue) {43 // Set URL or suffix44 await contract.methods.setProperties(tokenId, [{key: propertyKey, value: Buffer.from(propertyValue)}]).send();45 }4647 const event = result.events.Transfer;48 expect(event.address).to.be.equal(collectionAddress);49 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');50 expect(event.returnValues.to).to.be.equal(receiver);51 expect(event.returnValues.tokenId).to.be.equal(tokenId);5253 return {contract, nextTokenId: tokenId};54 }5556 itEth('Empty tokenURI', async ({helper}) => {57 const {contract, nextTokenId} = await setup(helper, '');58 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');59 });6061 itEth('TokenURI from url', async ({helper}) => {62 const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URI', 'Token URI');63 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');64 });6566 itEth('TokenURI from baseURI', async ({helper}) => {67 const {contract, nextTokenId} = await setup(helper, 'BaseURI_');68 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_');69 });7071 itEth('TokenURI from baseURI + suffix', async ({helper}) => {72 const suffix = '/some/suffix';73 const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URISuffix', suffix);74 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);75 });76});7778describe('NFT: Plain calls', () => {79 let donor: IKeyringPair;80 let minter: IKeyringPair;81 let bob: IKeyringPair;82 let charlie: IKeyringPair;8384 before(async function() {85 await usingEthPlaygrounds(async (helper, privateKey) => {86 donor = await privateKey({url: import.meta.url});87 [minter, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);88 });89 });9091 // TODO combine all minting tests in one place92 [93 'substrate' as const,94 'ethereum' as const,95 ].map(testCase => {96 itEth(`Can perform mintCross() for ${testCase} address`, async ({helper}) => {97 const collectionAdmin = await helper.eth.createAccountWithBalance(donor);9899 const receiverEth = helper.eth.createAccount();100 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);101 const receiverSub = bob;102 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);103104 // const receiverCross = helper.ethCrossAccount.fromKeyringPair(bob);105 const properties = Array(5).fill(0).map((_, i) => ({key: `key_${i}`, value: Buffer.from(`value_${i}`)}));106 const permissions: ITokenPropertyPermission[] = properties107 .map(p => ({108 key: p.key, permission: {109 tokenOwner: false,110 collectionAdmin: true,111 mutable: false,112 },113 }));114115 const collection = await helper.nft.mintCollection(minter, {116 tokenPrefix: 'ethp',117 tokenPropertyPermissions: permissions,118 });119 await collection.addAdmin(minter, {Ethereum: collectionAdmin});120121 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);122 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', collectionAdmin, true);123 let expectedTokenId = await contract.methods.nextTokenId().call();124 let result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, []).send();125 let tokenId = result.events.Transfer.returnValues.tokenId;126 expect(tokenId).to.be.equal(expectedTokenId);127128 let event = result.events.Transfer;129 expect(event.address).to.be.equal(collectionAddress);130 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');131 expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));132 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);133134 expectedTokenId = await contract.methods.nextTokenId().call();135 result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, properties).send();136 event = result.events.Transfer;137 expect(event.address).to.be.equal(collectionAddress);138 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');139 expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));140 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);141142 tokenId = result.events.Transfer.returnValues.tokenId;143144 expect(tokenId).to.be.equal(expectedTokenId);145146 expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties147 .map(p => helper.ethProperty.property(p.key, p.value.toString())));148149 expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId))150 .to.deep.eq(testCase === 'ethereum' ? {Ethereum: receiverEth.toLowerCase()} : {Substrate: receiverSub.address});151 });152 });153154 itEth('Non-owner and non admin cannot mintCross', async ({helper}) => {155 const nonOwner = await helper.eth.createAccountWithBalance(donor);156 const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);157158 const collection = await helper.nft.mintCollection(minter);159 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);160 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft');161162 await expect(collectionEvm.methods.mintCross(nonOwnerCross, []).call({from: nonOwner}))163 .to.be.rejectedWith('PublicMintingNotAllowed');164 });165166 //TODO: CORE-302 add eth methods167 itEth.skip('Can perform mintBulk()', async ({helper}) => {168 const caller = await helper.eth.createAccountWithBalance(donor);169 const receiver = helper.eth.createAccount();170171 const collection = await helper.nft.mintCollection(minter);172 await collection.addAdmin(minter, {Ethereum: caller});173174 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);175 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', caller);176 {177 const bulkSize = 3;178 const nextTokenId = await contract.methods.nextTokenId().call();179 expect(nextTokenId).to.be.equal('1');180 const result = await contract.methods.mintBulkWithTokenURI(181 receiver,182 Array.from({length: bulkSize}, (_, i) => (183 [+nextTokenId + i, `Test URI ${i}`]184 )),185 ).send({from: caller});186187 const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.tokenId - b.returnValues.tokenId);188 for(let i = 0; i < bulkSize; i++) {189 const event = events[i];190 expect(event.address).to.equal(collectionAddress);191 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');192 expect(event.returnValues.to).to.equal(receiver);193 expect(event.returnValues.tokenId).to.equal(`${+nextTokenId+i}`);194195 expect(await contract.methods.tokenURI(+nextTokenId + i).call()).to.be.equal(`Test URI ${i}`);196 }197 }198 });199200 itEth('Can perform burn()', async ({helper}) => {201 const caller = await helper.eth.createAccountWithBalance(donor);202203 const collection = await helper.nft.mintCollection(minter, {});204 const {tokenId} = await collection.mintToken(minter, {Ethereum: caller});205206 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);207 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', caller);208209 {210 const result = await contract.methods.burn(tokenId).send({from: caller});211212 const event = result.events.Transfer;213 expect(event.address).to.be.equal(collectionAddress);214 expect(event.returnValues.from).to.be.equal(caller);215 expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');216 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);217 }218 });219220 itEth('Can perform approve()', async ({helper}) => {221 const owner = await helper.eth.createAccountWithBalance(donor);222 const spender = helper.eth.createAccount();223224 const collection = await helper.nft.mintCollection(minter, {});225 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});226227 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);228 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);229230 {231 const badTokenId = await contract.methods.nextTokenId().call() + 1;232 await expect(contract.methods.getApproved(badTokenId).call()).to.be.rejectedWith('revert TokenNotFound');233 }234 {235 const approved = await contract.methods.getApproved(tokenId).call();236 expect(approved).to.be.equal('0x0000000000000000000000000000000000000000');237 }238 {239 const result = await contract.methods.approve(spender, tokenId).send({from: owner});240241 const event = result.events.Approval;242 expect(event.address).to.be.equal(collectionAddress);243 expect(event.returnValues.owner).to.be.equal(owner);244 expect(event.returnValues.approved).to.be.equal(spender);245 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);246 }247 {248 const approved = await contract.methods.getApproved(tokenId).call();249 expect(approved).to.be.equal(spender);250 }251 });252253 itEth('Can perform setApprovalForAll()', async ({helper}) => {254 const owner = await helper.eth.createAccountWithBalance(donor);255 const operator = helper.eth.createAccount();256257 const collection = await helper.nft.mintCollection(minter, {});258259 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);260 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);261262 const approvedBefore = await contract.methods.isApprovedForAll(owner, operator).call();263 expect(approvedBefore).to.be.equal(false);264265 {266 const result = await contract.methods.setApprovalForAll(operator, true).send({from: owner});267268 expect(result.events.ApprovalForAll).to.be.like({269 address: collectionAddress,270 event: 'ApprovalForAll',271 returnValues: {272 owner,273 operator,274 approved: true,275 },276 });277278 const approvedAfter = await contract.methods.isApprovedForAll(owner, operator).call();279 expect(approvedAfter).to.be.equal(true);280 }281282 {283 const result = await contract.methods.setApprovalForAll(operator, false).send({from: owner});284285 expect(result.events.ApprovalForAll).to.be.like({286 address: collectionAddress,287 event: 'ApprovalForAll',288 returnValues: {289 owner,290 operator,291 approved: false,292 },293 });294295 const approvedAfter = await contract.methods.isApprovedForAll(owner, operator).call();296 expect(approvedAfter).to.be.equal(false);297 }298 });299300 itEth('Can perform burn with ApprovalForAll', async ({helper}) => {301 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});302303 const owner = await helper.eth.createAccountWithBalance(donor);304 const operator = await helper.eth.createAccountWithBalance(donor);305306 const token = await collection.mintToken(minter, {Ethereum: owner});307308 const address = helper.ethAddress.fromCollectionId(collection.collectionId);309 const contract = await helper.ethNativeContract.collection(address, 'nft');310311 {312 await contract.methods.setApprovalForAll(operator, true).send({from: owner});313 const ownerCross = helper.ethCrossAccount.fromAddress(owner);314 const result = await contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: operator});315 const events = result.events.Transfer;316317 expect(events).to.be.like({318 address,319 event: 'Transfer',320 returnValues: {321 from: owner,322 to: '0x0000000000000000000000000000000000000000',323 tokenId: token.tokenId.toString(),324 },325 });326 }327328 expect(await helper.nft.doesTokenExist(collection.collectionId, token.tokenId)).to.be.false;329 });330331 itEth('Can perform transfer with ApprovalForAll', async ({helper}) => {332 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});333334 const owner = await helper.eth.createAccountWithBalance(donor);335 const operator = await helper.eth.createAccountWithBalance(donor);336 const receiver = charlie;337338 const token = await collection.mintToken(minter, {Ethereum: owner});339340 const address = helper.ethAddress.fromCollectionId(collection.collectionId);341 const contract = await helper.ethNativeContract.collection(address, 'nft');342343 {344 await contract.methods.setApprovalForAll(operator, true).send({from: owner});345 const ownerCross = helper.ethCrossAccount.fromAddress(owner);346 const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);347 const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: operator});348 const event = result.events.Transfer;349 expect(event).to.be.like({350 address: helper.ethAddress.fromCollectionId(collection.collectionId),351 event: 'Transfer',352 returnValues: {353 from: owner,354 to: helper.address.substrateToEth(receiver.address),355 tokenId: token.tokenId.toString(),356 },357 });358 }359360 expect(await token.getOwner()).to.be.like({Substrate: receiver.address});361 });362363 itEth('Can perform burnFromCross()', async ({helper}) => {364 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});365 const ownerSub = bob;366 const ownerCrossSub = helper.ethCrossAccount.fromKeyringPair(ownerSub);367 const ownerEth = await helper.eth.createAccountWithBalance(donor);368 const ownerCrossEth = helper.ethCrossAccount.fromAddress(ownerEth);369370 const burnerEth = await helper.eth.createAccountWithBalance(donor);371 const burnerCrossEth = helper.ethCrossAccount.fromAddress(burnerEth);372373 const token1 = await collection.mintToken(minter, {Substrate: ownerSub.address});374 const token2 = await collection.mintToken(minter, {Ethereum: ownerEth});375376 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);377 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft');378379 // Approve tokens from substrate and ethereum:380 await token1.approve(ownerSub, {Ethereum: burnerEth});381 await collectionEvm.methods.approveCross(burnerCrossEth, token2.tokenId).send({from: ownerEth});382383 // can burnFromCross:384 const result1 = await collectionEvm.methods.burnFromCross(ownerCrossSub, token1.tokenId).send({from: burnerEth});385 const result2 = await collectionEvm.methods.burnFromCross(ownerCrossEth, token2.tokenId).send({from: burnerEth});386 const events1 = result1.events.Transfer;387 const events2 = result2.events.Transfer;388389 // Check events for burnFromCross (substrate and ethereum):390 [391 [events1, token1, helper.address.substrateToEth(ownerSub.address)],392 [events2, token2, ownerEth],393 ].map(burnData => {394 expect(burnData[0]).to.be.like({395 address: collectionAddress,396 event: 'Transfer',397 returnValues: {398 from: burnData[2],399 to: '0x0000000000000000000000000000000000000000',400 tokenId: burnData[1].tokenId.toString(),401 },402 });403 });404405 expect(await token1.doesExist()).to.be.false;406 expect(await token2.doesExist()).to.be.false;407 });408409 // TODO combine all approve tests in one place410 itEth('Can perform approveCross()', async ({helper}) => {411 // arrange: create accounts412 const owner = await helper.eth.createAccountWithBalance(donor);413 const ownerCross = helper.ethCrossAccount.fromAddress(owner);414 const receiverSub = charlie;415 const recieverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);416 const receiverEth = await helper.eth.createAccountWithBalance(donor);417 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);418419 // arrange: create collection and tokens:420 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});421 const token1 = await collection.mintToken(minter, {Ethereum: owner});422 const token2 = await collection.mintToken(minter, {Ethereum: owner});423424 const collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');425426 // Can approveCross substrate and ethereum address:427 const resultSub = await collectionEvm.methods.approveCross(recieverCrossSub, token1.tokenId).send({from: owner});428 const resultEth = await collectionEvm.methods.approveCross(receiverCrossEth, token2.tokenId).send({from: owner});429 const eventSub = resultSub.events.Approval;430 const eventEth = resultEth.events.Approval;431 expect(eventSub).to.be.like({432 address: helper.ethAddress.fromCollectionId(collection.collectionId),433 event: 'Approval',434 returnValues: {435 owner,436 approved: helper.address.substrateToEth(receiverSub.address),437 tokenId: token1.tokenId.toString(),438 },439 });440 expect(eventEth).to.be.like({441 address: helper.ethAddress.fromCollectionId(collection.collectionId),442 event: 'Approval',443 returnValues: {444 owner,445 approved: receiverEth,446 tokenId: token2.tokenId.toString(),447 },448 });449450 // Substrate address can transferFrom approved tokens:451 await helper.nft.transferTokenFrom(receiverSub, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiverSub.address});452 expect(await helper.nft.getTokenOwner(collection.collectionId, token1.tokenId)).to.deep.eq({Substrate: receiverSub.address});453 // Ethereum address can transferFromCross approved tokens:454 await collectionEvm.methods.transferFromCross(ownerCross, receiverCrossEth, token2.tokenId).send({from: receiverEth});455 expect(await helper.nft.getTokenOwner(collection.collectionId, token2.tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});456 });457458 itEth('Non-owner and non admin cannot approveCross', async ({helper}) => {459 const nonOwner = await helper.eth.createAccountWithBalance(donor);460 const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);461 const owner = await helper.eth.createAccountWithBalance(donor);462 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});463 const collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');464 const token = await collection.mintToken(minter, {Ethereum: owner});465466 await expect(collectionEvm.methods.approveCross(nonOwnerCross, token.tokenId).call({from: nonOwner})).to.be.rejectedWith('CantApproveMoreThanOwned');467 });468469 itEth('Can reaffirm approved address', async ({helper}) => {470 const owner = await helper.eth.createAccountWithBalance(donor);471 const ownerCrossEth = helper.ethCrossAccount.fromAddress(owner);472 const [receiver1, receiver2] = await helper.arrange.createAccounts([100n, 100n], donor);473 const receiver1Cross = helper.ethCrossAccount.fromKeyringPair(receiver1);474 const receiver2Cross = helper.ethCrossAccount.fromKeyringPair(receiver2);475 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});476 const token1 = await collection.mintToken(minter, {Ethereum: owner});477 const token2 = await collection.mintToken(minter, {Ethereum: owner});478 const collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');479480 // Can approve and reaffirm approved address:481 await collectionEvm.methods.approveCross(receiver1Cross, token1.tokenId).send({from: owner});482 await collectionEvm.methods.approveCross(receiver2Cross, token1.tokenId).send({from: owner});483484 // receiver1 cannot transferFrom:485 await expect(helper.nft.transferTokenFrom(receiver1, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiver1.address})).to.be.rejected;486 // receiver2 can transferFrom:487 await helper.nft.transferTokenFrom(receiver2, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiver2.address});488489 // can set approved address to self address to remove approval:490 await collectionEvm.methods.approveCross(receiver1Cross, token2.tokenId).send({from: owner});491 await collectionEvm.methods.approveCross(ownerCrossEth, token2.tokenId).send({from: owner});492493 // receiver1 cannot transfer token anymore:494 await expect(helper.nft.transferTokenFrom(receiver1, collection.collectionId, token2.tokenId, {Ethereum: owner}, {Substrate: receiver1.address})).to.be.rejected;495 });496497 itEth('Can perform transferFrom()', async ({helper}) => {498 const owner = await helper.eth.createAccountWithBalance(donor);499 const spender = await helper.eth.createAccountWithBalance(donor);500 const receiver = helper.eth.createAccount();501502 const collection = await helper.nft.mintCollection(minter, {});503 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});504505 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);506 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);507508 await contract.methods.approve(spender, tokenId).send({from: owner});509510 {511 const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({from: spender});512513 const event = result.events.Transfer;514 expect(event.address).to.be.equal(collectionAddress);515 expect(event.returnValues.from).to.be.equal(owner);516 expect(event.returnValues.to).to.be.equal(receiver);517 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);518 }519520 {521 const balance = await contract.methods.balanceOf(receiver).call();522 expect(+balance).to.equal(1);523 }524525 {526 const balance = await contract.methods.balanceOf(owner).call();527 expect(+balance).to.equal(0);528 }529 });530531 itEth('Can perform transferFromCross()', async ({helper}) => {532 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});533534 const [owner, receiver] = await helper.arrange.createAccounts([100n, 100n], donor);535 const spender = await helper.eth.createAccountWithBalance(donor);536537 const token = await collection.mintToken(minter, {Substrate: owner.address});538539 const address = helper.ethAddress.fromCollectionId(collection.collectionId);540 const contract = await helper.ethNativeContract.collection(address, 'nft');541542 await token.approve(owner, {Ethereum: spender});543544 {545 const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);546 const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);547 const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});548 const event = result.events.Transfer;549 expect(event).to.be.like({550 address: helper.ethAddress.fromCollectionId(collection.collectionId),551 event: 'Transfer',552 returnValues: {553 from: helper.address.substrateToEth(owner.address),554 to: helper.address.substrateToEth(receiver.address),555 tokenId: token.tokenId.toString(),556 },557 });558 }559560 expect(await token.getOwner()).to.be.like({Substrate: receiver.address});561 });562563 itEth('Can perform transfer()', async ({helper}) => {564 const collection = await helper.nft.mintCollection(minter, {});565 const owner = await helper.eth.createAccountWithBalance(donor);566 const receiver = helper.eth.createAccount();567568 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});569570 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);571 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);572573 {574 const result = await contract.methods.transfer(receiver, tokenId).send({from: owner});575576 const event = result.events.Transfer;577 expect(event.address).to.be.equal(collectionAddress);578 expect(event.returnValues.from).to.be.equal(owner);579 expect(event.returnValues.to).to.be.equal(receiver);580 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);581 }582583 {584 const balance = await contract.methods.balanceOf(owner).call();585 expect(+balance).to.equal(0);586 }587588 {589 const balance = await contract.methods.balanceOf(receiver).call();590 expect(+balance).to.equal(1);591 }592 });593594 itEth('Can perform transferCross()', async ({helper}) => {595 const collection = await helper.nft.mintCollection(minter, {});596 const owner = await helper.eth.createAccountWithBalance(donor);597 const receiverEth = await helper.eth.createAccountWithBalance(donor);598 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);599 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);600601 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});602603 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);604 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);605606 {607 // Can transferCross to ethereum address:608 const result = await collectionEvm.methods.transferCross(receiverCrossEth, tokenId).send({from: owner});609 // Check events:610 const event = result.events.Transfer;611 expect(event.address).to.be.equal(collectionAddress);612 expect(event.returnValues.from).to.be.equal(owner);613 expect(event.returnValues.to).to.be.equal(receiverEth);614 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);615616 // owner has balance = 0:617 const ownerBalance = await collectionEvm.methods.balanceOf(owner).call();618 expect(+ownerBalance).to.equal(0);619 // receiver owns token:620 const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();621 expect(+receiverBalance).to.equal(1);622 expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});623 }624625 {626 // Can transferCross to substrate address:627 const substrateResult = await collectionEvm.methods.transferCross(receiverCrossSub, tokenId).send({from: receiverEth});628 // Check events:629 const event = substrateResult.events.Transfer;630 expect(event.address).to.be.equal(collectionAddress);631 expect(event.returnValues.from).to.be.equal(receiverEth);632 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));633 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);634635 // owner has balance = 0:636 const ownerBalance = await collectionEvm.methods.balanceOf(receiverEth).call();637 expect(+ownerBalance).to.equal(0);638 // receiver owns token:639 const receiverBalance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});640 expect(receiverBalance).to.contain(tokenId);641 }642 });643644 ['transfer', 'transferCross'].map(testCase => itEth(`Cannot ${testCase} non-owned token`, async ({helper}) => {645 const sender = await helper.eth.createAccountWithBalance(donor);646 const tokenOwner = await helper.eth.createAccountWithBalance(donor);647 const receiverSub = minter;648 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);649650 const collection = await helper.nft.mintCollection(minter, {});651 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);652 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', sender);653654 await collection.mintToken(minter, {Ethereum: sender});655 const nonSendersToken = await collection.mintToken(minter, {Ethereum: tokenOwner});656657 // Cannot transferCross someone else's token:658 const receiver = testCase === 'transfer' ? helper.address.substrateToEth(receiverSub.address) : receiverCrossSub;659 await expect(collectionEvm.methods[testCase](receiver, nonSendersToken.tokenId).send({from: sender})).to.be.rejected;660 // Cannot transfer token if it does not exist:661 await expect(collectionEvm.methods[testCase](receiver, 999999).send({from: sender})).to.be.rejected;662 }));663664 itEth('Check balanceOfCross()', async ({helper}) => {665 const collection = await helper.nft.mintCollection(minter, {});666 const owner = await helper.ethCrossAccount.createAccountWithBalance(donor);667 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);668 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner.eth);669670 expect(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})).to.be.eq('0');671672 for(let i = 1; i < 10; i++) {673 await collection.mintToken(minter, {Ethereum: owner.eth});674 expect(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})).to.be.eq(i.toString());675 }676 });677678 itEth('Check ownerOfCross()', async ({helper}) => {679 const collection = await helper.nft.mintCollection(minter, {});680 let owner = await helper.ethCrossAccount.createAccountWithBalance(donor);681 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);682 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner.eth);683 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner.eth});684685 for(let i = 1n; i < 10n; i++) {686 const ownerCross = await collectionEvm.methods.ownerOfCross(tokenId).call({from: owner.eth});687 expect(ownerCross.eth).to.be.eq(owner.eth);688 expect(ownerCross.sub).to.be.eq(owner.sub);689690 const newOwner = await helper.ethCrossAccount.createAccountWithBalance(donor);691 await collectionEvm.methods.transferCross(newOwner, tokenId).send({from: owner.eth});692 owner = newOwner;693 }694 });695});696697describe('NFT: Fees', () => {698 let donor: IKeyringPair;699 let alice: IKeyringPair;700 let bob: IKeyringPair;701 let charlie: IKeyringPair;702703 before(async function() {704 await usingEthPlaygrounds(async (helper, privateKey) => {705 donor = await privateKey({url: import.meta.url});706 [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);707 });708 });709710 itEth('approve() call fee is less than 0.2UNQ', async ({helper}) => {711 const owner = await helper.eth.createAccountWithBalance(donor);712 const spender = helper.eth.createAccount();713714 const collection = await helper.nft.mintCollection(alice, {});715 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});716717 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);718719 const cost = await helper.eth.recordCallFee(owner, () => contract.methods.approve(spender, tokenId).send({from: owner}));720 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));721 });722723 itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {724 const owner = await helper.eth.createAccountWithBalance(donor);725 const spender = await helper.eth.createAccountWithBalance(donor);726727 const collection = await helper.nft.mintCollection(alice, {});728 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});729730 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);731732 await contract.methods.approve(spender, tokenId).send({from: owner});733734 const cost = await helper.eth.recordCallFee(spender, () => contract.methods.transferFrom(owner, spender, tokenId).send({from: spender}));735 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));736 });737738 itEth('Can perform transferFromCross()', async ({helper}) => {739 const collectionMinter = alice;740 const owner = bob;741 const receiver = charlie;742 const collection = await helper.nft.mintCollection(collectionMinter, {name: 'A', description: 'B', tokenPrefix: 'C'});743744 const spender = await helper.eth.createAccountWithBalance(donor);745746 const token = await collection.mintToken(collectionMinter, {Substrate: owner.address});747748 const address = helper.ethAddress.fromCollectionId(collection.collectionId);749 const contract = await helper.ethNativeContract.collection(address, 'nft');750751 await token.approve(owner, {Ethereum: spender});752753 {754 const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);755 const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);756 const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});757 const event = result.events.Transfer;758 expect(event).to.be.like({759 address: helper.ethAddress.fromCollectionId(collection.collectionId),760 event: 'Transfer',761 returnValues: {762 from: helper.address.substrateToEth(owner.address),763 to: helper.address.substrateToEth(receiver.address),764 tokenId: token.tokenId.toString(),765 },766 });767 }768769 expect(await token.getOwner()).to.be.like({Substrate: receiver.address});770 });771772 itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {773 const owner = await helper.eth.createAccountWithBalance(donor);774 const receiver = helper.eth.createAccount();775776 const collection = await helper.nft.mintCollection(alice, {});777 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});778779 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);780781 const cost = await helper.eth.recordCallFee(owner, () => contract.methods.transfer(receiver, tokenId).send({from: owner}));782 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));783 });784});785786describe('NFT: Substrate calls', () => {787 let donor: IKeyringPair;788 let alice: IKeyringPair;789790 before(async function() {791 await usingEthPlaygrounds(async (helper, privateKey) => {792 donor = await privateKey({url: import.meta.url});793 [alice] = await helper.arrange.createAccounts([20n], donor);794 });795 });796797 itEth('Events emitted for mint()', async ({helper}) => {798 const collection = await helper.nft.mintCollection(alice, {});799 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);800 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');801802 const events: any = [];803 contract.events.allEvents((_: any, event: any) => {804 events.push(event);805 });806807 const {tokenId} = await collection.mintToken(alice);808 if(events.length == 0) await helper.wait.newBlocks(1);809 const event = events[0];810811 expect(event.event).to.be.equal('Transfer');812 expect(event.address).to.be.equal(collectionAddress);813 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');814 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(alice.address));815 expect(event.returnValues.tokenId).to.be.equal(tokenId.toString());816 });817818 itEth('Events emitted for burn()', async ({helper}) => {819 const collection = await helper.nft.mintCollection(alice, {});820 const token = await collection.mintToken(alice);821822 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);823 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');824825 const events: any = [];826 contract.events.allEvents((_: any, event: any) => {827 events.push(event);828 });829830 await token.burn(alice);831 if(events.length == 0) await helper.wait.newBlocks(1);832 const event = events[0];833834 expect(event.event).to.be.equal('Transfer');835 expect(event.address).to.be.equal(collectionAddress);836 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));837 expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');838 expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());839 });840841 itEth('Events emitted for approve()', async ({helper}) => {842 const receiver = helper.eth.createAccount();843844 const collection = await helper.nft.mintCollection(alice, {});845 const token = await collection.mintToken(alice);846847 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);848 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');849850 const events: any = [];851 contract.events.allEvents((_: any, event: any) => {852 events.push(event);853 });854855 await token.approve(alice, {Ethereum: receiver});856 if(events.length == 0) await helper.wait.newBlocks(1);857 const event = events[0];858859 expect(event.event).to.be.equal('Approval');860 expect(event.address).to.be.equal(collectionAddress);861 expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));862 expect(event.returnValues.approved).to.be.equal(receiver);863 expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());864 });865866 itEth('Events emitted for transferFrom()', async ({helper}) => {867 const [bob] = await helper.arrange.createAccounts([10n], donor);868 const receiver = helper.eth.createAccount();869870 const collection = await helper.nft.mintCollection(alice, {});871 const token = await collection.mintToken(alice);872 await token.approve(alice, {Substrate: bob.address});873874 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);875 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');876877 const events: any = [];878 contract.events.allEvents((_: any, event: any) => {879 events.push(event);880 });881882 await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver});883884 if(events.length == 0) await helper.wait.newBlocks(1);885 const event = events[0];886887 expect(event.address).to.be.equal(collectionAddress);888 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));889 expect(event.returnValues.to).to.be.equal(receiver);890 expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);891 });892893 itEth('Events emitted for transfer()', async ({helper}) => {894 const receiver = helper.eth.createAccount();895896 const collection = await helper.nft.mintCollection(alice, {});897 const token = await collection.mintToken(alice);898899 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);900 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');901902 const events: any = [];903 contract.events.allEvents((_: any, event: any) => {904 events.push(event);905 });906907 await token.transfer(alice, {Ethereum: receiver});908909 if(events.length == 0) await helper.wait.newBlocks(1);910 const event = events[0];911912 expect(event.address).to.be.equal(collectionAddress);913 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));914 expect(event.returnValues.to).to.be.equal(receiver);915 expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);916 });917});918919describe('Common metadata', () => {920 let donor: IKeyringPair;921 let alice: IKeyringPair;922923 before(async function() {924 await usingEthPlaygrounds(async (helper, privateKey) => {925 donor = await privateKey({url: import.meta.url});926 [alice] = await helper.arrange.createAccounts([20n], donor);927 });928 });929930 itEth('Returns collection name', async ({helper}) => {931 const caller = helper.eth.createAccount();932 const tokenPropertyPermissions = [{933 key: 'URI',934 permission: {935 mutable: true,936 collectionAdmin: true,937 tokenOwner: false,938 },939 }];940 const collection = await helper.nft.mintCollection(941 alice,942 {943 name: 'oh River',944 tokenPrefix: 'CHANGE',945 properties: [{key: 'ERC721Metadata', value: '1'}],946 tokenPropertyPermissions,947 },948 );949950 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);951 const name = await contract.methods.name().call();952 expect(name).to.equal('oh River');953 });954955 itEth('Returns symbol name', async ({helper}) => {956 const caller = await helper.eth.createAccountWithBalance(donor);957 const tokenPropertyPermissions = [{958 key: 'URI',959 permission: {960 mutable: true,961 collectionAdmin: true,962 tokenOwner: false,963 },964 }];965 const collection = await helper.nft.mintCollection(966 alice,967 {968 name: 'oh River',969 tokenPrefix: 'CHANGE',970 properties: [{key: 'ERC721Metadata', value: '1'}],971 tokenPropertyPermissions,972 },973 );974975 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);976 const symbol = await contract.methods.symbol().call();977 expect(symbol).to.equal('CHANGE');978 });979});980981describe('Negative tests', () => {982 let donor: IKeyringPair;983 let minter: IKeyringPair;984 let alice: IKeyringPair;985986 before(async function() {987 await usingEthPlaygrounds(async (helper, privateKey) => {988 donor = await privateKey({url: import.meta.url});989 [minter, alice] = await helper.arrange.createAccounts([100n, 100n], donor);990 });991 });992993 itEth('[negative] Cant perform burn without approval', async ({helper}) => {994 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});995996 const owner = await helper.eth.createAccountWithBalance(donor);997 const spender = await helper.eth.createAccountWithBalance(donor);998999 const token = await collection.mintToken(minter, {Ethereum: owner});10001001 const address = helper.ethAddress.fromCollectionId(collection.collectionId);1002 const contract = await helper.ethNativeContract.collection(address, 'nft');10031004 const ownerCross = helper.ethCrossAccount.fromAddress(owner);1005 await expect(contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender})).to.be.rejected;10061007 await contract.methods.setApprovalForAll(spender, true).send({from: owner});1008 await contract.methods.setApprovalForAll(spender, false).send({from: owner});10091010 await expect(contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender})).to.be.rejected;1011 });10121013 itEth('[negative] Cant perform transfer without approval', async ({helper}) => {1014 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});1015 const receiver = alice;10161017 const owner = await helper.eth.createAccountWithBalance(donor);1018 const spender = await helper.eth.createAccountWithBalance(donor);10191020 const token = await collection.mintToken(minter, {Ethereum: owner});10211022 const address = helper.ethAddress.fromCollectionId(collection.collectionId);1023 const contract = await helper.ethNativeContract.collection(address, 'nft');10241025 const ownerCross = helper.ethCrossAccount.fromAddress(owner);1026 const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);10271028 await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;10291030 await contract.methods.setApprovalForAll(spender, true).send({from: owner});1031 await contract.methods.setApprovalForAll(spender, false).send({from: owner});10321033 await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;1034 });1035});1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';18import {IKeyringPair} from '@polkadot/types/types';19import {Contract} from 'web3-eth-contract';20import {ITokenPropertyPermission} from '../util/playgrounds/types';21import {CREATE_COLLECTION_DATA_DEFAULTS, CollectionMode, CreateCollectionData, TokenPermissionField} from './util/playgrounds/types';2223describe('Check ERC721 token URI for NFT', () => {24 let donor: IKeyringPair;2526 before(async function() {27 await usingEthPlaygrounds(async (_helper, privateKey) => {28 donor = await privateKey({url: import.meta.url});29 });30 });3132 async function setup(helper: EthUniqueHelper, baseUri: string, propertyKey?: string, propertyValue?: string): Promise<{contract: Contract, nextTokenId: string}> {33 const owner = await helper.eth.createAccountWithBalance(donor);34 const receiver = helper.eth.createAccount();3536 const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', 'a', 'b', baseUri);37 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);3839 const result = await contract.methods.mint(receiver).send();40 const tokenId = result.events.Transfer.returnValues.tokenId;41 expect(tokenId).to.be.equal('1');4243 if(propertyKey && propertyValue) {44 // Set URL or suffix45 await contract.methods.setProperties(tokenId, [{key: propertyKey, value: Buffer.from(propertyValue)}]).send();46 }4748 const event = result.events.Transfer;49 expect(event.address).to.be.equal(collectionAddress);50 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');51 expect(event.returnValues.to).to.be.equal(receiver);52 expect(event.returnValues.tokenId).to.be.equal(tokenId);5354 return {contract, nextTokenId: tokenId};55 }5657 itEth('Empty tokenURI', async ({helper}) => {58 const {contract, nextTokenId} = await setup(helper, '');59 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');60 });6162 itEth('TokenURI from url', async ({helper}) => {63 const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URI', 'Token URI');64 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');65 });6667 itEth('TokenURI from baseURI', async ({helper}) => {68 const {contract, nextTokenId} = await setup(helper, 'BaseURI_');69 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_');70 });7172 itEth('TokenURI from baseURI + suffix', async ({helper}) => {73 const suffix = '/some/suffix';74 const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URISuffix', suffix);75 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);76 });77});7879describe('NFT: Plain calls', () => {80 let donor: IKeyringPair;81 let minter: IKeyringPair;82 let bob: IKeyringPair;83 let charlie: IKeyringPair;8485 before(async function() {86 await usingEthPlaygrounds(async (helper, privateKey) => {87 donor = await privateKey({url: import.meta.url});88 [minter, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);89 });90 });9192 // TODO combine all minting tests in one place93 [94 'substrate' as const,95 'ethereum' as const,96 ].map(testCase => {97 itEth(`Can perform mintCross() for ${testCase} address`, async ({helper}) => {98 const collectionAdmin = await helper.eth.createAccountWithBalance(donor);99100 const receiverEth = helper.eth.createAccount();101 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);102 const receiverSub = bob;103 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);104105 // const receiverCross = helper.ethCrossAccount.fromKeyringPair(bob);106 const properties = Array(5).fill(0).map((_, i) => ({key: `key_${i}`, value: Buffer.from(`value_${i}`)}));107 const permissions: ITokenPropertyPermission[] = properties108 .map(p => ({109 key: p.key, permission: {110 tokenOwner: false,111 collectionAdmin: true,112 mutable: false,113 },114 }));115116 const collection = await helper.nft.mintCollection(minter, {117 tokenPrefix: 'ethp',118 tokenPropertyPermissions: permissions,119 });120 await collection.addAdmin(minter, {Ethereum: collectionAdmin});121122 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);123 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', collectionAdmin, true);124 let expectedTokenId = await contract.methods.nextTokenId().call();125 let result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, []).send();126 let tokenId = result.events.Transfer.returnValues.tokenId;127 expect(tokenId).to.be.equal(expectedTokenId);128129 let event = result.events.Transfer;130 expect(event.address).to.be.equal(collectionAddress);131 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');132 expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));133 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);134135 expectedTokenId = await contract.methods.nextTokenId().call();136 result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, properties).send();137 event = result.events.Transfer;138 expect(event.address).to.be.equal(collectionAddress);139 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');140 expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));141 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);142143 tokenId = result.events.Transfer.returnValues.tokenId;144145 expect(tokenId).to.be.equal(expectedTokenId);146147 expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties148 .map(p => helper.ethProperty.property(p.key, p.value.toString())));149150 expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId))151 .to.deep.eq(testCase === 'ethereum' ? {Ethereum: receiverEth.toLowerCase()} : {Substrate: receiverSub.address});152 });153 });154155 itEth('Non-owner and non admin cannot mintCross', async ({helper}) => {156 const nonOwner = await helper.eth.createAccountWithBalance(donor);157 const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);158159 const collection = await helper.nft.mintCollection(minter);160 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);161 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft');162163 await expect(collectionEvm.methods.mintCross(nonOwnerCross, []).call({from: nonOwner}))164 .to.be.rejectedWith('PublicMintingNotAllowed');165 });166167 //TODO: CORE-302 add eth methods168 itEth.skip('Can perform mintBulk()', async ({helper}) => {169 const caller = await helper.eth.createAccountWithBalance(donor);170 const receiver = helper.eth.createAccount();171172 const collection = await helper.nft.mintCollection(minter);173 await collection.addAdmin(minter, {Ethereum: caller});174175 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);176 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', caller);177 {178 const bulkSize = 3;179 const nextTokenId = await contract.methods.nextTokenId().call();180 expect(nextTokenId).to.be.equal('1');181 const result = await contract.methods.mintBulkWithTokenURI(182 receiver,183 Array.from({length: bulkSize}, (_, i) => (184 [+nextTokenId + i, `Test URI ${i}`]185 )),186 ).send({from: caller});187188 const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.tokenId - b.returnValues.tokenId);189 for(let i = 0; i < bulkSize; i++) {190 const event = events[i];191 expect(event.address).to.equal(collectionAddress);192 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');193 expect(event.returnValues.to).to.equal(receiver);194 expect(event.returnValues.tokenId).to.equal(`${+nextTokenId+i}`);195196 expect(await contract.methods.tokenURI(+nextTokenId + i).call()).to.be.equal(`Test URI ${i}`);197 }198 }199 });200201 itEth('Can perform mintBulkCross()', async ({helper}) => {202 const caller = await helper.eth.createAccountWithBalance(donor);203 const callerCross = helper.ethCrossAccount.fromAddress(caller);204 const receiver = helper.eth.createAccount();205 const receiverCross = helper.ethCrossAccount.fromAddress(receiver);206207 const permissions = [208 {code: TokenPermissionField.Mutable, value: true},209 {code: TokenPermissionField.TokenOwner, value: true},210 {code: TokenPermissionField.CollectionAdmin, value: true},211 ];212 const {collectionAddress} = await helper.eth.createCollection(213 caller,214 {215 ...CREATE_COLLECTION_DATA_DEFAULTS,216 name: 'A',217 description: 'B',218 tokenPrefix: 'C',219 collectionMode: 'nft',220 adminList: [callerCross],221 tokenPropertyPermissions: [222 {key: 'key_0_0', permissions},223 {key: 'key_1_0', permissions},224 {key: 'key_1_1', permissions},225 {key: 'key_2_0', permissions},226 {key: 'key_2_1', permissions},227 {key: 'key_2_2', permissions},228 ],229 },230 ).send();231232 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', caller);233 {234 const nextTokenId = await contract.methods.nextTokenId().call();235 expect(nextTokenId).to.be.equal('1');236 const result = await contract.methods.mintBulkCross([237 {238 owner: receiverCross,239 properties: [240 {key: 'key_0_0', value: Buffer.from('value_0_0')},241 ],242 },243 {244 owner: receiverCross,245 properties: [246 {key: 'key_1_0', value: Buffer.from('value_1_0')},247 {key: 'key_1_1', value: Buffer.from('value_1_1')},248 ],249 },250 {251 owner: receiverCross,252 properties: [253 {key: 'key_2_0', value: Buffer.from('value_2_0')},254 {key: 'key_2_1', value: Buffer.from('value_2_1')},255 {key: 'key_2_2', value: Buffer.from('value_2_2')},256 ],257 },258 ]).send({from: caller});259 const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.tokenId - b.returnValues.tokenId);260 const bulkSize = 3;261 for(let i = 0; i < bulkSize; i++) {262 const event = events[i];263 expect(event.address).to.equal(collectionAddress);264 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');265 expect(event.returnValues.to).to.equal(receiver);266 expect(event.returnValues.tokenId).to.equal(`${+nextTokenId+i}`);267 }268269 const properties = [270 await contract.methods.properties(+nextTokenId, []).call(),271 await contract.methods.properties(+nextTokenId + 1, []).call(),272 await contract.methods.properties(+nextTokenId + 2, []).call(),273 ];274 expect(properties).to.be.deep.equal([275 [276 ['key_0_0', helper.getWeb3().utils.toHex('value_0_0')],277 ],278 [279 ['key_1_0', helper.getWeb3().utils.toHex('value_1_0')],280 ['key_1_1', helper.getWeb3().utils.toHex('value_1_1')],281 ],282 [283 ['key_2_0', helper.getWeb3().utils.toHex('value_2_0')],284 ['key_2_1', helper.getWeb3().utils.toHex('value_2_1')],285 ['key_2_2', helper.getWeb3().utils.toHex('value_2_2')],286 ],287 ]);288 }289 });290291 itEth('Can perform burn()', async ({helper}) => {292 const caller = await helper.eth.createAccountWithBalance(donor);293294 const collection = await helper.nft.mintCollection(minter, {});295 const {tokenId} = await collection.mintToken(minter, {Ethereum: caller});296297 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);298 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', caller);299300 {301 const result = await contract.methods.burn(tokenId).send({from: caller});302303 const event = result.events.Transfer;304 expect(event.address).to.be.equal(collectionAddress);305 expect(event.returnValues.from).to.be.equal(caller);306 expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');307 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);308 }309 });310311 itEth('Can perform approve()', async ({helper}) => {312 const owner = await helper.eth.createAccountWithBalance(donor);313 const spender = helper.eth.createAccount();314315 const collection = await helper.nft.mintCollection(minter, {});316 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});317318 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);319 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);320321 {322 const badTokenId = await contract.methods.nextTokenId().call() + 1;323 await expect(contract.methods.getApproved(badTokenId).call()).to.be.rejectedWith('revert TokenNotFound');324 }325 {326 const approved = await contract.methods.getApproved(tokenId).call();327 expect(approved).to.be.equal('0x0000000000000000000000000000000000000000');328 }329 {330 const result = await contract.methods.approve(spender, tokenId).send({from: owner});331332 const event = result.events.Approval;333 expect(event.address).to.be.equal(collectionAddress);334 expect(event.returnValues.owner).to.be.equal(owner);335 expect(event.returnValues.approved).to.be.equal(spender);336 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);337 }338 {339 const approved = await contract.methods.getApproved(tokenId).call();340 expect(approved).to.be.equal(spender);341 }342 });343344 itEth('Can perform setApprovalForAll()', async ({helper}) => {345 const owner = await helper.eth.createAccountWithBalance(donor);346 const operator = helper.eth.createAccount();347348 const collection = await helper.nft.mintCollection(minter, {});349350 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);351 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);352353 const approvedBefore = await contract.methods.isApprovedForAll(owner, operator).call();354 expect(approvedBefore).to.be.equal(false);355356 {357 const result = await contract.methods.setApprovalForAll(operator, true).send({from: owner});358359 expect(result.events.ApprovalForAll).to.be.like({360 address: collectionAddress,361 event: 'ApprovalForAll',362 returnValues: {363 owner,364 operator,365 approved: true,366 },367 });368369 const approvedAfter = await contract.methods.isApprovedForAll(owner, operator).call();370 expect(approvedAfter).to.be.equal(true);371 }372373 {374 const result = await contract.methods.setApprovalForAll(operator, false).send({from: owner});375376 expect(result.events.ApprovalForAll).to.be.like({377 address: collectionAddress,378 event: 'ApprovalForAll',379 returnValues: {380 owner,381 operator,382 approved: false,383 },384 });385386 const approvedAfter = await contract.methods.isApprovedForAll(owner, operator).call();387 expect(approvedAfter).to.be.equal(false);388 }389 });390391 itEth('Can perform burn with ApprovalForAll', async ({helper}) => {392 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});393394 const owner = await helper.eth.createAccountWithBalance(donor);395 const operator = await helper.eth.createAccountWithBalance(donor);396397 const token = await collection.mintToken(minter, {Ethereum: owner});398399 const address = helper.ethAddress.fromCollectionId(collection.collectionId);400 const contract = await helper.ethNativeContract.collection(address, 'nft');401402 {403 await contract.methods.setApprovalForAll(operator, true).send({from: owner});404 const ownerCross = helper.ethCrossAccount.fromAddress(owner);405 const result = await contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: operator});406 const events = result.events.Transfer;407408 expect(events).to.be.like({409 address,410 event: 'Transfer',411 returnValues: {412 from: owner,413 to: '0x0000000000000000000000000000000000000000',414 tokenId: token.tokenId.toString(),415 },416 });417 }418419 expect(await helper.nft.doesTokenExist(collection.collectionId, token.tokenId)).to.be.false;420 });421422 itEth('Can perform transfer with ApprovalForAll', async ({helper}) => {423 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});424425 const owner = await helper.eth.createAccountWithBalance(donor);426 const operator = await helper.eth.createAccountWithBalance(donor);427 const receiver = charlie;428429 const token = await collection.mintToken(minter, {Ethereum: owner});430431 const address = helper.ethAddress.fromCollectionId(collection.collectionId);432 const contract = await helper.ethNativeContract.collection(address, 'nft');433434 {435 await contract.methods.setApprovalForAll(operator, true).send({from: owner});436 const ownerCross = helper.ethCrossAccount.fromAddress(owner);437 const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);438 const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: operator});439 const event = result.events.Transfer;440 expect(event).to.be.like({441 address: helper.ethAddress.fromCollectionId(collection.collectionId),442 event: 'Transfer',443 returnValues: {444 from: owner,445 to: helper.address.substrateToEth(receiver.address),446 tokenId: token.tokenId.toString(),447 },448 });449 }450451 expect(await token.getOwner()).to.be.like({Substrate: receiver.address});452 });453454 itEth('Can perform burnFromCross()', async ({helper}) => {455 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});456 const ownerSub = bob;457 const ownerCrossSub = helper.ethCrossAccount.fromKeyringPair(ownerSub);458 const ownerEth = await helper.eth.createAccountWithBalance(donor);459 const ownerCrossEth = helper.ethCrossAccount.fromAddress(ownerEth);460461 const burnerEth = await helper.eth.createAccountWithBalance(donor);462 const burnerCrossEth = helper.ethCrossAccount.fromAddress(burnerEth);463464 const token1 = await collection.mintToken(minter, {Substrate: ownerSub.address});465 const token2 = await collection.mintToken(minter, {Ethereum: ownerEth});466467 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);468 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft');469470 // Approve tokens from substrate and ethereum:471 await token1.approve(ownerSub, {Ethereum: burnerEth});472 await collectionEvm.methods.approveCross(burnerCrossEth, token2.tokenId).send({from: ownerEth});473474 // can burnFromCross:475 const result1 = await collectionEvm.methods.burnFromCross(ownerCrossSub, token1.tokenId).send({from: burnerEth});476 const result2 = await collectionEvm.methods.burnFromCross(ownerCrossEth, token2.tokenId).send({from: burnerEth});477 const events1 = result1.events.Transfer;478 const events2 = result2.events.Transfer;479480 // Check events for burnFromCross (substrate and ethereum):481 [482 [events1, token1, helper.address.substrateToEth(ownerSub.address)],483 [events2, token2, ownerEth],484 ].map(burnData => {485 expect(burnData[0]).to.be.like({486 address: collectionAddress,487 event: 'Transfer',488 returnValues: {489 from: burnData[2],490 to: '0x0000000000000000000000000000000000000000',491 tokenId: burnData[1].tokenId.toString(),492 },493 });494 });495496 expect(await token1.doesExist()).to.be.false;497 expect(await token2.doesExist()).to.be.false;498 });499500 // TODO combine all approve tests in one place501 itEth('Can perform approveCross()', async ({helper}) => {502 // arrange: create accounts503 const owner = await helper.eth.createAccountWithBalance(donor);504 const ownerCross = helper.ethCrossAccount.fromAddress(owner);505 const receiverSub = charlie;506 const recieverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);507 const receiverEth = await helper.eth.createAccountWithBalance(donor);508 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);509510 // arrange: create collection and tokens:511 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});512 const token1 = await collection.mintToken(minter, {Ethereum: owner});513 const token2 = await collection.mintToken(minter, {Ethereum: owner});514515 const collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');516517 // Can approveCross substrate and ethereum address:518 const resultSub = await collectionEvm.methods.approveCross(recieverCrossSub, token1.tokenId).send({from: owner});519 const resultEth = await collectionEvm.methods.approveCross(receiverCrossEth, token2.tokenId).send({from: owner});520 const eventSub = resultSub.events.Approval;521 const eventEth = resultEth.events.Approval;522 expect(eventSub).to.be.like({523 address: helper.ethAddress.fromCollectionId(collection.collectionId),524 event: 'Approval',525 returnValues: {526 owner,527 approved: helper.address.substrateToEth(receiverSub.address),528 tokenId: token1.tokenId.toString(),529 },530 });531 expect(eventEth).to.be.like({532 address: helper.ethAddress.fromCollectionId(collection.collectionId),533 event: 'Approval',534 returnValues: {535 owner,536 approved: receiverEth,537 tokenId: token2.tokenId.toString(),538 },539 });540541 // Substrate address can transferFrom approved tokens:542 await helper.nft.transferTokenFrom(receiverSub, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiverSub.address});543 expect(await helper.nft.getTokenOwner(collection.collectionId, token1.tokenId)).to.deep.eq({Substrate: receiverSub.address});544 // Ethereum address can transferFromCross approved tokens:545 await collectionEvm.methods.transferFromCross(ownerCross, receiverCrossEth, token2.tokenId).send({from: receiverEth});546 expect(await helper.nft.getTokenOwner(collection.collectionId, token2.tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});547 });548549 itEth('Non-owner and non admin cannot approveCross', async ({helper}) => {550 const nonOwner = await helper.eth.createAccountWithBalance(donor);551 const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);552 const owner = await helper.eth.createAccountWithBalance(donor);553 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});554 const collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');555 const token = await collection.mintToken(minter, {Ethereum: owner});556557 await expect(collectionEvm.methods.approveCross(nonOwnerCross, token.tokenId).call({from: nonOwner})).to.be.rejectedWith('CantApproveMoreThanOwned');558 });559560 itEth('Can reaffirm approved address', async ({helper}) => {561 const owner = await helper.eth.createAccountWithBalance(donor);562 const ownerCrossEth = helper.ethCrossAccount.fromAddress(owner);563 const [receiver1, receiver2] = await helper.arrange.createAccounts([100n, 100n], donor);564 const receiver1Cross = helper.ethCrossAccount.fromKeyringPair(receiver1);565 const receiver2Cross = helper.ethCrossAccount.fromKeyringPair(receiver2);566 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});567 const token1 = await collection.mintToken(minter, {Ethereum: owner});568 const token2 = await collection.mintToken(minter, {Ethereum: owner});569 const collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');570571 // Can approve and reaffirm approved address:572 await collectionEvm.methods.approveCross(receiver1Cross, token1.tokenId).send({from: owner});573 await collectionEvm.methods.approveCross(receiver2Cross, token1.tokenId).send({from: owner});574575 // receiver1 cannot transferFrom:576 await expect(helper.nft.transferTokenFrom(receiver1, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiver1.address})).to.be.rejected;577 // receiver2 can transferFrom:578 await helper.nft.transferTokenFrom(receiver2, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiver2.address});579580 // can set approved address to self address to remove approval:581 await collectionEvm.methods.approveCross(receiver1Cross, token2.tokenId).send({from: owner});582 await collectionEvm.methods.approveCross(ownerCrossEth, token2.tokenId).send({from: owner});583584 // receiver1 cannot transfer token anymore:585 await expect(helper.nft.transferTokenFrom(receiver1, collection.collectionId, token2.tokenId, {Ethereum: owner}, {Substrate: receiver1.address})).to.be.rejected;586 });587588 itEth('Can perform transferFrom()', async ({helper}) => {589 const owner = await helper.eth.createAccountWithBalance(donor);590 const spender = await helper.eth.createAccountWithBalance(donor);591 const receiver = helper.eth.createAccount();592593 const collection = await helper.nft.mintCollection(minter, {});594 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});595596 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);597 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);598599 await contract.methods.approve(spender, tokenId).send({from: owner});600601 {602 const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({from: spender});603604 const event = result.events.Transfer;605 expect(event.address).to.be.equal(collectionAddress);606 expect(event.returnValues.from).to.be.equal(owner);607 expect(event.returnValues.to).to.be.equal(receiver);608 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);609 }610611 {612 const balance = await contract.methods.balanceOf(receiver).call();613 expect(+balance).to.equal(1);614 }615616 {617 const balance = await contract.methods.balanceOf(owner).call();618 expect(+balance).to.equal(0);619 }620 });621622 itEth('Can perform transferFromCross()', async ({helper}) => {623 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});624625 const [owner, receiver] = await helper.arrange.createAccounts([100n, 100n], donor);626 const spender = await helper.eth.createAccountWithBalance(donor);627628 const token = await collection.mintToken(minter, {Substrate: owner.address});629630 const address = helper.ethAddress.fromCollectionId(collection.collectionId);631 const contract = await helper.ethNativeContract.collection(address, 'nft');632633 await token.approve(owner, {Ethereum: spender});634635 {636 const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);637 const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);638 const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});639 const event = result.events.Transfer;640 expect(event).to.be.like({641 address: helper.ethAddress.fromCollectionId(collection.collectionId),642 event: 'Transfer',643 returnValues: {644 from: helper.address.substrateToEth(owner.address),645 to: helper.address.substrateToEth(receiver.address),646 tokenId: token.tokenId.toString(),647 },648 });649 }650651 expect(await token.getOwner()).to.be.like({Substrate: receiver.address});652 });653654 itEth('Can perform transfer()', async ({helper}) => {655 const collection = await helper.nft.mintCollection(minter, {});656 const owner = await helper.eth.createAccountWithBalance(donor);657 const receiver = helper.eth.createAccount();658659 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});660661 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);662 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);663664 {665 const result = await contract.methods.transfer(receiver, tokenId).send({from: owner});666667 const event = result.events.Transfer;668 expect(event.address).to.be.equal(collectionAddress);669 expect(event.returnValues.from).to.be.equal(owner);670 expect(event.returnValues.to).to.be.equal(receiver);671 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);672 }673674 {675 const balance = await contract.methods.balanceOf(owner).call();676 expect(+balance).to.equal(0);677 }678679 {680 const balance = await contract.methods.balanceOf(receiver).call();681 expect(+balance).to.equal(1);682 }683 });684685 itEth('Can perform transferCross()', async ({helper}) => {686 const collection = await helper.nft.mintCollection(minter, {});687 const owner = await helper.eth.createAccountWithBalance(donor);688 const receiverEth = await helper.eth.createAccountWithBalance(donor);689 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);690 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);691692 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});693694 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);695 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);696697 {698 // Can transferCross to ethereum address:699 const result = await collectionEvm.methods.transferCross(receiverCrossEth, tokenId).send({from: owner});700 // Check events:701 const event = result.events.Transfer;702 expect(event.address).to.be.equal(collectionAddress);703 expect(event.returnValues.from).to.be.equal(owner);704 expect(event.returnValues.to).to.be.equal(receiverEth);705 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);706707 // owner has balance = 0:708 const ownerBalance = await collectionEvm.methods.balanceOf(owner).call();709 expect(+ownerBalance).to.equal(0);710 // receiver owns token:711 const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();712 expect(+receiverBalance).to.equal(1);713 expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});714 }715716 {717 // Can transferCross to substrate address:718 const substrateResult = await collectionEvm.methods.transferCross(receiverCrossSub, tokenId).send({from: receiverEth});719 // Check events:720 const event = substrateResult.events.Transfer;721 expect(event.address).to.be.equal(collectionAddress);722 expect(event.returnValues.from).to.be.equal(receiverEth);723 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));724 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);725726 // owner has balance = 0:727 const ownerBalance = await collectionEvm.methods.balanceOf(receiverEth).call();728 expect(+ownerBalance).to.equal(0);729 // receiver owns token:730 const receiverBalance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});731 expect(receiverBalance).to.contain(tokenId);732 }733 });734735 ['transfer', 'transferCross'].map(testCase => itEth(`Cannot ${testCase} non-owned token`, async ({helper}) => {736 const sender = await helper.eth.createAccountWithBalance(donor);737 const tokenOwner = await helper.eth.createAccountWithBalance(donor);738 const receiverSub = minter;739 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);740741 const collection = await helper.nft.mintCollection(minter, {});742 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);743 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', sender);744745 await collection.mintToken(minter, {Ethereum: sender});746 const nonSendersToken = await collection.mintToken(minter, {Ethereum: tokenOwner});747748 // Cannot transferCross someone else's token:749 const receiver = testCase === 'transfer' ? helper.address.substrateToEth(receiverSub.address) : receiverCrossSub;750 await expect(collectionEvm.methods[testCase](receiver, nonSendersToken.tokenId).send({from: sender})).to.be.rejected;751 // Cannot transfer token if it does not exist:752 await expect(collectionEvm.methods[testCase](receiver, 999999).send({from: sender})).to.be.rejected;753 }));754755 itEth('Check balanceOfCross()', async ({helper}) => {756 const collection = await helper.nft.mintCollection(minter, {});757 const owner = await helper.ethCrossAccount.createAccountWithBalance(donor);758 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);759 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner.eth);760761 expect(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})).to.be.eq('0');762763 for(let i = 1; i < 10; i++) {764 await collection.mintToken(minter, {Ethereum: owner.eth});765 expect(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})).to.be.eq(i.toString());766 }767 });768769 itEth('Check ownerOfCross()', async ({helper}) => {770 const collection = await helper.nft.mintCollection(minter, {});771 let owner = await helper.ethCrossAccount.createAccountWithBalance(donor);772 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);773 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner.eth);774 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner.eth});775776 for(let i = 1n; i < 10n; i++) {777 const ownerCross = await collectionEvm.methods.ownerOfCross(tokenId).call({from: owner.eth});778 expect(ownerCross.eth).to.be.eq(owner.eth);779 expect(ownerCross.sub).to.be.eq(owner.sub);780781 const newOwner = await helper.ethCrossAccount.createAccountWithBalance(donor);782 await collectionEvm.methods.transferCross(newOwner, tokenId).send({from: owner.eth});783 owner = newOwner;784 }785 });786});787788describe('NFT: Fees', () => {789 let donor: IKeyringPair;790 let alice: IKeyringPair;791 let bob: IKeyringPair;792 let charlie: IKeyringPair;793794 before(async function() {795 await usingEthPlaygrounds(async (helper, privateKey) => {796 donor = await privateKey({url: import.meta.url});797 [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);798 });799 });800801 itEth('approve() call fee is less than 0.2UNQ', async ({helper}) => {802 const owner = await helper.eth.createAccountWithBalance(donor);803 const spender = helper.eth.createAccount();804805 const collection = await helper.nft.mintCollection(alice, {});806 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});807808 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);809810 const cost = await helper.eth.recordCallFee(owner, () => contract.methods.approve(spender, tokenId).send({from: owner}));811 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));812 });813814 itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {815 const owner = await helper.eth.createAccountWithBalance(donor);816 const spender = await helper.eth.createAccountWithBalance(donor);817818 const collection = await helper.nft.mintCollection(alice, {});819 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});820821 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);822823 await contract.methods.approve(spender, tokenId).send({from: owner});824825 const cost = await helper.eth.recordCallFee(spender, () => contract.methods.transferFrom(owner, spender, tokenId).send({from: spender}));826 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));827 });828829 itEth('Can perform transferFromCross()', async ({helper}) => {830 const collectionMinter = alice;831 const owner = bob;832 const receiver = charlie;833 const collection = await helper.nft.mintCollection(collectionMinter, {name: 'A', description: 'B', tokenPrefix: 'C'});834835 const spender = await helper.eth.createAccountWithBalance(donor);836837 const token = await collection.mintToken(collectionMinter, {Substrate: owner.address});838839 const address = helper.ethAddress.fromCollectionId(collection.collectionId);840 const contract = await helper.ethNativeContract.collection(address, 'nft');841842 await token.approve(owner, {Ethereum: spender});843844 {845 const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);846 const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);847 const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});848 const event = result.events.Transfer;849 expect(event).to.be.like({850 address: helper.ethAddress.fromCollectionId(collection.collectionId),851 event: 'Transfer',852 returnValues: {853 from: helper.address.substrateToEth(owner.address),854 to: helper.address.substrateToEth(receiver.address),855 tokenId: token.tokenId.toString(),856 },857 });858 }859860 expect(await token.getOwner()).to.be.like({Substrate: receiver.address});861 });862863 itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {864 const owner = await helper.eth.createAccountWithBalance(donor);865 const receiver = helper.eth.createAccount();866867 const collection = await helper.nft.mintCollection(alice, {});868 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});869870 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);871872 const cost = await helper.eth.recordCallFee(owner, () => contract.methods.transfer(receiver, tokenId).send({from: owner}));873 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));874 });875});876877describe('NFT: Substrate calls', () => {878 let donor: IKeyringPair;879 let alice: IKeyringPair;880881 before(async function() {882 await usingEthPlaygrounds(async (helper, privateKey) => {883 donor = await privateKey({url: import.meta.url});884 [alice] = await helper.arrange.createAccounts([20n], donor);885 });886 });887888 itEth('Events emitted for mint()', async ({helper}) => {889 const collection = await helper.nft.mintCollection(alice, {});890 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);891 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');892893 const events: any = [];894 contract.events.allEvents((_: any, event: any) => {895 events.push(event);896 });897898 const {tokenId} = await collection.mintToken(alice);899 if(events.length == 0) await helper.wait.newBlocks(1);900 const event = events[0];901902 expect(event.event).to.be.equal('Transfer');903 expect(event.address).to.be.equal(collectionAddress);904 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');905 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(alice.address));906 expect(event.returnValues.tokenId).to.be.equal(tokenId.toString());907 });908909 itEth('Events emitted for burn()', async ({helper}) => {910 const collection = await helper.nft.mintCollection(alice, {});911 const token = await collection.mintToken(alice);912913 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);914 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');915916 const events: any = [];917 contract.events.allEvents((_: any, event: any) => {918 events.push(event);919 });920921 await token.burn(alice);922 if(events.length == 0) await helper.wait.newBlocks(1);923 const event = events[0];924925 expect(event.event).to.be.equal('Transfer');926 expect(event.address).to.be.equal(collectionAddress);927 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));928 expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');929 expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());930 });931932 itEth('Events emitted for approve()', async ({helper}) => {933 const receiver = helper.eth.createAccount();934935 const collection = await helper.nft.mintCollection(alice, {});936 const token = await collection.mintToken(alice);937938 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);939 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');940941 const events: any = [];942 contract.events.allEvents((_: any, event: any) => {943 events.push(event);944 });945946 await token.approve(alice, {Ethereum: receiver});947 if(events.length == 0) await helper.wait.newBlocks(1);948 const event = events[0];949950 expect(event.event).to.be.equal('Approval');951 expect(event.address).to.be.equal(collectionAddress);952 expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));953 expect(event.returnValues.approved).to.be.equal(receiver);954 expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());955 });956957 itEth('Events emitted for transferFrom()', async ({helper}) => {958 const [bob] = await helper.arrange.createAccounts([10n], donor);959 const receiver = helper.eth.createAccount();960961 const collection = await helper.nft.mintCollection(alice, {});962 const token = await collection.mintToken(alice);963 await token.approve(alice, {Substrate: bob.address});964965 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);966 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');967968 const events: any = [];969 contract.events.allEvents((_: any, event: any) => {970 events.push(event);971 });972973 await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver});974975 if(events.length == 0) await helper.wait.newBlocks(1);976 const event = events[0];977978 expect(event.address).to.be.equal(collectionAddress);979 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));980 expect(event.returnValues.to).to.be.equal(receiver);981 expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);982 });983984 itEth('Events emitted for transfer()', async ({helper}) => {985 const receiver = helper.eth.createAccount();986987 const collection = await helper.nft.mintCollection(alice, {});988 const token = await collection.mintToken(alice);989990 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);991 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');992993 const events: any = [];994 contract.events.allEvents((_: any, event: any) => {995 events.push(event);996 });997998 await token.transfer(alice, {Ethereum: receiver});9991000 if(events.length == 0) await helper.wait.newBlocks(1);1001 const event = events[0];10021003 expect(event.address).to.be.equal(collectionAddress);1004 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));1005 expect(event.returnValues.to).to.be.equal(receiver);1006 expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);1007 });1008});10091010describe('Common metadata', () => {1011 let donor: IKeyringPair;1012 let alice: IKeyringPair;10131014 before(async function() {1015 await usingEthPlaygrounds(async (helper, privateKey) => {1016 donor = await privateKey({url: import.meta.url});1017 [alice] = await helper.arrange.createAccounts([20n], donor);1018 });1019 });10201021 itEth('Returns collection name', async ({helper}) => {1022 const caller = helper.eth.createAccount();1023 const tokenPropertyPermissions = [{1024 key: 'URI',1025 permission: {1026 mutable: true,1027 collectionAdmin: true,1028 tokenOwner: false,1029 },1030 }];1031 const collection = await helper.nft.mintCollection(1032 alice,1033 {1034 name: 'oh River',1035 tokenPrefix: 'CHANGE',1036 properties: [{key: 'ERC721Metadata', value: '1'}],1037 tokenPropertyPermissions,1038 },1039 );10401041 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);1042 const name = await contract.methods.name().call();1043 expect(name).to.equal('oh River');1044 });10451046 itEth('Returns symbol name', async ({helper}) => {1047 const caller = await helper.eth.createAccountWithBalance(donor);1048 const tokenPropertyPermissions = [{1049 key: 'URI',1050 permission: {1051 mutable: true,1052 collectionAdmin: true,1053 tokenOwner: false,1054 },1055 }];1056 const collection = await helper.nft.mintCollection(1057 alice,1058 {1059 name: 'oh River',1060 tokenPrefix: 'CHANGE',1061 properties: [{key: 'ERC721Metadata', value: '1'}],1062 tokenPropertyPermissions,1063 },1064 );10651066 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);1067 const symbol = await contract.methods.symbol().call();1068 expect(symbol).to.equal('CHANGE');1069 });1070});10711072describe('Negative tests', () => {1073 let donor: IKeyringPair;1074 let minter: IKeyringPair;1075 let alice: IKeyringPair;10761077 before(async function() {1078 await usingEthPlaygrounds(async (helper, privateKey) => {1079 donor = await privateKey({url: import.meta.url});1080 [minter, alice] = await helper.arrange.createAccounts([100n, 100n], donor);1081 });1082 });10831084 itEth('[negative] Cant perform burn without approval', async ({helper}) => {1085 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});10861087 const owner = await helper.eth.createAccountWithBalance(donor);1088 const spender = await helper.eth.createAccountWithBalance(donor);10891090 const token = await collection.mintToken(minter, {Ethereum: owner});10911092 const address = helper.ethAddress.fromCollectionId(collection.collectionId);1093 const contract = await helper.ethNativeContract.collection(address, 'nft');10941095 const ownerCross = helper.ethCrossAccount.fromAddress(owner);1096 await expect(contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender})).to.be.rejected;10971098 await contract.methods.setApprovalForAll(spender, true).send({from: owner});1099 await contract.methods.setApprovalForAll(spender, false).send({from: owner});11001101 await expect(contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender})).to.be.rejected;1102 });11031104 itEth('[negative] Cant perform transfer without approval', async ({helper}) => {1105 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});1106 const receiver = alice;11071108 const owner = await helper.eth.createAccountWithBalance(donor);1109 const spender = await helper.eth.createAccountWithBalance(donor);11101111 const token = await collection.mintToken(minter, {Ethereum: owner});11121113 const address = helper.ethAddress.fromCollectionId(collection.collectionId);1114 const contract = await helper.ethNativeContract.collection(address, 'nft');11151116 const ownerCross = helper.ethCrossAccount.fromAddress(owner);1117 const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);11181119 await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;11201121 await contract.methods.setApprovalForAll(spender, true).send({from: owner});1122 await contract.methods.setApprovalForAll(spender, false).send({from: owner});11231124 await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;1125 });1126});tests/src/eth/reFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -18,6 +18,7 @@
import {expect, itEth, usingEthPlaygrounds} from './util';
import {IKeyringPair} from '@polkadot/types/types';
import {ITokenPropertyPermission} from '../util/playgrounds/types';
+import {CREATE_COLLECTION_DATA_DEFAULTS, TokenPermissionField} from './util/playgrounds/types';
describe('Refungible: Plain calls', () => {
let donor: IKeyringPair;
@@ -125,6 +126,169 @@
}
});
+ itEth('Can perform mintBulkCross() with multiple tokens', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const callerCross = helper.ethCrossAccount.fromAddress(caller);
+ const receiver = helper.eth.createAccount();
+ const receiverCross = helper.ethCrossAccount.fromAddress(receiver);
+
+ const permissions = [
+ {code: TokenPermissionField.Mutable, value: true},
+ {code: TokenPermissionField.TokenOwner, value: true},
+ {code: TokenPermissionField.CollectionAdmin, value: true},
+ ];
+ const {collectionAddress} = await helper.eth.createCollection(
+ caller,
+ {
+ ...CREATE_COLLECTION_DATA_DEFAULTS,
+ name: 'A',
+ description: 'B',
+ tokenPrefix: 'C',
+ collectionMode: 'rft',
+ adminList: [callerCross],
+ tokenPropertyPermissions: [
+ {key: 'key_0_0', permissions},
+ {key: 'key_1_0', permissions},
+ {key: 'key_1_1', permissions},
+ {key: 'key_2_0', permissions},
+ {key: 'key_2_1', permissions},
+ {key: 'key_2_2', permissions},
+ ],
+ },
+ ).send();
+
+ const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
+ const nextTokenId = await contract.methods.nextTokenId().call();
+ expect(nextTokenId).to.be.equal('1');
+ const result = await contract.methods.mintBulkCross([
+ {
+ owners: [{
+ owner: receiverCross,
+ pieces: 1,
+ }],
+ properties: [
+ {key: 'key_0_0', value: Buffer.from('value_0_0')},
+ ],
+ },
+ {
+ owners: [{
+ owner: receiverCross,
+ pieces: 2,
+ }],
+ properties: [
+ {key: 'key_1_0', value: Buffer.from('value_1_0')},
+ {key: 'key_1_1', value: Buffer.from('value_1_1')},
+ ],
+ },
+ {
+ owners: [{
+ owner: receiverCross,
+ pieces: 1,
+ }],
+ properties: [
+ {key: 'key_2_0', value: Buffer.from('value_2_0')},
+ {key: 'key_2_1', value: Buffer.from('value_2_1')},
+ {key: 'key_2_2', value: Buffer.from('value_2_2')},
+ ],
+ },
+ ]).send({from: caller});
+ const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.tokenId - b.returnValues.tokenId);
+ const bulkSize = 3;
+ for(let i = 0; i < bulkSize; i++) {
+ const event = events[i];
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.equal(receiver);
+ expect(event.returnValues.tokenId).to.equal(`${+nextTokenId + i}`);
+ }
+
+ const properties = [
+ await contract.methods.properties(+nextTokenId, []).call(),
+ await contract.methods.properties(+nextTokenId + 1, []).call(),
+ await contract.methods.properties(+nextTokenId + 2, []).call(),
+ ];
+ expect(properties).to.be.deep.equal([
+ [
+ ['key_0_0', helper.getWeb3().utils.toHex('value_0_0')],
+ ],
+ [
+ ['key_1_0', helper.getWeb3().utils.toHex('value_1_0')],
+ ['key_1_1', helper.getWeb3().utils.toHex('value_1_1')],
+ ],
+ [
+ ['key_2_0', helper.getWeb3().utils.toHex('value_2_0')],
+ ['key_2_1', helper.getWeb3().utils.toHex('value_2_1')],
+ ['key_2_2', helper.getWeb3().utils.toHex('value_2_2')],
+ ],
+ ]);
+ });
+
+ itEth('Can perform mintBulkCross() with multiple owners', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const callerCross = helper.ethCrossAccount.fromAddress(caller);
+ const receiver = helper.eth.createAccount();
+ const receiverCross = helper.ethCrossAccount.fromAddress(receiver);
+ const receiver2 = helper.eth.createAccount();
+ const receiver2Cross = helper.ethCrossAccount.fromAddress(receiver2);
+
+ const permissions = [
+ {code: TokenPermissionField.Mutable, value: true},
+ {code: TokenPermissionField.TokenOwner, value: true},
+ {code: TokenPermissionField.CollectionAdmin, value: true},
+ ];
+ const {collectionAddress} = await helper.eth.createCollection(
+ caller,
+ {
+ ...CREATE_COLLECTION_DATA_DEFAULTS,
+ name: 'A',
+ description: 'B',
+ tokenPrefix: 'C',
+ collectionMode: 'rft',
+ adminList: [callerCross],
+ tokenPropertyPermissions: [
+ {key: 'key_2_0', permissions},
+ {key: 'key_2_1', permissions},
+ {key: 'key_2_2', permissions},
+ ],
+ },
+ ).send();
+
+ const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
+ const nextTokenId = await contract.methods.nextTokenId().call();
+ expect(nextTokenId).to.be.equal('1');
+ const result = await contract.methods.mintBulkCross([{
+ owners: [
+ {
+ owner: receiverCross,
+ pieces: 1,
+ },
+ {
+ owner: receiver2Cross,
+ pieces: 2,
+ },
+ ],
+ properties: [
+ {key: 'key_2_0', value: Buffer.from('value_2_0')},
+ {key: 'key_2_1', value: Buffer.from('value_2_1')},
+ {key: 'key_2_2', value: Buffer.from('value_2_2')},
+ ],
+ }]).send({from: caller});
+ const event = result.events.Transfer;
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');
+ expect(event.returnValues.tokenId).to.equal(`${+nextTokenId}`);
+
+ const properties = [
+ await contract.methods.properties(+nextTokenId, []).call(),
+ ];
+ expect(properties).to.be.deep.equal([[
+ ['key_2_0', helper.getWeb3().utils.toHex('value_2_0')],
+ ['key_2_1', helper.getWeb3().utils.toHex('value_2_1')],
+ ['key_2_2', helper.getWeb3().utils.toHex('value_2_2')],
+ ]]);
+ });
+
itEth('Can perform setApprovalForAll()', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const operator = helper.eth.createAccount();
@@ -786,4 +950,70 @@
await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;
});
+
+ itEth('[negative] Can perform mintBulkCross() with multiple owners and multiple tokens', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const callerCross = helper.ethCrossAccount.fromAddress(caller);
+ const receiver = helper.eth.createAccount();
+ const receiverCross = helper.ethCrossAccount.fromAddress(receiver);
+ const receiver2 = helper.eth.createAccount();
+ const receiver2Cross = helper.ethCrossAccount.fromAddress(receiver2);
+
+ const permissions = [
+ {code: TokenPermissionField.Mutable, value: true},
+ {code: TokenPermissionField.TokenOwner, value: true},
+ {code: TokenPermissionField.CollectionAdmin, value: true},
+ ];
+ const {collectionAddress} = await helper.eth.createCollection(
+ caller,
+ {
+ ...CREATE_COLLECTION_DATA_DEFAULTS,
+ name: 'A',
+ description: 'B',
+ tokenPrefix: 'C',
+ collectionMode: 'rft',
+ adminList: [callerCross],
+ tokenPropertyPermissions: [
+ {key: 'key_0_0', permissions},
+ {key: 'key_2_0', permissions},
+ {key: 'key_2_1', permissions},
+ {key: 'key_2_2', permissions},
+ ],
+ },
+ ).send();
+
+ const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
+ const nextTokenId = await contract.methods.nextTokenId().call();
+ expect(nextTokenId).to.be.equal('1');
+ const createData = [
+ {
+ owners: [{
+ owner: receiverCross,
+ pieces: 1,
+ }],
+ properties: [
+ {key: 'key_0_0', value: Buffer.from('value_0_0')},
+ ],
+ },
+ {
+ owners: [
+ {
+ owner: receiverCross,
+ pieces: 1,
+ },
+ {
+ owner: receiver2Cross,
+ pieces: 2,
+ },
+ ],
+ properties: [
+ {key: 'key_2_0', value: Buffer.from('value_2_0')},
+ {key: 'key_2_1', value: Buffer.from('value_2_1')},
+ {key: 'key_2_2', value: Buffer.from('value_2_2')},
+ ],
+ },
+ ];
+
+ await expect(contract.methods.mintBulkCross(createData).call({from: caller})).to.be.rejectedWith('creation of multiple tokens supported only if they have single owner each');
+ });
});