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.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;
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.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 {IKeyringPair} from '@polkadot/types/types';20import {itSub, usingPlaygrounds} from './util/playgrounds';2122chai.use(chaiAsPromised);23const expect = chai.expect;2425describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {26 let alice: IKeyringPair;27 let bob: IKeyringPair;2829 before(async () => {30 await usingPlaygrounds(async (helper, privateKey) => {31 const donor = privateKey('//Alice');32 [alice, bob] = await helper.arrange.createAccounts([20n, 10n], donor);33 });34 });3536 itSub('Remove collection admin', async ({helper}) => {37 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-1', tokenPrefix: 'RCA'});38 const collectionInfo = await collection.getData();39 expect(collectionInfo?.raw.owner.toString()).to.be.deep.eq(alice.address);40 // first - add collection admin Bob41 await collection.addAdmin(alice, {Substrate: bob.address});4243 const adminListAfterAddAdmin = await collection.getAdmins();44 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});4546 // then remove bob from admins of collection47 await collection.removeAdmin(alice, {Substrate: bob.address});4849 const adminListAfterRemoveAdmin = await collection.getAdmins();50 expect(adminListAfterRemoveAdmin).not.to.be.deep.contains({Substrate: bob.address});51 });5253 itSub('Remove admin from collection that has no admins', async ({helper}) => {54 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-2', tokenPrefix: 'RCA'});5556 const adminListBeforeAddAdmin = await collection.getAdmins();57 expect(adminListBeforeAddAdmin).to.have.lengthOf(0);5859 await collection.removeAdmin(alice, {Substrate: alice.address});60 });61});6263describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {64 let alice: IKeyringPair;65 let bob: IKeyringPair;66 let charlie: IKeyringPair;6768 before(async () => {69 await usingPlaygrounds(async (helper, privateKey) => {70 const donor = privateKey('//Alice');71 [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);72 });73 });7475 itSub('Can\'t remove collection admin from not existing collection', async ({helper}) => {76 const collectionId = (1 << 32) - 1;7778 await expect(helper.collection.removeAdmin(alice, collectionId, {Substrate: bob.address}))79 .to.be.rejectedWith(/common\.CollectionNotFound/);80 });8182 itSub('Can\'t remove collection admin from deleted collection', async ({helper}) => {83 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-Neg-2', tokenPrefix: 'RCA'});8485 expect(await collection.burn(alice)).to.be.true;8687 await expect(helper.collection.removeAdmin(alice, collection.collectionId, {Substrate: bob.address}))88 .to.be.rejectedWith(/common\.CollectionNotFound/);89 });9091 itSub('Regular user can\'t remove collection admin', async ({helper}) => {92 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-Neg-3', tokenPrefix: 'RCA'});9394 await collection.addAdmin(alice, {Substrate: bob.address});9596 await expect(collection.removeAdmin(charlie, {Substrate: bob.address}))97 .to.be.rejectedWith(/common\.NoPermission/);98 });99100 itSub('Admin can\'t remove collection admin.', async ({helper}) => {101 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-Neg-4', tokenPrefix: 'RCA'});102 103 await collection.addAdmin(alice, {Substrate: bob.address});104 await collection.addAdmin(alice, {Substrate: charlie.address});105106 const adminListAfterAddAdmin = await collection.getAdmins();107 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});108 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: charlie.address});109110 await expect(collection.removeAdmin(charlie, {Substrate: bob.address}))111 .to.be.rejectedWith(/common\.NoPermission/);112113 const adminListAfterRemoveAdmin = await collection.getAdmins();114 expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: bob.address});115 expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: charlie.address});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 {itSub, usingPlaygrounds, expect} from './util/playgrounds';1920describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {21 let alice: IKeyringPair;22 let bob: IKeyringPair;2324 before(async () => {25 await usingPlaygrounds(async (helper, privateKey) => {26 const donor = privateKey('//Alice');27 [alice, bob] = await helper.arrange.createAccounts([20n, 10n], donor);28 });29 });3031 itSub('Remove collection admin', async ({helper}) => {32 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-1', tokenPrefix: 'RCA'});33 const collectionInfo = await collection.getData();34 expect(collectionInfo?.raw.owner.toString()).to.be.deep.eq(alice.address);35 // first - add collection admin Bob36 await collection.addAdmin(alice, {Substrate: bob.address});3738 const adminListAfterAddAdmin = await collection.getAdmins();39 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});4041 // then remove bob from admins of collection42 await collection.removeAdmin(alice, {Substrate: bob.address});4344 const adminListAfterRemoveAdmin = await collection.getAdmins();45 expect(adminListAfterRemoveAdmin).not.to.be.deep.contains({Substrate: bob.address});46 });4748 itSub('Remove admin from collection that has no admins', async ({helper}) => {49 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-2', tokenPrefix: 'RCA'});5051 const adminListBeforeAddAdmin = await collection.getAdmins();52 expect(adminListBeforeAddAdmin).to.have.lengthOf(0);5354 await collection.removeAdmin(alice, {Substrate: alice.address});55 });56});5758describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {59 let alice: IKeyringPair;60 let bob: IKeyringPair;61 let charlie: IKeyringPair;6263 before(async () => {64 await usingPlaygrounds(async (helper, privateKey) => {65 const donor = privateKey('//Alice');66 [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);67 });68 });6970 itSub('Can\'t remove collection admin from not existing collection', async ({helper}) => {71 const collectionId = (1 << 32) - 1;7273 await expect(helper.collection.removeAdmin(alice, collectionId, {Substrate: bob.address}))74 .to.be.rejectedWith(/common\.CollectionNotFound/);75 });7677 itSub('Can\'t remove collection admin from deleted collection', async ({helper}) => {78 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-Neg-2', tokenPrefix: 'RCA'});7980 expect(await collection.burn(alice)).to.be.true;8182 await expect(helper.collection.removeAdmin(alice, collection.collectionId, {Substrate: bob.address}))83 .to.be.rejectedWith(/common\.CollectionNotFound/);84 });8586 itSub('Regular user can\'t remove collection admin', async ({helper}) => {87 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-Neg-3', tokenPrefix: 'RCA'});8889 await collection.addAdmin(alice, {Substrate: bob.address});9091 await expect(collection.removeAdmin(charlie, {Substrate: bob.address}))92 .to.be.rejectedWith(/common\.NoPermission/);93 });9495 itSub('Admin can\'t remove collection admin.', async ({helper}) => {96 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-Neg-4', tokenPrefix: 'RCA'});97 98 await collection.addAdmin(alice, {Substrate: bob.address});99 await collection.addAdmin(alice, {Substrate: charlie.address});100101 const adminListAfterAddAdmin = await collection.getAdmins();102 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});103 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: charlie.address});104105 await expect(collection.removeAdmin(charlie, {Substrate: bob.address}))106 .to.be.rejectedWith(/common\.NoPermission/);107108 const adminListAfterRemoveAdmin = await collection.getAdmins();109 expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: bob.address});110 expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: charlie.address});111 });112});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();