difftreelog
CORE-345 Add check that contract is unique collection
in: master
3 files changed
pallets/common/src/eth.rsdiffbeforeafterboth38 H160(out)38 H160(out)39}39}4041pub fn is_collection(address: &H160) -> bool {42 address[0..16] == ETH_COLLECTION_PREFIX43}4044pallets/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.tsdiffbeforeafterboth--- 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);