git.delta.rocks / unique-network / refs/commits / 3e10430eed1f

difftreelog

chore add check in `supports_metadata`

Grigoriy Simonov2022-10-13parent: #b713559.patch.diff
in: master

9 files changed

modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -225,10 +225,6 @@
 	/// @return token's const_metadata
 	#[solidity(rename_selector = "tokenURI")]
 	fn token_uri(&self, token_id: uint256) -> Result<string> {
-		if !self.supports_metadata() {
-			return Ok("".into());
-		}
-
 		let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
 
 		match get_token_property(self, token_id_u32, &key::url()).as_deref() {
@@ -714,13 +710,17 @@
 
 impl<T: Config> NonfungibleHandle<T> {
 	pub fn supports_metadata(&self) -> bool {
-		if let Some(erc721_metadata) =
+		let has_metadata_support_enabled = if let Some(erc721_metadata) =
 			pallet_common::Pallet::<T>::get_collection_property(self.id, &key::erc721_metadata())
 		{
 			*erc721_metadata.into_inner() == *value::ERC721_METADATA_SUPPORTED
 		} else {
 			false
-		}
+		};
+
+		let has_url_property_permissions = get_token_permission::<T>(self.id, &key::url()).is_ok();
+
+		has_metadata_support_enabled && has_url_property_permissions
 	}
 }
 
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -108,7 +108,6 @@
 use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};
 use pallet_common::{
 	Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, CollectionHandle,
-	erc::static_property::{key, value},
 	eth::collection_id_to_address,
 };
 use pallet_structure::{Pallet as PalletStructure, Error as StructureError};
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -218,10 +218,6 @@
 	/// @return token's const_metadata
 	#[solidity(rename_selector = "tokenURI")]
 	fn token_uri(&self, token_id: uint256) -> Result<string> {
-		if !self.supports_metadata() {
-			return Ok("".into());
-		}
-
 		let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
 
 		match get_token_property(self, token_id_u32, &key::url()).as_deref() {
@@ -770,13 +766,17 @@
 
 impl<T: Config> RefungibleHandle<T> {
 	pub fn supports_metadata(&self) -> bool {
-		if let Some(erc721_metadata) =
+		let has_metadata_support_enabled = if let Some(erc721_metadata) =
 			pallet_common::Pallet::<T>::get_collection_property(self.id, &key::erc721_metadata())
 		{
 			*erc721_metadata.into_inner() == *value::ERC721_METADATA_SUPPORTED
 		} else {
 			false
-		}
+		};
+
+		let has_url_property_permissions = get_token_permission::<T>(self.id, &key::url()).is_ok();
+
+		has_metadata_support_enabled && has_url_property_permissions
 	}
 }
 
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -101,10 +101,7 @@
 use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};
 use pallet_evm_coder_substrate::WithRecorder;
 use pallet_common::{
-	CommonCollectionOperations,
-	erc::static_property::{key, value},
-	Error as CommonError,
-	eth::collection_id_to_address,
+	CommonCollectionOperations, Error as CommonError, eth::collection_id_to_address,
 	Event as CommonEvent, Pallet as PalletCommon,
 };
 use pallet_structure::Pallet as PalletStructure;
modifiedtests/src/eth/base.test.tsdiffbeforeafterboth
--- a/tests/src/eth/base.test.ts
+++ b/tests/src/eth/base.test.ts
@@ -80,7 +80,23 @@
     await usingEthPlaygrounds(async (helper, privateKey) => {
       const donor = privateKey('//Alice');
       const [alice] = await helper.arrange.createAccounts([10n], donor);
-      ({collectionId: collection} = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test', properties: [{key: 'ERC721Metadata', value: '1'}]}));
+      ({collectionId: collection} = await helper.nft.mintCollection(
+        alice,
+        {
+          name: 'test',
+          description: 'test',
+          tokenPrefix: 'test',
+          properties: [{key: 'ERC721Metadata', value: '1'}],
+          tokenPropertyPermissions: [{
+            key: 'URI',
+            permission: {
+              mutable: true,
+              collectionAdmin: true,
+              tokenOwner: false,
+            },
+          }],
+        },
+      ));
       minter = helper.eth.createAccount();
     });
   });
