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
--- a/tests/src/eth/collectionProperties.test.ts
+++ b/tests/src/eth/collectionProperties.test.ts
@@ -67,7 +67,15 @@
 
   itEth('ERC721Metadata property can be set for NFT collection', async({helper}) => {
     const caller = await helper.eth.createAccountWithBalance(donor);
-    const collection = await helper.nft.mintCollection(donor, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+    const tokenPropertyPermissions = [{
+      key: 'URI',
+      permission: {
+        mutable: true,
+        collectionAdmin: true,
+        tokenOwner: false,
+      },
+    }];
+    const collection = await helper.nft.mintCollection(donor, {name: 'col', description: 'descr', tokenPrefix: 'COL', tokenPropertyPermissions});
 
     await collection.addAdmin(donor, {Ethereum: caller});
     const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);
@@ -83,7 +91,15 @@
 
   itEth.ifWithPallets('ERC721Metadata property can be set for RFT collection', [Pallets.ReFungible], async({helper}) => {
     const caller = await helper.eth.createAccountWithBalance(donor);
-    const collection = await helper.rft.mintCollection(donor, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+    const tokenPropertyPermissions = [{
+      key: 'URI',
+      permission: {
+        mutable: true,
+        collectionAdmin: true,
+        tokenOwner: false,
+      },
+    }];
+    const collection = await helper.rft.mintCollection(donor, {name: 'col', description: 'descr', tokenPrefix: 'COL', tokenPropertyPermissions});
 
     await collection.addAdmin(donor, {Ethereum: caller});
 
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
377377
378 itEth('Returns collection name', async ({helper}) => {378 itEth('Returns collection name', async ({helper}) => {
379 const caller = helper.eth.createAccount();379 const caller = helper.eth.createAccount();
380 const tokenPropertyPermissions = [{
381 key: 'URI',
382 permission: {
383 mutable: true,
384 collectionAdmin: true,
385 tokenOwner: false,
386 },
387 }];
380 const collection = await helper.rft.mintCollection(alice, {name: 'Leviathan', tokenPrefix: '11', properties: [{key: 'ERC721Metadata', value: '1'}]});388 const collection = await helper.rft.mintCollection(
381 389 alice,
390 {
391 name: 'Leviathan',
392 tokenPrefix: '11',
393 properties: [{key: 'ERC721Metadata', value: '1'}],
394 tokenPropertyPermissions,
395 },
396 );
397
382 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'rft', caller);398 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'rft', caller);
386402
387 itEth('Returns symbol name', async ({helper}) => {403 itEth('Returns symbol name', async ({helper}) => {
388 const caller = await helper.eth.createAccountWithBalance(donor);404 const caller = await helper.eth.createAccountWithBalance(donor);
405 const tokenPropertyPermissions = [{
406 key: 'URI',
407 permission: {
408 mutable: true,
409 collectionAdmin: true,
410 tokenOwner: false,
411 },
412 }];
389 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'Leviathan', tokenPrefix: '12', properties: [{key: 'ERC721Metadata', value: '1'}]});413 const {collectionId} = await helper.rft.mintCollection(
414 alice,
415 {
416 name: 'Leviathan',
417 tokenPrefix: '12',
418 properties: [{key: 'ERC721Metadata', value: '1'}],
419 tokenPropertyPermissions,
420 },
421 );
422
390 const contract = helper.ethNativeContract.collectionById(collectionId, 'rft', caller);423 const contract = helper.ethNativeContract.collectionById(collectionId, 'rft', caller);
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);