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.soldiffbeforeafterboth21 }21 }22}22}232324// Selector: 951c015124// Selector: 56c215c525contract CollectionHelper is Dummy, ERC165 {25contract CollectionHelper is Dummy, ERC165 {26 // Selector: create721Collection(string,string,string) 951c015126 // Selector: create721Collection(string,string,string) 951c015127 function create721Collection(27 function create721Collection(37 return 0x0000000000000000000000000000000000000000;37 return 0x0000000000000000000000000000000000000000;38 }38 }3940 // Selector: isCollectionExist(address) c3de149441 function isCollectionExist(address collectionAddress)42 public43 view44 returns (bool)45 {46 require(false, stub_error);47 collectionAddress;48 dummy;49 return false;50 }39}51}4052tests/src/eth/api/CollectionHelper.soldiffbeforeafterboth12 function supportsInterface(bytes4 interfaceID) external view returns (bool);12 function supportsInterface(bytes4 interfaceID) external view returns (bool);13}13}141415// Selector: 951c015115// Selector: 56c215c516interface CollectionHelper is Dummy, ERC165 {16interface CollectionHelper is Dummy, ERC165 {17 // Selector: create721Collection(string,string,string) 951c015117 // Selector: create721Collection(string,string,string) 951c015118 function create721Collection(18 function create721Collection(21 string memory tokenPrefix21 string memory tokenPrefix22 ) external view returns (address);22 ) external view returns (address);2324 // Selector: isCollectionExist(address) c3de149425 function isCollectionExist(address collectionAddress)26 external27 view28 returns (bool);23}29}2430tests/src/eth/collectionHelperAbi.jsondiffbeforeafterboth10 "stateMutability": "view",10 "stateMutability": "view",11 "type": "function"11 "type": "function"12 },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 },13 {26 {14 "inputs": [27 "inputs": [15 { "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }28 { "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }tests/src/eth/createCollection.test.tsdiffbeforeafterboth31 normalizeAddress,31 normalizeAddress,32 normalizeEvents,32 normalizeEvents,33} from './util/helpers';33} from './util/helpers';34import util from 'util';353436async function getCollectionAddressFromResult(api: ApiPromise, result: any) {35async function getCollectionAddressFromResult(api: ApiPromise, result: any) {37 const collectionIdAddress = normalizeAddress(result.events[0].raw.topics[2]);36 const collectionIdAddress = normalizeAddress(result.events[0].raw.topics[2]);63 expect(collection.schemaVersion.type).to.be.eq('ImageURL');62 expect(collection.schemaVersion.type).to.be.eq('ImageURL');64 });63 });65 6465 itWeb3('Check collection address exist', async ({api, web3}) => {66 const owner = await createEthAccountWithBalance(api, web3);67 const collectionHelper = evmCollectionHelper(web3, owner);68 69 const expectedCollectionId = await getCreatedCollectionCount(api) + 1;70 const expectedCollectionAddress = collectionIdToAddress(expectedCollectionId);71 expect(await collectionHelper.methods72 .isCollectionExist(expectedCollectionAddress)73 .call()).to.be.false;7475 await collectionHelper.methods76 .create721Collection('A', 'A', 'A')77 .send();78 79 expect(await collectionHelper.methods80 .isCollectionExist(expectedCollectionAddress)81 .call()).to.be.true;82 });83 66 itWeb3('Set sponsorship', async ({api, web3}) => {84 itWeb3('Set sponsorship', async ({api, web3}) => {67 const owner = await createEthAccountWithBalance(api, web3);85 const owner = await createEthAccountWithBalance(api, web3);