git.delta.rocks / unique-network / refs/commits / 6b1c924f3c5d

difftreelog

CORE-345 Add check that contract is unique collection

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

3 files changed

modifiedpallets/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
+}
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
318 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 }
324
321 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)
modifiedtests/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);