git.delta.rocks / unique-network / refs/commits / 3f7f6aa6cd8e

difftreelog

tests: displace chai-expect header copypasta

Fahrrader2022-09-09parent: #e1baaf9.patch.diff
in: master

15 files changed

modifiedtests/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;
modifiedtests/src/fungible.test.tsdiffbeforeafterboth
--- a/tests/src/fungible.test.ts
+++ b/tests/src/fungible.test.ts
@@ -16,13 +16,9 @@
 
 import {IKeyringPair} from '@polkadot/types/types';
 import {U128_MAX} from './util/helpers';
-import {itSub, usingPlaygrounds} from './util/playgrounds';
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
+import {itSub, usingPlaygrounds, expect} from './util/playgrounds';
 
-chai.use(chaiAsPromised);
-const expect = chai.expect;
-
+// todo:playgrounds get rid of globals
 let alice: IKeyringPair;
 let bob: IKeyringPair;
 
modifiedtests/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 = [
modifiedtests/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;
modifiedtests/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;
modifiedtests/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;
modifiedtests/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;
modifiedtests/src/rpc.test.tsdiffbeforeafterboth
before · tests/src/rpc.test.ts
1import {IKeyringPair} from '@polkadot/types/types';2import chai from 'chai';3import chaiAsPromised from 'chai-as-promised';4import {usingPlaygrounds, itSub} from './util/playgrounds';5import {crossAccountIdFromLower} from './util/playgrounds/unique';67chai.use(chaiAsPromised);8const expect = chai.expect;910describe('integration test: RPC methods', () => {11  let donor: IKeyringPair;12  let alice: IKeyringPair;13  let bob: IKeyringPair;1415  before(async () => {16    await usingPlaygrounds(async (helper, privateKey) => {17      donor = privateKey('//Alice');18      [alice, bob] = await helper.arrange.createAccounts([20n, 10n], donor);19    });20  });2122  itSub('returns None for fungible collection', async ({helper}) => {23    const collection = await helper.ft.mintCollection(alice, {name: 'RPC-1', tokenPrefix: 'RPC'});24    const owner = (await helper.callRpc('api.rpc.unique.tokenOwner', [collection.collectionId, 0])).toJSON() as any;25    expect(owner).to.be.null;26  });27  28  itSub('RPC method tokenOwners for fungible collection and token', async ({helper}) => {29    // Set-up a few token owners of all stripes30    const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};31    const facelessCrowd = (await helper.arrange.createAccounts([0n, 0n, 0n, 0n, 0n, 0n, 0n], donor))32      .map(i => {return {Substrate: i.address};});33    34    const collection = await helper.ft.mintCollection(alice, {name: 'RPC-2', tokenPrefix: 'RPC'});35    // mint some maximum (u128) amounts of tokens possible36    await collection.mint(alice, {Substrate: alice.address}, (1n << 128n) - 1n);37    38    await collection.transfer(alice, {Substrate: bob.address}, 1000n);39    await collection.transfer(alice, ethAcc, 900n);40          41    for (let i = 0; i < facelessCrowd.length; i++) {42      await collection.transfer(alice, facelessCrowd[i], 1n);43    }44    // Set-up over4546    const owners = await helper.callRpc('api.rpc.unique.tokenOwners', [collection.collectionId, 0]);47    const ids = (owners.toJSON() as any[]).map(crossAccountIdFromLower);4849    expect(ids).to.deep.include.members([{Substrate: alice.address}, ethAcc, {Substrate: bob.address}, ...facelessCrowd]);50    expect(owners.length == 10).to.be.true;51    52    // Make sure only 10 results are returned with this RPC53    const [eleven] = await helper.arrange.createAccounts([0n], donor);54    expect(await collection.transfer(alice, {Substrate: eleven.address}, 10n)).to.be.true;55    expect((await helper.callRpc('api.rpc.unique.tokenOwners', [collection.collectionId, 0])).length).to.be.equal(10);56  });57});
after · tests/src/rpc.test.ts
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 {usingPlaygrounds, itSub, expect} from './util/playgrounds';19import {crossAccountIdFromLower} from './util/playgrounds/unique';2021describe('integration test: RPC methods', () => {22  let donor: IKeyringPair;23  let alice: IKeyringPair;24  let bob: IKeyringPair;2526  before(async () => {27    await usingPlaygrounds(async (helper, privateKey) => {28      donor = privateKey('//Alice');29      [alice, bob] = await helper.arrange.createAccounts([20n, 10n], donor);30    });31  });3233  itSub('returns None for fungible collection', async ({helper}) => {34    const collection = await helper.ft.mintCollection(alice, {name: 'RPC-1', tokenPrefix: 'RPC'});35    const owner = (await helper.callRpc('api.rpc.unique.tokenOwner', [collection.collectionId, 0])).toJSON() as any;36    expect(owner).to.be.null;37  });38  39  itSub('RPC method tokenOwners for fungible collection and token', async ({helper}) => {40    // Set-up a few token owners of all stripes41    const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};42    const facelessCrowd = (await helper.arrange.createAccounts([0n, 0n, 0n, 0n, 0n, 0n, 0n], donor))43      .map(i => {return {Substrate: i.address};});44    45    const collection = await helper.ft.mintCollection(alice, {name: 'RPC-2', tokenPrefix: 'RPC'});46    // mint some maximum (u128) amounts of tokens possible47    await collection.mint(alice, {Substrate: alice.address}, (1n << 128n) - 1n);48    49    await collection.transfer(alice, {Substrate: bob.address}, 1000n);50    await collection.transfer(alice, ethAcc, 900n);51          52    for (let i = 0; i < facelessCrowd.length; i++) {53      await collection.transfer(alice, facelessCrowd[i], 1n);54    }55    // Set-up over5657    const owners = await helper.callRpc('api.rpc.unique.tokenOwners', [collection.collectionId, 0]);58    const ids = (owners.toJSON() as any[]).map(crossAccountIdFromLower);5960    expect(ids).to.deep.include.members([{Substrate: alice.address}, ethAcc, {Substrate: bob.address}, ...facelessCrowd]);61    expect(owners.length == 10).to.be.true;62    63    // Make sure only 10 results are returned with this RPC64    const [eleven] = await helper.arrange.createAccounts([0n], donor);65    expect(await collection.transfer(alice, {Substrate: eleven.address}, 10n)).to.be.true;66    expect((await helper.callRpc('api.rpc.unique.tokenOwners', [collection.collectionId, 0])).length).to.be.equal(10);67  });68});
modifiedtests/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;
modifiedtests/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;
modifiedtests/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;
modifiedtests/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;
modifiedtests/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;
modifiedtests/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;
modifiedtests/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();