difftreelog
CORE-345 Add method "isCollectionExist"
in: master
6 files changed
pallets/unique/src/eth/mod.rsdiffbeforeafterboth107 };107 };108 use frame_support::traits::Get;108 use frame_support::traits::Get;109 use sp_core::H160;109 use sp_core::H160;110 use pallet_common::{CollectionHandle, save_eth};110 use pallet_common::{CollectionHandle, save_eth, pallet::CollectionById};111 111 112 use sp_std::{vec::Vec, rc::Rc};112 use sp_std::{vec::Vec, rc::Rc};113 use alloc::format;113 use alloc::format;178 Ok(address)178 Ok(address)179 }179 }180181 fn is_collection_exist(&self, _caller: caller, collection_address: address) -> Result<bool> {182 if let Some(id) = pallet_common::eth::map_eth_to_id(&collection_address) {183 let collection_id = id;184 return Ok(<CollectionById<T>>::contains_key(collection_id));185 }186187 Ok(false)188 }180 }189 }181 190 182 struct EvmCollection<T: Config>(Rc<SubstrateRecorder<T>>);191 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.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);
}
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);