git.delta.rocks / unique-network / refs/commits / cea54c5de896

difftreelog

Tests: move explicit solc calls to playgrounds

Andrey2022-10-07parent: #05841c0.patch.diff
in: master

4 files changed

modifiedtests/package.jsondiffbeforeafterboth
--- a/tests/package.json
+++ b/tests/package.json
@@ -32,6 +32,7 @@
     "testEthNesting": "mocha --timeout 9999999 -r ts-node/register './**/eth/nesting/**/*.test.ts'",
     "testEthFractionalizer": "mocha --timeout 9999999 -r ts-node/register './**/eth/fractionalizer/**/*.test.ts'",
     "testEthPayable": "mocha --timeout 9999999 -r ts-node/register './**/eth/payable.test.ts'",
+    "testEvmCoder": "mocha --timeout 9999999 -r ts-node/register './**/eth/evmCoder.test.ts'",
     "load": "mocha --timeout 9999999 -r ts-node/register './**/*.load.ts'",
     "loadTransfer": "ts-node src/transfer.nload.ts",
     "testCollision": "mocha --timeout 9999999 -r ts-node/register ./src/collision-tests/*.test.ts",
@@ -67,7 +68,7 @@
     "testAdminTransferAndBurn": "mocha --timeout 9999999 -r ts-node/register ./**/adminTransferAndBurn.test.ts",
     "testSetPermissions": "mocha --timeout 9999999 -r ts-node/register ./**/setPermissions.test.ts",
     "testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",
-    "testContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/contractSponsoring.test.ts",
+    "testContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/eth/contractSponsoring.test.ts",
     "testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",
     "testRemoveFromContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromContractAllowList.test.ts",
     "testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts",
modifiedtests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth
--- a/tests/src/eth/contractSponsoring.test.ts
+++ b/tests/src/eth/contractSponsoring.test.ts
@@ -15,7 +15,6 @@
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
 import {IKeyringPair} from '@polkadot/types/types';
-import * as solc from 'solc';
 import {EthUniqueHelper} from './util/playgrounds/unique.dev';
 import {itEth, expect, SponsoringMode, usingEthPlaygrounds} from '../eth/util/playgrounds';
 import {usingPlaygrounds} from '../util/playgrounds';
