git.delta.rocks / unique-network / refs/commits / 44771a5df696

difftreelog

feat updates for createERC721MetadataCompatibleCollections

Grigoriy Simonov2022-10-12parent: #876ef62.patch.diff
in: master

13 files changed

modifiedpallets/common/src/erc.rsdiffbeforeafterboth
--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -665,6 +665,11 @@
 			property_key_from_bytes(b"schemaName").expect(EXPECT_CONVERT_ERROR)
 		}
 
+		/// Key "schemaVersion".
+		pub fn schema_version() -> up_data_structs::PropertyKey {
+			property_key_from_bytes(b"schemaVersion").expect(EXPECT_CONVERT_ERROR)
+		}
+
 		/// Key "baseURI".
 		pub fn base_uri() -> up_data_structs::PropertyKey {
 			property_key_from_bytes(b"baseURI").expect(EXPECT_CONVERT_ERROR)
@@ -672,12 +677,12 @@
 
 		/// Key "url".
 		pub fn url() -> up_data_structs::PropertyKey {
-			property_key_from_bytes(b"url").expect(EXPECT_CONVERT_ERROR)
+			property_key_from_bytes(b"URI").expect(EXPECT_CONVERT_ERROR)
 		}
 
 		/// Key "suffix".
 		pub fn suffix() -> up_data_structs::PropertyKey {
-			property_key_from_bytes(b"suffix").expect(EXPECT_CONVERT_ERROR)
+			property_key_from_bytes(b"URISuffix").expect(EXPECT_CONVERT_ERROR)
 		}
 
 		/// Key "parentNft".
@@ -685,7 +690,7 @@
 			property_key_from_bytes(b"parentNft").expect(EXPECT_CONVERT_ERROR)
 		}
 
-		/// Key "parentNft".
+		/// Key "ERC721Metadata".
 		pub fn erc721_metadata() -> up_data_structs::PropertyKey {
 			property_key_from_bytes(b"ERC721Metadata").expect(EXPECT_CONVERT_ERROR)
 		}
@@ -695,6 +700,9 @@
 	pub mod value {
 		use super::*;
 
+		/// Value "Schema version".
+		pub const SCHEMA_VERSION: &[u8] = b"1.0.0";
+
 		/// Value "ERC721Metadata".
 		pub const ERC721_METADATA: &[u8] = b"ERC721Metadata";
 
@@ -709,7 +717,12 @@
 			property_value_from_bytes(ERC721_METADATA).expect(EXPECT_CONVERT_ERROR)
 		}
 
-		/// Value for [`ERC721_METADATA`].
+		/// Value for [`SCHEMA_VERSION`].
+		pub fn schema_version() -> up_data_structs::PropertyValue {
+			property_value_from_bytes(SCHEMA_VERSION).expect(EXPECT_CONVERT_ERROR)
+		}
+
+		/// Value for [`ERC721_METADATA_SUPPORTED`].
 		pub fn erc721_metadata_supported() -> up_data_structs::PropertyValue {
 			property_value_from_bytes(ERC721_METADATA_SUPPORTED).expect(EXPECT_CONVERT_ERROR)
 		}
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -116,7 +116,18 @@
 			.try_push(up_data_structs::PropertyKeyPermission {
 				key: key::suffix(),
 				permission: up_data_structs::PropertyPermission {
-					mutable: false,
+					mutable: true,
+					collection_admin: true,
+					token_owner: false,
+				},
+			})
+			.map_err(|e| Error::Revert(format!("{:?}", e)))?;
+
+		token_property_permissions
+			.try_push(up_data_structs::PropertyKeyPermission {
+				key: key::url(),
+				permission: up_data_structs::PropertyPermission {
+					mutable: true,
 					collection_admin: true,
 					token_owner: false,
 				},
@@ -129,6 +140,13 @@
 				value: property_value::erc721(),
 			})
 			.map_err(|e| Error::Revert(format!("{:?}", e)))?;
