git.delta.rocks / unique-network / refs/commits / 4afba3743846

difftreelog

add `collectionComtractAddress` funtion to `CollectionHelpers` interface

PraetorP2022-11-28parent: #b7593be.patch.diff
in: master

13 files changed

modifiedpallets/fungible/src/stubs/UniqueFungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -490,8 +490,8 @@
 		// TODO: Not implemetable
 		Err("not implemented".into())
 	}
-	
-	/// @notice Returns collection helper contract address 
+
+	/// @notice Returns collection helper contract address
 	fn collection_helper_address(&self) -> Result<address> {
 		Ok(T::ContractAddress::get())
 	}
modifiedpallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -482,7 +482,7 @@
 		// TODO: Not implemetable
 		Err("not implemented".into())
 	}
-	
+
 	/// @notice Returns collection helper contract address
 	fn collection_helper_address(&self) -> Result<address> {
 		Ok(T::ContractAddress::get())
modifiedpallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -28,6 +28,7 @@
 	CollectionById,
 	dispatch::CollectionDispatch,
 	erc::{CollectionHelpersEvents, static_property::key},
+	eth::{map_eth_to_id, collection_id_to_address},
 	Pallet as PalletCommon,
 };
 use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};
@@ -35,7 +36,7 @@
 use sp_std::vec;
 use up_data_structs::{
 	CollectionDescription, CollectionMode, CollectionName, CollectionTokenPrefix,
-	CreateCollectionData,
+	CreateCollectionData, CollectionId,
 };
 
 use crate::{weights::WeightInfo, Config, SelfWeightOf};
@@ -361,6 +362,25 @@
 			.expect("Collection creation price should be convertible to u128");
 		Ok(price.into())
 	}
+
+	/// Returns address of a collection.
+	/// @param collectionId  - CollectionId  of the collection
+	/// @return eth mirror address of the collection
+	fn collection_address(&self, collection_id: uint32) -> Result<address> {
+		Ok(collection_id_to_address(collection_id.into()))
+	}
+
+	/// Returns collectionId of a collection.
+	/// @param collectionAddress  - Eth address of the collection
+	/// @return collectionId of the collection
+	fn collection_id(&self, collection_address: address) -> Result<uint32> {
+		map_eth_to_id(&collection_address)
+			.map(|id| id.0)
+			.ok_or(Error::Revert(format!(
+				"failed to convert address {} into collectionId.",
+				collection_address
+			)))
+	}
 }
 
 /// Implements [`OnMethodCall`], which delegates call to [`EvmCollectionHelpers`]
