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

difftreelog

CORE-345 Split evm collection to collection and helper

Trubnikov Sergey2022-05-18parent: #2cfa7af.patch.diff
in: master

16 files changed

modifiedMakefilediffbeforeafterboth
--- a/Makefile
+++ b/Makefile
@@ -18,6 +18,9 @@
 COLLECTION_STUBS=./pallets/unique/src/eth/stubs/
 COLLECTION_ABI=./tests/src/eth/collectionAbi.json
 
+COLLECTION_HELPER_STUBS=$(COLLECTION_STUBS)
+COLLECTION_HELPER_ABI=./tests/src/eth/collectionHelperAbi.json
+
 TESTS_API=./tests/src/eth/api/
 
 .PHONY: regenerate_solidity
@@ -36,9 +39,13 @@
 	PACKAGE=pallet-evm-contract-helpers NAME=eth::contract_helpers_impl OUTPUT=$(CONTRACT_HELPERS_STUBS)/$@ ./.maintain/scripts/generate_sol.sh
 
 Collection.sol:
-	PACKAGE=pallet-unique NAME=eth::pallet_evm_collection::collection_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh
-	PACKAGE=pallet-unique NAME=eth::pallet_evm_collection::collection_impl OUTPUT=$(COLLECTION_STUBS)/$@ ./.maintain/scripts/generate_sol.sh
+	PACKAGE=pallet-unique NAME=eth::evm_collection::collection_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh
+	PACKAGE=pallet-unique NAME=eth::evm_collection::collection_impl OUTPUT=$(COLLECTION_STUBS)/$@ ./.maintain/scripts/generate_sol.sh
 
+CollectionHelper.sol:
+	PACKAGE=pallet-unique NAME=eth::evm_collection::collection_helper_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh
+	PACKAGE=pallet-unique NAME=eth::evm_collection::collection_helper_impl OUTPUT=$(COLLECTION_HELPER_STUBS)/$@ ./.maintain/scripts/generate_sol.sh
+
 UniqueFungible: UniqueFungible.sol
 	INPUT=$(FUNGIBLE_EVM_STUBS)/$< OUTPUT=$(FUNGIBLE_EVM_STUBS)/UniqueFungible.raw ./.maintain/scripts/compile_stub.sh
 	INPUT=$(FUNGIBLE_EVM_STUBS)/$< OUTPUT=$(FUNGIBLE_EVM_ABI) ./.maintain/scripts/generate_abi.sh
@@ -55,7 +62,11 @@
 	INPUT=$(COLLECTION_STUBS)/$< OUTPUT=$(COLLECTION_STUBS)/Collection.raw ./.maintain/scripts/compile_stub.sh
 	INPUT=$(COLLECTION_STUBS)/$< OUTPUT=$(COLLECTION_ABI) ./.maintain/scripts/generate_abi.sh
 
-evm_stubs: UniqueFungible UniqueNFT ContractHelpers Collection
+CollectionHelper: CollectionHelper.sol
+	INPUT=$(COLLECTION_HELPER_STUBS)/$< OUTPUT=$(COLLECTION_HELPER_STUBS)/CollectionHelper.raw ./.maintain/scripts/compile_stub.sh
+	INPUT=$(COLLECTION_HELPER_STUBS)/$< OUTPUT=$(COLLECTION_HELPER_ABI) ./.maintain/scripts/generate_abi.sh
+
+evm_stubs: UniqueFungible UniqueNFT ContractHelpers Collection CollectionHelper
 
 .PHONY: _bench
 _bench:
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -112,7 +112,6 @@
 	use sp_std::{vec::Vec, rc::Rc};
 	use alloc::format;
 	
-	// #[pallet::config]
 	pub trait Config:
 		frame_system::Config
 		+ pallet_evm_coder_substrate::Config
@@ -122,8 +121,8 @@
 		type ContractAddress: Get<H160>;
 	}
 
-	struct EvmCollection<T: Config>(Rc<SubstrateRecorder<T>>);
-	impl<T: Config> WithRecorder<T> for EvmCollection<T> {
+	struct EvmCollectionHelper<T: Config>(Rc<SubstrateRecorder<T>>);
+	impl<T: Config> WithRecorder<T> for EvmCollectionHelper<T> {
 		fn recorder(&self) -> &SubstrateRecorder<T> {
 			&self.0
 		}
@@ -132,19 +131,9 @@
 			self.0
 		}
 	}
-	
-	#[derive(ToLog)]
-	pub enum EthCollectionEvent {
-		CollectionCreated {
-			#[indexed]
-			owner: address,
-			#[indexed]
-			collection_id: address,
-		},
-	}
-	
-	#[solidity_interface(name = "Collection")]
-	impl<T: Config> EvmCollection<T> {
+
+	#[solidity_interface(name = "CollectionHelper")]
+	impl<T: Config> EvmCollectionHelper<T> {
 		fn create_721_collection(
 			&self,
 			caller: caller,
@@ -188,14 +177,37 @@
 			});
 			Ok(address)
 		}
