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.rsdiffbeforeafterboth318 input: &[u8],318 input: &[u8],319 value: sp_core::U256,319 value: sp_core::U256,320 ) -> Option<PrecompileResult> {320 ) -> Option<PrecompileResult> {321 if !pallet_common::eth::is_collection(target) {322 return None;323 }324321 let helpers = EvmCollection::<T>(Rc::new(SubstrateRecorder::<T>::new(*target, gas_left)));325 let helpers = EvmCollection::<T>(Rc::new(SubstrateRecorder::<T>::new(*target, gas_left)));322 pallet_evm_coder_substrate::call(*source, helpers, value, input)326 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);