difftreelog
Merge pull request #603 from UniqueNetwork/tests/finish-refactoring-base-folder
in: master
8 files changed
tests/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 () => {
tests/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]);
});
});
tests/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;
});
});
tests/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) => {
tests/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) => {
tests/src/evmCoder.test.tsdiffbeforeafterboth1// 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 Web3 from 'web3';18import {createEthAccountWithBalance, createNonfungibleCollection, GAS_ARGS, itWeb3} from './eth/util/helpers';19import * as solc from 'solc';2021import chai from 'chai';22const expect = chai.expect;2324async function compileTestContract(collectionAddress: string, contractAddress: string) {25 const input = {26 language: 'Solidity',27 sources: {28 ['Test.sol']: {29 content: 30 `31 // SPDX-License-Identifier: MIT32 pragma solidity ^0.8.0;33 interface ITest {34 function ztestzzzzzzz() external returns (uint256 n);35 }36 contract Test {37 event Result(bool, uint256);38 function test1() public {39 try40 ITest(${collectionAddress}).ztestzzzzzzz()41 returns (uint256 n) {42 // enters43 emit Result(true, n); // => [true, BigNumber { value: "43648854190028290368124427828690944273759144372138548774646036134290060795932" }]44 } catch {45 emit Result(false, 0);46 }47 }48 function test2() public {49 try50 ITest(${contractAddress}).ztestzzzzzzz()51 returns (uint256 n) {52 emit Result(true, n);53 } catch {54 // enters55 emit Result(false, 0); // => [ false, BigNumber { value: "0" } ]56 }57 }58 function test3() public {59 ITest(${collectionAddress}).ztestzzzzzzz();60 }61 }62 `,63 },64 },65 settings: {66 outputSelection: {67 '*': {68 '*': ['*'],69 },70 },71 },72 };73 const json = JSON.parse(solc.compile(JSON.stringify(input)));74 const out = json.contracts['Test.sol']['Test'];7576 return {77 abi: out.abi,78 object: '0x' + out.evm.bytecode.object,79 };80}8182async function deployTestContract(web3: Web3, owner: string, collectionAddress: string, contractAddress: string) {83 const compiled = await compileTestContract(collectionAddress, contractAddress);84 const fractionalizerContract = new web3.eth.Contract(compiled.abi, undefined, {85 data: compiled.object,86 from: owner,87 ...GAS_ARGS,88 });89 return await fractionalizerContract.deploy({data: compiled.object}).send({from: owner});90}9192describe('Evm Coder tests', () => {93 itWeb3('Call non-existing function', async ({api, web3, privateKeyWrapper}) => {94 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);95 const {collectionIdAddress} = await createNonfungibleCollection(api, web3, owner);96 const contract = await deployTestContract(web3, owner, collectionIdAddress, '0x1bfed5D614b886b9Ab2eA4CBAc22A96B7EC29c9c');97 const testContract = await deployTestContract(web3, owner, collectionIdAddress, contract.options.address);98 {99 const result = await testContract.methods.test1().send();100 expect(result.events.Result.returnValues).to.deep.equal({101 '0': false,102 '1': '0',103 });104 }105 {106 const result = await testContract.methods.test2().send();107 expect(result.events.Result.returnValues).to.deep.equal({108 '0': false,109 '1': '0',110 });111 }112 {113 await expect(testContract.methods.test3().call())114 .to.be.rejectedWith(/unrecognized selector: 0xd9f02b36$/g);115 }116 });117});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 {IKeyringPair} from '@polkadot/types/types';18import Web3 from 'web3';19import {itEth, expect, usingEthPlaygrounds} from './eth/util/playgrounds';20import * as solc from 'solc';2122async function compileTestContract(collectionAddress: string, contractAddress: string) {23 const input = {24 language: 'Solidity',25 sources: {26 ['Test.sol']: {27 content: 28 `29 // SPDX-License-Identifier: MIT30 pragma solidity ^0.8.0;31 interface ITest {32 function ztestzzzzzzz() external returns (uint256 n);33 }34 contract Test {35 event Result(bool, uint256);36 function test1() public {37 try38 ITest(${collectionAddress}).ztestzzzzzzz()39 returns (uint256 n) {40 // enters41 emit Result(true, n); // => [true, BigNumber { value: "43648854190028290368124427828690944273759144372138548774646036134290060795932" }]42 } catch {43 emit Result(false, 0);44 }45 }46 function test2() public {47 try48 ITest(${contractAddress}).ztestzzzzzzz()49 returns (uint256 n) {50 emit Result(true, n);51 } catch {52 // enters53 emit Result(false, 0); // => [ false, BigNumber { value: "0" } ]54 }55 }56 function test3() public {57 ITest(${collectionAddress}).ztestzzzzzzz();58 }59 }60 `,61 },62 },63 settings: {64 outputSelection: {65 '*': {66 '*': ['*'],67 },68 },69 },70 };71 const json = JSON.parse(solc.compile(JSON.stringify(input)));72 const out = json.contracts['Test.sol']['Test'];7374 return {75 abi: out.abi,76 object: '0x' + out.evm.bytecode.object,77 };78}7980async function deployTestContract(web3: Web3, owner: string, collectionAddress: string, contractAddress: string, gas: number) {81 const compiled = await compileTestContract(collectionAddress, contractAddress);82 const fractionalizerContract = new web3.eth.Contract(compiled.abi, undefined, {83 data: compiled.object,84 from: owner,85 gas,86 });87 return await fractionalizerContract.deploy({data: compiled.object}).send({from: owner});88}8990describe('Evm Coder tests', () => {91 let donor: IKeyringPair;9293 before(async function() {94 await usingEthPlaygrounds(async (_helper, privateKey) => {95 donor = privateKey('//Alice');96 });97 });98 99 itEth('Call non-existing function', async ({helper}) => {100 const owner = await helper.eth.createAccountWithBalance(donor);101 const collection = await helper.eth.createNonfungibleCollection(owner, 'EVMCODER', '', 'TEST');102 const contract = await deployTestContract(helper.getWeb3(), owner, collection.collectionAddress, '0x1bfed5D614b886b9Ab2eA4CBAc22A96B7EC29c9c', helper.eth.DEFAULT_GAS);103 const testContract = await deployTestContract(helper.getWeb3(), owner, collection.collectionAddress, contract.options.address, helper.eth.DEFAULT_GAS);104 {105 const result = await testContract.methods.test1().send();106 expect(result.events.Result.returnValues).to.deep.equal({107 '0': false,108 '1': '0',109 });110 }111 {112 const result = await testContract.methods.test2().send();113 expect(result.events.Result.returnValues).to.deep.equal({114 '0': false,115 '1': '0',116 });117 }118 {119 await expect(testContract.methods.test3().call())120 .to.be.rejectedWith(/unrecognized selector: 0xd9f02b36$/g);121 }122 });123});tests/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) => {
tests/src/util/playgrounds/index.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/index.ts
+++ b/tests/src/util/playgrounds/index.ts
@@ -13,14 +13,14 @@
chai.use(chaiAsPromised);
export const expect = chai.expect;
-export const usingPlaygrounds = async (code: (helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {
+export const usingPlaygrounds = async (code: (helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>, url: string = config.substrateUrl) => {
const silentConsole = new SilentConsole();
silentConsole.enable();
const helper = new DevUniqueHelper(new SilentLogger());
try {
- await helper.connect(config.substrateUrl);
+ await helper.connect(url);
const ss58Format = helper.chain.getChainProperties().ss58Format;
const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);
await code(helper, privateKey);