+			
+		properties
+			.try_push(up_data_structs::Property {
+				key: key::schema_version(),
+				value: property_value::schema_version(),
+			})
+			.map_err(|e| Error::Revert(format!("{:?}", e)))?;
 
 		properties
 			.try_push(up_data_structs::Property {
@@ -266,7 +284,7 @@
 	}
 
 	#[weight(<SelfWeightOf<T>>::create_collection())]
-	#[solidity(rename_selector = "createERC721MetadataNFTCollection")]
+	#[solidity(rename_selector = "createERC721MetadataCompatibleNFTCollection")]
 	fn create_nonfungible_collection_with_properties(
 		&mut self,
 		caller: caller,
@@ -339,7 +357,7 @@
 	}
 
 	#[weight(<SelfWeightOf<T>>::create_collection())]
-	#[solidity(rename_selector = "createERC721MetadataRFTCollection")]
+	#[solidity(rename_selector = "createERC721MetadataCompatibleRFTCollection")]
 	fn create_refungible_collection_with_properties(
 		&mut self,
 		caller: caller,
modifiedpallets/unique/src/eth/stubs/CollectionHelpers.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/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 0xf62c7aa9
+/// @dev the ERC-165 identifier for this interface is 0x95eb98f4
 contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
 	/// Create an NFT collection
 	/// @param name Name of the collection
@@ -65,9 +65,9 @@
 		return 0x0000000000000000000000000000000000000000;
 	}
 
-	/// @dev EVM selector for this function is: 0xd1df968c,
-	///  or in textual repr: createERC721MetadataNFTCollection(string,string,string,string)
-	function createERC721MetadataNFTCollection(
+	/// @dev EVM selector for this function is: 0xa9e7b5c0,
+	///  or in textual repr: createERC721MetadataCompatibleNFTCollection(string,string,string,string)
+	function createERC721MetadataCompatibleNFTCollection(
 		string memory name,
 		string memory description,
 		string memory tokenPrefix,
@@ -112,9 +112,9 @@
 		return 0x0000000000000000000000000000000000000000;
 	}
 
-	/// @dev EVM selector for this function is: 0xbea6a299,
-	///  or in textual repr: createERC721MetadataRFTCollection(string,string,string,string)
-	function createERC721MetadataRFTCollection(
+	/// @dev EVM selector for this function is: 0xa5596388,
+	///  or in textual repr: createERC721MetadataCompatibleRFTCollection(string,string,string,string)
+	function createERC721MetadataCompatibleRFTCollection(
 		string memory name,
 		string memory description,
 		string memory tokenPrefix,
modifiedtests/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 0xf62c7aa9
+/// @dev the ERC-165 identifier for this interface is 0x95eb98f4
 interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
 	/// Create an NFT collection
 	/// @param name Name of the collection
@@ -46,9 +46,9 @@
 		string memory tokenPrefix
 	) external payable returns (address);
 
-	/// @dev EVM selector for this function is: 0xd1df968c,
-	///  or in textual repr: createERC721MetadataNFTCollection(string,string,string,string)
-	function createERC721MetadataNFTCollection(
+	/// @dev EVM selector for this function is: 0xa9e7b5c0,
+	///  or in textual repr: createERC721MetadataCompatibleNFTCollection(string,string,string,string)
+	function createERC721MetadataCompatibleNFTCollection(
 		string memory name,
 		string memory description,
 		string memory tokenPrefix,
@@ -71,9 +71,9 @@
 		string memory tokenPrefix
 	) external payable returns (address);
 
-	/// @dev EVM selector for this function is: 0xbea6a299,
-	///  or in textual repr: createERC721MetadataRFTCollection(string,string,string,string)
-	function createERC721MetadataRFTCollection(
+	/// @dev EVM selector for this function is: 0xa5596388,
+	///  or in textual repr: createERC721MetadataCompatibleRFTCollection(string,string,string,string)
+	function createERC721MetadataCompatibleRFTCollection(
 		string memory name,
 		string memory description,
 		string memory tokenPrefix,
modifiedtests/src/eth/collectionHelpersAbi.jsondiffbeforeafterboth
--- a/tests/src/eth/collectionHelpersAbi.json
+++ b/tests/src/eth/collectionHelpersAbi.json
@@ -32,7 +32,7 @@
       { "internalType": "string", "name": "tokenPrefix", "type": "string" },
       { "internalType": "string", "name": "baseUri", "type": "string" }
     ],
-    "name": "createERC721MetadataNFTCollection",
+    "name": "createERC721MetadataCompatibleNFTCollection",
     "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
     "stateMutability": "payable",
     "type": "function"
@@ -44,7 +44,7 @@
       { "internalType": "string", "name": "tokenPrefix", "type": "string" },
       { "internalType": "string", "name": "baseUri", "type": "string" }
     ],
-    "name": "createERC721MetadataRFTCollection",
+    "name": "createERC721MetadataCompatibleRFTCollection",
     "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
     "stateMutability": "payable",
     "type": "function"
modifiedtests/src/eth/collectionProperties.test.tsdiffbeforeafterboth
--- a/tests/src/eth/collectionProperties.test.ts
+++ b/tests/src/eth/collectionProperties.test.ts
@@ -14,7 +14,7 @@
 
   itEth('Can be set', async({helper}) => {
     const caller = await helper.eth.createAccountWithBalance(donor);
-    const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test'});
+    const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: []});
     await collection.addAdmin(alice, {Ethereum: caller});
 
     const address = helper.ethAddress.fromCollectionId(collection.collectionId);
@@ -24,7 +24,7 @@
 
     const raw = (await collection.getData())?.raw;
 
-    expect(raw.properties[1].value).to.equal('testValue');
+    expect(raw.properties[0].value).to.equal('testValue');
   });
 
   itEth('Can be deleted', async({helper}) => {
modifiedtests/src/eth/collectionSponsoring.test.tsdiffbeforeafterboth
--- a/tests/src/eth/collectionSponsoring.test.ts
+++ b/tests/src/eth/collectionSponsoring.test.ts
@@ -97,7 +97,7 @@
     const owner = await helper.eth.createAccountWithBalance(donor);
     const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
 
-    let result = await collectionHelpers.methods.createERC721MetadataNFTCollection('Sponsor collection', '1', '1', '').send({value: Number(2n * nominal)});
+    let result = await collectionHelpers.methods.createERC721MetadataCompatibleNFTCollection('Sponsor collection', '1', '1', '').send({value: Number(2n * nominal)});
     const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
     const collectionId = helper.ethAddress.extractCollectionId(collectionIdAddress);
     const collection = helper.nft.getCollectionObject(collectionId);
@@ -167,7 +167,7 @@
   // itWeb3('Sponsoring collection from substrate address via access list', async ({api, web3, privateKeyWrapper}) => {
   //   const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
   //   const collectionHelpers = evmCollectionHelpers(web3, owner);
-  //   const result = await collectionHelpers.methods.createERC721MetadataNFTCollection('Sponsor collection', '1', '1', '').send();
+  //   const result = await collectionHelpers.methods.createERC721MetadataCompatibleNFTCollection('Sponsor collection', '1', '1', '').send();
   //   const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
   //   const sponsor = privateKeyWrapper('//Alice');
   //   const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
@@ -223,7 +223,7 @@
     const owner = await helper.eth.createAccountWithBalance(donor);
     const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
 
-    let result = await collectionHelpers.methods.createERC721MetadataNFTCollection('Sponsor collection', '1', '1', '').send({value: Number(2n * nominal)});
+    let result = await collectionHelpers.methods.createERC721MetadataCompatibleNFTCollection('Sponsor collection', '1', '1', '').send({value: Number(2n * nominal)});
     const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
     const collectionId = helper.ethAddress.extractCollectionId(collectionIdAddress);
     const collection = helper.nft.getCollectionObject(collectionId);
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -83,14 +83,12 @@
     const owner = await helper.eth.createAccountWithBalance(donor);
     const receiver = helper.eth.createAccount();
 
-    const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
-    let result = await collectionHelper.methods.createERC721MetadataNFTCollection('Mint collection', 'a', 'b', tokenPrefix).send({value: Number(2n * helper.balance.getOneTokenNominal())});
-    const collectionAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
+    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', 'a', 'b', tokenPrefix);
     const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
     
     const nextTokenId = await contract.methods.nextTokenId().call();
     expect(nextTokenId).to.be.equal('1');
-    result = await contract.methods.mint(
+    const result = await contract.methods.mint(
       receiver,
       nextTokenId,
     ).send();
@@ -115,7 +113,7 @@
   });
 
   itEth('TokenURI from url', async ({helper}) => {
-    const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'url', 'Token URI');
+    const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URI', 'Token URI');
     expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');
   });
 
@@ -126,7 +124,7 @@
 
   itEth('TokenURI from baseURI + suffix', async ({helper}) => {
     const suffix = '/some/suffix';
-    const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'suffix', suffix);
+    const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URISuffix', suffix);
     expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);
   });
 });
