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.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.jsondiffbeforeafterboth1[2 {3 "inputs": [4 { "internalType": "string", "name": "name", "type": "string" },5 { "internalType": "string", "name": "description", "type": "string" },6 { "internalType": "string", "name": "tokenPrefix", "type": "string" }7 ],8 "name": "create721Collection",9 "outputs": [{ "internalType": "address", "name": "", "type": "address" }],10 "stateMutability": "view",11 "type": "function"12 },13 {14 "inputs": [15 { "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }16 ],17 "name": "supportsInterface",18 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],19 "stateMutability": "view",20 "type": "function"21 }22]1[2 {3 "inputs": [4 { "internalType": "string", "name": "name", "type": "string" },5 { "internalType": "string", "name": "description", "type": "string" },6 { "internalType": "string", "name": "tokenPrefix", "type": "string" }7 ],8 "name": "create721Collection",9 "outputs": [{ "internalType": "address", "name": "", "type": "address" }],10 "stateMutability": "view",11 "type": "function"12 },13 {14 "inputs": [15 {16 "internalType": "address",17 "name": "collectionAddress",18 "type": "address"19 }20 ],21 "name": "isCollectionExist",22 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],23 "stateMutability": "view",24 "type": "function"25 },26 {27 "inputs": [28 { "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }29 ],30 "name": "supportsInterface",31 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],32 "stateMutability": "view",33 "type": "function"34 }35]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);