+	}
+	
+	struct EvmCollection<T: Config>(Rc<SubstrateRecorder<T>>);
+	impl<T: Config> WithRecorder<T> for EvmCollection<T> {
+		fn recorder(&self) -> &SubstrateRecorder<T> {
+			&self.0
+		}
+	
+		fn into_recorder(self) -> Rc<SubstrateRecorder<T>> {
+			self.0
+		}
+	}
+	
+	#[derive(ToLog)]
+	pub enum EthCollectionEvent {
+		CollectionCreated {
+			#[indexed]
+			owner: address,
+			#[indexed]
+			collection_id: address,
+		},
+	}
 	
+	#[solidity_interface(name = "Collection")]
+	impl<T: Config> EvmCollection<T> {
 		fn set_sponsor(
 			&self,
 			caller: caller,
-			collection_address: address,
 			sponsor: address,
 		) -> Result<void> {
-			let mut collection = collection_from_address(collection_address, &self.0)?;
+			let mut collection = collection_from_address(self.contract_address(caller).unwrap(), &self.0)?;
 			check_is_owner(caller, &collection)?;
 	
 			let sponsor = T::CrossAccountId::from_eth(sponsor);
@@ -203,8 +215,8 @@
 			save_eth(collection)
 		}
 	
-		fn confirm_sponsorship(&self, caller: caller, collection_address: address) -> Result<void> {
-			let mut collection = collection_from_address(collection_address, &self.0)?;
+		fn confirm_sponsorship(&self, caller: caller) -> Result<void> {
+			let mut collection = collection_from_address(self.contract_address(caller).unwrap(), &self.0)?;
 			let caller = T::CrossAccountId::from_eth(caller);
 			if !collection.confirm_sponsorship(caller.as_sub()) {
 				return Err(Error::Revert("Caller is not set as sponsor".into()));
@@ -215,10 +227,9 @@
 		fn set_limits(
 			&self,
 			caller: caller,
-			collection_address: address,
 			limits_json: string,
 		) -> Result<void> {
-			let mut collection = collection_from_address(collection_address, &self.0)?;
+			let mut collection = collection_from_address(self.contract_address(caller).unwrap(), &self.0)?;
 			check_is_owner(caller, &collection)?;
 	
 			let limits = serde_json_core::from_str(limits_json.as_ref())
@@ -226,6 +237,10 @@
 			collection.limits = limits.0;
 			save_eth(collection)
 		}
+
+		fn contract_address(&self, _caller: caller) -> Result<address> {
+			Ok(self.0.contract())
+		}
 	}
 	
 	fn error_feild_too_long(feild: &str, bound: u32) -> Error {
@@ -251,9 +266,9 @@
 			.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
 		Ok(())
 	}
-	
-	pub struct CollectionOnMethodCall<T: Config>(PhantomData<*const T>);
-	impl<T: Config> OnMethodCall<T> for CollectionOnMethodCall<T> {
+
+	pub struct CollectionHelperOnMethodCall<T: Config>(PhantomData<*const T>);
+	impl<T: Config> OnMethodCall<T> for CollectionHelperOnMethodCall<T> {
 		fn is_reserved(contract: &sp_core::H160) -> bool {
 			contract == &T::ContractAddress::get()
 		}
@@ -273,6 +288,36 @@
 				return None;
 			}
 	
+			let helpers = EvmCollectionHelper::<T>(Rc::new(SubstrateRecorder::<T>::new(*target, gas_left)));
+			pallet_evm_coder_substrate::call(*source, helpers, value, input)
+		}
+	
+		fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {
+			(contract == &T::ContractAddress::get())
+				.then(|| include_bytes!("./stubs/CollectionHelper.raw").to_vec())
+		}
+	}
+	
+	generate_stubgen!(collection_helper_impl, CollectionHelperCall<()>, true);
+	generate_stubgen!(collection_helper_iface, CollectionHelperCall<()>, false);
+	
+	pub struct CollectionOnMethodCall<T: Config>(PhantomData<*const T>);
+	impl<T: Config> OnMethodCall<T> for CollectionOnMethodCall<T> {
+		fn is_reserved(contract: &sp_core::H160) -> bool {
+			contract == &T::ContractAddress::get()
+		}
+	
+		fn is_used(contract: &sp_core::H160) -> bool {
+			contract == &T::ContractAddress::get()
+		}
+	
+		fn call(
+			source: &sp_core::H160,
+			target: &sp_core::H160,
+			gas_left: u64,
+			input: &[u8],
+			value: sp_core::U256,
+		) -> Option<PrecompileResult> {
 			let helpers = EvmCollection::<T>(Rc::new(SubstrateRecorder::<T>::new(*target, gas_left)));
 			pallet_evm_coder_substrate::call(*source, helpers, value, input)
 		}
modifiedpallets/unique/src/eth/stubs/Collection.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/unique/src/eth/stubs/Collection.soldiffbeforeafterboth
--- a/pallets/unique/src/eth/stubs/Collection.sol
+++ b/pallets/unique/src/eth/stubs/Collection.sol
@@ -21,48 +21,32 @@
 	}
 }
 
-// Selector: 1e95830f
+// Selector: 15cc740e
 contract Collection is Dummy, ERC165 {
-	// Selector: create721Collection(string,string,string) 951c0151
-	function create721Collection(
-		string memory name,
-		string memory description,
-		string memory tokenPrefix
-	) public view returns (address) {
+	// Selector: setSponsor(address) 59753fb1
+	function setSponsor(address sponsor) public view {
 		require(false, stub_error);
-		name;
-		description;
-		tokenPrefix;
+		sponsor;
 		dummy;
-		return 0x0000000000000000000000000000000000000000;
 	}
 
-	// Selector: setSponsor(address,address) f01fba93
-	function setSponsor(address collectionAddress, address sponsor)
-		public
-		view
-	{
+	// Selector: confirmSponsorship() c8c6a056
+	function confirmSponsorship() public view {
 		require(false, stub_error);
-		collectionAddress;
-		sponsor;
 		dummy;
 	}
 
-	// Selector: confirmSponsorship(address) abc00001
-	function confirmSponsorship(address collectionAddress) public view {
+	// Selector: setLimits(string) 72cb345d
+	function setLimits(string memory limitsJson) public view {
 		require(false, stub_error);
-		collectionAddress;
+		limitsJson;
 		dummy;
 	}
 
-	// Selector: setLimits(address,string) d05638cc
-	function setLimits(address collectionAddress, string memory limitsJson)
-		public
-		view
-	{
+	// Selector: contractAddress() f6b4dfb4
+	function contractAddress() public view returns (address) {
 		require(false, stub_error);
-		collectionAddress;
-		limitsJson;
 		dummy;
+		return 0x0000000000000000000000000000000000000000;
 	}
 }
addedpallets/unique/src/eth/stubs/CollectionHelper.rawdiffbeforeafterboth

binary blob — no preview

addedpallets/unique/src/eth/stubs/CollectionHelper.soldiffbeforeafterboth
--- /dev/null
+++ b/pallets/unique/src/eth/stubs/CollectionHelper.sol
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: OTHER
+// This code is automatically generated
+
+pragma solidity >=0.8.0 <0.9.0;
+
+// Common stubs holder
+contract Dummy {
+	uint8 dummy;
+	string stub_error = "this contract is implemented in native";
+}
+
+contract ERC165 is Dummy {
+	function supportsInterface(bytes4 interfaceID)
+		external
+		view
+		returns (bool)
+	{
+		require(false, stub_error);
+		interfaceID;
+		return true;
+	}
+}
+
+// Selector: 951c0151
+contract CollectionHelper is Dummy, ERC165 {
+	// Selector: create721Collection(string,string,string) 951c0151
+	function create721Collection(
+		string memory name,
+		string memory description,
+		string memory tokenPrefix
+	) public view returns (address) {
+		require(false, stub_error);
+		name;
+		description;
+		tokenPrefix;
+		dummy;
+		return 0x0000000000000000000000000000000000000000;
+	}
+}
modifiedruntime/opal/src/lib.rsdiffbeforeafterboth
--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -308,6 +308,7 @@
 		pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,
 		CollectionDispatchT<Self>,
 		evm_collection::CollectionOnMethodCall<Self>,
+		evm_collection::CollectionHelperOnMethodCall<Self>,
 	);
 	type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;
 	type ChainId = ChainId;
@@ -978,7 +979,7 @@
 	]);
 
 	// 0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f
-	pub const EvmCollectionAddress: H160 = H160([
+	pub const EvmCollectionHelperAddress: H160 = H160([
 		0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,
 	]);
 }
@@ -989,7 +990,7 @@
 }
 
 impl evm_collection::Config for Runtime {
-	type ContractAddress = EvmCollectionAddress;
+	type ContractAddress = EvmCollectionHelperAddress;
 }
 
 construct_runtime!(
modifiedruntime/quartz/src/lib.rsdiffbeforeafterboth
--- a/runtime/quartz/src/lib.rs
+++ b/runtime/quartz/src/lib.rs
@@ -280,6 +280,7 @@
 		pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,
 		CollectionDispatchT<Self>,
 		evm_collection::CollectionOnMethodCall<Self>,
+		evm_collection::CollectionHelperOnMethodCall<Self>,
 	);
 	type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;
 	type ChainId = ChainId;
@@ -955,7 +956,7 @@
 	]);
 		
 	// 0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f