@@ -146,7 +144,7 @@
     const owner = await helper.eth.createAccountWithBalance(donor);
     const receiver = helper.eth.createAccount();
 
-    const {collectionAddress} = await helper.eth.createERC721MetadataNFTCollection(owner, 'Mint collection', '6', '6', '');
+    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', '6', '6', '');
     const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
     const nextTokenId = await contract.methods.nextTokenId().call();
 
modifiedtests/src/eth/proxy/nonFungibleProxy.test.tsdiffbeforeafterboth
before · tests/src/eth/proxy/nonFungibleProxy.test.ts
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 {readFile} from 'fs/promises';18import {IKeyringPair} from '@polkadot/types/types';19import {EthUniqueHelper, itEth, usingEthPlaygrounds, expect} from '../util/playgrounds';202122async function proxyWrap(helper: EthUniqueHelper, wrapped: any, donor: IKeyringPair) {23  // Proxy owner has no special privilegies, we don't need to reuse them24  const owner = await helper.eth.createAccountWithBalance(donor);25  const web3 = helper.getWeb3();26  const proxyContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueNFTProxy.abi`)).toString()), undefined, {27    from: owner,28    gas: helper.eth.DEFAULT_GAS,29  });30  const proxy = await proxyContract.deploy({data: (await readFile(`${__dirname}/UniqueNFTProxy.bin`)).toString(), arguments: [wrapped.options.address]}).send({from: owner});31  return proxy;32}3334describe('NFT (Via EVM proxy): Information getting', () => {35  let alice: IKeyringPair;36  let donor: IKeyringPair;3738  before(async function() {39    await usingEthPlaygrounds(async (helper, privateKey) => {40      donor = privateKey('//Alice');41      [alice] = await helper.arrange.createAccounts([10n], donor);42    });43  });4445  itEth('totalSupply', async ({helper}) => {46    const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});47    const caller = await helper.eth.createAccountWithBalance(donor);48    await collection.mintToken(alice, {Substrate: alice.address});4950    const address = helper.ethAddress.fromCollectionId(collection.collectionId);51    const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);52    const contract = await proxyWrap(helper, evmCollection, donor);53    const totalSupply = await contract.methods.totalSupply().call();5455    expect(totalSupply).to.equal('1');56  });5758  itEth('balanceOf', async ({helper}) => {59    const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});6061    const caller = await helper.eth.createAccountWithBalance(donor);62    await collection.mintMultipleTokens(alice, [63      {owner: {Ethereum: caller}},64      {owner: {Ethereum: caller}},65      {owner: {Ethereum: caller}},66    ]);6768    const address = helper.ethAddress.fromCollectionId(collection.collectionId);69    const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);70    const contract = await proxyWrap(helper, evmCollection, donor);71    const balance = await contract.methods.balanceOf(caller).call();7273    expect(balance).to.equal('3');74  });7576  itEth('ownerOf', async ({helper}) => {77    const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});7879    const caller = await helper.eth.createAccountWithBalance(donor);80    const {tokenId} = await collection.mintToken(alice, {Ethereum: caller});8182    const address = helper.ethAddress.fromCollectionId(collection.collectionId);83    const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);84    const contract = await proxyWrap(helper, evmCollection, donor);85    const owner = await contract.methods.ownerOf(tokenId).call();8687    expect(owner).to.equal(caller);88  });89});9091describe('NFT (Via EVM proxy): Plain calls', () => {92  let alice: IKeyringPair;93  let donor: IKeyringPair;9495  before(async function() {96    await usingEthPlaygrounds(async (helper, privateKey) => {97      donor = privateKey('//Alice');98      [alice] = await helper.arrange.createAccounts([10n], donor);99    });100  });101102  itEth('Can perform mint()', async ({helper}) => {103    const owner = await helper.eth.createAccountWithBalance(donor);104    const {collectionAddress} = await helper.eth.createERC721MetadataNFTCollection(owner, 'A', 'A', 'A', '');105    const caller = await helper.eth.createAccountWithBalance(donor);106    const receiver = helper.eth.createAccount();107108    const collectionEvmOwned = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);109    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', caller);110    const contract = await proxyWrap(helper, collectionEvm, donor);111    await collectionEvmOwned.methods.addCollectionAdmin(contract.options.address).send();112113    {114      const nextTokenId = await contract.methods.nextTokenId().call();115      expect(nextTokenId).to.be.equal('1');116      const result = await contract.methods.mintWithTokenURI(117        receiver,118        nextTokenId,119        'Test URI',120      ).send({from: caller});121      const events = helper.eth.normalizeEvents(result.events);122      events[0].address = events[0].address.toLocaleLowerCase();123124      expect(events).to.be.deep.equal([125        {126          address: collectionAddress.toLocaleLowerCase(),127          event: 'Transfer',128          args: {129            from: '0x0000000000000000000000000000000000000000',130            to: receiver,131            tokenId: nextTokenId,132          },133        },134      ]);135136      expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');137    }138  });139140  //TODO: CORE-302 add eth methods141  itEth.skip('Can perform mintBulk()', async ({helper}) => {142    const collection = await helper.nft.mintCollection(donor, {name: 'New', description: 'New collection', tokenPrefix: 'NEW'});143144    const caller = await helper.eth.createAccountWithBalance(donor, 30n);145    const receiver = helper.eth.createAccount();146147    const address = helper.ethAddress.fromCollectionId(collection.collectionId);148    const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);149    const contract = await proxyWrap(helper, evmCollection, donor);150    await collection.addAdmin(donor, {Ethereum: contract.options.address});151152    {153      const nextTokenId = await contract.methods.nextTokenId().call();154      expect(nextTokenId).to.be.equal('1');155      const result = await contract.methods.mintBulkWithTokenURI(156        receiver,157        [158          [nextTokenId, 'Test URI 0'],159          [+nextTokenId + 1, 'Test URI 1'],160          [+nextTokenId + 2, 'Test URI 2'],161        ],162      ).send({from: caller});163      const events = helper.eth.normalizeEvents(result.events);164165      expect(events).to.be.deep.equal([166        {167          address,168          event: 'Transfer',169          args: {170            from: '0x0000000000000000000000000000000000000000',171            to: receiver,172            tokenId: nextTokenId,173          },174        },175        {176          address,177          event: 'Transfer',178          args: {179            from: '0x0000000000000000000000000000000000000000',180            to: receiver,181            tokenId: String(+nextTokenId + 1),182          },183        },184        {185          address,186          event: 'Transfer',187          args: {188            from: '0x0000000000000000000000000000000000000000',189            to: receiver,190            tokenId: String(+nextTokenId + 2),191          },192        },193      ]);194195      expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');196      expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');197      expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');198    }199  });200201  itEth('Can perform burn()', async ({helper}) => {202    const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});203    const caller = await helper.eth.createAccountWithBalance(donor);204205    const address = helper.ethAddress.fromCollectionId(collection.collectionId);206    const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);207    const contract = await proxyWrap(helper, evmCollection, donor);208    const {tokenId} = await collection.mintToken(alice, {Ethereum: contract.options.address});209    await collection.addAdmin(alice, {Ethereum: contract.options.address});210211    {212      const result = await contract.methods.burn(tokenId).send({from: caller});213      const events = helper.eth.normalizeEvents(result.events);214215      expect(events).to.be.deep.equal([216        {217          address,218          event: 'Transfer',219          args: {220            from: contract.options.address,221            to: '0x0000000000000000000000000000000000000000',222            tokenId: tokenId.toString(),223          },224        },225      ]);226    }227  });228229  itEth('Can perform approve()', async ({helper}) => {230    const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});231    const caller = await helper.eth.createAccountWithBalance(donor);232    const spender = helper.eth.createAccount();233234    const address = helper.ethAddress.fromCollectionId(collection.collectionId);235    const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);236    const contract = await proxyWrap(helper, evmCollection, donor);237    const {tokenId} = await collection.mintToken(alice, {Ethereum: contract.options.address});238239    {240      const result = await contract.methods.approve(spender, tokenId).send({from: caller, gas: helper.eth.DEFAULT_GAS});241      const events = helper.eth.normalizeEvents(result.events);242243      expect(events).to.be.deep.equal([244        {245          address,246          event: 'Approval',247          args: {248            owner: contract.options.address,249            approved: spender,250            tokenId: tokenId.toString(),251          },252        },253      ]);254    }255  });256257  itEth('Can perform transferFrom()', async ({helper}) => {258    const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});259    const caller = await helper.eth.createAccountWithBalance(donor);260    const owner = await helper.eth.createAccountWithBalance(donor);261262    const receiver = helper.eth.createAccount();263264    const address = helper.ethAddress.fromCollectionId(collection.collectionId);265    const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);266    const contract = await proxyWrap(helper, evmCollection, donor);267    const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});268269    await evmCollection.methods.approve(contract.options.address, tokenId).send({from: owner});270271    {272      const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({from: caller});273      const events = helper.eth.normalizeEvents(result.events);274      expect(events).to.be.deep.equal([275        {276          address,277          event: 'Transfer',278          args: {279            from: owner,280            to: receiver,281            tokenId: tokenId.toString(),282          },283        },284      ]);285    }286287    {288      const balance = await contract.methods.balanceOf(receiver).call();289      expect(+balance).to.equal(1);290    }291292    {293      const balance = await contract.methods.balanceOf(contract.options.address).call();294      expect(+balance).to.equal(0);295    }296  });297298  itEth('Can perform transfer()', async ({helper}) => {299    const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});300    const caller = await helper.eth.createAccountWithBalance(donor);301    const receiver = helper.eth.createAccount();302303    const address = helper.ethAddress.fromCollectionId(collection.collectionId);304    const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);305    const contract = await proxyWrap(helper, evmCollection, donor);306    const {tokenId} = await collection.mintToken(alice, {Ethereum: contract.options.address});307308    {309      const result = await contract.methods.transfer(receiver, tokenId).send({from: caller});310      const events = helper.eth.normalizeEvents(result.events);311      expect(events).to.be.deep.equal([312        {313          address,314          event: 'Transfer',315          args: {316            from: contract.options.address,317            to: receiver,318            tokenId: tokenId.toString(),319          },320        },321      ]);322    }323324    {325      const balance = await contract.methods.balanceOf(contract.options.address).call();326      expect(+balance).to.equal(0);327    }328329    {330      const balance = await contract.methods.balanceOf(receiver).call();331      expect(+balance).to.equal(1);332    }333  });334});
after · tests/src/eth/proxy/nonFungibleProxy.test.ts
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 {readFile} from 'fs/promises';18import {IKeyringPair} from '@polkadot/types/types';19import {EthUniqueHelper, itEth, usingEthPlaygrounds, expect} from '../util/playgrounds';202122async function proxyWrap(helper: EthUniqueHelper, wrapped: any, donor: IKeyringPair) {23  // Proxy owner has no special privilegies, we don't need to reuse them24  const owner = await helper.eth.createAccountWithBalance(donor);25  const web3 = helper.getWeb3();26  const proxyContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueNFTProxy.abi`)).toString()), undefined, {27    from: owner,28    gas: helper.eth.DEFAULT_GAS,29  });30  const proxy = await proxyContract.deploy({data: (await readFile(`${__dirname}/UniqueNFTProxy.bin`)).toString(), arguments: [wrapped.options.address]}).send({from: owner});31  return proxy;32}3334describe('NFT (Via EVM proxy): Information getting', () => {35  let alice: IKeyringPair;36  let donor: IKeyringPair;3738  before(async function() {39    await usingEthPlaygrounds(async (helper, privateKey) => {40      donor = privateKey('//Alice');41      [alice] = await helper.arrange.createAccounts([10n], donor);42    });43  });4445  itEth('totalSupply', async ({helper}) => {46    const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});47    const caller = await helper.eth.createAccountWithBalance(donor);48    await collection.mintToken(alice, {Substrate: alice.address});4950    const address = helper.ethAddress.fromCollectionId(collection.collectionId);51    const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);52    const contract = await proxyWrap(helper, evmCollection, donor);53    const totalSupply = await contract.methods.totalSupply().call();5455    expect(totalSupply).to.equal('1');56  });5758  itEth('balanceOf', async ({helper}) => {59    const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});6061    const caller = await helper.eth.createAccountWithBalance(donor);62    await collection.mintMultipleTokens(alice, [63      {owner: {Ethereum: caller}},64      {owner: {Ethereum: caller}},65      {owner: {Ethereum: caller}},66    ]);6768    const address = helper.ethAddress.fromCollectionId(collection.collectionId);69    const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);70    const contract = await proxyWrap(helper, evmCollection, donor);71    const balance = await contract.methods.balanceOf(caller).call();7273    expect(balance).to.equal('3');74  });7576  itEth('ownerOf', async ({helper}) => {77    const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});7879    const caller = await helper.eth.createAccountWithBalance(donor);80    const {tokenId} = await collection.mintToken(alice, {Ethereum: caller});8182    const address = helper.ethAddress.fromCollectionId(collection.collectionId);83    const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);84    const contract = await proxyWrap(helper, evmCollection, donor);85    const owner = await contract.methods.ownerOf(tokenId).call();8687    expect(owner).to.equal(caller);88  });89});9091describe('NFT (Via EVM proxy): Plain calls', () => {92  let alice: IKeyringPair;93  let donor: IKeyringPair;9495  before(async function() {96    await usingEthPlaygrounds(async (helper, privateKey) => {97      donor = privateKey('//Alice');98      [alice] = await helper.arrange.createAccounts([10n], donor);99    });100  });101102  itEth('Can perform mint()', async ({helper}) => {103    const owner = await helper.eth.createAccountWithBalance(donor);104    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'A', 'A', 'A', '');105    const caller = await helper.eth.createAccountWithBalance(donor);106    const receiver = helper.eth.createAccount();107108    const collectionEvmOwned = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);109    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', caller);110    const contract = await proxyWrap(helper, collectionEvm, donor);111    await collectionEvmOwned.methods.addCollectionAdmin(contract.options.address).send();112113    {114      const nextTokenId = await contract.methods.nextTokenId().call();115      expect(nextTokenId).to.be.equal('1');116      const result = await contract.methods.mintWithTokenURI(117        receiver,118        nextTokenId,119        'Test URI',120      ).send({from: caller});121      const events = helper.eth.normalizeEvents(result.events);122      events[0].address = events[0].address.toLocaleLowerCase();123124      expect(events).to.be.deep.equal([125        {126          address: collectionAddress.toLocaleLowerCase(),127          event: 'Transfer',128          args: {129            from: '0x0000000000000000000000000000000000000000',130            to: receiver,131            tokenId: nextTokenId,132          },133        },134      ]);135136      expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');137    }138  });139140  //TODO: CORE-302 add eth methods141  itEth.skip('Can perform mintBulk()', async ({helper}) => {142    const collection = await helper.nft.mintCollection(donor, {name: 'New', description: 'New collection', tokenPrefix: 'NEW'});143144    const caller = await helper.eth.createAccountWithBalance(donor, 30n);145    const receiver = helper.eth.createAccount();146147    const address = helper.ethAddress.fromCollectionId(collection.collectionId);148    const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);149    const contract = await proxyWrap(helper, evmCollection, donor);150    await collection.addAdmin(donor, {Ethereum: contract.options.address});151152    {153      const nextTokenId = await contract.methods.nextTokenId().call();154      expect(nextTokenId).to.be.equal('1');155      const result = await contract.methods.mintBulkWithTokenURI(156        receiver,157        [158          [nextTokenId, 'Test URI 0'],159          [+nextTokenId + 1, 'Test URI 1'],160          [+nextTokenId + 2, 'Test URI 2'],161        ],162      ).send({from: caller});163      const events = helper.eth.normalizeEvents(result.events);164165      expect(events).to.be.deep.equal([166        {167          address,168          event: 'Transfer',169          args: {170            from: '0x0000000000000000000000000000000000000000',171            to: receiver,172            tokenId: nextTokenId,173          },174        },175        {176          address,177          event: 'Transfer',178          args: {179            from: '0x0000000000000000000000000000000000000000',180            to: receiver,181            tokenId: String(+nextTokenId + 1),182          },183        },184        {185          address,186          event: 'Transfer',187          args: {188            from: '0x0000000000000000000000000000000000000000',189            to: receiver,190            tokenId: String(+nextTokenId + 2),191          },192        },193      ]);194195      expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');196      expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');197      expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');198    }199  });200201  itEth('Can perform burn()', async ({helper}) => {202    const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});203    const caller = await helper.eth.createAccountWithBalance(donor);204205    const address = helper.ethAddress.fromCollectionId(collection.collectionId);206    const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);207    const contract = await proxyWrap(helper, evmCollection, donor);208    const {tokenId} = await collection.mintToken(alice, {Ethereum: contract.options.address});209    await collection.addAdmin(alice, {Ethereum: contract.options.address});210211    {212      const result = await contract.methods.burn(tokenId).send({from: caller});213      const events = helper.eth.normalizeEvents(result.events);214215      expect(events).to.be.deep.equal([216        {217          address,218          event: 'Transfer',219          args: {220            from: contract.options.address,221            to: '0x0000000000000000000000000000000000000000',222            tokenId: tokenId.toString(),223          },224        },225      ]);226    }227  });228229  itEth('Can perform approve()', async ({helper}) => {230    const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});231    const caller = await helper.eth.createAccountWithBalance(donor);232    const spender = helper.eth.createAccount();233234    const address = helper.ethAddress.fromCollectionId(collection.collectionId);235    const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);236    const contract = await proxyWrap(helper, evmCollection, donor);237    const {tokenId} = await collection.mintToken(alice, {Ethereum: contract.options.address});238239    {240      const result = await contract.methods.approve(spender, tokenId).send({from: caller, gas: helper.eth.DEFAULT_GAS});241      const events = helper.eth.normalizeEvents(result.events);242243      expect(events).to.be.deep.equal([244        {245          address,246          event: 'Approval',247          args: {248            owner: contract.options.address,249            approved: spender,250            tokenId: tokenId.toString(),251          },252        },253      ]);254    }255  });256257  itEth('Can perform transferFrom()', async ({helper}) => {258    const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});259    const caller = await helper.eth.createAccountWithBalance(donor);260    const owner = await helper.eth.createAccountWithBalance(donor);261262    const receiver = helper.eth.createAccount();263264    const address = helper.ethAddress.fromCollectionId(collection.collectionId);265    const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);266    const contract = await proxyWrap(helper, evmCollection, donor);267    const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});268269    await evmCollection.methods.approve(contract.options.address, tokenId).send({from: owner});270271    {272      const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({from: caller});273      const events = helper.eth.normalizeEvents(result.events);274      expect(events).to.be.deep.equal([275        {276          address,277          event: 'Transfer',278          args: {279            from: owner,280            to: receiver,281            tokenId: tokenId.toString(),282          },283        },284      ]);285    }286287    {288      const balance = await contract.methods.balanceOf(receiver).call();289      expect(+balance).to.equal(1);290    }291292    {293      const balance = await contract.methods.balanceOf(contract.options.address).call();294      expect(+balance).to.equal(0);295    }296  });297298  itEth('Can perform transfer()', async ({helper}) => {299    const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});300    const caller = await helper.eth.createAccountWithBalance(donor);301    const receiver = helper.eth.createAccount();302303    const address = helper.ethAddress.fromCollectionId(collection.collectionId);304    const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);305    const contract = await proxyWrap(helper, evmCollection, donor);306    const {tokenId} = await collection.mintToken(alice, {Ethereum: contract.options.address});307308    {309      const result = await contract.methods.transfer(receiver, tokenId).send({from: caller});310      const events = helper.eth.normalizeEvents(result.events);311      expect(events).to.be.deep.equal([312        {313          address,314          event: 'Transfer',315          args: {316            from: contract.options.address,317            to: receiver,318            tokenId: tokenId.toString(),319          },320        },321      ]);322    }323324    {325      const balance = await contract.methods.balanceOf(contract.options.address).call();326      expect(+balance).to.equal(0);327    }328329    {330      const balance = await contract.methods.balanceOf(receiver).call();331      expect(+balance).to.equal(1);332    }333  });334});
modifiedtests/src/eth/reFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -124,7 +124,7 @@
   itEth('Can perform mint()', async ({helper}) => {
     const owner = await helper.eth.createAccountWithBalance(donor);
     const receiver = helper.eth.createAccount();
-    const {collectionAddress} = await helper.eth.createERC721MetadataRFTCollection(owner, 'Minty', '6', '6', '');
+    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'Minty', '6', '6', '');
     const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
     
     const nextTokenId = await contract.methods.nextTokenId().call();
@@ -147,7 +147,7 @@
   itEth('Can perform mintBulk()', async ({helper}) => {
     const owner = await helper.eth.createAccountWithBalance(donor);
     const receiver = helper.eth.createAccount();
-    const {collectionAddress} = await helper.eth.createERC721MetadataRFTCollection(owner, 'MintBulky', '6', '6', '');
+    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'MintBulky', '6', '6', '');
     const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
 
     {
modifiedtests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth
--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -80,14 +80,12 @@
     const owner = await helper.eth.createAccountWithBalance(donor);
     const receiver = helper.eth.createAccount();
 
-    const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
-    let result = await collectionHelper.methods.createERC721MetadataNFTCollection('Mint collection', 'a', 'b', tokenPrefix).send({value: Number(2n * helper.balance.getOneTokenNominal())});
-    const collectionAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
+    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'Mint collection', 'a', 'b', tokenPrefix);
     const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
     
     const nextTokenId = await contract.methods.nextTokenId().call();
     expect(nextTokenId).to.be.equal('1');
-    result = await contract.methods.mint(
+    const result = await contract.methods.mint(
       receiver,
       nextTokenId,
     ).send();
@@ -112,7 +110,7 @@
   });
 
   itEth('TokenURI from url', async ({helper}) => {
-    const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'url', 'Token URI');
+    const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URI', 'Token URI');
     expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');
   });
 
@@ -123,7 +121,7 @@
 
   itEth('TokenURI from baseURI + suffix', async ({helper}) => {
     const suffix = '/some/suffix';
-    const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'suffix', suffix);
+    const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URISuffix', suffix);
     expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);
   });
 });
