From 34309ac789c2e49531c6622ddc2c38a793a5f006 Mon Sep 17 00:00:00 2001 From: Trubnikov Sergey Date: Wed, 18 May 2022 15:23:17 +0000 Subject: [PATCH] CORE-345 Add method "isCollectionExist" --- --- 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 { + if let Some(id) = pallet_common::eth::map_eth_to_id(&collection_address) { + let collection_id = id; + return Ok(>::contains_key(collection_id)); + } + + Ok(false) + } } struct EvmCollection(Rc>); --- 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; + } } --- 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); } --- 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", --- 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); -- gitstuff