git.delta.rocks / unique-network / refs/commits / 3c77c1e2ea04

difftreelog

tests: eth_getCode

Max Andreev2023-01-13parent: #48a519d.patch.diff
in: master

5 files changed

modifiedtests/src/apiConsts.test.tsdiffbeforeafterboth
--- a/tests/src/apiConsts.test.ts
+++ b/tests/src/apiConsts.test.ts
@@ -15,7 +15,7 @@
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
 import {ApiPromise} from '@polkadot/api';
-import {usingPlaygrounds, itSub, expect} from './util';
+import {usingPlaygrounds, itSub, expect, COLLECTION_HELPER, CONTRACT_HELPER} from './util';
 
 
 const MAX_COLLECTION_DESCRIPTION_LENGTH = 256n;
@@ -40,9 +40,6 @@
   ownerCanDestroy: true,
   transfersEnabled: true,
 };
-
-const EVM_COLLECTION_HELPERS_ADDRESS = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';
-const HELPERS_CONTRACT_ADDRESS = '0x842899ECF380553E8a4de75bF534cdf6fBF64049';
 
 describe('integration test: API UNIQUE consts', () => {
   let api: ApiPromise;
@@ -106,11 +103,11 @@
   });
 
   itSub('HELPERS_CONTRACT_ADDRESS', () => {
-    expect(api.consts.evmContractHelpers.contractAddress.toString().toLowerCase()).to.be.equal(HELPERS_CONTRACT_ADDRESS.toLowerCase());
+    expect(api.consts.evmContractHelpers.contractAddress.toString().toLowerCase()).to.be.equal(CONTRACT_HELPER.toLowerCase());
   });
 
   itSub('EVM_COLLECTION_HELPERS_ADDRESS', () => {
-    expect(api.consts.common.contractAddress.toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS.toLowerCase());
+    expect(api.consts.common.contractAddress.toString().toLowerCase()).to.be.equal(COLLECTION_HELPER.toLowerCase());
   });
 });
 
