git.delta.rocks / unique-network / refs/commits / ec9052988b69

difftreelog

feat add eth methots for bulk properties

Trubnikov Sergey2022-10-24parent: #0321433.patch.diff
in: master

14 files changed

modifiedpallets/common/src/erc.rsdiffbeforeafterboth
--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -27,7 +27,7 @@
 use sp_std::vec::Vec;
 use up_data_structs::{
 	AccessMode, CollectionMode, CollectionPermissions, OwnerRestrictedSet, Property,
-	SponsoringRateLimit, SponsorshipState,
+	SponsoringRateLimit, SponsorshipState, PropertyKey,
 };
 use alloc::format;
 
@@ -97,6 +97,21 @@
 			.map_err(dispatch_to_evm::<T>)
 	}
 
+	/// Set collection properties.
+	///
+	/// @param properties Vector of properties key/value pair.
+	#[weight(<SelfWeightOf<T>>::set_collection_properties(properties.len() as u32))]
+	fn set_collection_properties(
+		&mut self,
+		caller: caller,
+		properties: Vec<(string, bytes)>,
+	) -> Result<void> {
+		for (key, value) in properties.into_iter() {
+			self.set_collection_property(caller, key, value)?;
+		}
+		Ok(())
+	}
+
 	/// Delete collection property.
 	///
 	/// @param key Property key.
@@ -123,12 +138,38 @@
 			.try_into()
 			.map_err(|_| "key too large")?;
 
-		let props = <CollectionProperties<T>>::get(self.id);
+		let props = CollectionProperties::<T>::get(self.id);
 		let prop = props.get(&key).ok_or("key not found")?;
 
 		Ok(bytes(prop.to_vec()))
 	}
 
+	/// Get collection properties.
+	///
+	/// @param keys Properties keys.
+	/// @return Vector of properties key/value pairs.
+	fn collection_properties(&self, keys: Vec<string>) -> Result<Vec<(string, bytes)>> {
+		let mut keys_ = Vec::<PropertyKey>::with_capacity(keys.len());
+		for key in keys {
+			keys_.push(
+				<Vec<u8>>::from(key)
+					.try_into()
+					.map_err(|_| Error::Revert("key too large".into()))?,
+			)
+		}
+		let properties = Pallet::<T>::filter_collection_properties(self.id, Some(keys_))
+			.map_err(dispatch_to_evm::<T>)?;
+
+		let mut properties_ = Vec::<(string, bytes)>::with_capacity(properties.len());
+		for p in properties {
+			let key =
+				string::from_utf8(p.key.into()).map_err(|e| Error::Revert(format!("{}", e)))?;
+			let value = bytes(p.value.to_vec());
+			properties_.push((key, value));
+		}
+		Ok(properties_)
+	}
+
 	/// Set the sponsor of the collection.
 	///
 	/// @dev In order for sponsorship to work, it must be confirmed on behalf of the sponsor.
modifiedpallets/fungible/src/stubs/UniqueFungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/fungible/src/stubs/UniqueFungible.soldiffbeforeafterboth
--- a/pallets/fungible/src/stubs/UniqueFungible.sol
+++ b/pallets/fungible/src/stubs/UniqueFungible.sol
@@ -18,7 +18,7 @@
 }
 
 /// @title A contract that allows you to work with collections.
-/// @dev the ERC-165 identifier for this interface is 0x25d897dc
+/// @dev the ERC-165 identifier for this interface is 0x5d354410
 contract Collection is Dummy, ERC165 {
 	/// Set collection property.
 	///
@@ -33,6 +33,17 @@
 		dummy = 0;
 	}
 
+	/// Set collection properties.
+	///
+	/// @param properties Vector of properties key/value pair.
+	/// @dev EVM selector for this function is: 0x50b26b2a,
+	///  or in textual repr: setCollectionProperties((string,bytes)[])
+	function setCollectionProperties(Tuple10[] memory properties) public {
+		require(false, stub_error);
+		properties;
+		dummy = 0;
+	}
+
 	/// Delete collection property.
 	///
 	/// @param key Property key.
@@ -59,6 +70,19 @@
 		return hex"";
 	}
 