modifiedpallets/unique/src/eth/stubs/CollectionHelpers.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/unique/src/eth/stubs/CollectionHelpers.soldiffbeforeafterboth
before · pallets/unique/src/eth/stubs/CollectionHelpers.sol
1// SPDX-License-Identifier: OTHER2// This code is automatically generated34pragma solidity >=0.8.0 <0.9.0;56/// @dev common stubs holder7contract Dummy {8	uint8 dummy;9	string stub_error = "this contract is implemented in native";10}1112contract ERC165 is Dummy {13	function supportsInterface(bytes4 interfaceID) external view returns (bool) {14		require(false, stub_error);15		interfaceID;16		return true;17	}18}1920/// @dev inlined interface21contract CollectionHelpersEvents {22	event CollectionCreated(address indexed owner, address indexed collectionId);23	event CollectionDestroyed(address indexed collectionId);24}2526/// @title Contract, which allows users to operate with collections27/// @dev the ERC-165 identifier for this interface is 0x7dea03b128contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {29	/// Create an NFT collection30	/// @param name Name of the collection31	/// @param description Informative description of the collection32	/// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications33	/// @return address Address of the newly created collection34	/// @dev EVM selector for this function is: 0x844af658,35	///  or in textual repr: createNFTCollection(string,string,string)36	function createNFTCollection(37		string memory name,38		string memory description,39		string memory tokenPrefix40	) public payable returns (address) {41		require(false, stub_error);42		name;43		description;44		tokenPrefix;45		dummy = 0;46		return 0x0000000000000000000000000000000000000000;47	}4849	// /// Create an NFT collection50	// /// @param name Name of the collection51	// /// @param description Informative description of the collection52	// /// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications53	// /// @return address Address of the newly created collection54	// /// @dev EVM selector for this function is: 0xe34a6844,55	// ///  or in textual repr: createNonfungibleCollection(string,string,string)56	// function createNonfungibleCollection(string memory name, string memory description, string memory tokenPrefix) public payable returns (address) {57	// 	require(false, stub_error);58	// 	name;59	// 	description;60	// 	tokenPrefix;61	// 	dummy = 0;62	// 	return 0x0000000000000000000000000000000000000000;63	// }6465	/// @dev EVM selector for this function is: 0xab173450,66	///  or in textual repr: createRFTCollection(string,string,string)67	function createRFTCollection(68		string memory name,69		string memory description,70		string memory tokenPrefix71	) public payable returns (address) {72		require(false, stub_error);73		name;74		description;75		tokenPrefix;76		dummy = 0;77		return 0x0000000000000000000000000000000000000000;78	}7980	/// @dev EVM selector for this function is: 0x7335b79f,81	///  or in textual repr: createFTCollection(string,uint8,string,string)82	function createFTCollection(83		string memory name,84		uint8 decimals,85		string memory description,86		string memory tokenPrefix87	) public payable returns (address) {88		require(false, stub_error);89		name;90		decimals;91		description;92		tokenPrefix;93		dummy = 0;94		return 0x0000000000000000000000000000000000000000;95	}9697	/// @dev EVM selector for this function is: 0x85624258,98	///  or in textual repr: makeCollectionERC721MetadataCompatible(address,string)99	function makeCollectionERC721MetadataCompatible(address collection, string memory baseUri) public {100		require(false, stub_error);101		collection;102		baseUri;103		dummy = 0;104	}105106	/// @dev EVM selector for this function is: 0x564e321f,107	///  or in textual repr: destroyCollection(address)108	function destroyCollection(address collectionAddress) public {109		require(false, stub_error);110		collectionAddress;111		dummy = 0;112	}113114	/// Check if a collection exists115	/// @param collectionAddress Address of the collection in question116	/// @return bool Does the collection exist?117	/// @dev EVM selector for this function is: 0xc3de1494,118	///  or in textual repr: isCollectionExist(address)119	function isCollectionExist(address collectionAddress) public view returns (bool) {120		require(false, stub_error);121		collectionAddress;122		dummy;123		return false;124	}125126	/// @dev EVM selector for this function is: 0xd23a7ab1,127	///  or in textual repr: collectionCreationFee()128	function collectionCreationFee() public view returns (uint256) {129		require(false, stub_error);130		dummy;131		return 0;132	}133}
after · pallets/unique/src/eth/stubs/CollectionHelpers.sol
1// SPDX-License-Identifier: OTHER2// This code is automatically generated34pragma solidity >=0.8.0 <0.9.0;56/// @dev common stubs holder7contract Dummy {8	uint8 dummy;9	string stub_error = "this contract is implemented in native";10}1112contract ERC165 is Dummy {13	function supportsInterface(bytes4 interfaceID) external view returns (bool) {14		require(false, stub_error);15		interfaceID;16		return true;17	}18}1920/// @dev inlined interface21contract CollectionHelpersEvents {22	event CollectionCreated(address indexed owner, address indexed collectionId);23	event CollectionDestroyed(address indexed collectionId);24}2526/// @title Contract, which allows users to operate with collections27/// @dev the ERC-165 identifier for this interface is 0xe65011aa28contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {29	/// Create an NFT collection30	/// @param name Name of the collection31	/// @param description Informative description of the collection32	/// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications33	/// @return address Address of the newly created collection34	/// @dev EVM selector for this function is: 0x844af658,35	///  or in textual repr: createNFTCollection(string,string,string)36	function createNFTCollection(37		string memory name,38		string memory description,39		string memory tokenPrefix40	) public payable returns (address) {41		require(false, stub_error);42		name;43		description;44		tokenPrefix;45		dummy = 0;46		return 0x0000000000000000000000000000000000000000;47	}4849	// /// Create an NFT collection50	// /// @param name Name of the collection51	// /// @param description Informative description of the collection52	// /// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications53	// /// @return address Address of the newly created collection54	// /// @dev EVM selector for this function is: 0xe34a6844,55	// ///  or in textual repr: createNonfungibleCollection(string,string,string)56	// function createNonfungibleCollection(string memory name, string memory description, string memory tokenPrefix) public payable returns (address) {57	// 	require(false, stub_error);58	// 	name;59	// 	description;60	// 	tokenPrefix;61	// 	dummy = 0;62	// 	return 0x0000000000000000000000000000000000000000;63	// }6465	/// @dev EVM selector for this function is: 0xab173450,66	///  or in textual repr: createRFTCollection(string,string,string)67	function createRFTCollection(68		string memory name,69		string memory description,70		string memory tokenPrefix71	) public payable returns (address) {72		require(false, stub_error);73		name;74		description;75		tokenPrefix;76		dummy = 0;77		return 0x0000000000000000000000000000000000000000;78	}7980	/// @dev EVM selector for this function is: 0x7335b79f,81	///  or in textual repr: createFTCollection(string,uint8,string,string)82	function createFTCollection(83		string memory name,84		uint8 decimals,85		string memory description,86		string memory tokenPrefix87	) public payable returns (address) {88		require(false, stub_error);89		name;90		decimals;91		description;92		tokenPrefix;93		dummy = 0;94		return 0x0000000000000000000000000000000000000000;95	}9697	/// @dev EVM selector for this function is: 0x85624258,98	///  or in textual repr: makeCollectionERC721MetadataCompatible(address,string)99	function makeCollectionERC721MetadataCompatible(address collection, string memory baseUri) public {100		require(false, stub_error);101		collection;102		baseUri;103		dummy = 0;104	}105106	/// @dev EVM selector for this function is: 0x564e321f,107	///  or in textual repr: destroyCollection(address)108	function destroyCollection(address collectionAddress) public {109		require(false, stub_error);110		collectionAddress;111		dummy = 0;112	}113114	/// Check if a collection exists115	/// @param collectionAddress Address of the collection in question116	/// @return bool Does the collection exist?117	/// @dev EVM selector for this function is: 0xc3de1494,118	///  or in textual repr: isCollectionExist(address)119	function isCollectionExist(address collectionAddress) public view returns (bool) {120		require(false, stub_error);121		collectionAddress;122		dummy;123		return false;124	}125126	/// @dev EVM selector for this function is: 0xd23a7ab1,127	///  or in textual repr: collectionCreationFee()128	function collectionCreationFee() public view returns (uint256) {129		require(false, stub_error);130		dummy;131		return 0;132	}133134	/// Returns address of a collection.135	/// @param collectionId  - CollectionId  of the collection136	/// @return eth mirror address of the collection137	/// @dev EVM selector for this function is: 0x2e716683,138	///  or in textual repr: collectionAddress(uint32)139	function collectionAddress(uint32 collectionId) public view returns (address) {140		require(false, stub_error);141		collectionId;142		dummy;143		return 0x0000000000000000000000000000000000000000;144	}145146	/// Returns collectionId of a collection.147	/// @param collectionAddress  - Eth address of the collection148	/// @return collectionId of the collection149	/// @dev EVM selector for this function is: 0xb5cb7498,150	///  or in textual repr: collectionId(address)151	function collectionId(address collectionAddress) public view returns (uint32) {152		require(false, stub_error);153		collectionAddress;154		dummy;155		return 0;156	}157}
modifiedtests/src/eth/abi/collectionHelpers.jsondiffbeforeafterboth
--- a/tests/src/eth/abi/collectionHelpers.json
+++ b/tests/src/eth/abi/collectionHelpers.json
@@ -32,6 +32,15 @@
     "type": "event"
   },
   {
+    "inputs": [
+      { "internalType": "uint32", "name": "collectionId", "type": "uint32" }
+    ],
+    "name": "collectionAddress",
+    "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
+    "stateMutability": "view",
+    "type": "function"
+  },
+  {
     "inputs": [],
     "name": "collectionCreationFee",
     "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
@@ -40,6 +49,19 @@
   },
   {
     "inputs": [
+      {
+        "internalType": "address",
+        "name": "collectionAddress",
+        "type": "address"
+      }
+    ],
+    "name": "collectionId",
+    "outputs": [{ "internalType": "uint32", "name": "", "type": "uint32" }],
+    "stateMutability": "view",
+    "type": "function"
+  },
+  {
+    "inputs": [
       { "internalType": "string", "name": "name", "type": "string" },
       { "internalType": "uint8", "name": "decimals", "type": "uint8" },
       { "internalType": "string", "name": "description", "type": "string" },
modifiedtests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth
--- a/tests/src/eth/api/CollectionHelpers.sol
+++ b/tests/src/eth/api/CollectionHelpers.sol
@@ -19,7 +19,7 @@
 }
 
 /// @title Contract, which allows users to operate with collections
-/// @dev the ERC-165 identifier for this interface is 0x7dea03b1
+/// @dev the ERC-165 identifier for this interface is 0xe65011aa
 interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
 	/// Create an NFT collection
 	/// @param name Name of the collection
@@ -78,4 +78,18 @@
 	/// @dev EVM selector for this function is: 0xd23a7ab1,
 	///  or in textual repr: collectionCreationFee()
 	function collectionCreationFee() external view returns (uint256);
+
+	/// Returns address of a collection.
+	/// @param collectionId  - CollectionId  of the collection
+	/// @return eth mirror address of the collection
+	/// @dev EVM selector for this function is: 0x2e716683,
+	///  or in textual repr: collectionAddress(uint32)
+	function collectionAddress(uint32 collectionId) external view returns (address);
+
+	/// Returns collectionId of a collection.
+	/// @param collectionAddress  - Eth address of the collection
+	/// @return collectionId of the collection
+	/// @dev EVM selector for this function is: 0xb5cb7498,
+	///  or in textual repr: collectionId(address)
+	function collectionId(address collectionAddress) external view returns (uint32);
 }