modifiedtests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth
--- a/tests/src/eth/util/playgrounds/unique.dev.ts
+++ b/tests/src/eth/util/playgrounds/unique.dev.ts
@@ -186,11 +186,11 @@
     return {collectionId, collectionAddress};
   }
 
-  async createERC721MetadataNFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string}> {
+  async createERC721MetadataCompatibleNFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string}> {
     const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();
     const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);
         
-    const result = await collectionHelper.methods.createERC721MetadataNFTCollection(name, description, tokenPrefix, baseUri).send({value: Number(collectionCreationPrice)});
+    const result = await collectionHelper.methods.createERC721MetadataCompatibleNFTCollection(name, description, tokenPrefix, baseUri).send({value: Number(collectionCreationPrice)});
 
     const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
     const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);
@@ -210,11 +210,11 @@
     return {collectionId, collectionAddress};
   }
 
-  async createERC721MetadataRFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string}> {
+  async createERC721MetadataCompatibleRFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string}> {
     const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();
     const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);
         
-    const result = await collectionHelper.methods.createERC721MetadataRFTCollection(name, description, tokenPrefix, baseUri).send({value: Number(collectionCreationPrice)});
+    const result = await collectionHelper.methods.createERC721MetadataCompatibleRFTCollection(name, description, tokenPrefix, baseUri).send({value: Number(collectionCreationPrice)});
 
     const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
     const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);