+	/// Get collection properties.
+	///
+	/// @param keys Properties keys.
+	/// @return Vector of properties key/value pairs.
+	/// @dev EVM selector for this function is: 0x285fb8e6,
+	///  or in textual repr: collectionProperties(string[])
+	function collectionProperties(string[] memory keys) public view returns (Tuple10[] memory) {
+		require(false, stub_error);
+		keys;
+		dummy;
+		return new Tuple10[](0);
+	}
+
 	/// Set the sponsor of the collection.
 	///
 	/// @dev In order for sponsorship to work, it must be confirmed on behalf of the sponsor.
@@ -397,6 +421,12 @@
 	}
 }
 
+/// @dev anonymous struct
+struct Tuple10 {
+	string field_0;
+	bytes field_1;
+}
+
 /// @dev the ERC-165 identifier for this interface is 0x032e5926
 contract ERC20UniqueExtensions is Dummy, ERC165 {
 	/// @dev EVM selector for this function is: 0x0ecd0ab0,
modifiedpallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth
--- a/pallets/nonfungible/src/stubs/UniqueNFT.sol
+++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol
@@ -91,7 +91,7 @@
 }
 
 /// @title A contract that allows you to work with collections.
-/// @dev the ERC-165 identifier for this interface is 0x25d897dc
+/// @dev the ERC-165 identifier for this interface is 0x5d354410
 contract Collection is Dummy, ERC165 {
 	/// Set collection property.
 	///
@@ -106,6 +106,17 @@
 		dummy = 0;
 	}
 
+	/// Set collection properties.
+	///
+	/// @param properties Vector of properties key/value pair.
+	/// @dev EVM selector for this function is: 0x50b26b2a,
+	///  or in textual repr: setCollectionProperties((string,bytes)[])
+	function setCollectionProperties(Tuple19[] memory properties) public {
+		require(false, stub_error);
+		properties;
+		dummy = 0;
+	}
+
 	/// Delete collection property.
 	///
 	/// @param key Property key.
@@ -132,6 +143,19 @@
 		return hex"";
 	}
 
+	/// Get collection properties.
+	///
+	/// @param keys Properties keys.
+	/// @return Vector of properties key/value pairs.
+	/// @dev EVM selector for this function is: 0x285fb8e6,
+	///  or in textual repr: collectionProperties(string[])
+	function collectionProperties(string[] memory keys) public view returns (Tuple19[] memory) {
+		require(false, stub_error);
+		keys;
+		dummy;
+		return new Tuple19[](0);
+	}
+
 	/// Set the sponsor of the collection.
 	///
 	/// @dev In order for sponsorship to work, it must be confirmed on behalf of the sponsor.
@@ -470,6 +494,12 @@
 	}
 }
 
+/// @dev anonymous struct
+struct Tuple19 {
+	string field_0;
+	bytes field_1;
+}
+
 /// @title ERC-721 Non-Fungible Token Standard, optional metadata extension
 /// @dev See https://eips.ethereum.org/EIPS/eip-721
 /// @dev the ERC-165 identifier for this interface is 0x5b5e139f
modifiedpallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth
--- a/pallets/refungible/src/stubs/UniqueRefungible.sol
+++ b/pallets/refungible/src/stubs/UniqueRefungible.sol
@@ -91,7 +91,7 @@
 }
 
 /// @title A contract that allows you to work with collections.
-/// @dev the ERC-165 identifier for this interface is 0x25d897dc
+/// @dev the ERC-165 identifier for this interface is 0x5d354410
 contract Collection is Dummy, ERC165 {
 	/// Set collection property.
 	///
@@ -106,6 +106,17 @@
 		dummy = 0;
 	}
 
+	/// Set collection properties.
+	///
+	/// @param properties Vector of properties key/value pair.
+	/// @dev EVM selector for this function is: 0x50b26b2a,
+	///  or in textual repr: setCollectionProperties((string,bytes)[])
+	function setCollectionProperties(Tuple19[] memory properties) public {
+		require(false, stub_error);
+		properties;
+		dummy = 0;
+	}
+
 	/// Delete collection property.
 	///
 	/// @param key Property key.
@@ -132,6 +143,19 @@
 		return hex"";
 	}
 
