difftreelog
chore code review requests
in: master
20 files changed
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -34,15 +34,14 @@
use sp_std::vec::Vec;
use pallet_common::{
erc::{
- CommonEvmHandler, PrecompileResult, CollectionCall,
- static_property::{key, value as property_value},
+ CommonEvmHandler, PrecompileResult, CollectionCall, static_property::key,
+ static_property::value,
},
CollectionHandle, CollectionPropertyPermissions,
};
use pallet_evm::{account::CrossAccountId, PrecompileHandle};
use pallet_evm_coder_substrate::call;
use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};
-use alloc::string::ToString;
use crate::{
AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,
@@ -226,37 +225,44 @@
/// @return token's const_metadata
#[solidity(rename_selector = "tokenURI")]
fn token_uri(&self, token_id: uint256) -> Result<string> {
+ if !self.supports_metadata() {
+ return Ok("".into());
+ }
+
let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
- if let Ok(url) = get_token_property(self, token_id_u32, &key::url()) {
- if !url.is_empty() {
- return Ok(url);
+ match get_token_property(self, token_id_u32, &key::url()).as_deref() {
+ Err(_) | Ok("") => (),
+ Ok(url) => {
+ return Ok(url.into());
}
- } else if !self.supports_metadata() {
- return Err("tokenURI not set".into());
- }
+ };
- if let Some(base_uri) =
+ let base_uri =
pallet_common::Pallet::<T>::get_collection_property(self.id, &key::base_uri())
- {
- if !base_uri.is_empty() {
- let base_uri = string::from_utf8(base_uri.into_inner()).map_err(|e| {
+ .map(BoundedVec::into_inner)
+ .map(string::from_utf8)
+ .transpose()
+ .map_err(|e| {
Error::Revert(alloc::format!(
"Can not convert value \"baseURI\" to string with error \"{}\"",
e
))
})?;
- if let Ok(suffix) = get_token_property(self, token_id_u32, &key::suffix()) {
- if !suffix.is_empty() {
- return Ok(base_uri + suffix.as_str());
- }
- }
- return Ok(base_uri);
+ let base_uri = match base_uri.as_deref() {
+ None | Some("") => {
+ return Ok("".into());
}
- }
+ Some(base_uri) => base_uri.into(),
+ };
- Ok("".into())
+ Ok(
+ match get_token_property(self, token_id_u32, &key::suffix()).as_deref() {
+ Err(_) | Ok("") => base_uri,
+ Ok(suffix) => base_uri + suffix,
+ },
+ )
}
}
@@ -706,17 +712,29 @@
}
}
+impl<T: Config> NonfungibleHandle<T> {
+ pub fn supports_metadata(&self) -> bool {
+ if let Some(erc721_metadata) =
+ pallet_common::Pallet::<T>::get_collection_property(self.id, &key::erc721_metadata())
+ {
+ *erc721_metadata.into_inner() == *value::ERC721_METADATA_SUPPORTED
+ } else {
+ false
+ }
+ }
+}
+
#[solidity_interface(
name = UniqueNFT,
is(
ERC721,
- ERC721Metadata(if(this.supports_metadata())),
ERC721Enumerable,
ERC721UniqueExtensions,
ERC721Mintable,
ERC721Burnable,
Collection(via(common_mut returns CollectionHandle<T>)),
TokenProperties,
+ ERC721Metadata(if(this.supports_metadata())),
)
)]
impl<T: Config> NonfungibleHandle<T> where T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]> {}
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -297,18 +297,6 @@
}
}
-impl<T: Config> NonfungibleHandle<T> {
- pub fn supports_metadata(&self) -> bool {
- if let Some(erc721_metadata) =
- pallet_common::Pallet::<T>::get_collection_property(self.id, &key::erc721_metadata())
- {
- *erc721_metadata.into_inner() == *value::ERC721_METADATA_SUPPORTED
- } else {
- false
- }
- }
-}
-
impl<T: Config> WithRecorder<T> for NonfungibleHandle<T> {
fn recorder(&self) -> &SubstrateRecorder<T> {
self.0.recorder()
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
@@ -17,6 +17,47 @@
}
}
+/// @title ERC-721 Non-Fungible Token Standard, optional metadata extension
+/// @dev See https://eips.ethereum.org/EIPS/eip-721
+/// @dev the ERC-165 identifier for this interface is 0x5b5e139f
+contract ERC721Metadata is Dummy, ERC165 {
+ /// @notice A descriptive name for a collection of NFTs in this contract
+ /// @dev EVM selector for this function is: 0x06fdde03,
+ /// or in textual repr: name()
+ function name() public view returns (string memory) {
+ require(false, stub_error);
+ dummy;
+ return "";
+ }
+
+ /// @notice An abbreviated name for NFTs in this contract
+ /// @dev EVM selector for this function is: 0x95d89b41,
+ /// or in textual repr: symbol()
+ function symbol() public view returns (string memory) {
+ require(false, stub_error);
+ dummy;
+ return "";
+ }
+
+ /// @notice A distinct Uniform Resource Identifier (URI) for a given asset.
+ ///
+ /// @dev If the token has a `url` property and it is not empty, it is returned.
+ /// Else If the collection does not have a property with key `schemaName` or its value is not equal to `ERC721Metadata`, it return an error `tokenURI not set`.
+ /// If the collection property `baseURI` is empty or absent, return "" (empty string)
+ /// otherwise, if token property `suffix` present and is non-empty, return concatenation of baseURI and suffix
+ /// otherwise, return concatenation of `baseURI` and stringified token id (decimal stringifying, without paddings).
+ ///
+ /// @return token's const_metadata
+ /// @dev EVM selector for this function is: 0xc87b56dd,
+ /// or in textual repr: tokenURI(uint256)
+ function tokenURI(uint256 tokenId) public view returns (string memory) {
+ require(false, stub_error);
+ tokenId;
+ dummy;
+ return "";
+ }
+}
+
/// @title A contract that allows to set and delete token properties and change token property permissions.
/// @dev the ERC-165 identifier for this interface is 0x41369377
contract TokenProperties is Dummy, ERC165 {
@@ -177,10 +218,10 @@
/// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.
/// @dev EVM selector for this function is: 0x6ec0a9f1,
/// or in textual repr: collectionSponsor()
- function collectionSponsor() public view returns (Tuple17 memory) {
+ function collectionSponsor() public view returns (Tuple15 memory) {
require(false, stub_error);
dummy;
- return Tuple17(0x0000000000000000000000000000000000000000, 0);
+ return Tuple15(0x0000000000000000000000000000000000000000, 0);
}
/// Set limits for the collection.
@@ -359,10 +400,10 @@
/// If address is canonical then substrate mirror is zero and vice versa.
/// @dev EVM selector for this function is: 0xdf727d3b,
/// or in textual repr: collectionOwner()
- function collectionOwner() public view returns (Tuple17 memory) {
+ function collectionOwner() public view returns (Tuple15 memory) {
require(false, stub_error);
dummy;
- return Tuple17(0x0000000000000000000000000000000000000000, 0);
+ return Tuple15(0x0000000000000000000000000000000000000000, 0);
}
/// Changes collection owner to another account
@@ -379,7 +420,7 @@
}
/// @dev anonymous struct
-struct Tuple17 {
+struct Tuple15 {
address field_0;
uint256 field_1;
}
@@ -525,7 +566,7 @@
/// @param tokens array of pairs of token ID and token URI for minted tokens
/// @dev EVM selector for this function is: 0x36543006,
/// or in textual repr: mintBulkWithTokenURI(address,(uint256,string)[])
- function mintBulkWithTokenURI(address to, Tuple8[] memory tokens) public returns (bool) {
+ function mintBulkWithTokenURI(address to, Tuple6[] memory tokens) public returns (bool) {
require(false, stub_error);
to;
tokens;
@@ -535,7 +576,7 @@
}
/// @dev anonymous struct
-struct Tuple8 {
+struct Tuple6 {
uint256 field_0;
string field_1;
}
@@ -577,48 +618,7 @@
require(false, stub_error);
dummy;
return 0;
- }
-}
-
-/// @title ERC-721 Non-Fungible Token Standard, optional metadata extension
-/// @dev See https://eips.ethereum.org/EIPS/eip-721
-/// @dev the ERC-165 identifier for this interface is 0x5b5e139f
-contract ERC721Metadata is Dummy, ERC165 {
- /// @notice A descriptive name for a collection of NFTs in this contract
- /// @dev EVM selector for this function is: 0x06fdde03,
- /// or in textual repr: name()
- function name() public view returns (string memory) {
- require(false, stub_error);
- dummy;
- return "";
- }
-
- /// @notice An abbreviated name for NFTs in this contract
- /// @dev EVM selector for this function is: 0x95d89b41,
- /// or in textual repr: symbol()
- function symbol() public view returns (string memory) {
- require(false, stub_error);
- dummy;
- return "";
}
-
- /// @notice A distinct Uniform Resource Identifier (URI) for a given asset.
- ///
- /// @dev If the token has a `url` property and it is not empty, it is returned.
- /// Else If the collection does not have a property with key `schemaName` or its value is not equal to `ERC721Metadata`, it return an error `tokenURI not set`.
- /// If the collection property `baseURI` is empty or absent, return "" (empty string)
- /// otherwise, if token property `suffix` present and is non-empty, return concatenation of baseURI and suffix
- /// otherwise, return concatenation of `baseURI` and stringified token id (decimal stringifying, without paddings).
- ///
- /// @return token's const_metadata
- /// @dev EVM selector for this function is: 0xc87b56dd,
- /// or in textual repr: tokenURI(uint256)
- function tokenURI(uint256 tokenId) public view returns (string memory) {
- require(false, stub_error);
- tokenId;
- dummy;
- return "";
- }
}
/// @dev inlined interface
@@ -766,11 +766,11 @@
Dummy,
ERC165,
ERC721,
- ERC721Metadata,
ERC721Enumerable,
ERC721UniqueExtensions,
ERC721Mintable,
ERC721Burnable,
Collection,
- TokenProperties
+ TokenProperties,
+ ERC721Metadata
{}
pallets/refungible/src/erc.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -21,19 +21,15 @@
extern crate alloc;
-use alloc::string::ToString;
use core::{
char::{REPLACEMENT_CHARACTER, decode_utf16},
convert::TryInto,
};
use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*, weight};
-use frame_support::BoundedBTreeMap;
+use frame_support::{BoundedBTreeMap, BoundedVec};
use pallet_common::{
CollectionHandle, CollectionPropertyPermissions,
- erc::{
- CommonEvmHandler, CollectionCall,
- static_property::{key, value as property_value},
- },
+ erc::{CommonEvmHandler, CollectionCall, static_property::key, static_property::value},
};
use pallet_evm::{account::CrossAccountId, PrecompileHandle};
use pallet_evm_coder_substrate::{call, dispatch_to_evm};
@@ -222,37 +218,44 @@
/// @return token's const_metadata
#[solidity(rename_selector = "tokenURI")]
fn token_uri(&self, token_id: uint256) -> Result<string> {
+ if !self.supports_metadata() {
+ return Ok("".into());
+ }
+
let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
- if let Ok(url) = get_token_property(self, token_id_u32, &key::url()) {
- if !url.is_empty() {
- return Ok(url);
+ match get_token_property(self, token_id_u32, &key::url()).as_deref() {
+ Err(_) | Ok("") => (),
+ Ok(url) => {
+ return Ok(url.into());
}
- } else if !self.supports_metadata() {
- return Err("tokenURI not set".into());
- }
+ };
- if let Some(base_uri) =
+ let base_uri =
pallet_common::Pallet::<T>::get_collection_property(self.id, &key::base_uri())
- {
- if !base_uri.is_empty() {
- let base_uri = string::from_utf8(base_uri.into_inner()).map_err(|e| {
+ .map(BoundedVec::into_inner)
+ .map(string::from_utf8)
+ .transpose()
+ .map_err(|e| {
Error::Revert(alloc::format!(
"Can not convert value \"baseURI\" to string with error \"{}\"",
e
))
})?;
- if let Ok(suffix) = get_token_property(self, token_id_u32, &key::suffix()) {
- if !suffix.is_empty() {
- return Ok(base_uri + suffix.as_str());
- }
- }
- return Ok(base_uri);
+ let base_uri = match base_uri.as_deref() {
+ None | Some("") => {
+ return Ok("".into());
}
- }
+ Some(base_uri) => base_uri.into(),
+ };
- Ok("".into())
+ Ok(
+ match get_token_property(self, token_id_u32, &key::suffix()).as_deref() {
+ Err(_) | Ok("") => base_uri,
+ Ok(suffix) => base_uri + suffix,
+ },
+ )
}
}
@@ -765,17 +768,29 @@
}
}
+impl<T: Config> RefungibleHandle<T> {
+ pub fn supports_metadata(&self) -> bool {
+ if let Some(erc721_metadata) =
+ pallet_common::Pallet::<T>::get_collection_property(self.id, &key::erc721_metadata())
+ {
+ *erc721_metadata.into_inner() == *value::ERC721_METADATA_SUPPORTED
+ } else {
+ false
+ }
+ }
+}
+
#[solidity_interface(
name = UniqueRefungible,
is(
ERC721,
- ERC721Metadata(if(this.supports_metadata())),
ERC721Enumerable,
ERC721UniqueExtensions,
ERC721Mintable,
ERC721Burnable,
Collection(via(common_mut returns CollectionHandle<T>)),
TokenProperties,
+ ERC721Metadata(if(this.supports_metadata())),
)
)]
impl<T: Config> RefungibleHandle<T> where T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]> {}
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -304,18 +304,6 @@
}
}
-impl<T: Config> RefungibleHandle<T> {
- pub fn supports_metadata(&self) -> bool {
- if let Some(erc721_metadata) =
- pallet_common::Pallet::<T>::get_collection_property(self.id, &key::erc721_metadata())
- {
- *erc721_metadata.into_inner() == *value::ERC721_METADATA_SUPPORTED
- } else {
- false
- }
- }
-}
-
impl<T: Config> Deref for RefungibleHandle<T> {
type Target = pallet_common::CollectionHandle<T>;
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
@@ -17,6 +17,45 @@
}
}
+/// @dev the ERC-165 identifier for this interface is 0x5b5e139f
+contract ERC721Metadata is Dummy, ERC165 {
+ /// @notice A descriptive name for a collection of RFTs in this contract
+ /// @dev EVM selector for this function is: 0x06fdde03,
+ /// or in textual repr: name()
+ function name() public view returns (string memory) {
+ require(false, stub_error);
+ dummy;
+ return "";
+ }
+
+ /// @notice An abbreviated name for RFTs in this contract
+ /// @dev EVM selector for this function is: 0x95d89b41,
+ /// or in textual repr: symbol()
+ function symbol() public view returns (string memory) {
+ require(false, stub_error);
+ dummy;
+ return "";
+ }
+
+ /// @notice A distinct Uniform Resource Identifier (URI) for a given asset.
+ ///
+ /// @dev If the token has a `url` property and it is not empty, it is returned.
+ /// Else If the collection does not have a property with key `schemaName` or its value is not equal to `ERC721Metadata`, it return an error `tokenURI not set`.
+ /// If the collection property `baseURI` is empty or absent, return "" (empty string)
+ /// otherwise, if token property `suffix` present and is non-empty, return concatenation of baseURI and suffix
+ /// otherwise, return concatenation of `baseURI` and stringified token id (decimal stringifying, without paddings).
+ ///
+ /// @return token's const_metadata
+ /// @dev EVM selector for this function is: 0xc87b56dd,
+ /// or in textual repr: tokenURI(uint256)
+ function tokenURI(uint256 tokenId) public view returns (string memory) {
+ require(false, stub_error);
+ tokenId;
+ dummy;
+ return "";
+ }
+}
+
/// @title A contract that allows to set and delete token properties and change token property permissions.
/// @dev the ERC-165 identifier for this interface is 0x41369377
contract TokenProperties is Dummy, ERC165 {
@@ -177,10 +216,10 @@
/// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.
/// @dev EVM selector for this function is: 0x6ec0a9f1,
/// or in textual repr: collectionSponsor()
- function collectionSponsor() public view returns (Tuple17 memory) {
+ function collectionSponsor() public view returns (Tuple15 memory) {
require(false, stub_error);
dummy;
- return Tuple17(0x0000000000000000000000000000000000000000, 0);
+ return Tuple15(0x0000000000000000000000000000000000000000, 0);
}
/// Set limits for the collection.
@@ -359,10 +398,10 @@
/// If address is canonical then substrate mirror is zero and vice versa.
/// @dev EVM selector for this function is: 0xdf727d3b,
/// or in textual repr: collectionOwner()
- function collectionOwner() public view returns (Tuple17 memory) {
+ function collectionOwner() public view returns (Tuple15 memory) {
require(false, stub_error);
dummy;
- return Tuple17(0x0000000000000000000000000000000000000000, 0);
+ return Tuple15(0x0000000000000000000000000000000000000000, 0);
}
/// Changes collection owner to another account
@@ -379,7 +418,7 @@
}
/// @dev anonymous struct
-struct Tuple17 {
+struct Tuple15 {
address field_0;
uint256 field_1;
}
@@ -527,7 +566,7 @@
/// @param tokens array of pairs of token ID and token URI for minted tokens
/// @dev EVM selector for this function is: 0x36543006,
/// or in textual repr: mintBulkWithTokenURI(address,(uint256,string)[])
- function mintBulkWithTokenURI(address to, Tuple8[] memory tokens) public returns (bool) {
+ function mintBulkWithTokenURI(address to, Tuple6[] memory tokens) public returns (bool) {
require(false, stub_error);
to;
tokens;
@@ -549,7 +588,7 @@
}
/// @dev anonymous struct
-struct Tuple8 {
+struct Tuple6 {
uint256 field_0;
string field_1;
}
@@ -591,45 +630,6 @@
require(false, stub_error);
dummy;
return 0;
- }
-}
-
-/// @dev the ERC-165 identifier for this interface is 0x5b5e139f
-contract ERC721Metadata is Dummy, ERC165 {
- /// @notice A descriptive name for a collection of RFTs in this contract
- /// @dev EVM selector for this function is: 0x06fdde03,
- /// or in textual repr: name()
- function name() public view returns (string memory) {
- require(false, stub_error);
- dummy;
- return "";
- }
-
- /// @notice An abbreviated name for RFTs in this contract
- /// @dev EVM selector for this function is: 0x95d89b41,
- /// or in textual repr: symbol()
- function symbol() public view returns (string memory) {
- require(false, stub_error);
- dummy;
- return "";
- }
-
- /// @notice A distinct Uniform Resource Identifier (URI) for a given asset.
- ///
- /// @dev If the token has a `url` property and it is not empty, it is returned.
- /// Else If the collection does not have a property with key `schemaName` or its value is not equal to `ERC721Metadata`, it return an error `tokenURI not set`.
- /// If the collection property `baseURI` is empty or absent, return "" (empty string)
- /// otherwise, if token property `suffix` present and is non-empty, return concatenation of baseURI and suffix
- /// otherwise, return concatenation of `baseURI` and stringified token id (decimal stringifying, without paddings).
- ///
- /// @return token's const_metadata
- /// @dev EVM selector for this function is: 0xc87b56dd,
- /// or in textual repr: tokenURI(uint256)
- function tokenURI(uint256 tokenId) public view returns (string memory) {
- require(false, stub_error);
- tokenId;
- dummy;
- return "";
}
}
@@ -776,11 +776,11 @@
Dummy,
ERC165,
ERC721,
- ERC721Metadata,
ERC721Enumerable,
ERC721UniqueExtensions,
ERC721Mintable,
ERC721Burnable,
Collection,
- TokenProperties
+ TokenProperties,
+ ERC721Metadata
{}
pallets/unique/src/eth/mod.rsdiffbeforeafterboth--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -336,27 +336,6 @@
}
#[weight(<SelfWeightOf<T>>::create_collection())]
- #[deprecated(note = "mathod was renamed to `create_rft_collection`, prefer it instead")]
- fn create_refungible_collection(
- &mut self,
- caller: caller,
- value: value,
- name: string,
- description: string,
- token_prefix: string,
- ) -> Result<address> {
- create_refungible_collection_internal::<T>(
- caller,
- value,
- name,
- description,
- token_prefix,
- Default::default(),
- false,
- )
- }
-
- #[weight(<SelfWeightOf<T>>::create_collection())]
#[solidity(rename_selector = "createERC721MetadataCompatibleRFTCollection")]
fn create_refungible_collection_with_properties(
&mut self,
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
@@ -23,7 +23,7 @@
}
/// @title Contract, which allows users to operate with collections
-/// @dev the ERC-165 identifier for this interface is 0x95eb98f4
+/// @dev the ERC-165 identifier for this interface is 0xd14d1221
contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
/// Create an NFT collection
/// @param name Name of the collection
@@ -85,21 +85,6 @@
/// @dev EVM selector for this function is: 0xab173450,
/// or in textual repr: createRFTCollection(string,string,string)
function createRFTCollection(
- string memory name,
- string memory description,
- string memory tokenPrefix
- ) public payable returns (address) {
- require(false, stub_error);
- name;
- description;
- tokenPrefix;
- dummy = 0;
- return 0x0000000000000000000000000000000000000000;
- }
-
- /// @dev EVM selector for this function is: 0x44a68ad5,
- /// or in textual repr: createRefungibleCollection(string,string,string)
- function createRefungibleCollection(
string memory name,
string memory description,
string memory tokenPrefix
tests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth--- a/tests/src/eth/api/CollectionHelpers.sol
+++ b/tests/src/eth/api/CollectionHelpers.sol
@@ -18,7 +18,7 @@
}
/// @title Contract, which allows users to operate with collections
-/// @dev the ERC-165 identifier for this interface is 0x95eb98f4
+/// @dev the ERC-165 identifier for this interface is 0xd14d1221
interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
/// Create an NFT collection
/// @param name Name of the collection
@@ -58,14 +58,6 @@
/// @dev EVM selector for this function is: 0xab173450,
/// or in textual repr: createRFTCollection(string,string,string)
function createRFTCollection(
- string memory name,
- string memory description,
- string memory tokenPrefix
- ) external payable returns (address);
-
- /// @dev EVM selector for this function is: 0x44a68ad5,
- /// or in textual repr: createRefungibleCollection(string,string,string)
- function createRefungibleCollection(
string memory name,
string memory description,
string memory tokenPrefix
tests/src/eth/api/UniqueNFT.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -12,6 +12,34 @@
function supportsInterface(bytes4 interfaceID) external view returns (bool);
}
+/// @title ERC-721 Non-Fungible Token Standard, optional metadata extension
+/// @dev See https://eips.ethereum.org/EIPS/eip-721
+/// @dev the ERC-165 identifier for this interface is 0x5b5e139f
+interface ERC721Metadata is Dummy, ERC165 {
+ /// @notice A descriptive name for a collection of NFTs in this contract
+ /// @dev EVM selector for this function is: 0x06fdde03,
+ /// or in textual repr: name()
+ function name() external view returns (string memory);
+
+ /// @notice An abbreviated name for NFTs in this contract
+ /// @dev EVM selector for this function is: 0x95d89b41,
+ /// or in textual repr: symbol()
+ function symbol() external view returns (string memory);
+
+ /// @notice A distinct Uniform Resource Identifier (URI) for a given asset.
+ ///
+ /// @dev If the token has a `url` property and it is not empty, it is returned.
+ /// Else If the collection does not have a property with key `schemaName` or its value is not equal to `ERC721Metadata`, it return an error `tokenURI not set`.
+ /// If the collection property `baseURI` is empty or absent, return "" (empty string)
+ /// otherwise, if token property `suffix` present and is non-empty, return concatenation of baseURI and suffix
+ /// otherwise, return concatenation of `baseURI` and stringified token id (decimal stringifying, without paddings).
+ ///
+ /// @return token's const_metadata
+ /// @dev EVM selector for this function is: 0xc87b56dd,
+ /// or in textual repr: tokenURI(uint256)
+ function tokenURI(uint256 tokenId) external view returns (string memory);
+}
+
/// @title A contract that allows to set and delete token properties and change token property permissions.
/// @dev the ERC-165 identifier for this interface is 0x41369377
interface TokenProperties is Dummy, ERC165 {
@@ -120,7 +148,7 @@
/// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.
/// @dev EVM selector for this function is: 0x6ec0a9f1,
/// or in textual repr: collectionSponsor()
- function collectionSponsor() external view returns (Tuple17 memory);
+ function collectionSponsor() external view returns (Tuple15 memory);
/// Set limits for the collection.
/// @dev Throws error if limit not found.
@@ -237,7 +265,7 @@
/// If address is canonical then substrate mirror is zero and vice versa.
/// @dev EVM selector for this function is: 0xdf727d3b,
/// or in textual repr: collectionOwner()
- function collectionOwner() external view returns (Tuple17 memory);
+ function collectionOwner() external view returns (Tuple15 memory);
/// Changes collection owner to another account
///
@@ -249,7 +277,7 @@
}
/// @dev anonymous struct
-struct Tuple17 {
+struct Tuple15 {
address field_0;
uint256 field_1;
}
@@ -350,11 +378,11 @@
/// @param tokens array of pairs of token ID and token URI for minted tokens
/// @dev EVM selector for this function is: 0x36543006,
/// or in textual repr: mintBulkWithTokenURI(address,(uint256,string)[])
- function mintBulkWithTokenURI(address to, Tuple8[] memory tokens) external returns (bool);
+ function mintBulkWithTokenURI(address to, Tuple6[] memory tokens) external returns (bool);
}
/// @dev anonymous struct
-struct Tuple8 {
+struct Tuple6 {
uint256 field_0;
string field_1;
}
@@ -383,35 +411,7 @@
/// or in textual repr: totalSupply()
function totalSupply() external view returns (uint256);
}
-
-/// @title ERC-721 Non-Fungible Token Standard, optional metadata extension
-/// @dev See https://eips.ethereum.org/EIPS/eip-721
-/// @dev the ERC-165 identifier for this interface is 0x5b5e139f
-interface ERC721Metadata is Dummy, ERC165 {
- /// @notice A descriptive name for a collection of NFTs in this contract
- /// @dev EVM selector for this function is: 0x06fdde03,
- /// or in textual repr: name()
- function name() external view returns (string memory);
- /// @notice An abbreviated name for NFTs in this contract
- /// @dev EVM selector for this function is: 0x95d89b41,
- /// or in textual repr: symbol()
- function symbol() external view returns (string memory);
-
- /// @notice A distinct Uniform Resource Identifier (URI) for a given asset.
- ///
- /// @dev If the token has a `url` property and it is not empty, it is returned.
- /// Else If the collection does not have a property with key `schemaName` or its value is not equal to `ERC721Metadata`, it return an error `tokenURI not set`.
- /// If the collection property `baseURI` is empty or absent, return "" (empty string)
- /// otherwise, if token property `suffix` present and is non-empty, return concatenation of baseURI and suffix
- /// otherwise, return concatenation of `baseURI` and stringified token id (decimal stringifying, without paddings).
- ///
- /// @return token's const_metadata
- /// @dev EVM selector for this function is: 0xc87b56dd,
- /// or in textual repr: tokenURI(uint256)
- function tokenURI(uint256 tokenId) external view returns (string memory);
-}
-
/// @dev inlined interface
interface ERC721Events {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
@@ -507,11 +507,11 @@
Dummy,
ERC165,
ERC721,
- ERC721Metadata,
ERC721Enumerable,
ERC721UniqueExtensions,
ERC721Mintable,
ERC721Burnable,
Collection,
- TokenProperties
+ TokenProperties,
+ ERC721Metadata
{}
tests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueRefungible.sol
+++ b/tests/src/eth/api/UniqueRefungible.sol
@@ -12,6 +12,32 @@
function supportsInterface(bytes4 interfaceID) external view returns (bool);
}
+/// @dev the ERC-165 identifier for this interface is 0x5b5e139f
+interface ERC721Metadata is Dummy, ERC165 {
+ /// @notice A descriptive name for a collection of RFTs in this contract
+ /// @dev EVM selector for this function is: 0x06fdde03,
+ /// or in textual repr: name()
+ function name() external view returns (string memory);
+
+ /// @notice An abbreviated name for RFTs in this contract
+ /// @dev EVM selector for this function is: 0x95d89b41,
+ /// or in textual repr: symbol()
+ function symbol() external view returns (string memory);
+
+ /// @notice A distinct Uniform Resource Identifier (URI) for a given asset.
+ ///
+ /// @dev If the token has a `url` property and it is not empty, it is returned.
+ /// Else If the collection does not have a property with key `schemaName` or its value is not equal to `ERC721Metadata`, it return an error `tokenURI not set`.
+ /// If the collection property `baseURI` is empty or absent, return "" (empty string)
+ /// otherwise, if token property `suffix` present and is non-empty, return concatenation of baseURI and suffix
+ /// otherwise, return concatenation of `baseURI` and stringified token id (decimal stringifying, without paddings).
+ ///
+ /// @return token's const_metadata
+ /// @dev EVM selector for this function is: 0xc87b56dd,
+ /// or in textual repr: tokenURI(uint256)
+ function tokenURI(uint256 tokenId) external view returns (string memory);
+}
+
/// @title A contract that allows to set and delete token properties and change token property permissions.
/// @dev the ERC-165 identifier for this interface is 0x41369377
interface TokenProperties is Dummy, ERC165 {
@@ -120,7 +146,7 @@
/// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.
/// @dev EVM selector for this function is: 0x6ec0a9f1,
/// or in textual repr: collectionSponsor()
- function collectionSponsor() external view returns (Tuple17 memory);
+ function collectionSponsor() external view returns (Tuple15 memory);
/// Set limits for the collection.
/// @dev Throws error if limit not found.
@@ -237,7 +263,7 @@
/// If address is canonical then substrate mirror is zero and vice versa.
/// @dev EVM selector for this function is: 0xdf727d3b,
/// or in textual repr: collectionOwner()
- function collectionOwner() external view returns (Tuple17 memory);
+ function collectionOwner() external view returns (Tuple15 memory);
/// Changes collection owner to another account
///
@@ -249,7 +275,7 @@
}
/// @dev anonymous struct
-struct Tuple17 {
+struct Tuple15 {
address field_0;
uint256 field_1;
}
@@ -352,7 +378,7 @@
/// @param tokens array of pairs of token ID and token URI for minted tokens
/// @dev EVM selector for this function is: 0x36543006,
/// or in textual repr: mintBulkWithTokenURI(address,(uint256,string)[])
- function mintBulkWithTokenURI(address to, Tuple8[] memory tokens) external returns (bool);
+ function mintBulkWithTokenURI(address to, Tuple6[] memory tokens) external returns (bool);
/// Returns EVM address for refungible token
///
@@ -363,7 +389,7 @@
}
/// @dev anonymous struct
-struct Tuple8 {
+struct Tuple6 {
uint256 field_0;
string field_1;
}
@@ -393,32 +419,6 @@
function totalSupply() external view returns (uint256);
}
-/// @dev the ERC-165 identifier for this interface is 0x5b5e139f
-interface ERC721Metadata is Dummy, ERC165 {
- /// @notice A descriptive name for a collection of RFTs in this contract
- /// @dev EVM selector for this function is: 0x06fdde03,
- /// or in textual repr: name()
- function name() external view returns (string memory);
-
- /// @notice An abbreviated name for RFTs in this contract
- /// @dev EVM selector for this function is: 0x95d89b41,
- /// or in textual repr: symbol()
- function symbol() external view returns (string memory);
-
- /// @notice A distinct Uniform Resource Identifier (URI) for a given asset.
- ///
- /// @dev If the token has a `url` property and it is not empty, it is returned.
- /// Else If the collection does not have a property with key `schemaName` or its value is not equal to `ERC721Metadata`, it return an error `tokenURI not set`.
- /// If the collection property `baseURI` is empty or absent, return "" (empty string)
- /// otherwise, if token property `suffix` present and is non-empty, return concatenation of baseURI and suffix
- /// otherwise, return concatenation of `baseURI` and stringified token id (decimal stringifying, without paddings).
- ///
- /// @return token's const_metadata
- /// @dev EVM selector for this function is: 0xc87b56dd,
- /// or in textual repr: tokenURI(uint256)
- function tokenURI(uint256 tokenId) external view returns (string memory);
-}
-
/// @dev inlined interface
interface ERC721Events {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
@@ -512,11 +512,11 @@
Dummy,
ERC165,
ERC721,
- ERC721Metadata,
ERC721Enumerable,
ERC721UniqueExtensions,
ERC721Mintable,
ERC721Burnable,
Collection,
- TokenProperties
+ TokenProperties,
+ ERC721Metadata
{}
tests/src/eth/collectionHelpersAbi.jsondiffbeforeafterboth--- a/tests/src/eth/collectionHelpersAbi.json
+++ b/tests/src/eth/collectionHelpersAbi.json
@@ -84,17 +84,6 @@
},
{
"inputs": [
- { "internalType": "string", "name": "name", "type": "string" },
- { "internalType": "string", "name": "description", "type": "string" },
- { "internalType": "string", "name": "tokenPrefix", "type": "string" }
- ],
- "name": "createRefungibleCollection",
- "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
- "stateMutability": "payable",
- "type": "function"
- },
- {
- "inputs": [
{
"internalType": "address",
"name": "collectionAddress",
tests/src/eth/collectionProperties.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionProperties.test.ts
+++ b/tests/src/eth/collectionProperties.test.ts
@@ -1,5 +1,6 @@
import {itEth, usingEthPlaygrounds, expect} from './util/playgrounds';
import {IKeyringPair} from '@polkadot/types/types';
+import {Pallets} from '../util/playgrounds';
describe('EVM collection properties', () => {
let donor: IKeyringPair;
@@ -80,7 +81,7 @@
expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.false;
});
- itEth('ERC721Metadata property can be set for RFT collection', async({helper}) => {
+ itEth.ifWithPallets('ERC721Metadata property can be set for RFT collection', [Pallets.ReFungible], async({helper}) => {
const caller = await helper.eth.createAccountWithBalance(donor);
const collection = await helper.rft.mintCollection(donor, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
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/playgrounds';18import {IKeyringPair} from '@polkadot/types/types';19import {Contract} from 'web3-eth-contract';202122describe('NFT: Information getting', () => {23 let donor: IKeyringPair;24 let alice: IKeyringPair;2526 before(async function() {27 await usingEthPlaygrounds(async (helper, privateKey) => {28 donor = privateKey('//Alice');29 [alice] = await helper.arrange.createAccounts([10n], donor);30 });31 });32 33 itEth('totalSupply', async ({helper}) => {34 const collection = await helper.nft.mintCollection(alice, {});35 await collection.mintToken(alice);3637 const caller = await helper.eth.createAccountWithBalance(donor);3839 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);40 const totalSupply = await contract.methods.totalSupply().call();4142 expect(totalSupply).to.equal('1');43 });4445 itEth('balanceOf', async ({helper}) => {46 const collection = await helper.nft.mintCollection(alice, {});47 const caller = await helper.eth.createAccountWithBalance(donor);4849 await collection.mintToken(alice, {Ethereum: caller});50 await collection.mintToken(alice, {Ethereum: caller});51 await collection.mintToken(alice, {Ethereum: caller});5253 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);54 const balance = await contract.methods.balanceOf(caller).call();5556 expect(balance).to.equal('3');57 });5859 itEth('ownerOf', async ({helper}) => {60 const collection = await helper.nft.mintCollection(alice, {});61 const caller = await helper.eth.createAccountWithBalance(donor);6263 const token = await collection.mintToken(alice, {Ethereum: caller});6465 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);6667 const owner = await contract.methods.ownerOf(token.tokenId).call();6869 expect(owner).to.equal(caller);70 });71});7273describe('Check ERC721 token URI for NFT', () => {74 let donor: IKeyringPair;7576 before(async function() {77 await usingEthPlaygrounds(async (_helper, privateKey) => {78 donor = privateKey('//Alice');79 });80 });8182 async function setup(helper: EthUniqueHelper, tokenPrefix: string, propertyKey?: string, propertyValue?: string): Promise<{contract: Contract, nextTokenId: string}> {83 const owner = await helper.eth.createAccountWithBalance(donor);84 const receiver = helper.eth.createAccount();8586 const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', 'a', 'b', tokenPrefix);87 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);88 89 const nextTokenId = await contract.methods.nextTokenId().call();90 expect(nextTokenId).to.be.equal('1');91 const result = await contract.methods.mint(92 receiver,93 nextTokenId,94 ).send();9596 if (propertyKey && propertyValue) {97 // Set URL or suffix98 await contract.methods.setProperty(nextTokenId, propertyKey, Buffer.from(propertyValue)).send();99 }100101 const event = result.events.Transfer;102 expect(event.address).to.be.equal(collectionAddress);103 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');104 expect(event.returnValues.to).to.be.equal(receiver);105 expect(event.returnValues.tokenId).to.be.equal(nextTokenId);106107 return {contract, nextTokenId};108 }109110 itEth('Empty tokenURI', async ({helper}) => {111 const {contract, nextTokenId} = await setup(helper, '');112 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');113 });114115 itEth('TokenURI from url', async ({helper}) => {116 const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URI', 'Token URI');117 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');118 });119120 itEth('TokenURI from baseURI', async ({helper}) => {121 const {contract, nextTokenId} = await setup(helper, 'BaseURI_');122 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_');123 });124125 itEth('TokenURI from baseURI + suffix', async ({helper}) => {126 const suffix = '/some/suffix';127 const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URISuffix', suffix);128 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);129 });130});131132describe('NFT: Plain calls', () => {133 let donor: IKeyringPair;134 let alice: IKeyringPair;135136 before(async function() {137 await usingEthPlaygrounds(async (helper, privateKey) => {138 donor = privateKey('//Alice');139 [alice] = await helper.arrange.createAccounts([10n], donor);140 });141 });142143 itEth('Can perform mint()', async ({helper}) => {144 const owner = await helper.eth.createAccountWithBalance(donor);145 const receiver = helper.eth.createAccount();146147 const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', '6', '6', '');148 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);149 const nextTokenId = await contract.methods.nextTokenId().call();150151 expect(nextTokenId).to.be.equal('1');152 const result = await contract.methods.mintWithTokenURI(153 receiver,154 nextTokenId,155 'Test URI',156 ).send();157158 const event = result.events.Transfer;159 expect(event.address).to.be.equal(collectionAddress);160 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');161 expect(event.returnValues.to).to.be.equal(receiver);162 expect(event.returnValues.tokenId).to.be.equal(nextTokenId);163164 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');165166 // TODO: this wont work right now, need release 919000 first167 // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();168 // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();169 // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);170 });171172 //TODO: CORE-302 add eth methods173 itEth.skip('Can perform mintBulk()', async ({helper}) => {174 const caller = await helper.eth.createAccountWithBalance(donor);175 const receiver = helper.eth.createAccount();176177 const collection = await helper.nft.mintCollection(alice);178 await collection.addAdmin(alice, {Ethereum: caller});179180 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);181 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', caller);182 {183 const bulkSize = 3;184 const nextTokenId = await contract.methods.nextTokenId().call();185 expect(nextTokenId).to.be.equal('1');186 const result = await contract.methods.mintBulkWithTokenURI(187 receiver,188 Array.from({length: bulkSize}, (_, i) => (189 [+nextTokenId + i, `Test URI ${i}`]190 )),191 ).send({from: caller});192193 const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.tokenId - b.returnValues.tokenId);194 for (let i = 0; i < bulkSize; i++) {195 const event = events[i];196 expect(event.address).to.equal(collectionAddress);197 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');198 expect(event.returnValues.to).to.equal(receiver);199 expect(event.returnValues.tokenId).to.equal(`${+nextTokenId+i}`);200201 expect(await contract.methods.tokenURI(+nextTokenId + i).call()).to.be.equal(`Test URI ${i}`);202 }203 }204 });205206 itEth('Can perform burn()', async ({helper}) => {207 const caller = await helper.eth.createAccountWithBalance(donor);208209 const collection = await helper.nft.mintCollection(alice, {});210 const {tokenId} = await collection.mintToken(alice, {Ethereum: caller});211212 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);213 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', caller);214215 {216 const result = await contract.methods.burn(tokenId).send({from: caller});217 218 const event = result.events.Transfer;219 expect(event.address).to.be.equal(collectionAddress);220 expect(event.returnValues.from).to.be.equal(caller);221 expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');222 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);223 }224 });225226 itEth('Can perform approve()', async ({helper}) => {227 const owner = await helper.eth.createAccountWithBalance(donor);228 const spender = helper.eth.createAccount();229230 const collection = await helper.nft.mintCollection(alice, {});231 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});232233 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);234 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);235236 {237 const result = await contract.methods.approve(spender, tokenId).send({from: owner});238239 const event = result.events.Approval;240 expect(event.address).to.be.equal(collectionAddress);241 expect(event.returnValues.owner).to.be.equal(owner);242 expect(event.returnValues.approved).to.be.equal(spender);243 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);244 }245 });246247 itEth('Can perform transferFrom()', async ({helper}) => {248 const owner = await helper.eth.createAccountWithBalance(donor);249 const spender = await helper.eth.createAccountWithBalance(donor);250 const receiver = helper.eth.createAccount();251252 const collection = await helper.nft.mintCollection(alice, {});253 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});254255 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);256 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);257258 await contract.methods.approve(spender, tokenId).send({from: owner});259260 {261 const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({from: spender});262263 const event = result.events.Transfer;264 expect(event.address).to.be.equal(collectionAddress);265 expect(event.returnValues.from).to.be.equal(owner);266 expect(event.returnValues.to).to.be.equal(receiver);267 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);268 }269270 {271 const balance = await contract.methods.balanceOf(receiver).call();272 expect(+balance).to.equal(1);273 }274275 {276 const balance = await contract.methods.balanceOf(owner).call();277 expect(+balance).to.equal(0);278 }279 });280281 itEth('Can perform transfer()', async ({helper}) => {282 const collection = await helper.nft.mintCollection(alice, {});283 const owner = await helper.eth.createAccountWithBalance(donor);284 const receiver = helper.eth.createAccount();285286 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});287288 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);289 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);290291 {292 const result = await contract.methods.transfer(receiver, tokenId).send({from: owner});293294 const event = result.events.Transfer;295 expect(event.address).to.be.equal(collectionAddress);296 expect(event.returnValues.from).to.be.equal(owner);297 expect(event.returnValues.to).to.be.equal(receiver);298 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);299 }300301 {302 const balance = await contract.methods.balanceOf(owner).call();303 expect(+balance).to.equal(0);304 }305306 {307 const balance = await contract.methods.balanceOf(receiver).call();308 expect(+balance).to.equal(1);309 }310 });311});312313describe('NFT: Fees', () => {314 let donor: IKeyringPair;315 let alice: IKeyringPair;316317 before(async function() {318 await usingEthPlaygrounds(async (helper, privateKey) => {319 donor = privateKey('//Alice');320 [alice] = await helper.arrange.createAccounts([10n], donor);321 });322 });323 324 itEth('approve() call fee is less than 0.2UNQ', async ({helper}) => {325 const owner = await helper.eth.createAccountWithBalance(donor);326 const spender = helper.eth.createAccount();327328 const collection = await helper.nft.mintCollection(alice, {});329 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});330331 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);332333 const cost = await helper.eth.recordCallFee(owner, () => contract.methods.approve(spender, tokenId).send({from: owner}));334 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));335 });336337 itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {338 const owner = await helper.eth.createAccountWithBalance(donor);339 const spender = await helper.eth.createAccountWithBalance(donor);340341 const collection = await helper.nft.mintCollection(alice, {});342 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});343344 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);345346 await contract.methods.approve(spender, tokenId).send({from: owner});347348 const cost = await helper.eth.recordCallFee(spender, () => contract.methods.transferFrom(owner, spender, tokenId).send({from: spender}));349 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));350 });351352 itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {353 const owner = await helper.eth.createAccountWithBalance(donor);354 const receiver = helper.eth.createAccount();355356 const collection = await helper.nft.mintCollection(alice, {});357 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});358359 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);360361 const cost = await helper.eth.recordCallFee(owner, () => contract.methods.transfer(receiver, tokenId).send({from: owner}));362 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));363 });364});365366describe('NFT: Substrate calls', () => {367 let donor: IKeyringPair;368 let alice: IKeyringPair;369370 before(async function() {371 await usingEthPlaygrounds(async (helper, privateKey) => {372 donor = privateKey('//Alice');373 [alice] = await helper.arrange.createAccounts([20n], donor);374 });375 });376377 itEth('Events emitted for mint()', async ({helper}) => {378 const collection = await helper.nft.mintCollection(alice, {});379 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);380 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');381382 const events: any = [];383 contract.events.allEvents((_: any, event: any) => {384 events.push(event);385 });386 const {tokenId} = await collection.mintToken(alice);387388 const event = events[0];389 expect(event.event).to.be.equal('Transfer');390 expect(event.address).to.be.equal(collectionAddress);391 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');392 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(alice.address));393 expect(event.returnValues.tokenId).to.be.equal(tokenId.toString());394 });395396 itEth('Events emitted for burn()', async ({helper}) => {397 const collection = await helper.nft.mintCollection(alice, {});398 const token = await collection.mintToken(alice);399400 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);401 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');402 403 const events: any = [];404 contract.events.allEvents((_: any, event: any) => {405 events.push(event);406 });407408 await token.burn(alice);409410 const event = events[0];411 expect(event.event).to.be.equal('Transfer');412 expect(event.address).to.be.equal(collectionAddress);413 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));414 expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');415 expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());416 });417418 itEth('Events emitted for approve()', async ({helper}) => {419 const receiver = helper.eth.createAccount();420421 const collection = await helper.nft.mintCollection(alice, {});422 const token = await collection.mintToken(alice);423424 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);425 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');426 427 const events: any = [];428 contract.events.allEvents((_: any, event: any) => {429 events.push(event);430 });431432 await token.approve(alice, {Ethereum: receiver});433434 const event = events[0];435 expect(event.event).to.be.equal('Approval');436 expect(event.address).to.be.equal(collectionAddress);437 expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));438 expect(event.returnValues.approved).to.be.equal(receiver);439 expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());440 });441442 itEth('Events emitted for transferFrom()', async ({helper}) => {443 const [bob] = await helper.arrange.createAccounts([10n], donor);444 const receiver = helper.eth.createAccount();445446 const collection = await helper.nft.mintCollection(alice, {});447 const token = await collection.mintToken(alice);448 await token.approve(alice, {Substrate: bob.address});449450 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);451 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');452 453 const events: any = [];454 contract.events.allEvents((_: any, event: any) => {455 events.push(event);456 });457458 await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver});459 460 const event = events[0];461 expect(event.address).to.be.equal(collectionAddress);462 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));463 expect(event.returnValues.to).to.be.equal(receiver);464 expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);465 });466467 itEth('Events emitted for transfer()', async ({helper}) => {468 const receiver = helper.eth.createAccount();469470 const collection = await helper.nft.mintCollection(alice, {});471 const token = await collection.mintToken(alice);472473 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);474 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');475 476 const events: any = [];477 contract.events.allEvents((_: any, event: any) => {478 events.push(event);479 });480481 await token.transfer(alice, {Ethereum: receiver});482 483 const event = events[0];484 expect(event.address).to.be.equal(collectionAddress);485 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));486 expect(event.returnValues.to).to.be.equal(receiver);487 expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);488 });489});490491describe('Common metadata', () => {492 let donor: IKeyringPair;493 let alice: IKeyringPair;494495 before(async function() {496 await usingEthPlaygrounds(async (helper, privateKey) => {497 donor = privateKey('//Alice');498 [alice] = await helper.arrange.createAccounts([20n], donor);499 });500 });501502 itEth('Returns collection name', async ({helper}) => {503 const caller = await helper.eth.createAccountWithBalance(donor);504 const collection = await helper.nft.mintCollection(alice, {name: 'oh River', tokenPrefix: 'CHANGE'});505506 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);507 const name = await contract.methods.name().call();508 expect(name).to.equal('oh River');509 });510511 itEth('Returns symbol name', async ({helper}) => {512 const caller = await helper.eth.createAccountWithBalance(donor);513 const collection = await helper.nft.mintCollection(alice, {name: 'oh River', tokenPrefix: 'CHANGE'});514515 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);516 const symbol = await contract.methods.symbol().call();517 expect(symbol).to.equal('CHANGE');518 });519});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/playgrounds';18import {IKeyringPair} from '@polkadot/types/types';19import {Contract} from 'web3-eth-contract';202122describe('NFT: Information getting', () => {23 let donor: IKeyringPair;24 let alice: IKeyringPair;2526 before(async function() {27 await usingEthPlaygrounds(async (helper, privateKey) => {28 donor = privateKey('//Alice');29 [alice] = await helper.arrange.createAccounts([10n], donor);30 });31 });32 33 itEth('totalSupply', async ({helper}) => {34 const collection = await helper.nft.mintCollection(alice, {});35 await collection.mintToken(alice);3637 const caller = await helper.eth.createAccountWithBalance(donor);3839 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);40 const totalSupply = await contract.methods.totalSupply().call();4142 expect(totalSupply).to.equal('1');43 });4445 itEth('balanceOf', async ({helper}) => {46 const collection = await helper.nft.mintCollection(alice, {});47 const caller = await helper.eth.createAccountWithBalance(donor);4849 await collection.mintToken(alice, {Ethereum: caller});50 await collection.mintToken(alice, {Ethereum: caller});51 await collection.mintToken(alice, {Ethereum: caller});5253 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);54 const balance = await contract.methods.balanceOf(caller).call();5556 expect(balance).to.equal('3');57 });5859 itEth('ownerOf', async ({helper}) => {60 const collection = await helper.nft.mintCollection(alice, {});61 const caller = await helper.eth.createAccountWithBalance(donor);6263 const token = await collection.mintToken(alice, {Ethereum: caller});6465 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);6667 const owner = await contract.methods.ownerOf(token.tokenId).call();6869 expect(owner).to.equal(caller);70 });71});7273describe('Check ERC721 token URI for NFT', () => {74 let donor: IKeyringPair;7576 before(async function() {77 await usingEthPlaygrounds(async (_helper, privateKey) => {78 donor = privateKey('//Alice');79 });80 });8182 async function setup(helper: EthUniqueHelper, baseUri: string, propertyKey?: string, propertyValue?: string): Promise<{contract: Contract, nextTokenId: string}> {83 const owner = await helper.eth.createAccountWithBalance(donor);84 const receiver = helper.eth.createAccount();8586 const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', 'a', 'b', baseUri);87 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);88 89 const nextTokenId = await contract.methods.nextTokenId().call();90 expect(nextTokenId).to.be.equal('1');91 const result = await contract.methods.mint(92 receiver,93 nextTokenId,94 ).send();9596 if (propertyKey && propertyValue) {97 // Set URL or suffix98 await contract.methods.setProperty(nextTokenId, propertyKey, Buffer.from(propertyValue)).send();99 }100101 const event = result.events.Transfer;102 expect(event.address).to.be.equal(collectionAddress);103 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');104 expect(event.returnValues.to).to.be.equal(receiver);105 expect(event.returnValues.tokenId).to.be.equal(nextTokenId);106107 return {contract, nextTokenId};108 }109110 itEth('Empty tokenURI', async ({helper}) => {111 const {contract, nextTokenId} = await setup(helper, '');112 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');113 });114115 itEth('TokenURI from url', async ({helper}) => {116 const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URI', 'Token URI');117 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');118 });119120 itEth('TokenURI from baseURI', async ({helper}) => {121 const {contract, nextTokenId} = await setup(helper, 'BaseURI_');122 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_');123 });124125 itEth('TokenURI from baseURI + suffix', async ({helper}) => {126 const suffix = '/some/suffix';127 const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URISuffix', suffix);128 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);129 });130});131132describe('NFT: Plain calls', () => {133 let donor: IKeyringPair;134 let alice: IKeyringPair;135136 before(async function() {137 await usingEthPlaygrounds(async (helper, privateKey) => {138 donor = privateKey('//Alice');139 [alice] = await helper.arrange.createAccounts([10n], donor);140 });141 });142143 itEth('Can perform mint()', async ({helper}) => {144 const owner = await helper.eth.createAccountWithBalance(donor);145 const receiver = helper.eth.createAccount();146147 const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', '6', '6', '');148 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);149 const nextTokenId = await contract.methods.nextTokenId().call();150151 expect(nextTokenId).to.be.equal('1');152 const result = await contract.methods.mintWithTokenURI(153 receiver,154 nextTokenId,155 'Test URI',156 ).send();157158 const event = result.events.Transfer;159 expect(event.address).to.be.equal(collectionAddress);160 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');161 expect(event.returnValues.to).to.be.equal(receiver);162 expect(event.returnValues.tokenId).to.be.equal(nextTokenId);163164 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');165166 // TODO: this wont work right now, need release 919000 first167 // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();168 // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();169 // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);170 });171172 //TODO: CORE-302 add eth methods173 itEth.skip('Can perform mintBulk()', async ({helper}) => {174 const caller = await helper.eth.createAccountWithBalance(donor);175 const receiver = helper.eth.createAccount();176177 const collection = await helper.nft.mintCollection(alice);178 await collection.addAdmin(alice, {Ethereum: caller});179180 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);181 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', caller);182 {183 const bulkSize = 3;184 const nextTokenId = await contract.methods.nextTokenId().call();185 expect(nextTokenId).to.be.equal('1');186 const result = await contract.methods.mintBulkWithTokenURI(187 receiver,188 Array.from({length: bulkSize}, (_, i) => (189 [+nextTokenId + i, `Test URI ${i}`]190 )),191 ).send({from: caller});192193 const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.tokenId - b.returnValues.tokenId);194 for (let i = 0; i < bulkSize; i++) {195 const event = events[i];196 expect(event.address).to.equal(collectionAddress);197 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');198 expect(event.returnValues.to).to.equal(receiver);199 expect(event.returnValues.tokenId).to.equal(`${+nextTokenId+i}`);200201 expect(await contract.methods.tokenURI(+nextTokenId + i).call()).to.be.equal(`Test URI ${i}`);202 }203 }204 });205206 itEth('Can perform burn()', async ({helper}) => {207 const caller = await helper.eth.createAccountWithBalance(donor);208209 const collection = await helper.nft.mintCollection(alice, {});210 const {tokenId} = await collection.mintToken(alice, {Ethereum: caller});211212 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);213 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', caller);214215 {216 const result = await contract.methods.burn(tokenId).send({from: caller});217 218 const event = result.events.Transfer;219 expect(event.address).to.be.equal(collectionAddress);220 expect(event.returnValues.from).to.be.equal(caller);221 expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');222 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);223 }224 });225226 itEth('Can perform approve()', async ({helper}) => {227 const owner = await helper.eth.createAccountWithBalance(donor);228 const spender = helper.eth.createAccount();229230 const collection = await helper.nft.mintCollection(alice, {});231 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});232233 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);234 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);235236 {237 const result = await contract.methods.approve(spender, tokenId).send({from: owner});238239 const event = result.events.Approval;240 expect(event.address).to.be.equal(collectionAddress);241 expect(event.returnValues.owner).to.be.equal(owner);242 expect(event.returnValues.approved).to.be.equal(spender);243 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);244 }245 });246247 itEth('Can perform transferFrom()', async ({helper}) => {248 const owner = await helper.eth.createAccountWithBalance(donor);249 const spender = await helper.eth.createAccountWithBalance(donor);250 const receiver = helper.eth.createAccount();251252 const collection = await helper.nft.mintCollection(alice, {});253 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});254255 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);256 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);257258 await contract.methods.approve(spender, tokenId).send({from: owner});259260 {261 const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({from: spender});262263 const event = result.events.Transfer;264 expect(event.address).to.be.equal(collectionAddress);265 expect(event.returnValues.from).to.be.equal(owner);266 expect(event.returnValues.to).to.be.equal(receiver);267 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);268 }269270 {271 const balance = await contract.methods.balanceOf(receiver).call();272 expect(+balance).to.equal(1);273 }274275 {276 const balance = await contract.methods.balanceOf(owner).call();277 expect(+balance).to.equal(0);278 }279 });280281 itEth('Can perform transfer()', async ({helper}) => {282 const collection = await helper.nft.mintCollection(alice, {});283 const owner = await helper.eth.createAccountWithBalance(donor);284 const receiver = helper.eth.createAccount();285286 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});287288 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);289 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);290291 {292 const result = await contract.methods.transfer(receiver, tokenId).send({from: owner});293294 const event = result.events.Transfer;295 expect(event.address).to.be.equal(collectionAddress);296 expect(event.returnValues.from).to.be.equal(owner);297 expect(event.returnValues.to).to.be.equal(receiver);298 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);299 }300301 {302 const balance = await contract.methods.balanceOf(owner).call();303 expect(+balance).to.equal(0);304 }305306 {307 const balance = await contract.methods.balanceOf(receiver).call();308 expect(+balance).to.equal(1);309 }310 });311});312313describe('NFT: Fees', () => {314 let donor: IKeyringPair;315 let alice: IKeyringPair;316317 before(async function() {318 await usingEthPlaygrounds(async (helper, privateKey) => {319 donor = privateKey('//Alice');320 [alice] = await helper.arrange.createAccounts([10n], donor);321 });322 });323 324 itEth('approve() call fee is less than 0.2UNQ', async ({helper}) => {325 const owner = await helper.eth.createAccountWithBalance(donor);326 const spender = helper.eth.createAccount();327328 const collection = await helper.nft.mintCollection(alice, {});329 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});330331 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);332333 const cost = await helper.eth.recordCallFee(owner, () => contract.methods.approve(spender, tokenId).send({from: owner}));334 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));335 });336337 itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {338 const owner = await helper.eth.createAccountWithBalance(donor);339 const spender = await helper.eth.createAccountWithBalance(donor);340341 const collection = await helper.nft.mintCollection(alice, {});342 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});343344 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);345346 await contract.methods.approve(spender, tokenId).send({from: owner});347348 const cost = await helper.eth.recordCallFee(spender, () => contract.methods.transferFrom(owner, spender, tokenId).send({from: spender}));349 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));350 });351352 itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {353 const owner = await helper.eth.createAccountWithBalance(donor);354 const receiver = helper.eth.createAccount();355356 const collection = await helper.nft.mintCollection(alice, {});357 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});358359 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);360361 const cost = await helper.eth.recordCallFee(owner, () => contract.methods.transfer(receiver, tokenId).send({from: owner}));362 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));363 });364});365366describe('NFT: Substrate calls', () => {367 let donor: IKeyringPair;368 let alice: IKeyringPair;369370 before(async function() {371 await usingEthPlaygrounds(async (helper, privateKey) => {372 donor = privateKey('//Alice');373 [alice] = await helper.arrange.createAccounts([20n], donor);374 });375 });376377 itEth('Events emitted for mint()', async ({helper}) => {378 const collection = await helper.nft.mintCollection(alice, {});379 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);380 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');381382 const events: any = [];383 contract.events.allEvents((_: any, event: any) => {384 events.push(event);385 });386 const {tokenId} = await collection.mintToken(alice);387388 const event = events[0];389 expect(event.event).to.be.equal('Transfer');390 expect(event.address).to.be.equal(collectionAddress);391 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');392 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(alice.address));393 expect(event.returnValues.tokenId).to.be.equal(tokenId.toString());394 });395396 itEth('Events emitted for burn()', async ({helper}) => {397 const collection = await helper.nft.mintCollection(alice, {});398 const token = await collection.mintToken(alice);399400 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);401 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');402 403 const events: any = [];404 contract.events.allEvents((_: any, event: any) => {405 events.push(event);406 });407408 await token.burn(alice);409410 const event = events[0];411 expect(event.event).to.be.equal('Transfer');412 expect(event.address).to.be.equal(collectionAddress);413 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));414 expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');415 expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());416 });417418 itEth('Events emitted for approve()', async ({helper}) => {419 const receiver = helper.eth.createAccount();420421 const collection = await helper.nft.mintCollection(alice, {});422 const token = await collection.mintToken(alice);423424 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);425 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');426 427 const events: any = [];428 contract.events.allEvents((_: any, event: any) => {429 events.push(event);430 });431432 await token.approve(alice, {Ethereum: receiver});433434 const event = events[0];435 expect(event.event).to.be.equal('Approval');436 expect(event.address).to.be.equal(collectionAddress);437 expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));438 expect(event.returnValues.approved).to.be.equal(receiver);439 expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());440 });441442 itEth('Events emitted for transferFrom()', async ({helper}) => {443 const [bob] = await helper.arrange.createAccounts([10n], donor);444 const receiver = helper.eth.createAccount();445446 const collection = await helper.nft.mintCollection(alice, {});447 const token = await collection.mintToken(alice);448 await token.approve(alice, {Substrate: bob.address});449450 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);451 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');452 453 const events: any = [];454 contract.events.allEvents((_: any, event: any) => {455 events.push(event);456 });457458 await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver});459 460 const event = events[0];461 expect(event.address).to.be.equal(collectionAddress);462 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));463 expect(event.returnValues.to).to.be.equal(receiver);464 expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);465 });466467 itEth('Events emitted for transfer()', async ({helper}) => {468 const receiver = helper.eth.createAccount();469470 const collection = await helper.nft.mintCollection(alice, {});471 const token = await collection.mintToken(alice);472473 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);474 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');475 476 const events: any = [];477 contract.events.allEvents((_: any, event: any) => {478 events.push(event);479 });480481 await token.transfer(alice, {Ethereum: receiver});482 483 const event = events[0];484 expect(event.address).to.be.equal(collectionAddress);485 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));486 expect(event.returnValues.to).to.be.equal(receiver);487 expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);488 });489});490491describe('Common metadata', () => {492 let donor: IKeyringPair;493 let alice: IKeyringPair;494495 before(async function() {496 await usingEthPlaygrounds(async (helper, privateKey) => {497 donor = privateKey('//Alice');498 [alice] = await helper.arrange.createAccounts([20n], donor);499 });500 });501502 itEth('Returns collection name', async ({helper}) => {503 const caller = await helper.eth.createAccountWithBalance(donor);504 const collection = await helper.nft.mintCollection(alice, {name: 'oh River', tokenPrefix: 'CHANGE'});505506 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);507 const name = await contract.methods.name().call();508 expect(name).to.equal('oh River');509 });510511 itEth('Returns symbol name', async ({helper}) => {512 const caller = await helper.eth.createAccountWithBalance(donor);513 const collection = await helper.nft.mintCollection(alice, {name: 'oh River', tokenPrefix: 'CHANGE'});514515 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);516 const symbol = await contract.methods.symbol().call();517 expect(symbol).to.equal('CHANGE');518 });519});tests/src/eth/nonFungibleAbi.jsondiffbeforeafterboth--- a/tests/src/eth/nonFungibleAbi.json
+++ b/tests/src/eth/nonFungibleAbi.json
@@ -154,7 +154,7 @@
{ "internalType": "address", "name": "field_0", "type": "address" },
{ "internalType": "uint256", "name": "field_1", "type": "uint256" }
],
- "internalType": "struct Tuple17",
+ "internalType": "struct Tuple15",
"name": "",
"type": "tuple"
}
@@ -178,7 +178,7 @@
{ "internalType": "address", "name": "field_0", "type": "address" },
{ "internalType": "uint256", "name": "field_1", "type": "uint256" }
],
- "internalType": "struct Tuple17",
+ "internalType": "struct Tuple15",
"name": "",
"type": "tuple"
}
@@ -287,7 +287,7 @@
{ "internalType": "uint256", "name": "field_0", "type": "uint256" },
{ "internalType": "string", "name": "field_1", "type": "string" }
],
- "internalType": "struct Tuple8[]",
+ "internalType": "struct Tuple6[]",
"name": "tokens",
"type": "tuple[]"
}
tests/src/eth/reFungibleAbi.jsondiffbeforeafterboth--- a/tests/src/eth/reFungibleAbi.json
+++ b/tests/src/eth/reFungibleAbi.json
@@ -154,7 +154,7 @@
{ "internalType": "address", "name": "field_0", "type": "address" },
{ "internalType": "uint256", "name": "field_1", "type": "uint256" }
],
- "internalType": "struct Tuple17",
+ "internalType": "struct Tuple15",
"name": "",
"type": "tuple"
}
@@ -178,7 +178,7 @@
{ "internalType": "address", "name": "field_0", "type": "address" },
{ "internalType": "uint256", "name": "field_1", "type": "uint256" }
],
- "internalType": "struct Tuple17",
+ "internalType": "struct Tuple15",
"name": "",
"type": "tuple"
}
@@ -287,7 +287,7 @@
{ "internalType": "uint256", "name": "field_0", "type": "uint256" },
{ "internalType": "string", "name": "field_1", "type": "string" }
],
- "internalType": "struct Tuple8[]",
+ "internalType": "struct Tuple6[]",
"name": "tokens",
"type": "tuple[]"
}
tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -76,11 +76,11 @@
});
});
- async function setup(helper: EthUniqueHelper, tokenPrefix: string, propertyKey?: string, propertyValue?: string): Promise<{contract: Contract, nextTokenId: string}> {
+ async function setup(helper: EthUniqueHelper, baseUri: string, propertyKey?: string, propertyValue?: string): Promise<{contract: Contract, nextTokenId: string}> {
const owner = await helper.eth.createAccountWithBalance(donor);
const receiver = helper.eth.createAccount();
- const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'Mint collection', 'a', 'b', tokenPrefix);
+ const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'Mint collection', 'a', 'b', baseUri);
const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
const nextTokenId = await contract.methods.nextTokenId().call();