-	pub const EvmCollectionAddress: H160 = H160([
+	pub const EvmCollectionHelperAddress: H160 = H160([
 		0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,
 	]);
 }
@@ -966,7 +967,7 @@
 }
 
 impl evm_collection::Config for Runtime {
-	type ContractAddress = EvmCollectionAddress;
+	type ContractAddress = EvmCollectionHelperAddress;
 }
 
 construct_runtime!(
modifiedruntime/unique/src/lib.rsdiffbeforeafterboth
--- a/runtime/unique/src/lib.rs
+++ b/runtime/unique/src/lib.rs
@@ -284,6 +284,7 @@
 		pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,
 		CollectionDispatchT<Self>,
 		evm_collection::CollectionOnMethodCall<Self>,
+		evm_collection::CollectionHelperOnMethodCall<Self>,
 	);
 	type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;
 	type ChainId = ChainId;
@@ -960,7 +961,7 @@
 	]);
 		
 	// 0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f
-	pub const EvmCollectionAddress: H160 = H160([
+	pub const EvmCollectionHelperAddress: H160 = H160([
 		0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,
 	]);
 }
@@ -971,7 +972,7 @@
 }
 
 impl evm_collection::Config for Runtime {
-	type ContractAddress = EvmCollectionAddress;
+	type ContractAddress = EvmCollectionHelperAddress;
 }
 
 construct_runtime!(
modifiedtests/src/eth/api/Collection.soldiffbeforeafterboth
--- a/tests/src/eth/api/Collection.sol
+++ b/tests/src/eth/api/Collection.sol
@@ -12,25 +12,17 @@
 	function supportsInterface(bytes4 interfaceID) external view returns (bool);
 }
 
