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
21 }21 }
22}22}
2323
24// Selector: 951c015124// Selector: 56c215c5
25contract CollectionHelper is Dummy, ERC165 {25contract CollectionHelper is Dummy, ERC165 {
26 // Selector: create721Collection(string,string,string) 951c015126 // Selector: create721Collection(string,string,string) 951c0151
27 function create721Collection(27 function create721Collection(
37 return 0x0000000000000000000000000000000000000000;37 return 0x0000000000000000000000000000000000000000;
38 }38 }
39
40 // Selector: isCollectionExist(address) c3de1494
41 function isCollectionExist(address collectionAddress)
42 public
43 view
44 returns (bool)
45 {
46 require(false, stub_error);
47 collectionAddress;
48 dummy;
49 return false;
50 }
39}51}
4052
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
--- a/tests/src/eth/createCollection.test.ts
+++ b/tests/src/eth/createCollection.test.ts
@@ -31,7 +31,6 @@
   normalizeAddress,
   normalizeEvents,
 } from './util/helpers';
-import util from 'util';
 
 async function getCollectionAddressFromResult(api: ApiPromise, result: any) {
   const collectionIdAddress = normalizeAddress(result.events[0].raw.topics[2]);
@@ -62,6 +61,25 @@
     expect(collection.tokenPrefix.toHuman()).to.be.eq(tokenPrefix);
     expect(collection.schemaVersion.type).to.be.eq('ImageURL');
   });
+
+  itWeb3('Check collection address exist', async ({api, web3}) => {
+    const owner = await createEthAccountWithBalance(api, web3);
+    const collectionHelper = evmCollectionHelper(web3, owner);
+  
+    const expectedCollectionId = await getCreatedCollectionCount(api) + 1;
+    const expectedCollectionAddress = collectionIdToAddress(expectedCollectionId);
+    expect(await collectionHelper.methods
+      .isCollectionExist(expectedCollectionAddress)
+      .call()).to.be.false;
+
+    await collectionHelper.methods
+      .create721Collection('A', 'A', 'A')
+      .send();
+    
+    expect(await collectionHelper.methods
+      .isCollectionExist(expectedCollectionAddress)
+      .call()).to.be.true;
+  });
   
   itWeb3('Set sponsorship', async ({api, web3}) => {
     const owner = await createEthAccountWithBalance(api, web3);