modifiedtests/src/eth/collectionProperties.test.tsdiffbeforeafterboth
before · tests/src/eth/collectionProperties.test.ts
1import {itEth, usingEthPlaygrounds, expect} from './util/playgrounds';2import {IKeyringPair} from '@polkadot/types/types';3import {Pallets} from '../util/playgrounds';45describe('EVM collection properties', () => {6  let donor: IKeyringPair;7  let alice: IKeyringPair;89  before(async function() {10    await usingEthPlaygrounds(async (_helper, privateKey) => {11      donor = privateKey('//Alice');12      [alice] = await _helper.arrange.createAccounts([10n], donor);13    });14  });1516  itEth('Can be set', async({helper}) => {17    const caller = await helper.eth.createAccountWithBalance(donor);18    const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: []});19    await collection.addAdmin(alice, {Ethereum: caller});2021    const address = helper.ethAddress.fromCollectionId(collection.collectionId);22    const contract = helper.ethNativeContract.collection(address, 'nft', caller);2324    await contract.methods.setCollectionProperty('testKey', Buffer.from('testValue')).send({from: caller});2526    const raw = (await collection.getData())?.raw;2728    expect(raw.properties[0].value).to.equal('testValue');29  });3031  itEth('Can be deleted', async({helper}) => {32    const caller = await helper.eth.createAccountWithBalance(donor);33    const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: [{key: 'testKey', value: 'testValue'}]});3435    await collection.addAdmin(alice, {Ethereum: caller});3637    const address = helper.ethAddress.fromCollectionId(collection.collectionId);38    const contract = helper.ethNativeContract.collection(address, 'nft', caller);3940    await contract.methods.deleteCollectionProperty('testKey').send({from: caller});4142    const raw = (await collection.getData())?.raw;4344    expect(raw.properties.length).to.equal(0);45  });4647  itEth('Can be read', async({helper}) => {48    const caller = helper.eth.createAccount();49    const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: [{key: 'testKey', value: 'testValue'}]});5051    const address = helper.ethAddress.fromCollectionId(collection.collectionId);52    const contract = helper.ethNativeContract.collection(address, 'nft', caller);5354    const value = await contract.methods.collectionProperty('testKey').call();55    expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));56  });57});5859describe('Supports ERC721Metadata', () => {60  let donor: IKeyringPair;6162  before(async function() {63    await usingEthPlaygrounds(async (_helper, privateKey) => {64      donor = privateKey('//Alice');65    });66  });6768  itEth('ERC721Metadata property can be set for NFT collection', async({helper}) => {69    const caller = await helper.eth.createAccountWithBalance(donor);70    const collection = await helper.nft.mintCollection(donor, {name: 'col', description: 'descr', tokenPrefix: 'COL'});7172    await collection.addAdmin(donor, {Ethereum: caller});73    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);7475    await contract.methods.setCollectionProperty('ERC721Metadata', Buffer.from('1')).send({from: caller});7677    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.true;7879    await contract.methods.setCollectionProperty('ERC721Metadata', Buffer.from('0')).send({from: caller});8081    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.false;82  });8384  itEth.ifWithPallets('ERC721Metadata property can be set for RFT collection', [Pallets.ReFungible], async({helper}) => {85    const caller = await helper.eth.createAccountWithBalance(donor);86    const collection = await helper.rft.mintCollection(donor, {name: 'col', description: 'descr', tokenPrefix: 'COL'});8788    await collection.addAdmin(donor, {Ethereum: caller});8990    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);9192    await contract.methods.setCollectionProperty('ERC721Metadata', Buffer.from('1')).send({from: caller});9394    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.true;9596    await contract.methods.setCollectionProperty('ERC721Metadata', Buffer.from('0')).send({from: caller});9798    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.false;99  });100});
after · tests/src/eth/collectionProperties.test.ts
1import {itEth, usingEthPlaygrounds, expect} from './util/playgrounds';2import {IKeyringPair} from '@polkadot/types/types';3import {Pallets} from '../util/playgrounds';45describe('EVM collection properties', () => {6  let donor: IKeyringPair;7  let alice: IKeyringPair;89  before(async function() {10    await usingEthPlaygrounds(async (_helper, privateKey) => {11      donor = privateKey('//Alice');12      [alice] = await _helper.arrange.createAccounts([10n], donor);13    });14  });1516  itEth('Can be set', async({helper}) => {17    const caller = await helper.eth.createAccountWithBalance(donor);18    const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: []});19    await collection.addAdmin(alice, {Ethereum: caller});2021    const address = helper.ethAddress.fromCollectionId(collection.collectionId);22    const contract = helper.ethNativeContract.collection(address, 'nft', caller);2324    await contract.methods.setCollectionProperty('testKey', Buffer.from('testValue')).send({from: caller});2526    const raw = (await collection.getData())?.raw;2728    expect(raw.properties[0].value).to.equal('testValue');29  });3031  itEth('Can be deleted', async({helper}) => {32    const caller = await helper.eth.createAccountWithBalance(donor);33    const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: [{key: 'testKey', value: 'testValue'}]});3435    await collection.addAdmin(alice, {Ethereum: caller});3637    const address = helper.ethAddress.fromCollectionId(collection.collectionId);38    const contract = helper.ethNativeContract.collection(address, 'nft', caller);3940    await contract.methods.deleteCollectionProperty('testKey').send({from: caller});4142    const raw = (await collection.getData())?.raw;4344    expect(raw.properties.length).to.equal(0);45  });4647  itEth('Can be read', async({helper}) => {48    const caller = helper.eth.createAccount();49    const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: [{key: 'testKey', value: 'testValue'}]});5051    const address = helper.ethAddress.fromCollectionId(collection.collectionId);52    const contract = helper.ethNativeContract.collection(address, 'nft', caller);5354    const value = await contract.methods.collectionProperty('testKey').call();55    expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));56  });57});5859describe('Supports ERC721Metadata', () => {60  let donor: IKeyringPair;6162  before(async function() {63    await usingEthPlaygrounds(async (_helper, privateKey) => {64      donor = privateKey('//Alice');65    });66  });6768  itEth('ERC721Metadata property can be set for NFT collection', async({helper}) => {69    const caller = await helper.eth.createAccountWithBalance(donor);70    const tokenPropertyPermissions = [{71      key: 'URI',72      permission: {73        mutable: true,74        collectionAdmin: true,75        tokenOwner: false,76      },77    }];78    const collection = await helper.nft.mintCollection(donor, {name: 'col', description: 'descr', tokenPrefix: 'COL', tokenPropertyPermissions});7980    await collection.addAdmin(donor, {Ethereum: caller});81    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);8283    await contract.methods.setCollectionProperty('ERC721Metadata', Buffer.from('1')).send({from: caller});8485    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.true;8687    await contract.methods.setCollectionProperty('ERC721Metadata', Buffer.from('0')).send({from: caller});8889    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.false;90  });9192  itEth.ifWithPallets('ERC721Metadata property can be set for RFT collection', [Pallets.ReFungible], async({helper}) => {93    const caller = await helper.eth.createAccountWithBalance(donor);94    const tokenPropertyPermissions = [{95      key: 'URI',96      permission: {97        mutable: true,98        collectionAdmin: true,99        tokenOwner: false,100      },101    }];102    const collection = await helper.rft.mintCollection(donor, {name: 'col', description: 'descr', tokenPrefix: 'COL', tokenPropertyPermissions});103104    await collection.addAdmin(donor, {Ethereum: caller});105106    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);107108    await contract.methods.setCollectionProperty('ERC721Metadata', Buffer.from('1')).send({from: caller});109110    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.true;111112    await contract.methods.setCollectionProperty('ERC721Metadata', Buffer.from('0')).send({from: caller});113114    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.false;115  });116});
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -501,7 +501,23 @@
 
   itEth('Returns collection name', async ({helper}) => {
     const caller = await helper.eth.createAccountWithBalance(donor);
-    const collection = await helper.nft.mintCollection(alice, {name: 'oh River', tokenPrefix: 'CHANGE', properties: [{key: 'ERC721Metadata', value: '1'}]});
+    const tokenPropertyPermissions = [{
+      key: 'URI',
+      permission: {
+        mutable: true,
+        collectionAdmin: true,
+        tokenOwner: false,
+      },
+    }];
+    const collection = await helper.nft.mintCollection(
+      alice,
+      {
+        name: 'oh River',
+        tokenPrefix: 'CHANGE',
+        properties: [{key: 'ERC721Metadata', value: '1'}],
+        tokenPropertyPermissions,
+      },
+    );
 
     const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);
     const name = await contract.methods.name().call();
@@ -510,7 +526,23 @@
 
   itEth('Returns symbol name', async ({helper}) => {
     const caller = await helper.eth.createAccountWithBalance(donor);
-    const collection = await helper.nft.mintCollection(alice, {name: 'oh River', tokenPrefix: 'CHANGE', properties: [{key: 'ERC721Metadata', value: '1'}]});
+    const tokenPropertyPermissions = [{
+      key: 'URI',
+      permission: {
+        mutable: true,
+        collectionAdmin: true,
+        tokenOwner: false,
+      },
+    }];
+    const collection = await helper.nft.mintCollection(
+      alice,
+      {
+        name: 'oh River',
+        tokenPrefix: 'CHANGE',
+        properties: [{key: 'ERC721Metadata', value: '1'}],
+        tokenPropertyPermissions,
+      },
+    );
 
     const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);
     const symbol = await contract.methods.symbol().call();
modifiedtests/src/eth/reFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -377,7 +377,23 @@
 
   itEth('Returns collection name', async ({helper}) => {
     const caller = helper.eth.createAccount();
-    const collection = await helper.rft.mintCollection(alice, {name: 'Leviathan', tokenPrefix: '11', properties: [{key: 'ERC721Metadata', value: '1'}]});
+    const tokenPropertyPermissions = [{
+      key: 'URI',
+      permission: {
+        mutable: true,
+        collectionAdmin: true,
+        tokenOwner: false,
+      },
+    }];
+    const collection = await helper.rft.mintCollection(
+      alice,
+      {
+        name: 'Leviathan',
+        tokenPrefix: '11',
+        properties: [{key: 'ERC721Metadata', value: '1'}],
+        tokenPropertyPermissions,
+      },
+    );
     
     const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'rft', caller);
     const name = await contract.methods.name().call();
@@ -386,7 +402,24 @@
 
   itEth('Returns symbol name', async ({helper}) => {
     const caller = await helper.eth.createAccountWithBalance(donor);
-    const {collectionId} = await helper.rft.mintCollection(alice, {name: 'Leviathan', tokenPrefix: '12', properties: [{key: 'ERC721Metadata', value: '1'}]});
+    const tokenPropertyPermissions = [{
+      key: 'URI',
+      permission: {
+        mutable: true,
+        collectionAdmin: true,
+        tokenOwner: false,
+      },
+    }];
+    const {collectionId} = await helper.rft.mintCollection(
+      alice,
+      {
+        name: 'Leviathan',
+        tokenPrefix: '12',
+        properties: [{key: 'ERC721Metadata', value: '1'}],
+        tokenPropertyPermissions,
+      },
+    );
+
     const contract = helper.ethNativeContract.collectionById(collectionId, 'rft', caller);
     const symbol = await contract.methods.symbol().call();
     expect(symbol).to.equal('12');
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
@@ -213,7 +213,7 @@
   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.createERC721MetadataCompatibleRFTCollection(name, description, tokenPrefix, baseUri).send({value: Number(collectionCreationPrice)});
 
     const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);