+	/// Get collection properties.
+	///
+	/// @param keys Properties keys.
+	/// @return Vector of properties key/value pairs.
+	/// @dev EVM selector for this function is: 0x285fb8e6,
+	///  or in textual repr: collectionProperties(string[])
+	function collectionProperties(string[] memory keys) public view returns (Tuple19[] memory) {
+		require(false, stub_error);
+		keys;
+		dummy;
+		return new Tuple19[](0);
+	}
+
 	/// Set the sponsor of the collection.
 	///
 	/// @dev In order for sponsorship to work, it must be confirmed on behalf of the sponsor.
@@ -470,6 +494,12 @@
 	}
 }
 
+/// @dev anonymous struct
+struct Tuple19 {
+	string field_0;
+	bytes field_1;
+}
+
 /// @dev the ERC-165 identifier for this interface is 0x5b5e139f
 contract ERC721Metadata is Dummy, ERC165 {
 	// /// @notice A descriptive name for a collection of NFTs in this contract
modifiedtests/src/eth/api/UniqueFungible.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueFungible.sol
+++ b/tests/src/eth/api/UniqueFungible.sol
@@ -13,7 +13,7 @@
 }
 
 /// @title A contract that allows you to work with collections.
-/// @dev the ERC-165 identifier for this interface is 0x25d897dc
+/// @dev the ERC-165 identifier for this interface is 0x5d354410
 interface Collection is Dummy, ERC165 {
 	/// Set collection property.
 	///
@@ -23,6 +23,13 @@
 	///  or in textual repr: setCollectionProperty(string,bytes)
 	function setCollectionProperty(string memory key, bytes memory value) external;
 
+	/// Set collection properties.
+	///
+	/// @param properties Vector of properties key/value pair.
+	/// @dev EVM selector for this function is: 0x50b26b2a,
+	///  or in textual repr: setCollectionProperties((string,bytes)[])
+	function setCollectionProperties(Tuple10[] memory properties) external;
+
 	/// Delete collection property.
 	///
 	/// @param key Property key.
@@ -40,6 +47,14 @@
 	///  or in textual repr: collectionProperty(string)
 	function collectionProperty(string memory key) external view returns (bytes memory);
 
+	/// Get collection properties.
+	///
+	/// @param keys Properties keys.
+	/// @return Vector of properties key/value pairs.
+	/// @dev EVM selector for this function is: 0x285fb8e6,
+	///  or in textual repr: collectionProperties(string[])
+	function collectionProperties(string[] memory keys) external view returns (Tuple10[] memory);
+
 	/// Set the sponsor of the collection.
 	///
 	/// @dev In order for sponsorship to work, it must be confirmed on behalf of the sponsor.
@@ -258,6 +273,12 @@
 	function setOwnerCross(Tuple6 memory newOwner) external;
 }
 
+/// @dev anonymous struct
+struct Tuple10 {
+	string field_0;
+	bytes field_1;
+}
+
 /// @dev the ERC-165 identifier for this interface is 0x032e5926
 interface ERC20UniqueExtensions is Dummy, ERC165 {
 	/// @dev EVM selector for this function is: 0x0ecd0ab0,
modifiedtests/src/eth/api/UniqueNFT.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -62,7 +62,7 @@
 }
 
 /// @title A contract that allows you to work with collections.
-/// @dev the ERC-165 identifier for this interface is 0x25d897dc
+/// @dev the ERC-165 identifier for this interface is 0x5d354410
 interface Collection is Dummy, ERC165 {
 	/// Set collection property.
 	///
@@ -72,6 +72,13 @@
 	///  or in textual repr: setCollectionProperty(string,bytes)
 	function setCollectionProperty(string memory key, bytes memory value) external;
 
+	/// Set collection properties.
+	///
+	/// @param properties Vector of properties key/value pair.
+	/// @dev EVM selector for this function is: 0x50b26b2a,
+	///  or in textual repr: setCollectionProperties((string,bytes)[])
+	function setCollectionProperties(Tuple19[] memory properties) external;
+
 	/// Delete collection property.
 	///
 	/// @param key Property key.
@@ -89,6 +96,14 @@
 	///  or in textual repr: collectionProperty(string)
 	function collectionProperty(string memory key) external view returns (bytes memory);
 
+	/// Get collection properties.
+	///
+	/// @param keys Properties keys.
+	/// @return Vector of properties key/value pairs.
+	/// @dev EVM selector for this function is: 0x285fb8e6,
+	///  or in textual repr: collectionProperties(string[])
+	function collectionProperties(string[] memory keys) external view returns (Tuple19[] memory);
+
 	/// Set the sponsor of the collection.
 	///
 	/// @dev In order for sponsorship to work, it must be confirmed on behalf of the sponsor.
@@ -307,6 +322,12 @@
 	function setOwnerCross(Tuple6 memory newOwner) external;
 }
 