modifiedtests/src/eth/collectionHelperAddress.test.tsdiffbeforeafterboth
--- a/tests/src/eth/collectionHelperAddress.test.ts
+++ b/tests/src/eth/collectionHelperAddress.test.ts
@@ -16,10 +16,11 @@
 
 import {itEth, usingEthPlaygrounds, expect} from './util';
 import {IKeyringPair} from '@polkadot/types/types';
+import {Pallets} from '../util';
 
 const EVM_COLLECTION_HELPERS_ADDRESS = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';
 
-describe('[eth]CollectionHelerpAddress test: ERC721 ', () => {
+describe('[eth]CollectionHelperAddress test: ERC20/ERC721 ', () => {
   let donor: IKeyringPair;
 
   before(async function() {
@@ -28,18 +29,22 @@
     });
   });
 
-  itEth('NFT\\RFT', async ({helper}) => {
+  itEth('NFT', async ({helper}) => {
     const owner =  await helper.eth.createAccountWithBalance(donor);
     
     const {collectionAddress: nftCollectionAddress} = await helper.eth.createNFTCollection(owner, 'Sponsor', 'absolutely anything', 'ROC');
     const nftCollection = helper.ethNativeContract.collection(nftCollectionAddress, 'nft', owner);
-    
-    const {collectionAddress: rftCollectionAddress} = await helper.eth.createRFTCollection(owner, 'Sponsor', 'absolutely anything', 'ROC');
-    const rftCollection = helper.ethNativeContract.collection(rftCollectionAddress, 'rft', owner);
     
     expect((await nftCollection.methods.collectionHelperAddress().call())
       .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);
-    
+  });
+  
+  itEth.ifWithPallets('RFT ', [Pallets.ReFungible], async ({helper}) => {
+    const owner =  await helper.eth.createAccountWithBalance(donor);
+
+    const {collectionAddress: rftCollectionAddress} = await helper.eth.createRFTCollection(owner, 'Sponsor', 'absolutely anything', 'ROC');
+
+    const rftCollection = helper.ethNativeContract.collection(rftCollectionAddress, 'rft', owner);
     expect((await rftCollection.methods.collectionHelperAddress().call())
       .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);
   });
@@ -53,5 +58,15 @@
     expect((await collection.methods.collectionHelperAddress().call())
       .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);
   });
+  
+  itEth('[collectionHelpers] convert collectionId into address', async ({helper}) => {
+    const owner = await helper.eth.createAccountWithBalance(donor);
+    const collectionId = 7;
+    const collectionAddress = helper.ethAddress.fromCollectionId(collectionId);
+    const helperContract = helper.ethNativeContract.collectionHelpers(owner);
+    
+    expect(await helperContract.methods.collectionAddress(collectionId).call()).to.be.equal(collectionAddress);
+    expect(parseInt(await helperContract.methods.collectionId(collectionAddress).call())).to.be.equal(collectionId);
+  });
  
 });
