difftreelog
CORE-345 Add method "isCollectionExist"
in: master
6 files changed
pallets/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>>);
pallets/unique/src/eth/stubs/CollectionHelper.rawdiffbeforeafterbothbinary blob — no preview
pallets/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;
+ }
}
tests/src/eth/api/CollectionHelper.soldiffbeforeafterboth1// SPDX-License-Identifier: OTHER2// This code is automatically generated34pragma solidity >=0.8.0 <0.9.0;56// Common stubs holder7interface Dummy {89}1011interface ERC165 is Dummy {12 function supportsInterface(bytes4 interfaceID) external view returns (bool);13}1415// Selector: 951c015116interface CollectionHelper is Dummy, ERC165 {17 // Selector: create721Collection(string,string,string) 951c015118 function create721Collection(19 string memory name,20 string memory description,21 string memory tokenPrefix22 ) external view returns (address);23}1// SPDX-License-Identifier: OTHER2// This code is automatically generated34pragma solidity >=0.8.0 <0.9.0;56// Common stubs holder7interface Dummy {89}1011interface ERC165 is Dummy {12 function supportsInterface(bytes4 interfaceID) external view returns (bool);13}1415// Selector: 56c215c516interface CollectionHelper is Dummy, ERC165 {17 // Selector: create721Collection(string,string,string) 951c015118 function create721Collection(19 string memory name,20 string memory description,21 string memory tokenPrefix22 ) external view returns (address);2324 // Selector: isCollectionExist(address) c3de149425 function isCollectionExist(address collectionAddress)26 external27 view28 returns (bool);29}tests/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",
tests/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);