-// Selector: 1e95830f
+// Selector: 15cc740e
 interface Collection is Dummy, ERC165 {
-	// Selector: create721Collection(string,string,string) 951c0151
-	function create721Collection(
-		string memory name,
-		string memory description,
-		string memory tokenPrefix
-	) external view returns (address);
+	// Selector: setSponsor(address) 59753fb1
+	function setSponsor(address sponsor) external view;
 
-	// Selector: setSponsor(address,address) f01fba93
-	function setSponsor(address collectionAddress, address sponsor)
-		external
-		view;
+	// Selector: confirmSponsorship() c8c6a056
+	function confirmSponsorship() external view;
 
-	// Selector: confirmSponsorship(address) abc00001
-	function confirmSponsorship(address collectionAddress) external view;
+	// Selector: setLimits(string) 72cb345d
+	function setLimits(string memory limitsJson) external view;
 
-	// Selector: setLimits(address,string) d05638cc
-	function setLimits(address collectionAddress, string memory limitsJson)
-		external
-		view;
+	// Selector: contractAddress() f6b4dfb4
+	function contractAddress() external view returns (address);
 }
addedtests/src/eth/api/CollectionHelper.soldiffbeforeafterboth
--- /dev/null
+++ b/tests/src/eth/api/CollectionHelper.sol
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: OTHER
+// This code is automatically generated
+
+pragma solidity >=0.8.0 <0.9.0;
+
+// Common stubs holder
+interface Dummy {
+
+}
+
+interface ERC165 is Dummy {
+	function supportsInterface(bytes4 interfaceID) external view returns (bool);
+}
+
+// Selector: 951c0151
+interface CollectionHelper is Dummy, ERC165 {
+	// Selector: create721Collection(string,string,string) 951c0151
+	function create721Collection(
+		string memory name,
+		string memory description,
+		string memory tokenPrefix
+	) external view returns (address);
+}
modifiedtests/src/eth/collectionAbi.jsondiffbeforeafterboth
--- a/tests/src/eth/collectionAbi.json
+++ b/tests/src/eth/collectionAbi.json
@@ -1,35 +1,20 @@
 [
   {
-    "inputs": [
-      {
-        "internalType": "address",
-        "name": "collectionAddress",
-        "type": "address"
-      }
-    ],
+    "inputs": [],
     "name": "confirmSponsorship",
     "outputs": [],
     "stateMutability": "view",
     "type": "function"
   },
   {
-    "inputs": [
-      { "internalType": "string", "name": "name", "type": "string" },
-      { "internalType": "string", "name": "description", "type": "string" },
-      { "internalType": "string", "name": "tokenPrefix", "type": "string" }
-    ],
-    "name": "create721Collection",
+    "inputs": [],
+    "name": "contractAddress",
     "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
     "stateMutability": "view",
     "type": "function"
   },
   {
     "inputs": [
-      {
-        "internalType": "address",
-        "name": "collectionAddress",
-        "type": "address"
-      },
       { "internalType": "string", "name": "limitsJson", "type": "string" }
     ],
     "name": "setLimits",
@@ -39,11 +24,6 @@
   },
   {
     "inputs": [
-      {
-        "internalType": "address",
-        "name": "collectionAddress",
-        "type": "address"
-      },
       { "internalType": "address", "name": "sponsor", "type": "address" }
     ],
     "name": "setSponsor",
addedtests/src/eth/collectionHelperAbi.jsondiffbeforeafterboth
--- /dev/null
+++ b/tests/src/eth/collectionHelperAbi.json
@@ -0,0 +1,22 @@
+[
+  {
+    "inputs": [
+      { "internalType": "string", "name": "name", "type": "string" },
+      { "internalType": "string", "name": "description", "type": "string" },
+      { "internalType": "string", "name": "tokenPrefix", "type": "string" }
+    ],
+    "name": "create721Collection",
+    "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
+    "stateMutability": "view",
+    "type": "function"
+  },
+  {
+    "inputs": [
+      { "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }
+    ],
+    "name": "supportsInterface",
+    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
+    "stateMutability": "view",
+    "type": "function"
+  }
+]
modifiedtests/src/eth/createCollection.test.tsdiffbeforeafterboth
20import {expect} from 'chai';20import {expect} from 'chai';
21import {getCreatedCollectionCount, getDetailedCollectionInfo} from '../util/helpers';21import {getCreatedCollectionCount, getDetailedCollectionInfo} from '../util/helpers';
22import {22import {
23 collectionHelper,23 evmCollectionHelper,
24 collectionIdFromAddress,24 collectionIdFromAddress,
25 collectionIdToAddress,25 collectionIdToAddress,
26 createEthAccount,26 createEthAccount,
27 createEthAccountWithBalance,27 createEthAccountWithBalance,
28 evmCollection,
28 GAS_ARGS,29 GAS_ARGS,
29 itWeb3,30 itWeb3,
30 normalizeAddress,31 normalizeAddress,
41describe('Create collection from EVM', () => {42describe('Create collection from EVM', () => {
42 itWeb3('Create collection', async ({api, web3}) => {43 itWeb3('Create collection', async ({api, web3}) => {
43 const owner = await createEthAccountWithBalance(api, web3);44 const owner = await createEthAccountWithBalance(api, web3);
44 const helper = collectionHelper(web3, owner);45 const helper = evmCollectionHelper(web3, owner);
45 const collectionName = 'CollectionEVM';46 const collectionName = 'CollectionEVM';
46 const description = 'Some description';47 const description = 'Some description';
47 const tokenPrefix = 'token prefix';48 const tokenPrefix = 'token prefix';
63 64
64 itWeb3('Set sponsorship', async ({api, web3}) => {65 itWeb3('Set sponsorship', async ({api, web3}) => {
65 const owner = await createEthAccountWithBalance(api, web3);66 const owner = await createEthAccountWithBalance(api, web3);
66 const helper = collectionHelper(web3, owner);67 const collectionHelper = evmCollectionHelper(web3, owner);
67 let result = await helper.methods.create721Collection('Sponsor collection', '1', '1').send();68 let result = await collectionHelper.methods.create721Collection('Sponsor collection', '1', '1').send();
68 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);69 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
69 const sponsor = await createEthAccountWithBalance(api, web3);70 const sponsor = await createEthAccountWithBalance(api, web3);
71 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
70 result = await helper.methods.setSponsor(collectionIdAddress, sponsor).send();72 result = await collectionEvm.methods.setSponsor(sponsor).send();
71 let collection = (await getDetailedCollectionInfo(api, collectionId))!;73 let collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;
72 expect(collection.sponsorship.isUnconfirmed).to.be.true;74 expect(collectionSub.sponsorship.isUnconfirmed).to.be.true;
73 expect(collection.sponsorship.asUnconfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));75 expect(collectionSub.sponsorship.asUnconfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));
74 await expect(helper.methods.confirmSponsorship(collectionIdAddress).call()).to.be.rejectedWith('Caller is not set as sponsor');76 await expect(collectionEvm.methods.confirmSponsorship().call()).to.be.rejectedWith('Caller is not set as sponsor');
75 const sponsorHelper = collectionHelper(web3, sponsor);77 const sponsorCollection = evmCollection(web3, sponsor, collectionIdAddress);
76 await sponsorHelper.methods.confirmSponsorship(collectionIdAddress).send();78 await sponsorCollection.methods.confirmSponsorship().send();
77 collection = (await getDetailedCollectionInfo(api, collectionId))!;79 collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;
78 expect(collection.sponsorship.isConfirmed).to.be.true;80 expect(collectionSub.sponsorship.isConfirmed).to.be.true;
79 expect(collection.sponsorship.asConfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));81 expect(collectionSub.sponsorship.asConfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));
80 });82 });
8183
82 itWeb3('Set limits', async ({api, web3}) => {84 itWeb3('Set limits', async ({api, web3}) => {
83 const owner = await createEthAccountWithBalance(api, web3);85 const owner = await createEthAccountWithBalance(api, web3);
84 const helper = collectionHelper(web3, owner);86 const collectionHelper = evmCollectionHelper(web3, owner);
85 const result = await helper.methods.create721Collection('Const collection', '5', '5').send();87 const result = await collectionHelper.methods.create721Collection('Const collection', '5', '5').send();
86 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);88 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
87 const limits = {89 const limits = {
88 accountTokenOwnershipLimit: 1000,90 accountTokenOwnershipLimit: 1000,
97 };99 };
98100
99 const limitsJson = JSON.stringify(limits, null, 1);101 const limitsJson = JSON.stringify(limits, null, 1);
102 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
100 await helper.methods.setLimits(collectionIdAddress, limitsJson).send();103 await collectionEvm.methods.setLimits(limitsJson).send();
101 104
102 const collection = (await getDetailedCollectionInfo(api, collectionId))!;105 const collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;
103 expect(collection.limits.accountTokenOwnershipLimit.unwrap().toNumber()).to.be.eq(limits.accountTokenOwnershipLimit);106 expect(collectionSub.limits.accountTokenOwnershipLimit.unwrap().toNumber()).to.be.eq(limits.accountTokenOwnershipLimit);
104 expect(collection.limits.sponsoredDataSize.unwrap().toNumber()).to.be.eq(limits.sponsoredDataSize);107 expect(collectionSub.limits.sponsoredDataSize.unwrap().toNumber()).to.be.eq(limits.sponsoredDataSize);
105 expect(collection.limits.sponsoredDataRateLimit.unwrap().asBlocks.toNumber()).to.be.eq(limits.sponsoredDataRateLimit.Blocks);108 expect(collectionSub.limits.sponsoredDataRateLimit.unwrap().asBlocks.toNumber()).to.be.eq(limits.sponsoredDataRateLimit.Blocks);
106 expect(collection.limits.tokenLimit.unwrap().toNumber()).to.be.eq(limits.tokenLimit);109 expect(collectionSub.limits.tokenLimit.unwrap().toNumber()).to.be.eq(limits.tokenLimit);
107 expect(collection.limits.sponsorTransferTimeout.unwrap().toNumber()).to.be.eq(limits.sponsorTransferTimeout);110 expect(collectionSub.limits.sponsorTransferTimeout.unwrap().toNumber()).to.be.eq(limits.sponsorTransferTimeout);
108 expect(collection.limits.sponsorApproveTimeout.unwrap().toNumber()).to.be.eq(limits.sponsorApproveTimeout);111 expect(collectionSub.limits.sponsorApproveTimeout.unwrap().toNumber()).to.be.eq(limits.sponsorApproveTimeout);
109 expect(collection.limits.ownerCanTransfer.toHuman()).to.be.eq(limits.ownerCanTransfer);112 expect(collectionSub.limits.ownerCanTransfer.toHuman()).to.be.eq(limits.ownerCanTransfer);
110 expect(collection.limits.ownerCanDestroy.toHuman()).to.be.eq(limits.ownerCanDestroy);113 expect(collectionSub.limits.ownerCanDestroy.toHuman()).to.be.eq(limits.ownerCanDestroy);
111 expect(collection.limits.transfersEnabled.toHuman()).to.be.eq(limits.transfersEnabled);114 expect(collectionSub.limits.transfersEnabled.toHuman()).to.be.eq(limits.transfersEnabled);
112 });115 });
113116
114 itWeb3('Check tokenURI', async ({web3, api}) => {117 itWeb3('Check tokenURI', async ({web3, api}) => {
115 const owner = await createEthAccountWithBalance(api, web3);118 const owner = await createEthAccountWithBalance(api, web3);
116 const helper = collectionHelper(web3, owner);119 const helper = evmCollectionHelper(web3, owner);
117 let result = await helper.methods.create721Collection('Mint collection', '6', '6').send();120 let result = await helper.methods.create721Collection('Mint collection', '6', '6').send();
118 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);121 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
119 const receiver = createEthAccount(web3);122 const receiver = createEthAccount(web3);
154describe('(!negative tests!) Create collection from EVM', () => {157describe('(!negative tests!) Create collection from EVM', () => {
155 itWeb3('(!negative test!) Create collection (bad lengths)', async ({api, web3}) => {158 itWeb3('(!negative test!) Create collection (bad lengths)', async ({api, web3}) => {
156 const owner = await createEthAccountWithBalance(api, web3);159 const owner = await createEthAccountWithBalance(api, web3);
157 const helper = collectionHelper(web3, owner);160 const helper = evmCollectionHelper(web3, owner);
158 {161 {
159 const MAX_NAME_LENGHT = 64;162 const MAX_NAME_LENGHT = 64;
160 const collectionName = 'A'.repeat(MAX_NAME_LENGHT + 1);163 const collectionName = 'A'.repeat(MAX_NAME_LENGHT + 1);
188 191
189 itWeb3('(!negative test!) Create collection (no funds)', async ({web3}) => {192 itWeb3('(!negative test!) Create collection (no funds)', async ({web3}) => {
190 const owner = await createEthAccount(web3);193 const owner = await createEthAccount(web3);
191 const helper = collectionHelper(web3, owner);194 const helper = evmCollectionHelper(web3, owner);
192 const collectionName = 'A';195 const collectionName = 'A';
193 const description = 'A';196 const description = 'A';
194 const tokenPrefix = 'A';197 const tokenPrefix = 'A';
200203
201 itWeb3('(!negative test!) Collection address (Contract is not an unique collection)', async ({api, web3}) => {204 itWeb3('(!negative test!) Collection address (Contract is not an unique collection)', async ({api, web3}) => {
202 const owner = await createEthAccountWithBalance(api, web3);205 const owner = await createEthAccountWithBalance(api, web3);
206 const collectionAddressWithBadPrefix = '0x00112233445566778899AABBCCDDEEFF00112233';
203 const helper = collectionHelper(web3, owner);207 const collectionEvm = evmCollection(web3, owner, collectionAddressWithBadPrefix);
204 const collectionAddressWithBadPrefix = '0x00112233445566778899AABBCCDDEEFF00112233';
205 const EXPECTED_ERROR = 'Contract is not an unique collection';208 const EXPECTED_ERROR = 'Contract is not an unique collection';
206 {209 {
207 const sponsor = await createEthAccountWithBalance(api, web3);210 const sponsor = await createEthAccountWithBalance(api, web3);
208 await expect(helper.methods211 await expect(collectionEvm.methods
209 .setSponsor(collectionAddressWithBadPrefix, sponsor)212 .setSponsor(sponsor)
210 .call()).to.be.rejectedWith(EXPECTED_ERROR);213 .call()).to.be.rejectedWith(EXPECTED_ERROR);
211 214
212 const sponsorHelper = collectionHelper(web3, sponsor);215 const sponsorCollection = evmCollection(web3, sponsor, collectionAddressWithBadPrefix);
213 await expect(sponsorHelper.methods216 await expect(sponsorCollection.methods
214 .confirmSponsorship(collectionAddressWithBadPrefix)217 .confirmSponsorship()
215 .call()).to.be.rejectedWith(EXPECTED_ERROR);218 .call()).to.be.rejectedWith(EXPECTED_ERROR);
216 }219 }
217 {220 {
218 const limits = '{"account_token_ownership_limit":1000}';221 const limits = '{"account_token_ownership_limit":1000}';
219 await expect(helper.methods222 await expect(collectionEvm.methods
220 .setLimits(collectionAddressWithBadPrefix, limits)223 .setLimits(limits)
221 .call()).to.be.rejectedWith(EXPECTED_ERROR);224 .call()).to.be.rejectedWith(EXPECTED_ERROR);
222 }225 }
223 });226 });
224227
225 itWeb3('(!negative test!) Check owner', async ({api, web3}) => {228 itWeb3('(!negative test!) Check owner', async ({api, web3}) => {
226 const owner = await createEthAccountWithBalance(api, web3);229 const owner = await createEthAccountWithBalance(api, web3);
227 const notOwner = await createEthAccount(web3);230 const notOwner = await createEthAccount(web3);
228 const helperFromOwner = collectionHelper(web3, owner);231 const collectionHelper = evmCollectionHelper(web3, owner);
229 const helperFromNotOwner = collectionHelper(web3, notOwner);
230 const result = await helperFromOwner.methods.create721Collection('A', 'A', 'A').send();232 const result = await collectionHelper.methods.create721Collection('A', 'A', 'A').send();
231 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);233 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
234 const contractEvmFromNotOwner = evmCollection(web3, notOwner, collectionIdAddress);
232 const EXPECTED_ERROR = 'NoPermission';235 const EXPECTED_ERROR = 'NoPermission';
233 {236 {
234 const sponsor = await createEthAccountWithBalance(api, web3);237 const sponsor = await createEthAccountWithBalance(api, web3);
235 await expect(helperFromNotOwner.methods238 await expect(contractEvmFromNotOwner.methods
236 .setSponsor(collectionIdAddress, sponsor)239 .setSponsor(sponsor)
237 .call()).to.be.rejectedWith(EXPECTED_ERROR);240 .call()).to.be.rejectedWith(EXPECTED_ERROR);
238 241
239 const sponsorHelper = collectionHelper(web3, sponsor);242 const sponsorCollection = evmCollection(web3, sponsor, collectionIdAddress);
240 await expect(sponsorHelper.methods243 await expect(sponsorCollection.methods
241 .confirmSponsorship(collectionIdAddress)244 .confirmSponsorship()
242 .call()).to.be.rejectedWith('Caller is not set as sponsor');245 .call()).to.be.rejectedWith('Caller is not set as sponsor');
243 }246 }
244 {247 {
245 const limits = '{"account_token_ownership_limit":1000}';248 const limits = '{"account_token_ownership_limit":1000}';
246 await expect(helperFromNotOwner.methods249 await expect(contractEvmFromNotOwner.methods
247 .setLimits(collectionIdAddress, limits)250 .setLimits(limits)
248 .call()).to.be.rejectedWith(EXPECTED_ERROR);251 .call()).to.be.rejectedWith(EXPECTED_ERROR);
249 }252 }
250 });253 });
251254
252 itWeb3('(!negative test!) Set limits', async ({api, web3}) => {255 itWeb3('(!negative test!) Set limits', async ({api, web3}) => {
253 const owner = await createEthAccountWithBalance(api, web3);256 const owner = await createEthAccountWithBalance(api, web3);
254 const helper = collectionHelper(web3, owner);257 const collectionHelper = evmCollectionHelper(web3, owner);
255 const result = await helper.methods.create721Collection('Schema collection', 'A', 'A').send();258 const result = await collectionHelper.methods.create721Collection('Schema collection', 'A', 'A').send();
256 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);259 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
260 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
257 const badJson = '{accountTokenOwnershipLimit: 1000}';261 const badJson = '{accountTokenOwnershipLimit: 1000}';
258 await expect(helper.methods262 await expect(collectionEvm.methods
259 .setLimits(collectionIdAddress, badJson)263 .setLimits(badJson)
260 .call()).to.be.rejectedWith('Parse JSON error:');264 .call()).to.be.rejectedWith('Parse JSON error:');
261 });265 });
262});266});
modifiedtests/src/eth/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/eth/util/helpers.ts
+++ b/tests/src/eth/util/helpers.ts
@@ -29,6 +29,7 @@
 import privateKey from '../../substrate/privateKey';
 import contractHelpersAbi from './contractHelpersAbi.json';
 import collectionAbi from '../collectionAbi.json';
+import collectionHelperAbi from '../collectionHelperAbi.json';
 import getBalance from '../../substrate/get-balance';
 import waitNewBlocks from '../../substrate/wait-new-blocks';
 
@@ -283,13 +284,23 @@
 }
 
 /** 
- * pallet evm_collection
+ * evm collection helper
  * @param web3 
  * @param caller - eth address
  * @returns 
  */
-export function collectionHelper(web3: Web3, caller: string) {
-  return new web3.eth.Contract(collectionAbi as any, '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f', {from: caller, ...GAS_ARGS});
+export function evmCollectionHelper(web3: Web3, caller: string) {
+  return new web3.eth.Contract(collectionHelperAbi as any, '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f', {from: caller, ...GAS_ARGS});
+}
+
+/** 
+ * evm collection
+ * @param web3 
+ * @param caller - eth address
+ * @returns 
+ */
+export function evmCollection(web3: Web3, caller: string, collection: string) {
+  return new web3.eth.Contract(collectionAbi as any, collection, {from: caller, ...GAS_ARGS});
 }
 
 /**
modifiedtests/src/interfaces/unique/types.tsdiffbeforeafterboth
--- a/tests/src/interfaces/unique/types.ts
+++ b/tests/src/interfaces/unique/types.ts
@@ -6,9 +6,6 @@
 import type { AccountId32, Call, H160, H256, MultiAddress, Perbill, Permill } from '@polkadot/types/interfaces/runtime';
 import type { Event } from '@polkadot/types/interfaces/system';
 
-/** @name BTreeSet */
-export interface BTreeSet extends BTreeSet<Bytes> {}
-
 /** @name CumulusPalletDmpQueueCall */
 export interface CumulusPalletDmpQueueCall extends Enum {
   readonly isServiceOverweight: boolean;