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
before · tests/src/eth/base.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 {Contract} from 'web3-eth-contract';1819import {IKeyringPair} from '@polkadot/types/types';20import {EthUniqueHelper, itEth, usingEthPlaygrounds, expect} from './util/playgrounds';212223describe('Contract calls', () => {24  let donor: IKeyringPair;2526  before(async function() {27    await usingEthPlaygrounds(async (_helper, privateKey) => {28      donor = privateKey('//Alice');29    });30  });3132  itEth('Call of simple contract fee is less than 0.2 UNQ', async ({helper}) => {33    const deployer = await helper.eth.createAccountWithBalance(donor);34    const flipper = await helper.eth.deployFlipper(deployer);3536    const cost = await helper.eth.calculateFee({Ethereum: deployer}, () => flipper.methods.flip().send({from: deployer}));37    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal()))).to.be.true;38  });3940  itEth('Balance transfer fee is less than 0.2 UNQ', async ({helper}) => {41    const userA = await helper.eth.createAccountWithBalance(donor);42    const userB = helper.eth.createAccount();43    const cost = await helper.eth.calculateFee({Ethereum: userA}, () => helper.getWeb3().eth.sendTransaction({from: userA, to: userB, value: '1000000', gas: helper.eth.DEFAULT_GAS}));44    const balanceB = await helper.balance.getEthereum(userB);45    expect(cost - balanceB < BigInt(0.2 * Number(helper.balance.getOneTokenNominal()))).to.be.true;46  });4748  itEth('NFT transfer is close to 0.15 UNQ', async ({helper}) => {49    const caller = await helper.eth.createAccountWithBalance(donor);50    const receiver = helper.eth.createAccount();5152    const [alice] = await helper.arrange.createAccounts([10n], donor);53    const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});54    const {tokenId} = await collection.mintToken(alice, {Ethereum: caller});5556    const address = helper.ethAddress.fromCollectionId(collection.collectionId);57    const contract = helper.ethNativeContract.collection(address, 'nft', caller);5859    const cost = await helper.eth.calculateFee({Ethereum: caller}, () => contract.methods.transfer(receiver, tokenId).send(caller));6061    const fee = Number(cost) / Number(helper.balance.getOneTokenNominal());62    const expectedFee = 0.15;63    const tolerance = 0.001;6465    expect(Math.abs(fee - expectedFee)).to.be.lessThan(tolerance);66  });67});6869describe('ERC165 tests', async () => {70  // https://eips.ethereum.org/EIPS/eip-1657172  let collection: number;73  let minter: string;7475  function contract(helper: EthUniqueHelper): Contract {76    return helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection), 'nft', minter);77  }7879  before(async () => {80    await usingEthPlaygrounds(async (helper, privateKey) => {81      const donor = privateKey('//Alice');82      const [alice] = await helper.arrange.createAccounts([10n], donor);83      ({collectionId: collection} = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test', properties: [{key: 'ERC721Metadata', value: '1'}]}));84      minter = helper.eth.createAccount();85    });86  });8788  itEth('interfaceID == 0xffffffff always false', async ({helper}) => {89    expect(await contract(helper).methods.supportsInterface('0xffffffff').call()).to.be.false;90  });9192  itEth('ERC721 support', async ({helper}) => {93    expect(await contract(helper).methods.supportsInterface('0x780e9d63').call()).to.be.true;94  });9596  itEth('ERC721Metadata support', async ({helper}) => {97    expect(await contract(helper).methods.supportsInterface('0x5b5e139f').call()).to.be.true;98  });99100  itEth('ERC721Mintable support', async ({helper}) => {101    expect(await contract(helper).methods.supportsInterface('0x68ccfe89').call()).to.be.true;102  });103104  itEth('ERC721Enumerable support', async ({helper}) => {105    expect(await contract(helper).methods.supportsInterface('0x780e9d63').call()).to.be.true;106  });107108  itEth('ERC721UniqueExtensions support', async ({helper}) => {109    expect(await contract(helper).methods.supportsInterface('0xd74d154f').call()).to.be.true;110  });111112  itEth('ERC721Burnable support', async ({helper}) => {113    expect(await contract(helper).methods.supportsInterface('0x42966c68').call()).to.be.true;114  });115116  itEth('ERC165 support', async ({helper}) => {117    expect(await contract(helper).methods.supportsInterface('0x01ffc9a7').call()).to.be.true;118  });119});
after · tests/src/eth/base.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 {Contract} from 'web3-eth-contract';1819import {IKeyringPair} from '@polkadot/types/types';20import {EthUniqueHelper, itEth, usingEthPlaygrounds, expect} from './util/playgrounds';212223describe('Contract calls', () => {24  let donor: IKeyringPair;2526  before(async function() {27    await usingEthPlaygrounds(async (_helper, privateKey) => {28      donor = privateKey('//Alice');29    });30  });3132  itEth('Call of simple contract fee is less than 0.2 UNQ', async ({helper}) => {33    const deployer = await helper.eth.createAccountWithBalance(donor);34    const flipper = await helper.eth.deployFlipper(deployer);3536    const cost = await helper.eth.calculateFee({Ethereum: deployer}, () => flipper.methods.flip().send({from: deployer}));37    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal()))).to.be.true;38  });3940  itEth('Balance transfer fee is less than 0.2 UNQ', async ({helper}) => {41    const userA = await helper.eth.createAccountWithBalance(donor);42    const userB = helper.eth.createAccount();43    const cost = await helper.eth.calculateFee({Ethereum: userA}, () => helper.getWeb3().eth.sendTransaction({from: userA, to: userB, value: '1000000', gas: helper.eth.DEFAULT_GAS}));44    const balanceB = await helper.balance.getEthereum(userB);45    expect(cost - balanceB < BigInt(0.2 * Number(helper.balance.getOneTokenNominal()))).to.be.true;46  });4748  itEth('NFT transfer is close to 0.15 UNQ', async ({helper}) => {49    const caller = await helper.eth.createAccountWithBalance(donor);50    const receiver = helper.eth.createAccount();5152    const [alice] = await helper.arrange.createAccounts([10n], donor);53    const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});54    const {tokenId} = await collection.mintToken(alice, {Ethereum: caller});5556    const address = helper.ethAddress.fromCollectionId(collection.collectionId);57    const contract = helper.ethNativeContract.collection(address, 'nft', caller);5859    const cost = await helper.eth.calculateFee({Ethereum: caller}, () => contract.methods.transfer(receiver, tokenId).send(caller));6061    const fee = Number(cost) / Number(helper.balance.getOneTokenNominal());62    const expectedFee = 0.15;63    const tolerance = 0.001;6465    expect(Math.abs(fee - expectedFee)).to.be.lessThan(tolerance);66  });67});6869describe('ERC165 tests', async () => {70  // https://eips.ethereum.org/EIPS/eip-1657172  let collection: number;73  let minter: string;7475  function contract(helper: EthUniqueHelper): Contract {76    return helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection), 'nft', minter);77  }7879  before(async () => {80    await usingEthPlaygrounds(async (helper, privateKey) => {81      const donor = privateKey('//Alice');82      const [alice] = await helper.arrange.createAccounts([10n], donor);83      ({collectionId: collection} = await helper.nft.mintCollection(84        alice,85        {86          name: 'test',87          description: 'test',88          tokenPrefix: 'test',89          properties: [{key: 'ERC721Metadata', value: '1'}],90          tokenPropertyPermissions: [{91            key: 'URI',92            permission: {93              mutable: true,94              collectionAdmin: true,95              tokenOwner: false,96            },97          }],98        },99      ));100      minter = helper.eth.createAccount();101    });102  });103104  itEth('interfaceID == 0xffffffff always false', async ({helper}) => {105    expect(await contract(helper).methods.supportsInterface('0xffffffff').call()).to.be.false;106  });107108  itEth('ERC721 support', async ({helper}) => {109    expect(await contract(helper).methods.supportsInterface('0x780e9d63').call()).to.be.true;110  });111112  itEth('ERC721Metadata support', async ({helper}) => {113    expect(await contract(helper).methods.supportsInterface('0x5b5e139f').call()).to.be.true;114  });115116  itEth('ERC721Mintable support', async ({helper}) => {117    expect(await contract(helper).methods.supportsInterface('0x68ccfe89').call()).to.be.true;118  });119120  itEth('ERC721Enumerable support', async ({helper}) => {121    expect(await contract(helper).methods.supportsInterface('0x780e9d63').call()).to.be.true;122  });123124  itEth('ERC721UniqueExtensions support', async ({helper}) => {125    expect(await contract(helper).methods.supportsInterface('0xd74d154f').call()).to.be.true;126  });127128  itEth('ERC721Burnable support', async ({helper}) => {129    expect(await contract(helper).methods.supportsInterface('0x42966c68').call()).to.be.true;130  });131132  itEth('ERC165 support', async ({helper}) => {133    expect(await contract(helper).methods.supportsInterface('0x01ffc9a7').call()).to.be.true;134  });135});
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
--- 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);