git.delta.rocks / unique-network / refs/commits / 34309ac789c2

difftreelog

CORE-345 Add method "isCollectionExist"

Trubnikov Sergey2022-05-18parent: #6b1c924.patch.diff
in: master

6 files changed

modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -107,7 +107,7 @@
 	};
 	use frame_support::traits::Get;
 	use sp_core::H160;
-	use pallet_common::{CollectionHandle, save_eth};
+	use pallet_common::{CollectionHandle, save_eth, pallet::CollectionById};
 	
 	use sp_std::{vec::Vec, rc::Rc};
 	use alloc::format;
@@ -177,6 +177,15 @@
 			});
 			Ok(address)
 		}
+
+		fn is_collection_exist(&self, _caller: caller, collection_address: address) -> Result<bool> {
+			if let Some(id) = pallet_common::eth::map_eth_to_id(&collection_address) {
+				let collection_id = id;
+				return Ok(<CollectionById<T>>::contains_key(collection_id));
+			}
+
+			Ok(false)
+		}
 	}
 	
 	struct EvmCollection<T: Config>(Rc<SubstrateRecorder<T>>);
modifiedpallets/unique/src/eth/stubs/CollectionHelper.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/unique/src/eth/stubs/CollectionHelper.soldiffbeforeafterboth
--- a/pallets/unique/src/eth/stubs/CollectionHelper.sol
+++ b/pallets/unique/src/eth/stubs/CollectionHelper.sol
@@ -21,7 +21,7 @@
 	}
 }
 
-// Selector: 951c0151
+// Selector: 56c215c5
 contract CollectionHelper is Dummy, ERC165 {
 	// Selector: create721Collection(string,string,string) 951c0151
 	function create721Collection(
@@ -36,4 +36,16 @@
 		dummy;
 		return 0x0000000000000000000000000000000000000000;
 	}
+
+	// Selector: isCollectionExist(address) c3de1494
+	function isCollectionExist(address collectionAddress)
+		public
+		view
+		returns (bool)
+	{
+		require(false, stub_error);
+		collectionAddress;
+		dummy;
+		return false;
+	}
 }
modifiedtests/src/eth/api/CollectionHelper.soldiffbeforeafterboth
--- a/tests/src/eth/api/CollectionHelper.sol
+++ b/tests/src/eth/api/CollectionHelper.sol
@@ -12,7 +12,7 @@
 	function supportsInterface(bytes4 interfaceID) external view returns (bool);
 }
 
-// Selector: 951c0151
+// Selector: 56c215c5
 interface CollectionHelper is Dummy, ERC165 {
 	// Selector: create721Collection(string,string,string) 951c0151
 	function create721Collection(
@@ -20,4 +20,10 @@
 		string memory description,
 		string memory tokenPrefix
 	) external view returns (address);
+
+	// Selector: isCollectionExist(address) c3de1494
+	function isCollectionExist(address collectionAddress)
+		external
+		view
+		returns (bool);
 }
modifiedtests/src/eth/collectionHelperAbi.jsondiffbeforeafterboth
--- a/tests/src/eth/collectionHelperAbi.json
+++ b/tests/src/eth/collectionHelperAbi.json
@@ -12,6 +12,19 @@
   },
   {
     "inputs": [
+      {
+        "internalType": "address",
+        "name": "collectionAddress",
+        "type": "address"
+      }
+    ],
+    "name": "isCollectionExist",
+    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
+    "stateMutability": "view",
+    "type": "function"
+  },
+  {
+    "inputs": [
       { "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }
     ],
     "name": "supportsInterface",
modifiedtests/src/eth/createCollection.test.tsdiffbeforeafterboth
31 normalizeAddress,31 normalizeAddress,
32 normalizeEvents,32 normalizeEvents,
33} from './util/helpers';33} from './util/helpers';
34import util from 'util';
3534
36async function getCollectionAddressFromResult(api: ApiPromise, result: any) {35async function getCollectionAddressFromResult(api: ApiPromise, result: any) {
37 const collectionIdAddress = normalizeAddress(result.events[0].raw.topics[2]);36 const collectionIdAddress = normalizeAddress(result.events[0].raw.topics[2]);
63 expect(collection.schemaVersion.type).to.be.eq('ImageURL');62 expect(collection.schemaVersion.type).to.be.eq('ImageURL');
64 });63 });
65 64
65 itWeb3('Check collection address exist', async ({api, web3}) => {
66 const owner = await createEthAccountWithBalance(api, web3);
67 const collectionHelper = evmCollectionHelper(web3, owner);
68
69 const expectedCollectionId = await getCreatedCollectionCount(api) + 1;
70 const expectedCollectionAddress = collectionIdToAddress(expectedCollectionId);
71 expect(await collectionHelper.methods
72 .isCollectionExist(expectedCollectionAddress)
73 .call()).to.be.false;
74
75 await collectionHelper.methods
76 .create721Collection('A', 'A', 'A')
77 .send();
78
79 expect(await collectionHelper.methods
80 .isCollectionExist(expectedCollectionAddress)
81 .call()).to.be.true;
82 });
83
66 itWeb3('Set sponsorship', async ({api, web3}) => {84 itWeb3('Set sponsorship', async ({api, web3}) => {
67 const owner = await createEthAccountWithBalance(api, web3);85 const owner = await createEthAccountWithBalance(api, web3);