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.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.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/>.1617// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits18import {IKeyringPair} from '@polkadot/types/types';19import {itSub, usingPlaygrounds, expect} from './util/playgrounds';2021const accountTokenOwnershipLimit = 0;22const sponsoredDataSize = 0;23const sponsorTransferTimeout = 1;24const tokenLimit = 10;2526describe('setCollectionLimits positive', () => {27 let alice: IKeyringPair;28 let bob: IKeyringPair;2930 before(async () => {31 await usingPlaygrounds(async (helper, privateKey) => {32 const donor = privateKey('//Alice');33 [alice, bob] = await helper.arrange.createAccounts([20n, 10n], donor);34 });35 });3637 itSub('execute setCollectionLimits with predefined params', async ({helper}) => {38 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-1', tokenPrefix: 'SCL'});3940 await collection.setLimits(41 alice,42 {43 accountTokenOwnershipLimit,44 sponsoredDataSize,45 tokenLimit,46 sponsorTransferTimeout,47 ownerCanTransfer: true,48 ownerCanDestroy: true,49 },50 );5152 // get collection limits defined previously53 const collectionInfo = await collection.getEffectiveLimits();5455 expect(collectionInfo.accountTokenOwnershipLimit).to.be.equal(accountTokenOwnershipLimit);56 expect(collectionInfo.sponsoredDataSize).to.be.equal(sponsoredDataSize);57 expect(collectionInfo.tokenLimit).to.be.equal(tokenLimit);58 expect(collectionInfo.sponsorTransferTimeout).to.be.equal(sponsorTransferTimeout);59 expect(collectionInfo.ownerCanTransfer).to.be.true;60 expect(collectionInfo.ownerCanDestroy).to.be.true;61 });6263 itSub('Set the same token limit twice', async ({helper}) => {64 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-2', tokenPrefix: 'SCL'});6566 const collectionLimits = {67 accountTokenOwnershipLimit,68 sponsoredDataSize,69 tokenLimit,70 sponsorTransferTimeout,71 ownerCanTransfer: true,72 ownerCanDestroy: true,73 };7475 await collection.setLimits(alice, collectionLimits);7677 const collectionInfo1 = await collection.getEffectiveLimits();78 79 expect(collectionInfo1.tokenLimit).to.be.equal(tokenLimit);8081 await collection.setLimits(alice, collectionLimits);82 const collectionInfo2 = await collection.getEffectiveLimits();83 expect(collectionInfo2.tokenLimit).to.be.equal(tokenLimit);84 });8586 itSub('execute setCollectionLimits from admin collection', async ({helper}) => {87 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-3', tokenPrefix: 'SCL'});88 await collection.addAdmin(alice, {Substrate: bob.address});8990 const collectionLimits = {91 accountTokenOwnershipLimit,92 sponsoredDataSize,93 // sponsoredMintSize,94 tokenLimit,95 };9697 await expect(collection.setLimits(alice, collectionLimits)).to.not.be.rejected;98 });99});100101describe('setCollectionLimits negative', () => {102 let alice: IKeyringPair;103 let bob: IKeyringPair;104105 before(async () => {106 await usingPlaygrounds(async (helper, privateKey) => {107 const donor = privateKey('//Alice');108 [alice, bob] = await helper.arrange.createAccounts([20n, 10n], donor);109 });110 });111 112 itSub('execute setCollectionLimits for not exists collection', async ({helper}) => {113 const nonExistentCollectionId = (1 << 32) - 1;114 await expect(helper.collection.setLimits(115 alice,116 nonExistentCollectionId,117 {118 accountTokenOwnershipLimit,119 sponsoredDataSize,120 // sponsoredMintSize,121 tokenLimit,122 },123 )).to.be.rejectedWith(/common\.CollectionNotFound/);124 });125126 itSub('execute setCollectionLimits from user who is not owner of this collection', async ({helper}) => {127 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-Neg-1', tokenPrefix: 'SCL'});128129 await expect(collection.setLimits(bob, {130 accountTokenOwnershipLimit,131 sponsoredDataSize,132 // sponsoredMintSize,133 tokenLimit,134 })).to.be.rejectedWith(/common\.NoPermission/);135 });136137 itSub('fails when trying to enable OwnerCanTransfer after it was disabled', async ({helper}) => {138 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-Neg-2', tokenPrefix: 'SCL'});139140 await collection.setLimits(alice, {141 accountTokenOwnershipLimit,142 sponsoredDataSize,143 tokenLimit,144 sponsorTransferTimeout,145 ownerCanTransfer: false,146 ownerCanDestroy: true,147 });148149 await expect(collection.setLimits(alice, {150 accountTokenOwnershipLimit,151 sponsoredDataSize,152 tokenLimit,153 sponsorTransferTimeout,154 ownerCanTransfer: true,155 ownerCanDestroy: true,156 })).to.be.rejectedWith(/common\.OwnerPermissionsCantBeReverted/);157 });158159 itSub('fails when trying to enable OwnerCanDestroy after it was disabled', async ({helper}) => {160 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-Neg-3', tokenPrefix: 'SCL'});161162 await collection.setLimits(alice, {163 accountTokenOwnershipLimit,164 sponsoredDataSize,165 tokenLimit,166 sponsorTransferTimeout,167 ownerCanTransfer: true,168 ownerCanDestroy: false,169 });170171 await expect(collection.setLimits(alice, {172 accountTokenOwnershipLimit,173 sponsoredDataSize,174 tokenLimit,175 sponsorTransferTimeout,176 ownerCanTransfer: true,177 ownerCanDestroy: true,178 })).to.be.rejectedWith(/common\.OwnerPermissionsCantBeReverted/);179 });180181 itSub('Setting the higher token limit fails', async ({helper}) => {182 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-Neg-4', tokenPrefix: 'SCL'});183 184 const collectionLimits = {185 accountTokenOwnershipLimit: accountTokenOwnershipLimit,186 sponsoredMintSize: sponsoredDataSize,187 tokenLimit: tokenLimit,188 sponsorTransferTimeout,189 ownerCanTransfer: true,190 ownerCanDestroy: true,191 };192193 // The first time194 await collection.setLimits(alice, collectionLimits);195196 // The second time - higher token limit197 collectionLimits.tokenLimit += 1;198 await expect(collection.setLimits(alice, collectionLimits)).to.be.rejectedWith(/common\.CollectionTokenLimitExceeded/);199 });200});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();