difftreelog
tests: displace chai-expect header copypasta
in: master
15 files changed
tests/src/addCollectionAdmin.test.tsdiffbeforeafterboth--- a/tests/src/addCollectionAdmin.test.ts
+++ b/tests/src/addCollectionAdmin.test.ts
@@ -15,12 +15,7 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {IKeyringPair} from '@polkadot/types/types';
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-import {itSub, usingPlaygrounds} from './util/playgrounds';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
+import {itSub, usingPlaygrounds, expect} from './util/playgrounds';
describe('Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {
let donor: IKeyringPair;
tests/src/fungible.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 {IKeyringPair} from '@polkadot/types/types';18import {U128_MAX} from './util/helpers';19import {itSub, usingPlaygrounds, expect} from './util/playgrounds';2021// todo:playgrounds get rid of globals22let alice: IKeyringPair;23let bob: IKeyringPair;2425describe('integration test: Fungible functionality:', () => {26 before(async () => {27 await usingPlaygrounds(async (helper, privateKey) => {28 alice = privateKey('//Alice');29 bob = privateKey('//Bob');30 });31 });3233 itSub('Create fungible collection and token', async ({helper}) => {34 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'trest'});35 const defaultTokenId = await collection.getLastTokenId();36 expect(defaultTokenId).to.be.equal(0);3738 await collection.mint(alice, {Substrate: alice.address}, U128_MAX);39 const aliceBalance = await collection.getBalance({Substrate: alice.address});40 const itemCountAfter = await collection.getLastTokenId();4142 expect(itemCountAfter).to.be.equal(defaultTokenId);43 expect(aliceBalance).to.be.equal(U128_MAX);44 });45 46 itSub('RPC method tokenOnewrs for fungible collection and token', async ({helper, privateKey}) => {47 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};48 const facelessCrowd = Array(7).fill(0).map((_, i) => ({Substrate: privateKey(`//Alice+${i}`).address}));4950 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});5152 await collection.mint(alice, {Substrate: alice.address}, U128_MAX);5354 await collection.transfer(alice, {Substrate: bob.address}, 1000n);55 await collection.transfer(alice, ethAcc, 900n);56 57 for (let i = 0; i < 7; i++) {58 await collection.transfer(alice, facelessCrowd[i], 1n);59 } 6061 const owners = await collection.getTop10Owners();6263 // What to expect64 expect(owners).to.deep.include.members([{Substrate: alice.address}, ethAcc, {Substrate: bob.address}, ...facelessCrowd]);65 expect(owners.length).to.be.equal(10);66 67 const eleven = privateKey('//ALice+11');68 expect(await collection.transfer(alice, {Substrate: eleven.address}, 10n)).to.be.true;69 expect((await collection.getTop10Owners()).length).to.be.equal(10);70 });71 72 itSub('Transfer token', async ({helper}) => {73 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};74 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});75 await collection.mint(alice, {Substrate: alice.address}, 500n);7677 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(500n);78 expect(await collection.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;79 expect(await collection.transfer(alice, ethAcc, 140n)).to.be.true;8081 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(300n);82 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(60n);83 expect(await collection.getBalance(ethAcc)).to.be.equal(140n);8485 await expect(collection.transfer(alice, {Substrate: bob.address}, 350n)).to.eventually.be.rejected;86 });8788 itSub('Tokens multiple creation', async ({helper}) => {89 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});9091 await collection.mintWithOneOwner(alice, {Substrate: alice.address}, [92 {value: 500n},93 {value: 400n},94 {value: 300n},95 ]);9697 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1200n);98 });99100 itSub('Burn some tokens ', async ({helper}) => {101 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});102 await collection.mint(alice, {Substrate: alice.address}, 500n);103104 expect(await collection.isTokenExists(0)).to.be.true;105 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(500n);106 expect(await collection.burnTokens(alice, 499n)).to.be.true;107 expect(await collection.isTokenExists(0)).to.be.true;108 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1n);109 });110 111 itSub('Burn all tokens ', async ({helper}) => {112 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});113 await collection.mint(alice, {Substrate: alice.address}, 500n);114115 expect(await collection.isTokenExists(0)).to.be.true;116 expect(await collection.burnTokens(alice, 500n)).to.be.true;117 expect(await collection.isTokenExists(0)).to.be.true;118119 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(0n);120 expect(await collection.getTotalPieces()).to.be.equal(0n);121 });122123 itSub('Set allowance for token', async ({helper}) => {124 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});125 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};126 await collection.mint(alice, {Substrate: alice.address}, 100n);127128 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(100n);129 130 expect(await collection.approveTokens(alice, {Substrate: bob.address}, 60n)).to.be.true;131 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(60n);132 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(0n);133134 expect(await collection.transferFrom(bob, {Substrate: alice.address}, {Substrate: bob.address}, 20n)).to.be.true;135 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(80n);136 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(20n);137 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(40n);138139 await collection.burnTokensFrom(bob, {Substrate: alice.address}, 10n);140141 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(70n);142 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(30n);143 expect(await collection.transferFrom(bob, {Substrate: alice.address}, ethAcc, 10n)).to.be.true;144 expect(await collection.getBalance(ethAcc)).to.be.equal(10n);145 });146});tests/src/pallet-presence.test.tsdiffbeforeafterboth--- a/tests/src/pallet-presence.test.ts
+++ b/tests/src/pallet-presence.test.ts
@@ -14,8 +14,7 @@
// 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} from 'chai';
-import {itSub, usingPlaygrounds} from './util/playgrounds';
+import {itSub, usingPlaygrounds, expect} from './util/playgrounds';
// Pallets that must always be present
const requiredPallets = [
tests/src/refungible.test.tsdiffbeforeafterboth--- a/tests/src/refungible.test.ts
+++ b/tests/src/refungible.test.ts
@@ -15,12 +15,7 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {IKeyringPair} from '@polkadot/types/types';
-import {itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from './util/playgrounds';
-
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-chai.use(chaiAsPromised);
-const expect = chai.expect;
+import {itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds, expect} from './util/playgrounds';
let alice: IKeyringPair;
let bob: IKeyringPair;
tests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth--- a/tests/src/removeCollectionAdmin.test.ts
+++ b/tests/src/removeCollectionAdmin.test.ts
@@ -14,13 +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 chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
import {IKeyringPair} from '@polkadot/types/types';
-import {itSub, usingPlaygrounds} from './util/playgrounds';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
+import {itSub, usingPlaygrounds, expect} from './util/playgrounds';
describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {
let alice: IKeyringPair;
tests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth--- a/tests/src/removeCollectionSponsor.test.ts
+++ b/tests/src/removeCollectionSponsor.test.ts
@@ -14,13 +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 chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
import {IKeyringPair} from '@polkadot/types/types';
-import {itSub, usingPlaygrounds} from './util/playgrounds';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
+import {itSub, usingPlaygrounds, expect} from './util/playgrounds';
describe('integration test: ext. removeCollectionSponsor():', () => {
let donor: IKeyringPair;
tests/src/removeFromAllowList.test.tsdiffbeforeafterboth--- a/tests/src/removeFromAllowList.test.ts
+++ b/tests/src/removeFromAllowList.test.ts
@@ -14,13 +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 chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
import {IKeyringPair} from '@polkadot/types/types';
-import {itSub, usingPlaygrounds} from './util/playgrounds';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
+import {itSub, usingPlaygrounds, expect} from './util/playgrounds';
describe('Integration Test removeFromAllowList', () => {
let alice: IKeyringPair;
tests/src/rpc.test.tsdiffbeforeafterboth--- a/tests/src/rpc.test.ts
+++ b/tests/src/rpc.test.ts
@@ -1,11 +1,22 @@
+// 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 chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-import {usingPlaygrounds, itSub} from './util/playgrounds';
+import {usingPlaygrounds, itSub, expect} from './util/playgrounds';
import {crossAccountIdFromLower} from './util/playgrounds/unique';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
describe('integration test: RPC methods', () => {
let donor: IKeyringPair;
tests/src/setCollectionLimits.test.tsdiffbeforeafterboth--- a/tests/src/setCollectionLimits.test.ts
+++ b/tests/src/setCollectionLimits.test.ts
@@ -16,12 +16,7 @@
// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
import {IKeyringPair} from '@polkadot/types/types';
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-import {itSub, usingPlaygrounds} from './util/playgrounds';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
+import {itSub, usingPlaygrounds, expect} from './util/playgrounds';
const accountTokenOwnershipLimit = 0;
const sponsoredDataSize = 0;
tests/src/setCollectionSponsor.test.tsdiffbeforeafterboth--- a/tests/src/setCollectionSponsor.test.ts
+++ b/tests/src/setCollectionSponsor.test.ts
@@ -14,13 +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 chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
import {IKeyringPair} from '@polkadot/types/types';
-import {itSub, usingPlaygrounds, Pallets} from './util/playgrounds';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
+import {itSub, usingPlaygrounds, expect, Pallets} from './util/playgrounds';
describe('integration test: ext. setCollectionSponsor():', () => {
let alice: IKeyringPair;
tests/src/setMintPermission.test.tsdiffbeforeafterboth--- a/tests/src/setMintPermission.test.ts
+++ b/tests/src/setMintPermission.test.ts
@@ -15,12 +15,7 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {IKeyringPair} from '@polkadot/types/types';
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-import {itSub, usingPlaygrounds} from './util/playgrounds';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
+import {itSub, usingPlaygrounds, expect} from './util/playgrounds';
describe('Integration Test setMintPermission', () => {
let alice: IKeyringPair;
tests/src/setPublicAccessMode.test.tsdiffbeforeafterboth--- a/tests/src/setPublicAccessMode.test.ts
+++ b/tests/src/setPublicAccessMode.test.ts
@@ -16,12 +16,7 @@
// https://unique-network.readthedocs.io/en/latest/jsapi.html#setschemaversion
import {IKeyringPair} from '@polkadot/types/types';
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-import {itSub, usingPlaygrounds} from './util/playgrounds';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
+import {itSub, usingPlaygrounds, expect} from './util/playgrounds';
describe('Integration Test setPublicAccessMode(): ', () => {
let alice: IKeyringPair;
tests/src/transfer.test.tsdiffbeforeafterboth--- a/tests/src/transfer.test.ts
+++ b/tests/src/transfer.test.ts
@@ -15,13 +15,8 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {IKeyringPair} from '@polkadot/types/types';
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
import {itEth, usingEthPlaygrounds} from './eth/util/playgrounds';
-import {itSub, Pallets, usingPlaygrounds} from './util/playgrounds';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
+import {itSub, Pallets, usingPlaygrounds, expect} from './util/playgrounds';
describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {
let alice: IKeyringPair;
tests/src/transferFrom.test.tsdiffbeforeafterboth--- a/tests/src/transferFrom.test.ts
+++ b/tests/src/transferFrom.test.ts
@@ -15,12 +15,7 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {IKeyringPair} from '@polkadot/types/types';
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-import {itSub, Pallets, usingPlaygrounds} from './util/playgrounds';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
+import {itSub, Pallets, usingPlaygrounds, expect} from './util/playgrounds';
describe('Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {
let alice: IKeyringPair;
tests/src/util/playgrounds/index.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/index.ts
+++ b/tests/src/util/playgrounds/index.ts
@@ -2,12 +2,17 @@
// SPDX-License-Identifier: Apache-2.0
import {IKeyringPair} from '@polkadot/types/types';
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
import {Context} from 'mocha';
import config from '../../config';
import '../../interfaces/augment-api-events';
import {DevUniqueHelper, SilentLogger, SilentConsole} from './unique.dev';
+chai.use(chaiAsPromised);
+export const expect = chai.expect;
+
export const usingPlaygrounds = async (code: (helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {
const silentConsole = new SilentConsole();
silentConsole.enable();