difftreelog
CORE-345 Add check that contract is unique collection
in: master
3 files changed
pallets/common/src/eth.rsdiffbeforeafterboth--- 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
+}
pallets/unique/src/eth/mod.rsdiffbeforeafterboth--- 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<PrecompileResult> {
+ if !pallet_common::eth::is_collection(target) {
+ return None;
+ }
+
let helpers = EvmCollection::<T>(Rc::new(SubstrateRecorder::<T>::new(*target, gas_left)));
pallet_evm_coder_substrate::call(*source, helpers, value, input)
}
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';343535async function getCollectionAddressFromResult(api: ApiPromise, result: any) {36async function getCollectionAddressFromResult(api: ApiPromise, result: any) {36 const collectionIdAddress = normalizeAddress(result.events[0].raw.topics[2]);37 const collectionIdAddress = normalizeAddress(result.events[0].raw.topics[2]);201 .call()).to.be.rejectedWith('NotSufficientFounds');202 .call()).to.be.rejectedWith('NotSufficientFounds');202 });203 });203204204 itWeb3('(!negative test!) Collection address (Contract is not an unique collection)', async ({api, web3}) => {205 itWeb3('(!negative test!) Collection address (Create collection handle error)', async ({api, web3}) => {205 const owner = await createEthAccountWithBalance(api, web3);206 const owner = await createEthAccountWithBalance(api, web3);206 const collectionAddressWithBadPrefix = '0x00112233445566778899AABBCCDDEEFF00112233';207 const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233';207 const collectionEvm = evmCollection(web3, owner, collectionAddressWithBadPrefix);208 const collectionEvm = evmCollection(web3, owner, collectionAddressForNonexistentCollection);208 const EXPECTED_ERROR = 'Contract is not an unique collection';209 const EXPECTED_ERROR = 'Create collection handle error';209 {210 {210 const sponsor = await createEthAccountWithBalance(api, web3);211 const sponsor = await createEthAccountWithBalance(api, web3);211 await expect(collectionEvm.methods212 await expect(collectionEvm.methods212 .setSponsor(sponsor)213 .setSponsor(sponsor)213 .call()).to.be.rejectedWith(EXPECTED_ERROR);214 .call()).to.be.rejectedWith(EXPECTED_ERROR);214 215 215 const sponsorCollection = evmCollection(web3, sponsor, collectionAddressWithBadPrefix);216 const sponsorCollection = evmCollection(web3, sponsor, collectionAddressForNonexistentCollection);216 await expect(sponsorCollection.methods217 await expect(sponsorCollection.methods217 .confirmSponsorship()218 .confirmSponsorship()218 .call()).to.be.rejectedWith(EXPECTED_ERROR);219 .call()).to.be.rejectedWith(EXPECTED_ERROR);