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
--- 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;
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
before · tests/src/setCollectionSponsor.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 chai from 'chai';18import chaiAsPromised from 'chai-as-promised';19import {IKeyringPair} from '@polkadot/types/types';20import {itSub, usingPlaygrounds, Pallets} from './util/playgrounds';2122chai.use(chaiAsPromised);23const expect = chai.expect;2425describe('integration test: ext. setCollectionSponsor():', () => {26  let alice: IKeyringPair;27  let bob: IKeyringPair;28  let charlie: IKeyringPair;2930  before(async () => {31    await usingPlaygrounds(async (helper, privateKey) => {32      const donor = privateKey('//Alice');33      [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);34    });35  });3637  itSub('Set NFT collection sponsor', async ({helper}) => {38    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-1-NFT', tokenPrefix: 'SCS'});39    await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;4041    expect((await collection.getData())?.raw.sponsorship).to.deep.equal({42      Unconfirmed: bob.address,43    });44  });45  46  itSub('Set Fungible collection sponsor', async ({helper}) => {47    const collection = await helper.ft.mintCollection(alice, {name: 'SetCollectionSponsor-1-FT', tokenPrefix: 'SCS'});48    await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;4950    expect((await collection.getData())?.raw.sponsorship).to.deep.equal({51      Unconfirmed: bob.address,52    });53  });5455  itSub.ifWithPallets('Set ReFungible collection sponsor', [Pallets.ReFungible], async ({helper}) => {56    const collection = await helper.rft.mintCollection(alice, {name: 'SetCollectionSponsor-1-RFT', tokenPrefix: 'SCS'});57    await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;5859    expect((await collection.getData())?.raw.sponsorship).to.deep.equal({60      Unconfirmed: bob.address,61    });62  });6364  itSub('Set the same sponsor repeatedly', async ({helper}) => {65    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-2', tokenPrefix: 'SCS'});66    await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;67    await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;6869    expect((await collection.getData())?.raw.sponsorship).to.deep.equal({70      Unconfirmed: bob.address,71    });72  });7374  itSub('Replace collection sponsor', async ({helper}) => {75    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-3', tokenPrefix: 'SCS'});76    await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;77    await expect(collection.setSponsor(alice, charlie.address)).to.be.not.rejected;7879    expect((await collection.getData())?.raw.sponsorship).to.deep.equal({80      Unconfirmed: charlie.address,81    });82  });83  84  itSub('Collection admin add sponsor', async ({helper}) => {85    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-4', tokenPrefix: 'SCS'});86    await collection.addAdmin(alice, {Substrate: bob.address});87    await expect(collection.setSponsor(bob, charlie.address)).to.be.not.rejected;8889    expect((await collection.getData())?.raw.sponsorship).to.deep.equal({90      Unconfirmed: charlie.address,91    });92  });93});9495describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {96  let alice: IKeyringPair;97  let bob: IKeyringPair;9899  before(async () => {100    await usingPlaygrounds(async (helper, privateKey) => {101      const donor = privateKey('//Alice');102      [alice, bob] = await helper.arrange.createAccounts([10n, 5n], donor);103    });104  });105106  itSub('(!negative test!) Add sponsor with a non-owner', async ({helper}) => {107    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-Neg-1', tokenPrefix: 'SCS'});108    await expect(collection.setSponsor(bob, bob.address))109      .to.be.rejectedWith(/common\.NoPermission/);110  });111112  itSub('(!negative test!) Add sponsor to a collection that never existed', async ({helper}) => {113    const collectionId = (1 << 32) - 1;114    await expect(helper.collection.setSponsor(alice, collectionId, bob.address))115      .to.be.rejectedWith(/common\.CollectionNotFound/);116  });117118  itSub('(!negative test!) Add sponsor to a collection that was destroyed', async ({helper}) => {119    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-Neg-2', tokenPrefix: 'SCS'});120    await collection.burn(alice);121    await expect(collection.setSponsor(alice, bob.address))122      .to.be.rejectedWith(/common\.CollectionNotFound/);123  });124});
after · tests/src/setCollectionSponsor.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 {itSub, usingPlaygrounds, expect, Pallets} from './util/playgrounds';1920describe('integration test: ext. setCollectionSponsor():', () => {21  let alice: IKeyringPair;22  let bob: IKeyringPair;23  let charlie: IKeyringPair;2425  before(async () => {26    await usingPlaygrounds(async (helper, privateKey) => {27      const donor = privateKey('//Alice');28      [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);29    });30  });3132  itSub('Set NFT collection sponsor', async ({helper}) => {33    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-1-NFT', tokenPrefix: 'SCS'});34    await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;3536    expect((await collection.getData())?.raw.sponsorship).to.deep.equal({37      Unconfirmed: bob.address,38    });39  });40  41  itSub('Set Fungible collection sponsor', async ({helper}) => {42    const collection = await helper.ft.mintCollection(alice, {name: 'SetCollectionSponsor-1-FT', tokenPrefix: 'SCS'});43    await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;4445    expect((await collection.getData())?.raw.sponsorship).to.deep.equal({46      Unconfirmed: bob.address,47    });48  });4950  itSub.ifWithPallets('Set ReFungible collection sponsor', [Pallets.ReFungible], async ({helper}) => {51    const collection = await helper.rft.mintCollection(alice, {name: 'SetCollectionSponsor-1-RFT', tokenPrefix: 'SCS'});52    await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;5354    expect((await collection.getData())?.raw.sponsorship).to.deep.equal({55      Unconfirmed: bob.address,56    });57  });5859  itSub('Set the same sponsor repeatedly', async ({helper}) => {60    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-2', tokenPrefix: 'SCS'});61    await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;62    await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;6364    expect((await collection.getData())?.raw.sponsorship).to.deep.equal({65      Unconfirmed: bob.address,66    });67  });6869  itSub('Replace collection sponsor', async ({helper}) => {70    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-3', tokenPrefix: 'SCS'});71    await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;72    await expect(collection.setSponsor(alice, charlie.address)).to.be.not.rejected;7374    expect((await collection.getData())?.raw.sponsorship).to.deep.equal({75      Unconfirmed: charlie.address,76    });77  });78  79  itSub('Collection admin add sponsor', async ({helper}) => {80    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-4', tokenPrefix: 'SCS'});81    await collection.addAdmin(alice, {Substrate: bob.address});82    await expect(collection.setSponsor(bob, charlie.address)).to.be.not.rejected;8384    expect((await collection.getData())?.raw.sponsorship).to.deep.equal({85      Unconfirmed: charlie.address,86    });87  });88});8990describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {91  let alice: IKeyringPair;92  let bob: IKeyringPair;9394  before(async () => {95    await usingPlaygrounds(async (helper, privateKey) => {96      const donor = privateKey('//Alice');97      [alice, bob] = await helper.arrange.createAccounts([10n, 5n], donor);98    });99  });100101  itSub('(!negative test!) Add sponsor with a non-owner', async ({helper}) => {102    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-Neg-1', tokenPrefix: 'SCS'});103    await expect(collection.setSponsor(bob, bob.address))104      .to.be.rejectedWith(/common\.NoPermission/);105  });106107  itSub('(!negative test!) Add sponsor to a collection that never existed', async ({helper}) => {108    const collectionId = (1 << 32) - 1;109    await expect(helper.collection.setSponsor(alice, collectionId, bob.address))110      .to.be.rejectedWith(/common\.CollectionNotFound/);111  });112113  itSub('(!negative test!) Add sponsor to a collection that was destroyed', async ({helper}) => {114    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-Neg-2', tokenPrefix: 'SCS'});115    await collection.burn(alice);116    await expect(collection.setSponsor(alice, bob.address))117      .to.be.rejectedWith(/common\.CollectionNotFound/);118  });119});
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();