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

difftreelog

Merge pull request #603 from UniqueNetwork/tests/finish-refactoring-base-folder

ut-akuznetsov2022-09-20parents: #2f6a65e #e876e8d.patch.diff
in: master

8 files changed

modifiedtests/src/addToContractAllowList.test.tsdiffbeforeafterboth
--- a/tests/src/addToContractAllowList.test.ts
+++ b/tests/src/addToContractAllowList.test.ts
@@ -27,6 +27,7 @@
 chai.use(chaiAsPromised);
 const expect = chai.expect;
 
+// todo:playgrounds skipped ~ postponed
 describe.skip('Integration Test addToContractAllowList', () => {
 
   it('Add an address to a contract allow list', async () => {
modifiedtests/src/block-production.test.tsdiffbeforeafterboth
--- a/tests/src/block-production.test.ts
+++ b/tests/src/block-production.test.ts
@@ -14,9 +14,8 @@
 // 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 usingApi from './substrate/substrate-api';
-import {expect} from 'chai';
 import {ApiPromise} from '@polkadot/api';
+import {expect, itSub} from './util/playgrounds';
 
 const BLOCK_TIME_MS = 12000;
 const TOLERANCE_MS = 3000;
@@ -37,10 +36,8 @@
 }
 
 describe('Block Production smoke test', () => {
-  it('Node produces new blocks', async () => {
-    await usingApi(async (api) => {
-      const blocks: number[] | undefined = await getBlocks(api);
-      expect(blocks[0]).to.be.lessThan(blocks[1]);
-    });
+  itSub('Node produces new blocks', async ({helper}) => {
+    const blocks: number[] | undefined = await getBlocks(helper.api!);
+    expect(blocks[0]).to.be.lessThan(blocks[1]);
   });
 });
modifiedtests/src/connection.test.tsdiffbeforeafterboth
--- a/tests/src/connection.test.ts
+++ b/tests/src/connection.test.ts
@@ -14,29 +14,19 @@
 // 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 usingApi from './substrate/substrate-api';
-import {WsProvider} from '@polkadot/api';
-import * as chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-
-chai.use(chaiAsPromised);
-
-const expect = chai.expect;
+import {itSub, expect, usingPlaygrounds} from './util/playgrounds';
 
 describe('Connection smoke test', () => {
-  it('Connection can be established', async () => {
-    await usingApi(async api => {
-      const health = await api.rpc.system.health();
-      expect(health).to.be.not.empty;
-    });
+  itSub('Connection can be established', async ({helper}) => {
+    const health = (await helper.callRpc('api.rpc.system.health')).toJSON();
+    expect(health).to.be.not.empty;
   });
 
   it('Cannot connect to 255.255.255.255', async () => {
-    const neverConnectProvider = new WsProvider('ws://255.255.255.255:9944');
     await expect((async () => {
-      await usingApi(async api => {
-        await api.rpc.system.health();
-      }, {provider: neverConnectProvider});
+      await usingPlaygrounds(async helper => {
+        await helper.callRpc('api.rpc.system.health');
+      }, 'ws://255.255.255.255:9944');
     })()).to.be.eventually.rejected;
   });
 });
modifiedtests/src/contracts.test.tsdiffbeforeafterboth
--- a/tests/src/contracts.test.ts
+++ b/tests/src/contracts.test.ts
@@ -47,6 +47,7 @@
 const gasLimit = 9000n * 1000000n;
 const marketContractAddress = '5CYN9j3YvRkqxewoxeSvRbhAym4465C57uMmX5j4yz99L5H6';
 
+// todo:playgrounds skipped ~ postponed
 describe.skip('Contracts', () => {
   it('Can deploy smart contract Flipper, instantiate it and call it\'s get and flip messages.', async () => {
     await usingApi(async (api, privateKeyWrapper) => {
modifiedtests/src/enableContractSponsoring.test.tsdiffbeforeafterboth
--- a/tests/src/enableContractSponsoring.test.ts
+++ b/tests/src/enableContractSponsoring.test.ts
@@ -29,6 +29,7 @@
 chai.use(chaiAsPromised);
 const expect = chai.expect;
 
+// todo:playgrounds skipped ~ postponed
 describe.skip('Integration Test enableContractSponsoring', () => {
   it('ensure tx fee is paid from endowment', async () => {
     await usingApi(async (api, privateKeyWrapper) => {
modifiedtests/src/evmCoder.test.tsdiffbeforeafterboth
--- a/tests/src/evmCoder.test.ts
+++ b/tests/src/evmCoder.test.ts
@@ -14,13 +14,11 @@
 // 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 {createEthAccountWithBalance, createNonfungibleCollection, GAS_ARGS, itWeb3} from './eth/util/helpers';
+import {itEth, expect, usingEthPlaygrounds} from './eth/util/playgrounds';
 import * as solc from 'solc';
 
-import chai from 'chai';
-const expect = chai.expect;
-
 async function compileTestContract(collectionAddress: string, contractAddress: string) {
   const input = {
     language: 'Solidity',
@@ -79,22 +77,30 @@
   };
 }
 
-async function deployTestContract(web3: Web3, owner: string, collectionAddress: string, contractAddress: string) {
+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_ARGS,
+    gas,
   });
   return await fractionalizerContract.deploy({data: compiled.object}).send({from: owner});
 }
 
 describe('Evm Coder tests', () => {
-  itWeb3('Call non-existing function', async ({api, web3, privateKeyWrapper}) => {
-    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
-    const {collectionIdAddress} = await createNonfungibleCollection(api, web3, owner);
-    const contract = await deployTestContract(web3, owner, collectionIdAddress, '0x1bfed5D614b886b9Ab2eA4CBAc22A96B7EC29c9c');
-    const testContract = await deployTestContract(web3, owner, collectionIdAddress, contract.options.address);
+  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({
modifiedtests/src/setContractSponsoringRateLimit.test.tsdiffbeforeafterboth
--- a/tests/src/setContractSponsoringRateLimit.test.ts
+++ b/tests/src/setContractSponsoringRateLimit.test.ts
@@ -25,7 +25,7 @@
   setContractSponsoringRateLimitExpectSuccess,
 } from './util/helpers';
 
-// todo:playgrounds postponed skipped test
+// todo:playgrounds skipped~postponed test
 describe.skip('Integration Test setContractSponsoringRateLimit', () => {
   it('ensure sponsored contract can\'t be called twice without pause for free', async () => {
     await usingApi(async (api, privateKeyWrapper) => {
modifiedtests/src/util/playgrounds/index.tsdiffbeforeafterboth
before · tests/src/util/playgrounds/index.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import {IKeyringPair} from '@polkadot/types/types';5import chai from 'chai';6import chaiAsPromised from 'chai-as-promised';7import {Context} from 'mocha';8import config from '../../config';9import '../../interfaces/augment-api-events';10import {DevUniqueHelper, SilentLogger, SilentConsole} from './unique.dev';111213chai.use(chaiAsPromised);14export const expect = chai.expect;1516export const usingPlaygrounds = async (code: (helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {17  const silentConsole = new SilentConsole();18  silentConsole.enable();1920  const helper = new DevUniqueHelper(new SilentLogger());2122  try {23    await helper.connect(config.substrateUrl);24    const ss58Format = helper.chain.getChainProperties().ss58Format;25    const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);26    await code(helper, privateKey);27  }28  finally {29    await helper.disconnect();30    silentConsole.disable();31  }32};3334export enum Pallets {35  Inflation = 'inflation',36  RmrkCore = 'rmrkcore',37  RmrkEquip = 'rmrkequip',38  ReFungible = 'refungible',39  Fungible = 'fungible',40  NFT = 'nonfungible',41  Scheduler = 'scheduler',42}4344export function requirePalletsOrSkip(test: Context, helper: DevUniqueHelper, requiredPallets: string[]) {45  const missingPallets = helper.fetchMissingPalletNames(requiredPallets);46    47  if (missingPallets.length > 0) {48    const skipMsg = `\tSkipping test '${test.test?.title}'.\n\tThe following pallets are missing:\n\t- ${missingPallets.join('\n\t- ')}`;49    console.warn('\x1b[38:5:208m%s\x1b[0m', skipMsg);50    test.skip();51  }52}5354export async function itSub(name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {55  (opts.only ? it.only : 56    opts.skip ? it.skip : it)(name, async function () {57    await usingPlaygrounds(async (helper, privateKey) => {58      if (opts.requiredPallets) {59        requirePalletsOrSkip(this, helper, opts.requiredPallets);60      }61      62      await cb({helper, privateKey});63    });64  });65}66itSub.only = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {only: true});67itSub.skip = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {skip: true});68itSub.ifWithPallets = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {requiredPallets: required});
after · tests/src/util/playgrounds/index.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import {IKeyringPair} from '@polkadot/types/types';5import chai from 'chai';6import chaiAsPromised from 'chai-as-promised';7import {Context} from 'mocha';8import config from '../../config';9import '../../interfaces/augment-api-events';10import {DevUniqueHelper, SilentLogger, SilentConsole} from './unique.dev';111213chai.use(chaiAsPromised);14export const expect = chai.expect;1516export const usingPlaygrounds = async (code: (helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>, url: string = config.substrateUrl) => {17  const silentConsole = new SilentConsole();18  silentConsole.enable();1920  const helper = new DevUniqueHelper(new SilentLogger());2122  try {23    await helper.connect(url);24    const ss58Format = helper.chain.getChainProperties().ss58Format;25    const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);26    await code(helper, privateKey);27  }28  finally {29    await helper.disconnect();30    silentConsole.disable();31  }32};3334export enum Pallets {35  Inflation = 'inflation',36  RmrkCore = 'rmrkcore',37  RmrkEquip = 'rmrkequip',38  ReFungible = 'refungible',39  Fungible = 'fungible',40  NFT = 'nonfungible',41  Scheduler = 'scheduler',42}4344export function requirePalletsOrSkip(test: Context, helper: DevUniqueHelper, requiredPallets: string[]) {45  const missingPallets = helper.fetchMissingPalletNames(requiredPallets);46    47  if (missingPallets.length > 0) {48    const skipMsg = `\tSkipping test '${test.test?.title}'.\n\tThe following pallets are missing:\n\t- ${missingPallets.join('\n\t- ')}`;49    console.warn('\x1b[38:5:208m%s\x1b[0m', skipMsg);50    test.skip();51  }52}5354export async function itSub(name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {55  (opts.only ? it.only : 56    opts.skip ? it.skip : it)(name, async function () {57    await usingPlaygrounds(async (helper, privateKey) => {58      if (opts.requiredPallets) {59        requirePalletsOrSkip(this, helper, opts.requiredPallets);60      }61      62      await cb({helper, privateKey});63    });64  });65}66itSub.only = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {only: true});67itSub.skip = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {skip: true});68itSub.ifWithPallets = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {requiredPallets: required});