From 6b1c924f3c5d6abe361eddddb9278cda1f94a572 Mon Sep 17 00:00:00 2001 From: Trubnikov Sergey Date: Wed, 18 May 2022 14:17:25 +0000 Subject: [PATCH] CORE-345 Add check that contract is unique collection --- --- a/pallets/common/src/eth.rs +++ b/pallets/common/src/eth.rs @@ -37,3 +37,7 @@ out[16..20].copy_from_slice(&u32::to_be_bytes(id.0)); H160(out) } + +pub fn is_collection(address: &H160) -> bool { + address[0..16] == ETH_COLLECTION_PREFIX +} --- a/pallets/unique/src/eth/mod.rs +++ b/pallets/unique/src/eth/mod.rs @@ -318,6 +318,10 @@ input: &[u8], value: sp_core::U256, ) -> Option { + if !pallet_common::eth::is_collection(target) { + return None; + } + let helpers = EvmCollection::(Rc::new(SubstrateRecorder::::new(*target, gas_left))); pallet_evm_coder_substrate::call(*source, helpers, value, input) } --- a/tests/src/eth/createCollection.test.ts +++ b/tests/src/eth/createCollection.test.ts @@ -31,6 +31,7 @@ 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]); @@ -201,18 +202,18 @@ .call()).to.be.rejectedWith('NotSufficientFounds'); }); - itWeb3('(!negative test!) Collection address (Contract is not an unique collection)', async ({api, web3}) => { + itWeb3('(!negative test!) Collection address (Create collection handle error)', async ({api, web3}) => { const owner = await createEthAccountWithBalance(api, web3); - const collectionAddressWithBadPrefix = '0x00112233445566778899AABBCCDDEEFF00112233'; - const collectionEvm = evmCollection(web3, owner, collectionAddressWithBadPrefix); - const EXPECTED_ERROR = 'Contract is not an unique collection'; + const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233'; + const collectionEvm = evmCollection(web3, owner, collectionAddressForNonexistentCollection); + const EXPECTED_ERROR = 'Create collection handle error'; { const sponsor = await createEthAccountWithBalance(api, web3); await expect(collectionEvm.methods .setSponsor(sponsor) .call()).to.be.rejectedWith(EXPECTED_ERROR); - const sponsorCollection = evmCollection(web3, sponsor, collectionAddressWithBadPrefix); + const sponsorCollection = evmCollection(web3, sponsor, collectionAddressForNonexistentCollection); await expect(sponsorCollection.methods .confirmSponsorship() .call()).to.be.rejectedWith(EXPECTED_ERROR); -- gitstuff