modifiedtests/src/eth/collectionHelperAddress.test.tsdiffbeforeafterboth
before · tests/src/eth/collectionHelperAddress.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {itEth, usingEthPlaygrounds, expect} from './util';18import {IKeyringPair} from '@polkadot/types/types';19import {Pallets} from '../util';2021const EVM_COLLECTION_HELPERS_ADDRESS = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';2223describe('[eth]CollectionHelperAddress test: ERC20/ERC721 ', () => {24  let donor: IKeyringPair;2526  before(async function() {27    await usingEthPlaygrounds(async (helper, privateKey) => {28      donor = await privateKey({filename: __filename});29    });30  });3132  itEth('NFT', async ({helper}) => {33    const owner =  await helper.eth.createAccountWithBalance(donor);3435    const {collectionAddress: nftCollectionAddress} = await helper.eth.createNFTCollection(owner, 'Sponsor', 'absolutely anything', 'ROC');36    const nftCollection = await helper.ethNativeContract.collection(nftCollectionAddress, 'nft', owner);3738    expect((await nftCollection.methods.collectionHelperAddress().call())39      .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);40  });4142  itEth.ifWithPallets('RFT ', [Pallets.ReFungible], async ({helper}) => {43    const owner =  await helper.eth.createAccountWithBalance(donor);4445    const {collectionAddress: rftCollectionAddress} = await helper.eth.createRFTCollection(owner, 'Sponsor', 'absolutely anything', 'ROC');4647    const rftCollection = await helper.ethNativeContract.collection(rftCollectionAddress, 'rft', owner);48    expect((await rftCollection.methods.collectionHelperAddress().call())49      .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);50  });5152  itEth('FT', async ({helper}) => {53    const owner = await helper.eth.createAccountWithBalance(donor);5455    const {collectionAddress} = await helper.eth.createFungibleCollection(owner, 'Sponsor', 18, 'absolutely anything', 'ROC');56    const collection = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);5758    expect((await collection.methods.collectionHelperAddress().call())59      .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);60  });6162  itEth('[collectionHelpers] convert collectionId into address', async ({helper}) => {63    const owner = await helper.eth.createAccountWithBalance(donor);64    const collectionId = 7;65    const collectionAddress = helper.ethAddress.fromCollectionId(collectionId);66    const helperContract = await helper.ethNativeContract.collectionHelpers(owner);6768    expect(await helperContract.methods.collectionAddress(collectionId).call()).to.be.equal(collectionAddress);69    expect(parseInt(await helperContract.methods.collectionId(collectionAddress).call())).to.be.equal(collectionId);70  });7172});
after · tests/src/eth/collectionHelperAddress.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {itEth, usingEthPlaygrounds, expect} from './util';18import {IKeyringPair} from '@polkadot/types/types';19import {COLLECTION_HELPER, Pallets} from '../util';2021describe('[eth]CollectionHelperAddress test: ERC20/ERC721 ', () => {22  let donor: IKeyringPair;2324  before(async function() {25    await usingEthPlaygrounds(async (helper, privateKey) => {26      donor = await privateKey({filename: __filename});27    });28  });2930  itEth('NFT', async ({helper}) => {31    const owner =  await helper.eth.createAccountWithBalance(donor);3233    const {collectionAddress: nftCollectionAddress} = await helper.eth.createNFTCollection(owner, 'Sponsor', 'absolutely anything', 'ROC');34    const nftCollection = await helper.ethNativeContract.collection(nftCollectionAddress, 'nft', owner);3536    expect((await nftCollection.methods.collectionHelperAddress().call())37      .toString().toLowerCase()).to.be.equal(COLLECTION_HELPER);38  });3940  itEth.ifWithPallets('RFT ', [Pallets.ReFungible], async ({helper}) => {41    const owner =  await helper.eth.createAccountWithBalance(donor);4243    const {collectionAddress: rftCollectionAddress} = await helper.eth.createRFTCollection(owner, 'Sponsor', 'absolutely anything', 'ROC');4445    const rftCollection = await helper.ethNativeContract.collection(rftCollectionAddress, 'rft', owner);46    expect((await rftCollection.methods.collectionHelperAddress().call())47      .toString().toLowerCase()).to.be.equal(COLLECTION_HELPER);48  });4950  itEth('FT', async ({helper}) => {51    const owner = await helper.eth.createAccountWithBalance(donor);5253    const {collectionAddress} = await helper.eth.createFungibleCollection(owner, 'Sponsor', 18, 'absolutely anything', 'ROC');54    const collection = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);5556    expect((await collection.methods.collectionHelperAddress().call())57      .toString().toLowerCase()).to.be.equal(COLLECTION_HELPER);58  });5960  itEth('[collectionHelpers] convert collectionId into address', async ({helper}) => {61    const owner = await helper.eth.createAccountWithBalance(donor);62    const collectionId = 7;63    const collectionAddress = helper.ethAddress.fromCollectionId(collectionId);64    const helperContract = await helper.ethNativeContract.collectionHelpers(owner);6566    expect(await helperContract.methods.collectionAddress(collectionId).call()).to.be.equal(collectionAddress);67    expect(parseInt(await helperContract.methods.collectionId(collectionAddress).call())).to.be.equal(collectionId);68  });6970});
modifiedtests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth
--- a/tests/src/eth/createNFTCollection.test.ts
+++ b/tests/src/eth/createNFTCollection.test.ts
@@ -18,6 +18,7 @@
 import {IKeyringPair} from '@polkadot/types/types';
 import {expect, itEth, usingEthPlaygrounds} from './util';
 import {CollectionLimitField} from './util/playgrounds/types';
