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 chai from 'chai';20import chaiAsPromised from 'chai-as-promised';21import {itSub, usingPlaygrounds} from './util/playgrounds';2223chai.use(chaiAsPromised);24const expect = chai.expect;2526const accountTokenOwnershipLimit = 0;27const sponsoredDataSize = 0;28const sponsorTransferTimeout = 1;29const tokenLimit = 10;3031describe('setCollectionLimits positive', () => {32 let alice: IKeyringPair;33 let bob: IKeyringPair;3435 before(async () => {36 await usingPlaygrounds(async (helper, privateKey) => {37 const donor = privateKey('//Alice');38 [alice, bob] = await helper.arrange.createAccounts([20n, 10n], donor);39 });40 });4142 itSub('execute setCollectionLimits with predefined params', async ({helper}) => {43 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-1', tokenPrefix: 'SCL'});4445 await collection.setLimits(46 alice,47 {48 accountTokenOwnershipLimit,49 sponsoredDataSize,50 tokenLimit,51 sponsorTransferTimeout,52 ownerCanTransfer: true,53 ownerCanDestroy: true,54 },55 );5657 // get collection limits defined previously58 const collectionInfo = await collection.getEffectiveLimits();5960 expect(collectionInfo.accountTokenOwnershipLimit).to.be.equal(accountTokenOwnershipLimit);61 expect(collectionInfo.sponsoredDataSize).to.be.equal(sponsoredDataSize);62 expect(collectionInfo.tokenLimit).to.be.equal(tokenLimit);63 expect(collectionInfo.sponsorTransferTimeout).to.be.equal(sponsorTransferTimeout);64 expect(collectionInfo.ownerCanTransfer).to.be.true;65 expect(collectionInfo.ownerCanDestroy).to.be.true;66 });6768 itSub('Set the same token limit twice', async ({helper}) => {69 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-2', tokenPrefix: 'SCL'});7071 const collectionLimits = {72 accountTokenOwnershipLimit,73 sponsoredDataSize,74 tokenLimit,75 sponsorTransferTimeout,76 ownerCanTransfer: true,77 ownerCanDestroy: true,78 };7980 await collection.setLimits(alice, collectionLimits);8182 const collectionInfo1 = await collection.getEffectiveLimits();83 84 expect(collectionInfo1.tokenLimit).to.be.equal(tokenLimit);8586 await collection.setLimits(alice, collectionLimits);87 const collectionInfo2 = await collection.getEffectiveLimits();88 expect(collectionInfo2.tokenLimit).to.be.equal(tokenLimit);89 });9091 itSub('execute setCollectionLimits from admin collection', async ({helper}) => {92 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-3', tokenPrefix: 'SCL'});93 await collection.addAdmin(alice, {Substrate: bob.address});9495 const collectionLimits = {96 accountTokenOwnershipLimit,97 sponsoredDataSize,98 // sponsoredMintSize,99 tokenLimit,100 };101102 await expect(collection.setLimits(alice, collectionLimits)).to.not.be.rejected;103 });104});105106describe('setCollectionLimits negative', () => {107 let alice: IKeyringPair;108 let bob: IKeyringPair;109110 before(async () => {111 await usingPlaygrounds(async (helper, privateKey) => {112 const donor = privateKey('//Alice');113 [alice, bob] = await helper.arrange.createAccounts([20n, 10n], donor);114 });115 });116 117 itSub('execute setCollectionLimits for not exists collection', async ({helper}) => {118 const nonExistentCollectionId = (1 << 32) - 1;119 await expect(helper.collection.setLimits(120 alice,121 nonExistentCollectionId,122 {123 accountTokenOwnershipLimit,124 sponsoredDataSize,125 // sponsoredMintSize,126 tokenLimit,127 },128 )).to.be.rejectedWith(/common\.CollectionNotFound/);129 });130131 itSub('execute setCollectionLimits from user who is not owner of this collection', async ({helper}) => {132 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-Neg-1', tokenPrefix: 'SCL'});133134 await expect(collection.setLimits(bob, {135 accountTokenOwnershipLimit,136 sponsoredDataSize,137 // sponsoredMintSize,138 tokenLimit,139 })).to.be.rejectedWith(/common\.NoPermission/);140 });141142 itSub('fails when trying to enable OwnerCanTransfer after it was disabled', async ({helper}) => {143 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-Neg-2', tokenPrefix: 'SCL'});144145 await collection.setLimits(alice, {146 accountTokenOwnershipLimit,147 sponsoredDataSize,148 tokenLimit,149 sponsorTransferTimeout,150 ownerCanTransfer: false,151 ownerCanDestroy: true,152 });153154 await expect(collection.setLimits(alice, {155 accountTokenOwnershipLimit,156 sponsoredDataSize,157 tokenLimit,158 sponsorTransferTimeout,159 ownerCanTransfer: true,160 ownerCanDestroy: true,161 })).to.be.rejectedWith(/common\.OwnerPermissionsCantBeReverted/);162 });163164 itSub('fails when trying to enable OwnerCanDestroy after it was disabled', async ({helper}) => {165 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-Neg-3', tokenPrefix: 'SCL'});166167 await collection.setLimits(alice, {168 accountTokenOwnershipLimit,169 sponsoredDataSize,170 tokenLimit,171 sponsorTransferTimeout,172 ownerCanTransfer: true,173 ownerCanDestroy: false,174 });175176 await expect(collection.setLimits(alice, {177 accountTokenOwnershipLimit,178 sponsoredDataSize,179 tokenLimit,180 sponsorTransferTimeout,181 ownerCanTransfer: true,182 ownerCanDestroy: true,183 })).to.be.rejectedWith(/common\.OwnerPermissionsCantBeReverted/);184 });185186 itSub('Setting the higher token limit fails', async ({helper}) => {187 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-Neg-4', tokenPrefix: 'SCL'});188 189 const collectionLimits = {190 accountTokenOwnershipLimit: accountTokenOwnershipLimit,191 sponsoredMintSize: sponsoredDataSize,192 tokenLimit: tokenLimit,193 sponsorTransferTimeout,194 ownerCanTransfer: true,195 ownerCanDestroy: true,196 };197198 // The first time199 await collection.setLimits(alice, collectionLimits);200201 // The second time - higher token limit202 collectionLimits.tokenLimit += 1;203 await expect(collection.setLimits(alice, collectionLimits)).to.be.rejectedWith(/common\.CollectionTokenLimitExceeded/);204 });205});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();