+/// @dev anonymous struct
+struct Tuple19 {
+	string field_0;
+	bytes field_1;
+}
+
 /// @title ERC-721 Non-Fungible Token Standard, optional metadata extension
 /// @dev See https://eips.ethereum.org/EIPS/eip-721
 /// @dev the ERC-165 identifier for this interface is 0x5b5e139f
modifiedtests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueRefungible.sol
+++ b/tests/src/eth/api/UniqueRefungible.sol
@@ -62,7 +62,7 @@
 }
 
 /// @title A contract that allows you to work with collections.
-/// @dev the ERC-165 identifier for this interface is 0x25d897dc
+/// @dev the ERC-165 identifier for this interface is 0x5d354410
 interface Collection is Dummy, ERC165 {
 	/// Set collection property.
 	///
@@ -72,6 +72,13 @@
 	///  or in textual repr: setCollectionProperty(string,bytes)
 	function setCollectionProperty(string memory key, bytes memory value) external;
 
+	/// Set collection properties.
+	///
+	/// @param properties Vector of properties key/value pair.
+	/// @dev EVM selector for this function is: 0x50b26b2a,
+	///  or in textual repr: setCollectionProperties((string,bytes)[])
+	function setCollectionProperties(Tuple19[] memory properties) external;
+
 	/// Delete collection property.
 	///
 	/// @param key Property key.
@@ -89,6 +96,14 @@
 	///  or in textual repr: collectionProperty(string)
 	function collectionProperty(string memory key) external view returns (bytes memory);
 
+	/// Get collection properties.
+	///
+	/// @param keys Properties keys.
+	/// @return Vector of properties key/value pairs.
+	/// @dev EVM selector for this function is: 0x285fb8e6,
+	///  or in textual repr: collectionProperties(string[])
+	function collectionProperties(string[] memory keys) external view returns (Tuple19[] memory);
+
 	/// Set the sponsor of the collection.
 	///
 	/// @dev In order for sponsorship to work, it must be confirmed on behalf of the sponsor.
@@ -307,6 +322,12 @@
 	function setOwnerCross(Tuple6 memory newOwner) external;
 }
 