+import {COLLECTION_HELPER} from '../util';
 
 
 describe('Create NFT collection from EVM', () => {
@@ -42,7 +43,7 @@
 
     expect(events).to.be.deep.equal([
       {
-        address: '0x6C4E9fE1AE37a41E93CEE429e8E1881aBdcbb54F',
+        address: COLLECTION_HELPER,
         event: 'CollectionCreated',
         args: {
           owner: owner,
addedtests/src/eth/getCode.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/eth/getCode.test.ts
@@ -0,0 +1,53 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {expect, itEth, usingEthPlaygrounds} from './util';
+import {IKeyringPair} from '@polkadot/types/types';
+import {COLLECTION_HELPER, CONTRACT_HELPER} from '../util';
+
+describe('RPC eth_getCode', () => {
+  let donor: IKeyringPair;
+
+  before(async function() {
+    await usingEthPlaygrounds(async (helper, privateKey) => {
+      donor = await privateKey({filename: __filename});
+    });
+  });
+
+  [
+    {address: COLLECTION_HELPER, expectedCode: '0x60e0604052602660808181529061073160a03960019061001f90826100d1565b5034801561002c57600080fd5b50610190565b634e487b7160e01b600052604160045260246000fd5b600181811c9082168061005c57607f821691505b60208210810361007c57634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156100cc57600081815260208120601f850160051c810160208610156100a95750805b601f850160051c820191505b818110156100c8578281556001016100b5565b5050505b505050565b81516001600160401b038111156100ea576100ea610032565b6100fe816100f88454610048565b84610082565b602080601f831160018114610133576000841561011b5750858301515b600019600386901b1c1916600185901b1785556100c8565b600085815260208120601f198616915b8281101561016257888601518255948401946001909101908401610143565b50858210156101805787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b6105928061019f6000396000f3fe6080604052600436106100915760003560e01c80638562425811610059578063856242581461013c578063ab1734501461012e578063b5cb749814610157578063c3de149414610187578063d23a7ab1146101a257600080fd5b806301ffc9a7146100965780632e716683146100cb578063564e321f146100fe5780637335b79f14610120578063844af6581461012e575b600080fd5b3480156100a257600080fd5b506100b66100b1366004610206565b6101c5565b60405190151581526020015b60405180910390f35b3480156100d757600080fd5b506100e66100b1366004610237565b6040516001600160a01b0390911681526020016100c2565b34801561010a57600080fd5b5061011e610119366004610279565b6101eb565b005b6100e66100b1366004610337565b6100e66100b13660046103da565b34801561014857600080fd5b5061011e610119366004610462565b34801561016357600080fd5b506101726100b1366004610279565b60405163ffffffff90911681526020016100c2565b34801561019357600080fd5b506100b66100b1366004610279565b3480156101ae57600080fd5b506101b76101c5565b6040519081526020016100c2565b6000600160405162461bcd60e51b81526004016101e291906104b0565b60405180910390fd5b600160405162461bcd60e51b81526004016101e291906104b0565b60006020828403121561021857600080fd5b81356001600160e01b03198116811461023057600080fd5b9392505050565b60006020828403121561024957600080fd5b813563ffffffff8116811461023057600080fd5b80356001600160a01b038116811461027457600080fd5b919050565b60006020828403121561028b57600080fd5b6102308261025d565b634e487b7160e01b600052604160045260246000fd5b600082601f8301126102bb57600080fd5b813567ffffffffffffffff808211156102d6576102d6610294565b604051601f8301601f19908116603f011681019082821181831017156102fe576102fe610294565b8160405283815286602085880101111561031757600080fd5b836020870160208301376000602085830101528094505050505092915050565b6000806000806080858703121561034d57600080fd5b843567ffffffffffffffff8082111561036557600080fd5b610371888389016102aa565b95506020870135915060ff8216821461038957600080fd5b9093506040860135908082111561039f57600080fd5b6103ab888389016102aa565b935060608701359150808211156103c157600080fd5b506103ce878288016102aa565b91505092959194509250565b6000806000606084860312156103ef57600080fd5b833567ffffffffffffffff8082111561040757600080fd5b610413878388016102aa565b9450602086013591508082111561042957600080fd5b610435878388016102aa565b9350604086013591508082111561044b57600080fd5b50610458868287016102aa565b9150509250925092565b6000806040838503121561047557600080fd5b61047e8361025d565b9150602083013567ffffffffffffffff81111561049a57600080fd5b6104a6858286016102aa565b9150509250929050565b600060208083526000845481600182811c9150808316806104d257607f831692505b85831081036104ef57634e487b7160e01b85526022600452602485fd5b87860183815260200181801561050c57600181146105225761054d565b60ff198616825284151560051b8201965061054d565b60008b81526020902060005b868110156105475781548482015290850190890161052e565b83019750505b5094999850505050505050505056fea2646970667358221220a43ca09fe677b7ab611be4b7ea2ed7e656ade53b3d1252c653ff4a84b36d3c3064736f6c634300081000337468697320636f6e747261637420697320696d706c656d656e74656420696e206e6174697665'},
+    {address: CONTRACT_HELPER, expectedCode: '0x60e0604052602660808181529061073060a03960019061001f90826100d1565b5034801561002c57600080fd5b50610190565b634e487b7160e01b600052604160045260246000fd5b600181811c9082168061005c57607f821691505b60208210810361007c57634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156100cc57600081815260208120601f850160051c810160208610156100a95750805b601f850160051c820191505b818110156100c8578281556001016100b5565b5050505b505050565b81516001600160401b038111156100ea576100ea610032565b6100fe816100f88454610048565b84610082565b602080601f831160018114610133576000841561011b5750858301515b600019600386901b1c1916600185901b1785556100c8565b600085815260208120601f198616915b8281101561016257888601518255948401946001909101908401610143565b50858210156101805787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b6105918061019f6000396000f3fe608060405234801561001057600080fd5b50600436106101215760003560e01c8063766c4f37116100ad578063c772ef6c11610071578063c772ef6c14610171578063ef7842501461022d578063f01fba931461023b578063f29694d814610249578063fde8a5601461026c57600080fd5b8063766c4f37146101dd57806377b6c9081461021f57806389f7d9ae1461022d5780639741860314610171578063abc000011461022d57600080fd5b80634706cc1c116100f45780634706cc1c1461017f5780635152b14c1461018d5780635c658165146101b35780636027dc611461017157806375b73606146101c157600080fd5b806301ffc9a71461012657806303aed6651461014e57806336de20f51461016357806339b9b24214610171575b600080fd5b6101396101343660046102fd565b61027a565b60405190151581526020015b60405180910390f35b61016161015c36600461034a565b6102a0565b005b61016161015c366004610384565b6101396101343660046103b7565b61016161015c3660046103d2565b61019b6101343660046103b7565b6040516001600160a01b039091168152602001610145565b610139610134366004610415565b6101cf6101343660046103b7565b604051908152602001610145565b6101f06101eb3660046103b7565b6102bb565b6040805182511515815260209283015180516001600160a01b0316848301529092015190820152606001610145565b61016161015c36600461043f565b61016161015c3660046103b7565b61016161015c366004610415565b6102576101343660046103b7565b60405163ffffffff9091168152602001610145565b61016161015c36600461047f565b6000600160405162461bcd60e51b815260040161029791906104af565b60405180910390fd5b600160405162461bcd60e51b815260040161029791906104af565b6102a060405180604001604052806000151581526020016102f8604051806040016040528060006001600160a01b03168152602001600081525090565b905290565b60006020828403121561030f57600080fd5b81356001600160e01b03198116811461032757600080fd5b9392505050565b80356001600160a01b038116811461034557600080fd5b919050565b6000806040838503121561035d57600080fd5b6103668361032e565b946020939093013593505050565b8035801515811461034557600080fd5b6000806040838503121561039757600080fd5b6103a08361032e565b91506103ae60208401610374565b90509250929050565b6000602082840312156103c957600080fd5b6103278261032e565b6000806000606084860312156103e757600080fd5b6103f08461032e565b92506103fe6020850161032e565b915061040c60408501610374565b90509250925092565b6000806040838503121561042857600080fd5b6104318361032e565b91506103ae6020840161032e565b6000806040838503121561045257600080fd5b61045b8361032e565b9150602083013563ffffffff8116811461047457600080fd5b809150509250929050565b6000806040838503121561049257600080fd5b61049b8361032e565b915060208301356003811061047457600080fd5b600060208083526000845481600182811c9150808316806104d157607f831692505b85831081036104ee57634e487b7160e01b85526022600452602485fd5b87860183815260200181801561050b57600181146105215761054c565b60ff198616825284151560051b8201965061054c565b60008b81526020902060005b868110156105465781548482015290850190890161052d565b83019750505b5094999850505050505050505056fea264697066735822122063505542f1c4602234fba58885c20aae30258ff8096b7f974a5563c90ad4a6c464736f6c634300081000337468697320636f6e747261637420697320696d706c656d656e74656420696e206e6174697665'},
+  ].map(testCase => {
+    itEth(`returns value for native contract: ${testCase.address}`, async ({helper}) => {
+      const contractCodeSub = (await helper.callRpc('api.rpc.eth.getCode', [testCase.address])).toJSON();
+      const contractCodeEth = (await helper.getWeb3().eth.getCode(testCase.address));
+
+      expect(contractCodeSub).to.eq(testCase.expectedCode);
+      expect(contractCodeEth).to.eq(testCase.expectedCode);
+    });
+  });
+
+  itEth('returns value for custom contract', async ({helper}) => {
+    const signer = await helper.eth.createAccountWithBalance(donor);
+    const flipper = await helper.eth.deployFlipper(signer);
+
+    const contractCodeSub = (await helper.callRpc('api.rpc.eth.getCode', [flipper.options.address])).toJSON();
+    const contractCodeEth = (await helper.getWeb3().eth.getCode(flipper.options.address));
+
+    expect(contractCodeSub).to.eq('0x6080604052348015600f57600080fd5b506004361060325760003560e01c806320965255146037578063cde4efa9146051575b600080fd5b603d6059565b6040516048919060b1565b60405180910390f35b6057606f565b005b60008060009054906101000a900460ff16905090565b60008054906101000a900460ff16156000806101000a81548160ff021916908315150217905550565b60008115159050919050565b60ab816098565b82525050565b600060208201905060c4600083018460a4565b9291505056fea264697066735822122077b6e0181f948cf0762391122339dd11290f54d8fd71596e8fe216ba8577e9f164736f6c63430008110033');
+    expect(contractCodeEth).to.eq('0x6080604052348015600f57600080fd5b506004361060325760003560e01c806320965255146037578063cde4efa9146051575b600080fd5b603d6059565b6040516048919060b1565b60405180910390f35b6057606f565b005b60008060009054906101000a900460ff16905090565b60008054906101000a900460ff16156000806101000a81548160ff021916908315150217905550565b60008115159050919050565b60ab816098565b82525050565b600060208201905060c4600083018460a4565b9291505056fea264697066735822122077b6e0181f948cf0762391122339dd11290f54d8fd71596e8fe216ba8577e9f164736f6c63430008110033');
+  });
+});
modifiedtests/src/util/index.tsdiffbeforeafterboth
--- a/tests/src/util/index.ts
+++ b/tests/src/util/index.ts
@@ -100,6 +100,9 @@
 export const LOCKING_PERIOD = 12n; // 12 blocks of relay
 export const UNLOCKING_PERIOD = 6n; // 6 blocks of parachain
 
+// Native contracts
+export const COLLECTION_HELPER = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';
+export const CONTRACT_HELPER = '0x842899ECF380553E8a4de75bF534cdf6fBF64049';
 
 export enum Pallets {
   Inflation = 'inflation',