@@ -455,70 +454,44 @@
 describe('Sponsoring Fee Limit', () => {
   let donor: IKeyringPair;
   let alice: IKeyringPair;
-  let DEFAULT_GAS: number;
+  let testContract: CompiledContract;
 
-  function compileTestContract() {
+  async function compileTestContract(helper: EthUniqueHelper) {
     if (!testContract) {
-      const input = {
-        language: 'Solidity',
-        sources: {
-          ['TestContract.sol']: {
-            content:
-            `
-            // SPDX-License-Identifier: MIT
-            pragma solidity ^0.8.0;
-            
-            contract TestContract {
-              event Result(bool);
+      testContract = await helper.ethContract.compile(
+        'TestContract',
+        `
+        // SPDX-License-Identifier: MIT
+        pragma solidity ^0.8.0;
+        
+        contract TestContract {
+          event Result(bool);
 
-              function test(uint32 cycles) public {
-                uint256 counter = 0;
-                while(true) {
-                  counter ++;
-                  if (counter > cycles){
-                    break;
-                  }
-                }
-                emit Result(true);
+          function test(uint32 cycles) public {
+            uint256 counter = 0;
+            while(true) {
+              counter ++;
+              if (counter > cycles){
+                break;
               }
             }
-            `,
-          },
-        },
-        settings: {
-          outputSelection: {
-            '*': {
-              '*': ['*'],
-            },
-          },
-        },
-      };
-      const json = JSON.parse(solc.compile(JSON.stringify(input)));
-      const out = json.contracts['TestContract.sol']['TestContract'];
-  
-      testContract = {
-        abi: out.abi,
-        object: '0x' + out.evm.bytecode.object,
-      };
+            emit Result(true);
+          }
+        }
+      `,
+      );
     }
     return testContract;
   }
   
   async function deployTestContract(helper: EthUniqueHelper, owner: string) {
-    const web3 = helper.getWeb3();
-    const compiled = compileTestContract();
-    const testContract = new web3.eth.Contract(compiled.abi, undefined, {
-      data: compiled.object,
-      from: owner,
-      gas: DEFAULT_GAS,
-    });
-    return await testContract.deploy({data: compiled.object}).send({from: owner});
+    const compiled = await compileTestContract(helper);
+    return await helper.ethContract.deployByAbi(owner, compiled.abi, compiled.object);
   }
 
   before(async () => {
-    await usingEthPlaygrounds(async (helper, privateKey) => {
+    await usingEthPlaygrounds(async (_helper, privateKey) => {
       donor = privateKey('//Alice');
-      DEFAULT_GAS = helper.eth.DEFAULT_GAS;
     });
   });
 
@@ -526,10 +499,7 @@
     await usingPlaygrounds(async (helper) => {
       [alice] = await helper.arrange.createAccounts([1000n], donor);
     });
-  });
-
-  let testContract: CompiledContract;
-  
+  });  
 
 
   itEth('Default fee limit', async ({helper}) => {
addedtests/src/eth/evmCoder.test.tsdiffbeforeafterboth

no changes

deletedtests/src/evmCoder.test.tsdiffbeforeafterboth
--- a/tests/src/evmCoder.test.ts
+++ /dev/null
@@ -1,123 +0,0 @@
-// 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 {IKeyringPair} from '@polkadot/types/types';
-import Web3 from 'web3';
-import {itEth, expect, usingEthPlaygrounds} from './eth/util/playgrounds';
-import * as solc from 'solc';
-
-async function compileTestContract(collectionAddress: string, contractAddress: string) {
-  const input = {
-    language: 'Solidity',
-    sources: {
-      ['Test.sol']: {
-        content: 
-        `
-        // SPDX-License-Identifier: MIT
-        pragma solidity ^0.8.0;
-        interface ITest {
-          function ztestzzzzzzz() external returns (uint256 n);
-        }
-        contract Test {
-          event Result(bool, uint256);
-          function test1() public {
-              try
-                  ITest(${collectionAddress}).ztestzzzzzzz()
-              returns (uint256 n) {
-                  // enters
-                  emit Result(true, n); // => [true, BigNumber { value: "43648854190028290368124427828690944273759144372138548774646036134290060795932" }]
-              } catch {
-                  emit Result(false, 0);
-              }
-          }
-          function test2() public {
-              try
-                  ITest(${contractAddress}).ztestzzzzzzz()
-              returns (uint256 n) {
-                  emit Result(true, n);
-              } catch {
-                  // enters
-                  emit Result(false, 0); // => [ false, BigNumber { value: "0" } ]
-              }
-          }
-          function test3() public {
-            ITest(${collectionAddress}).ztestzzzzzzz();
-          }
-        }
-        `,
-      },
-    },
-    settings: {
-      outputSelection: {
-        '*': {
-          '*': ['*'],
-        },
-      },
-    },
-  };
-  const json = JSON.parse(solc.compile(JSON.stringify(input)));
-  const out = json.contracts['Test.sol']['Test'];
-
-  return  {
-    abi: out.abi,
-    object: '0x' + out.evm.bytecode.object,
-  };
-}
-
-async function deployTestContract(web3: Web3, owner: string, collectionAddress: string, contractAddress: string, gas: number) {
-  const compiled = await compileTestContract(collectionAddress, contractAddress);
-  const fractionalizerContract = new web3.eth.Contract(compiled.abi, undefined, {
-    data: compiled.object,
-    from: owner,
-    gas,
-  });
-  return await fractionalizerContract.deploy({data: compiled.object}).send({from: owner});
-}
-
-describe('Evm Coder tests', () => {
-  let donor: IKeyringPair;
-
-  before(async function() {
-    await usingEthPlaygrounds(async (_helper, privateKey) => {
-      donor = privateKey('//Alice');
-    });
-  });
-  
-  itEth('Call non-existing function', async ({helper}) => {
-    const owner = await helper.eth.createAccountWithBalance(donor);
-    const collection = await helper.eth.createNonfungibleCollection(owner, 'EVMCODER', '', 'TEST');
-    const contract = await deployTestContract(helper.getWeb3(), owner, collection.collectionAddress, '0x1bfed5D614b886b9Ab2eA4CBAc22A96B7EC29c9c', helper.eth.DEFAULT_GAS);
-    const testContract = await deployTestContract(helper.getWeb3(), owner, collection.collectionAddress, contract.options.address, helper.eth.DEFAULT_GAS);
-    {
-      const result = await testContract.methods.test1().send();
-      expect(result.events.Result.returnValues).to.deep.equal({
-        '0': false,
-        '1': '0',
-      });
-    }
-    {
-      const result = await testContract.methods.test2().send();
-      expect(result.events.Result.returnValues).to.deep.equal({
-        '0': false,
-        '1': '0',
-      });
-    }
-    {
-      await expect(testContract.methods.test3().call())
-        .to.be.rejectedWith(/unrecognized selector: 0xd9f02b36$/g);
-    }
-  });
-});