+/// @dev anonymous struct
+struct Tuple19 {
+	string field_0;
+	bytes field_1;
+}
+
 /// @dev the ERC-165 identifier for this interface is 0x5b5e139f
 interface ERC721Metadata is Dummy, ERC165 {
 	// /// @notice A descriptive name for a collection of NFTs in this contract
modifiedtests/src/eth/collectionProperties.test.tsdiffbeforeafterboth
before · tests/src/eth/collectionProperties.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 {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';18import {Pallets} from '../util';19import {IProperty, ITokenPropertyPermission} from '../util/playgrounds/types';20import {IKeyringPair} from '@polkadot/types/types';2122describe('EVM collection properties', () => {23  let donor: IKeyringPair;24  let alice: IKeyringPair;2526  before(async function() {27    await usingEthPlaygrounds(async (_helper, privateKey) => {28      donor = await privateKey({filename: __filename});29      [alice] = await _helper.arrange.createAccounts([10n], donor);30    });31  });3233  itEth('Can be set', async({helper}) => {34    const caller = await helper.eth.createAccountWithBalance(donor);35    const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: []});36    await collection.addAdmin(alice, {Ethereum: caller});3738    const address = helper.ethAddress.fromCollectionId(collection.collectionId);39    const contract = helper.ethNativeContract.collection(address, 'nft', caller);4041    await contract.methods.setCollectionProperty('testKey', Buffer.from('testValue')).send({from: caller});4243    const raw = (await collection.getData())?.raw;4445    expect(raw.properties[0].value).to.equal('testValue');46  });4748  itEth('Can be deleted', async({helper}) => {49    const caller = await helper.eth.createAccountWithBalance(donor);50    const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: [{key: 'testKey', value: 'testValue'}]});5152    await collection.addAdmin(alice, {Ethereum: caller});5354    const address = helper.ethAddress.fromCollectionId(collection.collectionId);55    const contract = helper.ethNativeContract.collection(address, 'nft', caller);5657    await contract.methods.deleteCollectionProperty('testKey').send({from: caller});5859    const raw = (await collection.getData())?.raw;6061    expect(raw.properties.length).to.equal(0);62  });6364  itEth('Can be read', async({helper}) => {65    const caller = helper.eth.createAccount();66    const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: [{key: 'testKey', value: 'testValue'}]});6768    const address = helper.ethAddress.fromCollectionId(collection.collectionId);69    const contract = helper.ethNativeContract.collection(address, 'nft', caller);7071    const value = await contract.methods.collectionProperty('testKey').call();72    expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));73  });74});7576describe('Supports ERC721Metadata', () => {77  let donor: IKeyringPair;7879  before(async function() {80    await usingEthPlaygrounds(async (_helper, privateKey) => {81      donor = await privateKey({filename: __filename});82    });83  });8485  const checkERC721Metadata = async (helper: EthUniqueHelper, mode: 'nft' | 'rft') => {86    const caller = await helper.eth.createAccountWithBalance(donor);87    const bruh = await helper.eth.createAccountWithBalance(donor);8889    const BASE_URI = 'base/';90    const SUFFIX = 'suffix1';91    const URI = 'uri1';9293    const collectionHelpers = helper.ethNativeContract.collectionHelpers(caller);94    const creatorMethod = mode === 'rft' ? 'createRFTCollection' : 'createNFTCollection';9596    const {collectionId, collectionAddress} = await helper.eth[creatorMethod](caller, 'n', 'd', 'p');9798    const contract = helper.ethNativeContract.collectionById(collectionId, mode, caller);99    await contract.methods.addCollectionAdmin(bruh).send(); // to check that admin will work too100101    const collection1 = helper.nft.getCollectionObject(collectionId);102    const data1 = await collection1.getData();103    expect(data1?.raw.flags.erc721metadata).to.be.false;104    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.false;105106    await collectionHelpers.methods.makeCollectionERC721MetadataCompatible(collectionAddress, BASE_URI)107      .send({from: bruh});108109    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.true;110111    const collection2 = helper.nft.getCollectionObject(collectionId);112    const data2 = await collection2.getData();113    expect(data2?.raw.flags.erc721metadata).to.be.true;114115    const propertyPermissions = data2?.raw.tokenPropertyPermissions;116    expect(propertyPermissions?.length).to.equal(2);117118    expect(propertyPermissions.find((tpp: ITokenPropertyPermission) => {119      return tpp.key === 'URI' && tpp.permission.mutable && tpp.permission.collectionAdmin && !tpp.permission.tokenOwner;120    })).to.be.not.null;121122    expect(propertyPermissions.find((tpp: ITokenPropertyPermission) => {123      return tpp.key === 'URISuffix' && tpp.permission.mutable && tpp.permission.collectionAdmin && !tpp.permission.tokenOwner;124    })).to.be.not.null;125126    expect(data2?.raw.properties?.find((property: IProperty) => {127      return property.key === 'baseURI' && property.value === BASE_URI;128    })).to.be.not.null;129130    const token1Result = await contract.methods.mint(bruh).send();131    const tokenId1 = token1Result.events.Transfer.returnValues.tokenId;132133    expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(BASE_URI);134135    await contract.methods.setProperty(tokenId1, 'URISuffix', Buffer.from(SUFFIX)).send();136    expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(BASE_URI + SUFFIX);137138    await contract.methods.setProperty(tokenId1, 'URI', Buffer.from(URI)).send();139    expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(URI);140141    await contract.methods.deleteProperty(tokenId1, 'URI').send();142    expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(BASE_URI + SUFFIX);143144    const token2Result = await contract.methods.mintWithTokenURI(bruh, URI).send();145    const tokenId2 = token2Result.events.Transfer.returnValues.tokenId;146147    expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(URI);148149    await contract.methods.deleteProperty(tokenId2, 'URI').send();150    expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(BASE_URI);151152    await contract.methods.setProperty(tokenId2, 'URISuffix', Buffer.from(SUFFIX)).send();153    expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(BASE_URI + SUFFIX);154  };155156  itEth('ERC721Metadata property can be set for NFT collection', async({helper}) => {157    await checkERC721Metadata(helper, 'nft');158  });159160  itEth.ifWithPallets('ERC721Metadata property can be set for RFT collection', [Pallets.ReFungible], async({helper}) => {161    await checkERC721Metadata(helper, 'rft');162  });163});
after · tests/src/eth/collectionProperties.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 {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';18import {Pallets} from '../util';19import {IProperty, ITokenPropertyPermission} from '../util/playgrounds/types';20import {IKeyringPair} from '@polkadot/types/types';2122describe('EVM collection properties', () => {23  let donor: IKeyringPair;24  let alice: IKeyringPair;2526  before(async function() {27    await usingEthPlaygrounds(async (_helper, privateKey) => {28      donor = await privateKey({filename: __filename});29      [alice] = await _helper.arrange.createAccounts([10n], donor);30    });31  });3233  itEth('Can be set', async({helper}) => {34    const caller = await helper.eth.createAccountWithBalance(donor);35    const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: []});36    await collection.addAdmin(alice, {Ethereum: caller});3738    const address = helper.ethAddress.fromCollectionId(collection.collectionId);39    const contract = helper.ethNativeContract.collection(address, 'nft', caller);4041    await contract.methods.setCollectionProperty('testKey', Buffer.from('testValue')).send({from: caller});4243    const raw = (await collection.getData())?.raw;4445    expect(raw.properties[0].value).to.equal('testValue');46  });4748  itEth('Can be deleted', async({helper}) => {49    const caller = await helper.eth.createAccountWithBalance(donor);50    const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: [{key: 'testKey', value: 'testValue'}]});5152    await collection.addAdmin(alice, {Ethereum: caller});5354    const address = helper.ethAddress.fromCollectionId(collection.collectionId);55    const contract = helper.ethNativeContract.collection(address, 'nft', caller);5657    await contract.methods.deleteCollectionProperty('testKey').send({from: caller});5859    const raw = (await collection.getData())?.raw;6061    expect(raw.properties.length).to.equal(0);62  });6364  itEth('Can be read', async({helper}) => {65    const caller = helper.eth.createAccount();66    const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: [{key: 'testKey', value: 'testValue'}]});6768    const address = helper.ethAddress.fromCollectionId(collection.collectionId);69    const contract = helper.ethNativeContract.collection(address, 'nft', caller);7071    const value = await contract.methods.collectionProperty('testKey').call();72    expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));73  });74});7576describe('Supports ERC721Metadata', () => {77  let donor: IKeyringPair;7879  before(async function() {80    await usingEthPlaygrounds(async (_helper, privateKey) => {81      donor = await privateKey({filename: __filename});82    });83  });8485  const checkERC721Metadata = async (helper: EthUniqueHelper, mode: 'nft' | 'rft') => {86    const caller = await helper.eth.createAccountWithBalance(donor);87    const bruh = await helper.eth.createAccountWithBalance(donor);8889    const BASE_URI = 'base/';90    const SUFFIX = 'suffix1';91    const URI = 'uri1';9293    const collectionHelpers = helper.ethNativeContract.collectionHelpers(caller);94    const creatorMethod = mode === 'rft' ? 'createRFTCollection' : 'createNFTCollection';9596    const {collectionId, collectionAddress} = await helper.eth[creatorMethod](caller, 'n', 'd', 'p');9798    const contract = helper.ethNativeContract.collectionById(collectionId, mode, caller);99    await contract.methods.addCollectionAdmin(bruh).send(); // to check that admin will work too100101    const collection1 = helper.nft.getCollectionObject(collectionId);102    const data1 = await collection1.getData();103    expect(data1?.raw.flags.erc721metadata).to.be.false;104    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.false;105106    await collectionHelpers.methods.makeCollectionERC721MetadataCompatible(collectionAddress, BASE_URI)107      .send({from: bruh});108109    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.true;110111    const collection2 = helper.nft.getCollectionObject(collectionId);112    const data2 = await collection2.getData();113    expect(data2?.raw.flags.erc721metadata).to.be.true;114115    const propertyPermissions = data2?.raw.tokenPropertyPermissions;116    expect(propertyPermissions?.length).to.equal(2);117118    expect(propertyPermissions.find((tpp: ITokenPropertyPermission) => {119      return tpp.key === 'URI' && tpp.permission.mutable && tpp.permission.collectionAdmin && !tpp.permission.tokenOwner;120    })).to.be.not.null;121122    expect(propertyPermissions.find((tpp: ITokenPropertyPermission) => {123      return tpp.key === 'URISuffix' && tpp.permission.mutable && tpp.permission.collectionAdmin && !tpp.permission.tokenOwner;124    })).to.be.not.null;125126    expect(data2?.raw.properties?.find((property: IProperty) => {127      return property.key === 'baseURI' && property.value === BASE_URI;128    })).to.be.not.null;129130    const token1Result = await contract.methods.mint(bruh).send();131    const tokenId1 = token1Result.events.Transfer.returnValues.tokenId;132133    expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(BASE_URI);134135    await contract.methods.setProperty(tokenId1, 'URISuffix', Buffer.from(SUFFIX)).send();136    expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(BASE_URI + SUFFIX);137138    await contract.methods.setProperty(tokenId1, 'URI', Buffer.from(URI)).send();139    expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(URI);140141    await contract.methods.deleteProperty(tokenId1, 'URI').send();142    expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(BASE_URI + SUFFIX);143144    const token2Result = await contract.methods.mintWithTokenURI(bruh, URI).send();145    const tokenId2 = token2Result.events.Transfer.returnValues.tokenId;146147    expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(URI);148149    await contract.methods.deleteProperty(tokenId2, 'URI').send();150    expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(BASE_URI);151152    await contract.methods.setProperty(tokenId2, 'URISuffix', Buffer.from(SUFFIX)).send();153    expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(BASE_URI + SUFFIX);154  };155156  itEth('ERC721Metadata property can be set for NFT collection', async({helper}) => {157    await checkERC721Metadata(helper, 'nft');158  });159160  itEth.ifWithPallets('ERC721Metadata property can be set for RFT collection', [Pallets.ReFungible], async({helper}) => {161    await checkERC721Metadata(helper, 'rft');162  });163});164165describe('EVM collection property', () => {166  itEth('Set/read properties', async ({helper, privateKey}) => {167    const alice = await privateKey('//Alice');168    const collection = await helper.nft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'});169170    const sender = await helper.eth.createAccountWithBalance(alice, 100n);171    await collection.addAdmin(alice, {Ethereum: sender});172173    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);174    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', sender);175176    const key1 = 'key1';177    const value1 = Buffer.from('value1');178    179    const key2 = 'key2';180    const value2 = Buffer.from('value2');181182    const writeProperties = [183      [key1, '0x'+value1.toString('hex')],184      [key2, '0x'+value2.toString('hex')],185    ];186187    await contract.methods.setCollectionProperties(writeProperties).send();188    const readProperties = await contract.methods.collectionProperties([key1, key2]).call();189    expect(readProperties).to.be.like(writeProperties);190  });191});
modifiedtests/src/eth/fungibleAbi.jsondiffbeforeafterboth
--- a/tests/src/eth/fungibleAbi.json
+++ b/tests/src/eth/fungibleAbi.json
@@ -229,6 +229,25 @@
     "type": "function"
   },
   {
+    "inputs": [
+      { "internalType": "string[]", "name": "keys", "type": "string[]" }
+    ],
+    "name": "collectionProperties",
+    "outputs": [
+      {
+        "components": [
+          { "internalType": "string", "name": "field_0", "type": "string" },
+          { "internalType": "bytes", "name": "field_1", "type": "bytes" }
+        ],
+        "internalType": "struct Tuple10[]",
+        "name": "",
+        "type": "tuple[]"
+      }
+    ],
+    "stateMutability": "view",
+    "type": "function"
+  },
+  {
     "inputs": [{ "internalType": "string", "name": "key", "type": "string" }],
     "name": "collectionProperty",
     "outputs": [{ "internalType": "bytes", "name": "", "type": "bytes" }],
@@ -463,6 +482,23 @@
   },
   {
     "inputs": [
+      {
+        "components": [
+          { "internalType": "string", "name": "field_0", "type": "string" },
+          { "internalType": "bytes", "name": "field_1", "type": "bytes" }
+        ],
+        "internalType": "struct Tuple10[]",
+        "name": "properties",
+        "type": "tuple[]"
+      }
+    ],
+    "name": "setCollectionProperties",
+    "outputs": [],
+    "stateMutability": "nonpayable",
+    "type": "function"
+  },
+  {
+    "inputs": [
       { "internalType": "string", "name": "key", "type": "string" },
       { "internalType": "bytes", "name": "value", "type": "bytes" }
     ],
modifiedtests/src/eth/nonFungibleAbi.jsondiffbeforeafterboth
--- a/tests/src/eth/nonFungibleAbi.json
+++ b/tests/src/eth/nonFungibleAbi.json
@@ -259,6 +259,25 @@
     "type": "function"
   },
   {
+    "inputs": [
+      { "internalType": "string[]", "name": "keys", "type": "string[]" }
+    ],
+    "name": "collectionProperties",
+    "outputs": [
+      {
+        "components": [
+          { "internalType": "string", "name": "field_0", "type": "string" },
+          { "internalType": "bytes", "name": "field_1", "type": "bytes" }
+        ],
+        "internalType": "struct Tuple19[]",
+        "name": "",
+        "type": "tuple[]"
+      }
+    ],
+    "stateMutability": "view",
+    "type": "function"
+  },
+  {
     "inputs": [{ "internalType": "string", "name": "key", "type": "string" }],
     "name": "collectionProperty",
     "outputs": [{ "internalType": "bytes", "name": "", "type": "bytes" }],
@@ -578,6 +597,23 @@
   },
   {
     "inputs": [
+      {
+        "components": [
+          { "internalType": "string", "name": "field_0", "type": "string" },
+          { "internalType": "bytes", "name": "field_1", "type": "bytes" }
+        ],
+        "internalType": "struct Tuple19[]",
+        "name": "properties",
+        "type": "tuple[]"
+      }
+    ],
+    "name": "setCollectionProperties",
+    "outputs": [],
+    "stateMutability": "nonpayable",
+    "type": "function"
+  },
+  {
+    "inputs": [
       { "internalType": "string", "name": "key", "type": "string" },
       { "internalType": "bytes", "name": "value", "type": "bytes" }
     ],
modifiedtests/src/eth/reFungibleAbi.jsondiffbeforeafterboth
--- a/tests/src/eth/reFungibleAbi.json
+++ b/tests/src/eth/reFungibleAbi.json
@@ -241,6 +241,25 @@
     "type": "function"
   },
   {
+    "inputs": [
+      { "internalType": "string[]", "name": "keys", "type": "string[]" }
+    ],
+    "name": "collectionProperties",
+    "outputs": [
+      {
+        "components": [
+          { "internalType": "string", "name": "field_0", "type": "string" },
+          { "internalType": "bytes", "name": "field_1", "type": "bytes" }
+        ],
+        "internalType": "struct Tuple19[]",
+        "name": "",
+        "type": "tuple[]"
+      }
+    ],
+    "stateMutability": "view",
+    "type": "function"
+  },
+  {
     "inputs": [{ "internalType": "string", "name": "key", "type": "string" }],
     "name": "collectionProperty",
     "outputs": [{ "internalType": "bytes", "name": "", "type": "bytes" }],
@@ -560,6 +579,23 @@
   },
   {
     "inputs": [
+      {
+        "components": [
+          { "internalType": "string", "name": "field_0", "type": "string" },
+          { "internalType": "bytes", "name": "field_1", "type": "bytes" }
+        ],
+        "internalType": "struct Tuple19[]",
+        "name": "properties",
+        "type": "tuple[]"
+      }
+    ],
+    "name": "setCollectionProperties",
+    "outputs": [],
+    "stateMutability": "nonpayable",
+    "type": "function"
+  },
+  {
+    "inputs": [
       { "internalType": "string", "name": "key", "type": "string" },
       { "internalType": "bytes", "name": "value", "type": "bytes" }
     ],