difftreelog
Merge pull request #603 from UniqueNetwork/tests/finish-refactoring-base-folder
in: master
8 files changed
tests/src/addToContractAllowList.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 chai from 'chai';18import chaiAsPromised from 'chai-as-promised';19import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';20import {21 deployFlipper,22} from './util/contracthelpers';23import {24 getGenericResult,25} from './util/helpers';2627chai.use(chaiAsPromised);28const expect = chai.expect;2930describe.skip('Integration Test addToContractAllowList', () => {3132 it('Add an address to a contract allow list', async () => {33 await usingApi(async (api, privateKeyWrapper) => {34 const bob = privateKeyWrapper('//Bob');35 const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);3637 const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();38 const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);39 const addEvents = await submitTransactionAsync(deployer, addTx);40 const allowListedAfter = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();4142 expect(getGenericResult(addEvents).success).to.be.true;43 expect(allowListedBefore).to.be.false;44 expect(allowListedAfter).to.be.true;45 });46 });4748 it('Adding same address to allow list repeatedly should not produce errors', async () => {49 await usingApi(async (api, privateKeyWrapper) => {50 const bob = privateKeyWrapper('//Bob');51 const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);5253 const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();54 const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);55 const addEvents = await submitTransactionAsync(deployer, addTx);56 const allowListedAfter = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();57 const addAgainEvents = await submitTransactionAsync(deployer, addTx);58 const allowListedAgainAfter = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();5960 expect(getGenericResult(addEvents).success).to.be.true;61 expect(allowListedBefore).to.be.false;62 expect(allowListedAfter).to.be.true;63 expect(getGenericResult(addAgainEvents).success).to.be.true;64 expect(allowListedAgainAfter).to.be.true;65 });66 });67});6869describe.skip('Negative Integration Test addToContractAllowList', () => {7071 it('Add an address to a allow list of a non-contract', async () => {72 await usingApi(async (api, privateKeyWrapper) => {73 const alice = privateKeyWrapper('//Bob');74 const bob = privateKeyWrapper('//Bob');75 const charlieGuineaPig = privateKeyWrapper('//Charlie');7677 const allowListedBefore = (await api.query.unique.contractAllowList(charlieGuineaPig.address, bob.address)).toJSON();78 const addTx = api.tx.unique.addToContractAllowList(charlieGuineaPig.address, bob.address);79 await expect(submitTransactionExpectFailAsync(alice, addTx)).to.be.rejected;80 const allowListedAfter = (await api.query.unique.contractAllowList(charlieGuineaPig.address, bob.address)).toJSON();8182 expect(allowListedBefore).to.be.false;83 expect(allowListedAfter).to.be.false;84 });85 });8687 it('Add to a contract allow list using a non-owner address', async () => {88 await usingApi(async (api, privateKeyWrapper) => {89 const bob = privateKeyWrapper('//Bob');90 const [contract] = await deployFlipper(api, privateKeyWrapper);9192 const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();93 const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);94 await expect(submitTransactionExpectFailAsync(bob, addTx)).to.be.rejected;95 const allowListedAfter = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();9697 expect(allowListedBefore).to.be.false;98 expect(allowListedAfter).to.be.false;99 });100 });101102});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 chai from 'chai';18import chaiAsPromised from 'chai-as-promised';19import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';20import {21 deployFlipper,22} from './util/contracthelpers';23import {24 getGenericResult,25} from './util/helpers';2627chai.use(chaiAsPromised);28const expect = chai.expect;2930// todo:playgrounds skipped ~ postponed31describe.skip('Integration Test addToContractAllowList', () => {3233 it('Add an address to a contract allow list', async () => {34 await usingApi(async (api, privateKeyWrapper) => {35 const bob = privateKeyWrapper('//Bob');36 const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);3738 const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();39 const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);40 const addEvents = await submitTransactionAsync(deployer, addTx);41 const allowListedAfter = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();4243 expect(getGenericResult(addEvents).success).to.be.true;44 expect(allowListedBefore).to.be.false;45 expect(allowListedAfter).to.be.true;46 });47 });4849 it('Adding same address to allow list repeatedly should not produce errors', async () => {50 await usingApi(async (api, privateKeyWrapper) => {51 const bob = privateKeyWrapper('//Bob');52 const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);5354 const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();55 const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);56 const addEvents = await submitTransactionAsync(deployer, addTx);57 const allowListedAfter = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();58 const addAgainEvents = await submitTransactionAsync(deployer, addTx);59 const allowListedAgainAfter = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();6061 expect(getGenericResult(addEvents).success).to.be.true;62 expect(allowListedBefore).to.be.false;63 expect(allowListedAfter).to.be.true;64 expect(getGenericResult(addAgainEvents).success).to.be.true;65 expect(allowListedAgainAfter).to.be.true;66 });67 });68});6970describe.skip('Negative Integration Test addToContractAllowList', () => {7172 it('Add an address to a allow list of a non-contract', async () => {73 await usingApi(async (api, privateKeyWrapper) => {74 const alice = privateKeyWrapper('//Bob');75 const bob = privateKeyWrapper('//Bob');76 const charlieGuineaPig = privateKeyWrapper('//Charlie');7778 const allowListedBefore = (await api.query.unique.contractAllowList(charlieGuineaPig.address, bob.address)).toJSON();79 const addTx = api.tx.unique.addToContractAllowList(charlieGuineaPig.address, bob.address);80 await expect(submitTransactionExpectFailAsync(alice, addTx)).to.be.rejected;81 const allowListedAfter = (await api.query.unique.contractAllowList(charlieGuineaPig.address, bob.address)).toJSON();8283 expect(allowListedBefore).to.be.false;84 expect(allowListedAfter).to.be.false;85 });86 });8788 it('Add to a contract allow list using a non-owner address', async () => {89 await usingApi(async (api, privateKeyWrapper) => {90 const bob = privateKeyWrapper('//Bob');91 const [contract] = await deployFlipper(api, privateKeyWrapper);9293 const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();94 const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);95 await expect(submitTransactionExpectFailAsync(bob, addTx)).to.be.rejected;96 const allowListedAfter = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();9798 expect(allowListedBefore).to.be.false;99 expect(allowListedAfter).to.be.false;100 });101 });102103});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.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({
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);