git.delta.rocks / unique-network / refs/commits / 34309ac789c2

difftreelog

CORE-345 Add method "isCollectionExist"

Trubnikov Sergey2022-05-18parent: #6b1c924.patch.diff
in: master

6 files changed

modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
107 };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 }
180
181 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 }
186
187 Ok(false)
188 }
180 }189 }
181 190
182 struct EvmCollection<T: Config>(Rc<SubstrateRecorder<T>>);191 struct EvmCollection<T: Config>(Rc<SubstrateRecorder<T>>);
modifiedpallets/unique/src/eth/stubs/CollectionHelper.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/unique/src/eth/stubs/CollectionHelper.soldiffbeforeafterboth
21 }21 }
22}22}
2323
24// Selector: 951c015124// Selector: 56c215c5
25contract CollectionHelper is Dummy, ERC165 {25contract CollectionHelper is Dummy, ERC165 {
26 // Selector: create721Collection(string,string,string) 951c015126 // Selector: create721Collection(string,string,string) 951c0151
27 function create721Collection(27 function create721Collection(
37 return 0x0000000000000000000000000000000000000000;37 return 0x0000000000000000000000000000000000000000;
38 }38 }
39
40 // Selector: isCollectionExist(address) c3de1494
41 function isCollectionExist(address collectionAddress)
42 public
43 view
44 returns (bool)
45 {
46 require(false, stub_error);
47 collectionAddress;
48 dummy;
49 return false;
50 }
39}51}
4052
modifiedtests/src/eth/api/CollectionHelper.soldiffbeforeafterboth
12 function supportsInterface(bytes4 interfaceID) external view returns (bool);12 function supportsInterface(bytes4 interfaceID) external view returns (bool);
13}13}
1414
15// Selector: 951c015115// Selector: 56c215c5
16interface CollectionHelper is Dummy, ERC165 {16interface CollectionHelper is Dummy, ERC165 {
17 // Selector: create721Collection(string,string,string) 951c015117 // Selector: create721Collection(string,string,string) 951c0151
18 function create721Collection(18 function create721Collection(
21 string memory tokenPrefix21 string memory tokenPrefix
22 ) external view returns (address);22 ) external view returns (address);
23
24 // Selector: isCollectionExist(address) c3de1494
25 function isCollectionExist(address collectionAddress)
26 external
27 view
28 returns (bool);
23}29}
2430
modifiedtests/src/eth/collectionHelperAbi.jsondiffbeforeafterboth
10 "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" }
modifiedtests/src/eth/createCollection.test.tsdiffbeforeafterboth
31 normalizeAddress,31 normalizeAddress,
32 normalizeEvents,32 normalizeEvents,
33} from './util/helpers';33} from './util/helpers';
34import util from 'util';
3534
36async 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 64
65 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.methods
72 .isCollectionExist(expectedCollectionAddress)
73 .call()).to.be.false;
74
75 await collectionHelper.methods
76 .create721Collection('A', 'A', 'A')
77 .send();
78
79 expect(await collectionHelper.methods
80 .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);