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
before · tests/src/eth/collectionSponsoring.test.ts
1import {IKeyringPair} from '@polkadot/types/types';2import {usingPlaygrounds} from './../util/playgrounds/index';3import {itEth, expect} from '../eth/util/playgrounds';45describe('evm collection sponsoring', () => {6  let donor: IKeyringPair;7  let alice: IKeyringPair;8  let nominal: bigint;910  before(async () => {11    await usingPlaygrounds(async (helper, privateKey) => {12      donor = privateKey('//Alice');13      nominal = helper.balance.getOneTokenNominal();14    });15  });1617  beforeEach(async () => {18    await usingPlaygrounds(async (helper) => {19      [alice] = await helper.arrange.createAccounts([1000n], donor);20    });21  });2223  itEth('sponsors mint transactions', async ({helper}) => {24    const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'spnr', permissions: {mintMode: true}});25    await collection.setSponsor(alice, alice.address);26    await collection.confirmSponsorship(alice);2728    const minter = helper.eth.createAccount();29    expect(await helper.balance.getEthereum(minter)).to.equal(0n);3031    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);32    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', minter);3334    await collection.addToAllowList(alice, {Ethereum: minter});3536    const nextTokenId = await contract.methods.nextTokenId().call();37    expect(nextTokenId).to.equal('1');38    const result = await contract.methods.mint(minter, nextTokenId).send();39    const events = helper.eth.normalizeEvents(result.events);40    expect(events).to.be.deep.equal([41      {42        address: collectionAddress,43        event: 'Transfer',44        args: {45          from: '0x0000000000000000000000000000000000000000',46          to: minter,47          tokenId: nextTokenId,48        },49      },50    ]);51  });5253  // TODO: Temprorary off. Need refactor54  // itWeb3('Set substrate sponsor', async ({api, web3, privateKeyWrapper}) => {55  //   const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);56  //   const collectionHelpers = evmCollectionHelpers(web3, owner);57  //   let result = await collectionHelpers.methods.createNFTCollection('Sponsor collection', '1', '1').send();58  //   const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);59  //   const sponsor = privateKeyWrapper('//Alice');60  //   const collectionEvm = evmCollection(web3, owner, collectionIdAddress);6162  //   expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;63  //   result = await collectionEvm.methods.setCollectionSponsorSubstrate(sponsor.addressRaw).send({from: owner});64  //   expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.true;65    66  //   const confirmTx = await api.tx.unique.confirmSponsorship(collectionId);67  //   await submitTransactionAsync(sponsor, confirmTx);68  //   expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;69    70  //   const sponsorTuple = await collectionEvm.methods.collectionSponsor().call({from: owner});71  //   expect(bigIntToSub(api, BigInt(sponsorTuple[1]))).to.be.eq(sponsor.address);72  // });7374  itEth('Remove sponsor', async ({helper}) => {75    const owner = await helper.eth.createAccountWithBalance(donor);76    const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);7778    let result = await collectionHelpers.methods.createNFTCollection('Sponsor collection', '1', '1').send({value: Number(2n * nominal)});79    const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);80    const sponsor = await helper.eth.createAccountWithBalance(donor);81    const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner);8283    expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;84    result = await collectionEvm.methods.setCollectionSponsor(sponsor).send({from: owner});85    expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.true;86    87    await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});88    expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;89    90    await collectionEvm.methods.removeCollectionSponsor().send({from: owner});91    92    const sponsorTuple = await collectionEvm.methods.collectionSponsor().call({from: owner});93    expect(sponsorTuple.field_0).to.be.eq('0x0000000000000000000000000000000000000000');94  });9596  itEth('Sponsoring collection from evm address via access list', async ({helper}) => {97    const owner = await helper.eth.createAccountWithBalance(donor);98    const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);99100    let result = await collectionHelpers.methods.createERC721MetadataNFTCollection('Sponsor collection', '1', '1', '').send({value: Number(2n * nominal)});101    const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);102    const collectionId = helper.ethAddress.extractCollectionId(collectionIdAddress);103    const collection = helper.nft.getCollectionObject(collectionId);104    const sponsor = await helper.eth.createAccountWithBalance(donor);105    const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner);106107    result = await collectionEvm.methods.setCollectionSponsor(sponsor).send({from: owner});108    let collectionData = (await collection.getData())!;109    expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));110    await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');111112    await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});113    collectionData = (await collection.getData())!;114    expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));115116    const user = helper.eth.createAccount();117    const nextTokenId = await collectionEvm.methods.nextTokenId().call();118    expect(nextTokenId).to.be.equal('1');119120    const oldPermissions = (await collection.getData())!.raw.permissions; // (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();121    expect(oldPermissions.mintMode).to.be.false;122    expect(oldPermissions.access).to.be.equal('Normal');123124    await collectionEvm.methods.setCollectionAccess(1 /*'AllowList'*/).send({from: owner});125    await collectionEvm.methods.addToCollectionAllowList(user).send({from: owner});126    await collectionEvm.methods.setCollectionMintMode(true).send({from: owner});127128    const newPermissions = (await collection.getData())!.raw.permissions; // (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();129    expect(newPermissions.mintMode).to.be.true;130    expect(newPermissions.access).to.be.equal('AllowList');131132    const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));133    const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));134135    {136      const nextTokenId = await collectionEvm.methods.nextTokenId().call();137      expect(nextTokenId).to.be.equal('1');138      const result = await collectionEvm.methods.mintWithTokenURI(139        user,140        nextTokenId,141        'Test URI',142      ).send({from: user});143      const events = helper.eth.normalizeEvents(result.events);144145      expect(events).to.be.deep.equal([146        {147          address: collectionIdAddress,148          event: 'Transfer',149          args: {150            from: '0x0000000000000000000000000000000000000000',151            to: user,152            tokenId: nextTokenId,153          },154        },155      ]);156157      const ownerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(owner));158      const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));159160      expect(await collectionEvm.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');161      expect(ownerBalanceBefore).to.be.eq(ownerBalanceAfter);162      expect(sponsorBalanceBefore > sponsorBalanceAfter).to.be.true;163    }164  });165166  // TODO: Temprorary off. Need refactor167  // itWeb3('Sponsoring collection from substrate address via access list', async ({api, web3, privateKeyWrapper}) => {168  //   const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);169  //   const collectionHelpers = evmCollectionHelpers(web3, owner);170  //   const result = await collectionHelpers.methods.createERC721MetadataNFTCollection('Sponsor collection', '1', '1', '').send();171  //   const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);172  //   const sponsor = privateKeyWrapper('//Alice');173  //   const collectionEvm = evmCollection(web3, owner, collectionIdAddress);174175  //   await collectionEvm.methods.setCollectionSponsorSubstrate(sponsor.addressRaw).send({from: owner});176    177  //   const confirmTx = await api.tx.unique.confirmSponsorship(collectionId);178  //   await submitTransactionAsync(sponsor, confirmTx);179    180  //   const user = createEthAccount(web3);181  //   const nextTokenId = await collectionEvm.methods.nextTokenId().call();182  //   expect(nextTokenId).to.be.equal('1');183184  //   await collectionEvm.methods.setCollectionAccess(1 /*'AllowList'*/).send({from: owner});185  //   await collectionEvm.methods.addToCollectionAllowList(user).send({from: owner});186  //   await collectionEvm.methods.setCollectionMintMode(true).send({from: owner});187188  //   const ownerBalanceBefore = await ethBalanceViaSub(api, owner);189  //   const sponsorBalanceBefore = (await getBalance(api, [sponsor.address]))[0];190191  //   {192  //     const nextTokenId = await collectionEvm.methods.nextTokenId().call();193  //     expect(nextTokenId).to.be.equal('1');194  //     const result = await collectionEvm.methods.mintWithTokenURI(195  //       user,196  //       nextTokenId,197  //       'Test URI',198  //     ).send({from: user});199  //     const events = normalizeEvents(result.events);200201  //     expect(events).to.be.deep.equal([202  //       {203  //         address: collectionIdAddress,204  //         event: 'Transfer',205  //         args: {206  //           from: '0x0000000000000000000000000000000000000000',207  //           to: user,208  //           tokenId: nextTokenId,209  //         },210  //       },211  //     ]);212213  //     const ownerBalanceAfter = await ethBalanceViaSub(api, owner);214  //     const sponsorBalanceAfter = (await getBalance(api, [sponsor.address]))[0];215216  //     expect(await collectionEvm.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');217  //     expect(ownerBalanceBefore).to.be.eq(ownerBalanceAfter);218  //     expect(sponsorBalanceBefore > sponsorBalanceAfter).to.be.true;219  //   }220  // });221222  itEth('Check that transaction via EVM spend money from sponsor address', async ({helper}) => {223    const owner = await helper.eth.createAccountWithBalance(donor);224    const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);225226    let result = await collectionHelpers.methods.createERC721MetadataNFTCollection('Sponsor collection', '1', '1', '').send({value: Number(2n * nominal)});227    const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);228    const collectionId = helper.ethAddress.extractCollectionId(collectionIdAddress);229    const collection = helper.nft.getCollectionObject(collectionId);230    const sponsor = await helper.eth.createAccountWithBalance(donor);231    const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner);232233    result = await collectionEvm.methods.setCollectionSponsor(sponsor).send();234    let collectionData = (await collection.getData())!;235    expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));236    await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');237238    const sponsorCollection = helper.ethNativeContract.collection(collectionIdAddress, 'nft', sponsor);239    await sponsorCollection.methods.confirmCollectionSponsorship().send();240    collectionData = (await collection.getData())!;241    expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));242243    const user = helper.eth.createAccount();244    await collectionEvm.methods.addCollectionAdmin(user).send();245    246    const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));247    const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));248249    const userCollectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', user);250    const nextTokenId = await userCollectionEvm.methods.nextTokenId().call();251    expect(nextTokenId).to.be.equal('1');252    result = await userCollectionEvm.methods.mintWithTokenURI(253      user,254      nextTokenId,255      'Test URI',256    ).send();257258    const events = helper.eth.normalizeEvents(result.events);259    const address = helper.ethAddress.fromCollectionId(collectionId);260261    expect(events).to.be.deep.equal([262      {263        address,264        event: 'Transfer',265        args: {266          from: '0x0000000000000000000000000000000000000000',267          to: user,268          tokenId: nextTokenId,269        },270      },271    ]);272    expect(await userCollectionEvm.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');273  274    const ownerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));275    expect(ownerBalanceAfter).to.be.eq(ownerBalanceBefore);276    const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));277    expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;278  });279});
after · tests/src/eth/collectionSponsoring.test.ts
1import {IKeyringPair} from '@polkadot/types/types';2import {usingPlaygrounds} from './../util/playgrounds/index';3import {itEth, expect} from '../eth/util/playgrounds';45describe('evm collection sponsoring', () => {6  let donor: IKeyringPair;7  let alice: IKeyringPair;8  let nominal: bigint;910  before(async () => {11    await usingPlaygrounds(async (helper, privateKey) => {12      donor = privateKey('//Alice');13      nominal = helper.balance.getOneTokenNominal();14    });15  });1617  beforeEach(async () => {18    await usingPlaygrounds(async (helper) => {19      [alice] = await helper.arrange.createAccounts([1000n], donor);20    });21  });2223  itEth('sponsors mint transactions', async ({helper}) => {24    const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'spnr', permissions: {mintMode: true}});25    await collection.setSponsor(alice, alice.address);26    await collection.confirmSponsorship(alice);2728    const minter = helper.eth.createAccount();29    expect(await helper.balance.getEthereum(minter)).to.equal(0n);3031    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);32    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', minter);3334    await collection.addToAllowList(alice, {Ethereum: minter});3536    const nextTokenId = await contract.methods.nextTokenId().call();37    expect(nextTokenId).to.equal('1');38    const result = await contract.methods.mint(minter, nextTokenId).send();39    const events = helper.eth.normalizeEvents(result.events);40    expect(events).to.be.deep.equal([41      {42        address: collectionAddress,43        event: 'Transfer',44        args: {45          from: '0x0000000000000000000000000000000000000000',46          to: minter,47          tokenId: nextTokenId,48        },49      },50    ]);51  });5253  // TODO: Temprorary off. Need refactor54  // itWeb3('Set substrate sponsor', async ({api, web3, privateKeyWrapper}) => {55  //   const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);56  //   const collectionHelpers = evmCollectionHelpers(web3, owner);57  //   let result = await collectionHelpers.methods.createNFTCollection('Sponsor collection', '1', '1').send();58  //   const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);59  //   const sponsor = privateKeyWrapper('//Alice');60  //   const collectionEvm = evmCollection(web3, owner, collectionIdAddress);6162  //   expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;63  //   result = await collectionEvm.methods.setCollectionSponsorSubstrate(sponsor.addressRaw).send({from: owner});64  //   expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.true;65    66  //   const confirmTx = await api.tx.unique.confirmSponsorship(collectionId);67  //   await submitTransactionAsync(sponsor, confirmTx);68  //   expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;69    70  //   const sponsorTuple = await collectionEvm.methods.collectionSponsor().call({from: owner});71  //   expect(bigIntToSub(api, BigInt(sponsorTuple[1]))).to.be.eq(sponsor.address);72  // });7374  itEth('Remove sponsor', async ({helper}) => {75    const owner = await helper.eth.createAccountWithBalance(donor);76    const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);7778    let result = await collectionHelpers.methods.createNFTCollection('Sponsor collection', '1', '1').send({value: Number(2n * nominal)});79    const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);80    const sponsor = await helper.eth.createAccountWithBalance(donor);81    const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner);8283    expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;84    result = await collectionEvm.methods.setCollectionSponsor(sponsor).send({from: owner});85    expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.true;86    87    await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});88    expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;89    90    await collectionEvm.methods.removeCollectionSponsor().send({from: owner});91    92    const sponsorTuple = await collectionEvm.methods.collectionSponsor().call({from: owner});93    expect(sponsorTuple.field_0).to.be.eq('0x0000000000000000000000000000000000000000');94  });9596  itEth('Sponsoring collection from evm address via access list', async ({helper}) => {97    const owner = await helper.eth.createAccountWithBalance(donor);98    const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);99100    let result = await collectionHelpers.methods.createERC721MetadataCompatibleNFTCollection('Sponsor collection', '1', '1', '').send({value: Number(2n * nominal)});101    const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);102    const collectionId = helper.ethAddress.extractCollectionId(collectionIdAddress);103    const collection = helper.nft.getCollectionObject(collectionId);104    const sponsor = await helper.eth.createAccountWithBalance(donor);105    const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner);106107    result = await collectionEvm.methods.setCollectionSponsor(sponsor).send({from: owner});108    let collectionData = (await collection.getData())!;109    expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));110    await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');111112    await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});113    collectionData = (await collection.getData())!;114    expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));115116    const user = helper.eth.createAccount();117    const nextTokenId = await collectionEvm.methods.nextTokenId().call();118    expect(nextTokenId).to.be.equal('1');119120    const oldPermissions = (await collection.getData())!.raw.permissions; // (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();121    expect(oldPermissions.mintMode).to.be.false;122    expect(oldPermissions.access).to.be.equal('Normal');123124    await collectionEvm.methods.setCollectionAccess(1 /*'AllowList'*/).send({from: owner});125    await collectionEvm.methods.addToCollectionAllowList(user).send({from: owner});126    await collectionEvm.methods.setCollectionMintMode(true).send({from: owner});127128    const newPermissions = (await collection.getData())!.raw.permissions; // (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();129    expect(newPermissions.mintMode).to.be.true;130    expect(newPermissions.access).to.be.equal('AllowList');131132    const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));133    const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));134135    {136      const nextTokenId = await collectionEvm.methods.nextTokenId().call();137      expect(nextTokenId).to.be.equal('1');138      const result = await collectionEvm.methods.mintWithTokenURI(139        user,140        nextTokenId,141        'Test URI',142      ).send({from: user});143      const events = helper.eth.normalizeEvents(result.events);144145      expect(events).to.be.deep.equal([146        {147          address: collectionIdAddress,148          event: 'Transfer',149          args: {150            from: '0x0000000000000000000000000000000000000000',151            to: user,152            tokenId: nextTokenId,153          },154        },155      ]);156157      const ownerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(owner));158      const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));159160      expect(await collectionEvm.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');161      expect(ownerBalanceBefore).to.be.eq(ownerBalanceAfter);162      expect(sponsorBalanceBefore > sponsorBalanceAfter).to.be.true;163    }164  });165166  // TODO: Temprorary off. Need refactor167  // itWeb3('Sponsoring collection from substrate address via access list', async ({api, web3, privateKeyWrapper}) => {168  //   const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);169  //   const collectionHelpers = evmCollectionHelpers(web3, owner);170  //   const result = await collectionHelpers.methods.createERC721MetadataCompatibleNFTCollection('Sponsor collection', '1', '1', '').send();171  //   const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);172  //   const sponsor = privateKeyWrapper('//Alice');173  //   const collectionEvm = evmCollection(web3, owner, collectionIdAddress);174175  //   await collectionEvm.methods.setCollectionSponsorSubstrate(sponsor.addressRaw).send({from: owner});176    177  //   const confirmTx = await api.tx.unique.confirmSponsorship(collectionId);178  //   await submitTransactionAsync(sponsor, confirmTx);179    180  //   const user = createEthAccount(web3);181  //   const nextTokenId = await collectionEvm.methods.nextTokenId().call();182  //   expect(nextTokenId).to.be.equal('1');183184  //   await collectionEvm.methods.setCollectionAccess(1 /*'AllowList'*/).send({from: owner});185  //   await collectionEvm.methods.addToCollectionAllowList(user).send({from: owner});186  //   await collectionEvm.methods.setCollectionMintMode(true).send({from: owner});187188  //   const ownerBalanceBefore = await ethBalanceViaSub(api, owner);189  //   const sponsorBalanceBefore = (await getBalance(api, [sponsor.address]))[0];190191  //   {192  //     const nextTokenId = await collectionEvm.methods.nextTokenId().call();193  //     expect(nextTokenId).to.be.equal('1');194  //     const result = await collectionEvm.methods.mintWithTokenURI(195  //       user,196  //       nextTokenId,197  //       'Test URI',198  //     ).send({from: user});199  //     const events = normalizeEvents(result.events);200201  //     expect(events).to.be.deep.equal([202  //       {203  //         address: collectionIdAddress,204  //         event: 'Transfer',205  //         args: {206  //           from: '0x0000000000000000000000000000000000000000',207  //           to: user,208  //           tokenId: nextTokenId,209  //         },210  //       },211  //     ]);212213  //     const ownerBalanceAfter = await ethBalanceViaSub(api, owner);214  //     const sponsorBalanceAfter = (await getBalance(api, [sponsor.address]))[0];215216  //     expect(await collectionEvm.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');217  //     expect(ownerBalanceBefore).to.be.eq(ownerBalanceAfter);218  //     expect(sponsorBalanceBefore > sponsorBalanceAfter).to.be.true;219  //   }220  // });221222  itEth('Check that transaction via EVM spend money from sponsor address', async ({helper}) => {223    const owner = await helper.eth.createAccountWithBalance(donor);224    const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);225226    let result = await collectionHelpers.methods.createERC721MetadataCompatibleNFTCollection('Sponsor collection', '1', '1', '').send({value: Number(2n * nominal)});227    const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);228    const collectionId = helper.ethAddress.extractCollectionId(collectionIdAddress);229    const collection = helper.nft.getCollectionObject(collectionId);230    const sponsor = await helper.eth.createAccountWithBalance(donor);231    const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner);232233    result = await collectionEvm.methods.setCollectionSponsor(sponsor).send();234    let collectionData = (await collection.getData())!;235    expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));236    await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');237238    const sponsorCollection = helper.ethNativeContract.collection(collectionIdAddress, 'nft', sponsor);239    await sponsorCollection.methods.confirmCollectionSponsorship().send();240    collectionData = (await collection.getData())!;241    expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));242243    const user = helper.eth.createAccount();244    await collectionEvm.methods.addCollectionAdmin(user).send();245    246    const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));247    const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));248249    const userCollectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', user);250    const nextTokenId = await userCollectionEvm.methods.nextTokenId().call();251    expect(nextTokenId).to.be.equal('1');252    result = await userCollectionEvm.methods.mintWithTokenURI(253      user,254      nextTokenId,255      'Test URI',256    ).send();257258    const events = helper.eth.normalizeEvents(result.events);259    const address = helper.ethAddress.fromCollectionId(collectionId);260261    expect(events).to.be.deep.equal([262      {263        address,264        event: 'Transfer',265        args: {266          from: '0x0000000000000000000000000000000000000000',267          to: user,268          tokenId: nextTokenId,269        },270      },271    ]);272    expect(await userCollectionEvm.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');273  274    const ownerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));275    expect(ownerBalanceAfter).to.be.eq(ownerBalanceBefore);276    const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));277    expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;278  });279});
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
--- a/tests/src/eth/proxy/nonFungibleProxy.test.ts
+++ b/tests/src/eth/proxy/nonFungibleProxy.test.ts
@@ -101,7 +101,7 @@
 
   itEth('Can perform mint()', async ({helper}) => {
     const owner = await helper.eth.createAccountWithBalance(donor);
-    const {collectionAddress} = await helper.eth.createERC721MetadataNFTCollection(owner, 'A', 'A', 'A', '');
+    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'A', 'A', 'A', '');
     const caller = await helper.eth.createAccountWithBalance(donor);
     const receiver = helper.eth.createAccount();
 
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);