modifiedtests/src/interfaces/lookup.tsdiffbeforeafterboth
--- a/tests/src/interfaces/lookup.ts
+++ b/tests/src/interfaces/lookup.ts
@@ -2936,13 +2936,13 @@
     }
   },
   /**
-   * Lookup338: pallet_maintenance::pallet::Call<T>
+   * Lookup340: pallet_maintenance::pallet::Call<T>
    **/
   PalletMaintenanceCall: {
     _enum: ['enable', 'disable']
   },
   /**
-   * Lookup339: pallet_test_utils::pallet::Call<T>
+   * Lookup341: pallet_test_utils::pallet::Call<T>
    **/
   PalletTestUtilsCall: {
     _enum: {
modifiedtests/src/interfaces/types-lookup.tsdiffbeforeafterboth
--- a/tests/src/interfaces/types-lookup.ts
+++ b/tests/src/interfaces/types-lookup.ts
@@ -3175,14 +3175,14 @@
     readonly type: 'Begin' | 'SetData' | 'Finish' | 'InsertEthLogs' | 'InsertEvents';
   }
 
-  /** @name PalletMaintenanceCall (338) */
+  /** @name PalletMaintenanceCall (340) */
   interface PalletMaintenanceCall extends Enum {
     readonly isEnable: boolean;
     readonly isDisable: boolean;
     readonly type: 'Enable' | 'Disable';
   }
 
-  /** @name PalletTestUtilsCall (339) */
+  /** @name PalletTestUtilsCall (341) */
   interface PalletTestUtilsCall extends Enum {
     readonly isEnable: boolean;
     readonly isSetTestValue: boolean;