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.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.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 {IKeyringPair} from '@polkadot/types/types';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20import {itEth, usingEthPlaygrounds} from './eth/util/playgrounds';21import {itSub, Pallets, usingPlaygrounds} from './util/playgrounds';2223chai.use(chaiAsPromised);24const expect = chai.expect;2526describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {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([50n, 10n], donor);34 });35 });36 37 itSub('Balance transfers and check balance', async ({helper}) => {38 const alicesBalanceBefore = await helper.balance.getSubstrate(alice.address);39 const bobsBalanceBefore = await helper.balance.getSubstrate(bob.address);4041 expect(await helper.balance.transferToSubstrate(alice, bob.address, 1n)).to.be.true;4243 const alicesBalanceAfter = await helper.balance.getSubstrate(alice.address);44 const bobsBalanceAfter = await helper.balance.getSubstrate(bob.address);4546 expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;47 expect(bobsBalanceAfter > bobsBalanceBefore).to.be.true;48 });4950 itSub('Inability to pay fees error message is correct', async ({helper, privateKey}) => {51 const donor = privateKey('//Alice');52 const [zero] = await helper.arrange.createAccounts([0n], donor);5354 // console.error = () => {};55 // The following operation throws an error into the console and the logs. Pay it no heed as long as the test succeeds.56 await expect(helper.balance.transferToSubstrate(zero, donor.address, 1n))57 .to.be.rejectedWith('Inability to pay some fees , e.g. account balance too low');58 });5960 itSub('[nft] User can transfer owned token', async ({helper}) => {61 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-1-NFT', description: '', tokenPrefix: 'T'});62 const nft = await collection.mintToken(alice, {Substrate: alice.address});6364 await nft.transfer(alice, {Substrate: bob.address});65 expect(await nft.getOwner()).to.be.deep.equal({Substrate: bob.address});66 });6768 itSub('[fungible] User can transfer owned token', async ({helper}) => {69 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-1-FT', description: '', tokenPrefix: 'T'});70 await collection.mint(alice, {Substrate: alice.address}, 10n);7172 await collection.transfer(alice, {Substrate: bob.address}, 9n);73 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(9n);74 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1n);75 });7677 itSub.ifWithPallets('[refungible] User can transfer owned token', [Pallets.ReFungible], async ({helper}) => {78 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-1-RFT', description: '', tokenPrefix: 'T'});79 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);8081 await rft.transfer(alice, {Substrate: bob.address}, 9n);82 expect(await rft.getBalance({Substrate: bob.address})).to.be.equal(9n);83 expect(await rft.getBalance({Substrate: alice.address})).to.be.equal(1n);84 });8586 itSub('[nft] Collection admin can transfer owned token', async ({helper}) => {87 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-2-NFT', description: '', tokenPrefix: 'T'});88 await collection.addAdmin(alice, {Substrate: bob.address});8990 const nft = await collection.mintToken(bob, {Substrate: bob.address});91 await nft.transfer(bob, {Substrate: alice.address});9293 expect(await nft.getOwner()).to.be.deep.equal({Substrate: alice.address});94 });9596 itSub('[fungible] Collection admin can transfer owned token', async ({helper}) => {97 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-2-FT', description: '', tokenPrefix: 'T'});98 await collection.addAdmin(alice, {Substrate: bob.address});99100 await collection.mint(bob, {Substrate: bob.address}, 10n);101 await collection.transfer(bob, {Substrate: alice.address}, 1n);102103 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(9n);104 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1n);105 });106107 itSub.ifWithPallets('[refungible] Collection admin can transfer owned token', [Pallets.ReFungible], async ({helper}) => {108 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-2-RFT', description: '', tokenPrefix: 'T'});109 await collection.addAdmin(alice, {Substrate: bob.address});110111 const rft = await collection.mintToken(bob, {Substrate: bob.address}, 10n);112 await rft.transfer(bob, {Substrate: alice.address}, 1n);113114 expect(await rft.getBalance({Substrate: bob.address})).to.be.equal(9n);115 expect(await rft.getBalance({Substrate: alice.address})).to.be.equal(1n);116 });117});118119describe('Negative Integration Test Transfer(recipient, collection_id, item_id, value)', () => {120 let alice: IKeyringPair;121 let bob: IKeyringPair;122123 before(async () => {124 await usingPlaygrounds(async (helper, privateKey) => {125 const donor = privateKey('//Alice');126 [alice, bob] = await helper.arrange.createAccounts([50n, 10n], donor);127 });128 });129130 itSub('[nft] Transfer with not existed collection_id', async ({helper}) => {131 const collectionId = (1 << 32) - 1;132 await expect(helper.nft.transferToken(alice, collectionId, 1, {Substrate: bob.address}))133 .to.be.rejectedWith(/common\.CollectionNotFound/);134 });135136 itSub('[fungible] Transfer with not existed collection_id', async ({helper}) => {137 const collectionId = (1 << 32) - 1;138 await expect(helper.ft.transfer(alice, collectionId, {Substrate: bob.address}))139 .to.be.rejectedWith(/common\.CollectionNotFound/);140 });141142 itSub.ifWithPallets('[refungible] Transfer with not existed collection_id', [Pallets.ReFungible], async ({helper}) => {143 const collectionId = (1 << 32) - 1;144 await expect(helper.rft.transferToken(alice, collectionId, 1, {Substrate: bob.address}))145 .to.be.rejectedWith(/common\.CollectionNotFound/);146 });147148 itSub('[nft] Transfer with deleted collection_id', async ({helper}) => {149 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-1-NFT', description: '', tokenPrefix: 'T'});150 const nft = await collection.mintToken(alice, {Substrate: alice.address});151152 await nft.burn(alice);153 await collection.burn(alice);154155 await expect(nft.transfer(alice, {Substrate: bob.address}))156 .to.be.rejectedWith(/common\.CollectionNotFound/);157 });158159 itSub('[fungible] Transfer with deleted collection_id', async ({helper}) => {160 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-Neg-1-FT', description: '', tokenPrefix: 'T'});161 await collection.mint(alice, {Substrate: alice.address}, 10n);162163 await collection.burnTokens(alice, 10n);164 await collection.burn(alice);165166 await expect(collection.transfer(alice, {Substrate: bob.address}))167 .to.be.rejectedWith(/common\.CollectionNotFound/);168 });169 170 itSub.ifWithPallets('[refungible] Transfer with deleted collection_id', [Pallets.ReFungible], async ({helper}) => {171 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-Neg-1-RFT', description: '', tokenPrefix: 'T'});172 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);173174 await rft.burn(alice, 10n);175 await collection.burn(alice);176177 await expect(rft.transfer(alice, {Substrate: bob.address}))178 .to.be.rejectedWith(/common\.CollectionNotFound/);179 });180181 itSub('[nft] Transfer with not existed item_id', async ({helper}) => {182 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-2-NFT', description: '', tokenPrefix: 'T'});183 await expect(collection.transferToken(alice, 1, {Substrate: bob.address}))184 .to.be.rejectedWith(/common\.TokenNotFound/);185 });186187 itSub('[fungible] Transfer with not existed item_id', async ({helper}) => {188 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-Neg-2-FT', description: '', tokenPrefix: 'T'});189 await expect(collection.transfer(alice, {Substrate: bob.address}))190 .to.be.rejectedWith(/common\.TokenValueTooLow/);191 });192193 itSub.ifWithPallets('[refungible] Transfer with not existed item_id', [Pallets.ReFungible], async ({helper}) => {194 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-Neg-2-RFT', description: '', tokenPrefix: 'T'});195 await expect(collection.transferToken(alice, 1, {Substrate: bob.address}))196 .to.be.rejectedWith(/common\.TokenValueTooLow/);197 });198199 itSub('[nft] Transfer with deleted item_id', async ({helper}) => {200 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-3-NFT', description: '', tokenPrefix: 'T'});201 const nft = await collection.mintToken(alice, {Substrate: alice.address});202203 await nft.burn(alice);204205 await expect(nft.transfer(alice, {Substrate: bob.address}))206 .to.be.rejectedWith(/common\.TokenNotFound/);207 });208209 itSub('[fungible] Transfer with deleted item_id', async ({helper}) => {210 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-Neg-3-FT', description: '', tokenPrefix: 'T'});211 await collection.mint(alice, {Substrate: alice.address}, 10n);212213 await collection.burnTokens(alice, 10n);214215 await expect(collection.transfer(alice, {Substrate: bob.address}))216 .to.be.rejectedWith(/common\.TokenValueTooLow/);217 });218219 itSub.ifWithPallets('[refungible] Transfer with deleted item_id', [Pallets.ReFungible], async ({helper}) => {220 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-Neg-3-RFT', description: '', tokenPrefix: 'T'});221 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);222223 await rft.burn(alice, 10n);224225 await expect(rft.transfer(alice, {Substrate: bob.address}))226 .to.be.rejectedWith(/common\.TokenValueTooLow/);227 });228229 itSub('[nft] Transfer with recipient that is not owner', async ({helper}) => {230 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-4-NFT', description: '', tokenPrefix: 'T'});231 const nft = await collection.mintToken(alice, {Substrate: alice.address});232233 await expect(nft.transfer(bob, {Substrate: bob.address}))234 .to.be.rejectedWith(/common\.NoPermission/);235 expect(await nft.getOwner()).to.be.deep.equal({Substrate: alice.address});236 });237238 itSub('[fungible] Transfer with recipient that is not owner', async ({helper}) => {239 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-Neg-4-FT', description: '', tokenPrefix: 'T'});240 await collection.mint(alice, {Substrate: alice.address}, 10n);241242 await expect(collection.transfer(bob, {Substrate: bob.address}, 9n))243 .to.be.rejectedWith(/common\.TokenValueTooLow/);244 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(0n);245 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(10n);246 });247248 itSub.ifWithPallets('[refungible] Transfer with recipient that is not owner', [Pallets.ReFungible], async ({helper}) => {249 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-1-RFT', description: '', tokenPrefix: 'T'});250 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);251252 await expect(rft.transfer(bob, {Substrate: bob.address}, 9n))253 .to.be.rejectedWith(/common\.TokenValueTooLow/);254 expect(await rft.getBalance({Substrate: bob.address})).to.be.equal(0n);255 expect(await rft.getBalance({Substrate: alice.address})).to.be.equal(10n);256 });257});258259describe('Transfers to self (potentially over substrate-evm boundary)', () => {260 let donor: IKeyringPair;261262 before(async function() {263 await usingEthPlaygrounds(async (_, privateKey) => {264 donor = privateKey('//Alice');265 });266 });267 268 itEth('Transfers to self. In case of same frontend', async ({helper}) => {269 const [owner] = await helper.arrange.createAccounts([10n], donor);270 const collection = await helper.ft.mintCollection(owner, {});271 await collection.mint(owner, {Substrate: owner.address}, 100n);272273 const ownerProxy = helper.address.substrateToEth(owner.address);274275 // transfer to own proxy276 await collection.transfer(owner, {Ethereum: ownerProxy}, 10n);277 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(90n);278 expect(await collection.getBalance({Ethereum: ownerProxy})).to.be.equal(10n);279280 // transfer-from own proxy to own proxy again281 await collection.transferFrom(owner, {Ethereum: ownerProxy}, {Ethereum: ownerProxy}, 5n);282 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(90n);283 expect(await collection.getBalance({Ethereum: ownerProxy})).to.be.equal(10n);284 });285286 itEth('Transfers to self. In case of substrate-evm boundary', async ({helper}) => {287 const [owner] = await helper.arrange.createAccounts([10n], donor);288 const collection = await helper.ft.mintCollection(owner, {});289 await collection.mint(owner, {Substrate: owner.address}, 100n);290291 const ownerProxy = helper.address.substrateToEth(owner.address);292293 // transfer to own proxy294 await collection.transfer(owner, {Ethereum: ownerProxy}, 10n);295 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(90n);296 expect(await collection.getBalance({Ethereum: ownerProxy})).to.be.equal(10n);297298 // transfer-from own proxy to self299 await collection.transferFrom(owner, {Ethereum: ownerProxy}, {Substrate: owner.address}, 5n);300 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(95n);301 expect(await collection.getBalance({Ethereum: ownerProxy})).to.be.equal(5n);302 });303304 itEth('Transfers to self. In case of inside substrate-evm', async ({helper}) => {305 const [owner] = await helper.arrange.createAccounts([10n], donor);306 const collection = await helper.ft.mintCollection(owner, {});307 await collection.mint(owner, {Substrate: owner.address}, 100n);308309 // transfer to self again310 await collection.transfer(owner, {Substrate: owner.address}, 10n);311 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(100n);312313 // transfer-from self to self again314 await collection.transferFrom(owner, {Substrate: owner.address}, {Substrate: owner.address}, 5n);315 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(100n);316 });317318 itEth('Transfers to self. In case of inside substrate-evm when not enought "Fungibles"', async ({helper}) => {319 const [owner] = await helper.arrange.createAccounts([10n], donor);320 const collection = await helper.ft.mintCollection(owner, {});321 await collection.mint(owner, {Substrate: owner.address}, 10n);322323 // transfer to self again324 await expect(collection.transfer(owner, {Substrate: owner.address}, 11n))325 .to.be.rejectedWith(/common\.TokenValueTooLow/);326327 // transfer-from self to self again328 await expect(collection.transferFrom(owner, {Substrate: owner.address}, {Substrate: owner.address}, 12n))329 .to.be.rejectedWith(/common\.TokenValueTooLow/);330 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(10n);331 });332});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 {itEth, usingEthPlaygrounds} from './eth/util/playgrounds';19import {itSub, Pallets, usingPlaygrounds, expect} from './util/playgrounds';2021describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {22 let alice: IKeyringPair;23 let bob: IKeyringPair;2425 before(async () => {26 await usingPlaygrounds(async (helper, privateKey) => {27 const donor = privateKey('//Alice');28 [alice, bob] = await helper.arrange.createAccounts([50n, 10n], donor);29 });30 });31 32 itSub('Balance transfers and check balance', async ({helper}) => {33 const alicesBalanceBefore = await helper.balance.getSubstrate(alice.address);34 const bobsBalanceBefore = await helper.balance.getSubstrate(bob.address);3536 expect(await helper.balance.transferToSubstrate(alice, bob.address, 1n)).to.be.true;3738 const alicesBalanceAfter = await helper.balance.getSubstrate(alice.address);39 const bobsBalanceAfter = await helper.balance.getSubstrate(bob.address);4041 expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;42 expect(bobsBalanceAfter > bobsBalanceBefore).to.be.true;43 });4445 itSub('Inability to pay fees error message is correct', async ({helper, privateKey}) => {46 const donor = privateKey('//Alice');47 const [zero] = await helper.arrange.createAccounts([0n], donor);4849 // console.error = () => {};50 // The following operation throws an error into the console and the logs. Pay it no heed as long as the test succeeds.51 await expect(helper.balance.transferToSubstrate(zero, donor.address, 1n))52 .to.be.rejectedWith('Inability to pay some fees , e.g. account balance too low');53 });5455 itSub('[nft] User can transfer owned token', async ({helper}) => {56 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-1-NFT', description: '', tokenPrefix: 'T'});57 const nft = await collection.mintToken(alice, {Substrate: alice.address});5859 await nft.transfer(alice, {Substrate: bob.address});60 expect(await nft.getOwner()).to.be.deep.equal({Substrate: bob.address});61 });6263 itSub('[fungible] User can transfer owned token', async ({helper}) => {64 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-1-FT', description: '', tokenPrefix: 'T'});65 await collection.mint(alice, {Substrate: alice.address}, 10n);6667 await collection.transfer(alice, {Substrate: bob.address}, 9n);68 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(9n);69 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1n);70 });7172 itSub.ifWithPallets('[refungible] User can transfer owned token', [Pallets.ReFungible], async ({helper}) => {73 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-1-RFT', description: '', tokenPrefix: 'T'});74 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);7576 await rft.transfer(alice, {Substrate: bob.address}, 9n);77 expect(await rft.getBalance({Substrate: bob.address})).to.be.equal(9n);78 expect(await rft.getBalance({Substrate: alice.address})).to.be.equal(1n);79 });8081 itSub('[nft] Collection admin can transfer owned token', async ({helper}) => {82 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-2-NFT', description: '', tokenPrefix: 'T'});83 await collection.addAdmin(alice, {Substrate: bob.address});8485 const nft = await collection.mintToken(bob, {Substrate: bob.address});86 await nft.transfer(bob, {Substrate: alice.address});8788 expect(await nft.getOwner()).to.be.deep.equal({Substrate: alice.address});89 });9091 itSub('[fungible] Collection admin can transfer owned token', async ({helper}) => {92 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-2-FT', description: '', tokenPrefix: 'T'});93 await collection.addAdmin(alice, {Substrate: bob.address});9495 await collection.mint(bob, {Substrate: bob.address}, 10n);96 await collection.transfer(bob, {Substrate: alice.address}, 1n);9798 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(9n);99 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1n);100 });101102 itSub.ifWithPallets('[refungible] Collection admin can transfer owned token', [Pallets.ReFungible], async ({helper}) => {103 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-2-RFT', description: '', tokenPrefix: 'T'});104 await collection.addAdmin(alice, {Substrate: bob.address});105106 const rft = await collection.mintToken(bob, {Substrate: bob.address}, 10n);107 await rft.transfer(bob, {Substrate: alice.address}, 1n);108109 expect(await rft.getBalance({Substrate: bob.address})).to.be.equal(9n);110 expect(await rft.getBalance({Substrate: alice.address})).to.be.equal(1n);111 });112});113114describe('Negative Integration Test Transfer(recipient, collection_id, item_id, value)', () => {115 let alice: IKeyringPair;116 let bob: IKeyringPair;117118 before(async () => {119 await usingPlaygrounds(async (helper, privateKey) => {120 const donor = privateKey('//Alice');121 [alice, bob] = await helper.arrange.createAccounts([50n, 10n], donor);122 });123 });124125 itSub('[nft] Transfer with not existed collection_id', async ({helper}) => {126 const collectionId = (1 << 32) - 1;127 await expect(helper.nft.transferToken(alice, collectionId, 1, {Substrate: bob.address}))128 .to.be.rejectedWith(/common\.CollectionNotFound/);129 });130131 itSub('[fungible] Transfer with not existed collection_id', async ({helper}) => {132 const collectionId = (1 << 32) - 1;133 await expect(helper.ft.transfer(alice, collectionId, {Substrate: bob.address}))134 .to.be.rejectedWith(/common\.CollectionNotFound/);135 });136137 itSub.ifWithPallets('[refungible] Transfer with not existed collection_id', [Pallets.ReFungible], async ({helper}) => {138 const collectionId = (1 << 32) - 1;139 await expect(helper.rft.transferToken(alice, collectionId, 1, {Substrate: bob.address}))140 .to.be.rejectedWith(/common\.CollectionNotFound/);141 });142143 itSub('[nft] Transfer with deleted collection_id', async ({helper}) => {144 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-1-NFT', description: '', tokenPrefix: 'T'});145 const nft = await collection.mintToken(alice, {Substrate: alice.address});146147 await nft.burn(alice);148 await collection.burn(alice);149150 await expect(nft.transfer(alice, {Substrate: bob.address}))151 .to.be.rejectedWith(/common\.CollectionNotFound/);152 });153154 itSub('[fungible] Transfer with deleted collection_id', async ({helper}) => {155 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-Neg-1-FT', description: '', tokenPrefix: 'T'});156 await collection.mint(alice, {Substrate: alice.address}, 10n);157158 await collection.burnTokens(alice, 10n);159 await collection.burn(alice);160161 await expect(collection.transfer(alice, {Substrate: bob.address}))162 .to.be.rejectedWith(/common\.CollectionNotFound/);163 });164 165 itSub.ifWithPallets('[refungible] Transfer with deleted collection_id', [Pallets.ReFungible], async ({helper}) => {166 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-Neg-1-RFT', description: '', tokenPrefix: 'T'});167 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);168169 await rft.burn(alice, 10n);170 await collection.burn(alice);171172 await expect(rft.transfer(alice, {Substrate: bob.address}))173 .to.be.rejectedWith(/common\.CollectionNotFound/);174 });175176 itSub('[nft] Transfer with not existed item_id', async ({helper}) => {177 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-2-NFT', description: '', tokenPrefix: 'T'});178 await expect(collection.transferToken(alice, 1, {Substrate: bob.address}))179 .to.be.rejectedWith(/common\.TokenNotFound/);180 });181182 itSub('[fungible] Transfer with not existed item_id', async ({helper}) => {183 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-Neg-2-FT', description: '', tokenPrefix: 'T'});184 await expect(collection.transfer(alice, {Substrate: bob.address}))185 .to.be.rejectedWith(/common\.TokenValueTooLow/);186 });187188 itSub.ifWithPallets('[refungible] Transfer with not existed item_id', [Pallets.ReFungible], async ({helper}) => {189 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-Neg-2-RFT', description: '', tokenPrefix: 'T'});190 await expect(collection.transferToken(alice, 1, {Substrate: bob.address}))191 .to.be.rejectedWith(/common\.TokenValueTooLow/);192 });193194 itSub('[nft] Transfer with deleted item_id', async ({helper}) => {195 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-3-NFT', description: '', tokenPrefix: 'T'});196 const nft = await collection.mintToken(alice, {Substrate: alice.address});197198 await nft.burn(alice);199200 await expect(nft.transfer(alice, {Substrate: bob.address}))201 .to.be.rejectedWith(/common\.TokenNotFound/);202 });203204 itSub('[fungible] Transfer with deleted item_id', async ({helper}) => {205 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-Neg-3-FT', description: '', tokenPrefix: 'T'});206 await collection.mint(alice, {Substrate: alice.address}, 10n);207208 await collection.burnTokens(alice, 10n);209210 await expect(collection.transfer(alice, {Substrate: bob.address}))211 .to.be.rejectedWith(/common\.TokenValueTooLow/);212 });213214 itSub.ifWithPallets('[refungible] Transfer with deleted item_id', [Pallets.ReFungible], async ({helper}) => {215 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-Neg-3-RFT', description: '', tokenPrefix: 'T'});216 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);217218 await rft.burn(alice, 10n);219220 await expect(rft.transfer(alice, {Substrate: bob.address}))221 .to.be.rejectedWith(/common\.TokenValueTooLow/);222 });223224 itSub('[nft] Transfer with recipient that is not owner', async ({helper}) => {225 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-4-NFT', description: '', tokenPrefix: 'T'});226 const nft = await collection.mintToken(alice, {Substrate: alice.address});227228 await expect(nft.transfer(bob, {Substrate: bob.address}))229 .to.be.rejectedWith(/common\.NoPermission/);230 expect(await nft.getOwner()).to.be.deep.equal({Substrate: alice.address});231 });232233 itSub('[fungible] Transfer with recipient that is not owner', async ({helper}) => {234 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-Neg-4-FT', description: '', tokenPrefix: 'T'});235 await collection.mint(alice, {Substrate: alice.address}, 10n);236237 await expect(collection.transfer(bob, {Substrate: bob.address}, 9n))238 .to.be.rejectedWith(/common\.TokenValueTooLow/);239 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(0n);240 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(10n);241 });242243 itSub.ifWithPallets('[refungible] Transfer with recipient that is not owner', [Pallets.ReFungible], async ({helper}) => {244 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-1-RFT', description: '', tokenPrefix: 'T'});245 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);246247 await expect(rft.transfer(bob, {Substrate: bob.address}, 9n))248 .to.be.rejectedWith(/common\.TokenValueTooLow/);249 expect(await rft.getBalance({Substrate: bob.address})).to.be.equal(0n);250 expect(await rft.getBalance({Substrate: alice.address})).to.be.equal(10n);251 });252});253254describe('Transfers to self (potentially over substrate-evm boundary)', () => {255 let donor: IKeyringPair;256257 before(async function() {258 await usingEthPlaygrounds(async (_, privateKey) => {259 donor = privateKey('//Alice');260 });261 });262 263 itEth('Transfers to self. In case of same frontend', async ({helper}) => {264 const [owner] = await helper.arrange.createAccounts([10n], donor);265 const collection = await helper.ft.mintCollection(owner, {});266 await collection.mint(owner, {Substrate: owner.address}, 100n);267268 const ownerProxy = helper.address.substrateToEth(owner.address);269270 // transfer to own proxy271 await collection.transfer(owner, {Ethereum: ownerProxy}, 10n);272 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(90n);273 expect(await collection.getBalance({Ethereum: ownerProxy})).to.be.equal(10n);274275 // transfer-from own proxy to own proxy again276 await collection.transferFrom(owner, {Ethereum: ownerProxy}, {Ethereum: ownerProxy}, 5n);277 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(90n);278 expect(await collection.getBalance({Ethereum: ownerProxy})).to.be.equal(10n);279 });280281 itEth('Transfers to self. In case of substrate-evm boundary', async ({helper}) => {282 const [owner] = await helper.arrange.createAccounts([10n], donor);283 const collection = await helper.ft.mintCollection(owner, {});284 await collection.mint(owner, {Substrate: owner.address}, 100n);285286 const ownerProxy = helper.address.substrateToEth(owner.address);287288 // transfer to own proxy289 await collection.transfer(owner, {Ethereum: ownerProxy}, 10n);290 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(90n);291 expect(await collection.getBalance({Ethereum: ownerProxy})).to.be.equal(10n);292293 // transfer-from own proxy to self294 await collection.transferFrom(owner, {Ethereum: ownerProxy}, {Substrate: owner.address}, 5n);295 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(95n);296 expect(await collection.getBalance({Ethereum: ownerProxy})).to.be.equal(5n);297 });298299 itEth('Transfers to self. In case of inside substrate-evm', async ({helper}) => {300 const [owner] = await helper.arrange.createAccounts([10n], donor);301 const collection = await helper.ft.mintCollection(owner, {});302 await collection.mint(owner, {Substrate: owner.address}, 100n);303304 // transfer to self again305 await collection.transfer(owner, {Substrate: owner.address}, 10n);306 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(100n);307308 // transfer-from self to self again309 await collection.transferFrom(owner, {Substrate: owner.address}, {Substrate: owner.address}, 5n);310 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(100n);311 });312313 itEth('Transfers to self. In case of inside substrate-evm when not enought "Fungibles"', async ({helper}) => {314 const [owner] = await helper.arrange.createAccounts([10n], donor);315 const collection = await helper.ft.mintCollection(owner, {});316 await collection.mint(owner, {Substrate: owner.address}, 10n);317318 // transfer to self again319 await expect(collection.transfer(owner, {Substrate: owner.address}, 11n))320 .to.be.rejectedWith(/common\.TokenValueTooLow/);321322 // transfer-from self to self again323 await expect(collection.transferFrom(owner, {Substrate: owner.address}, {Substrate: owner.address}, 12n))324 .to.be.rejectedWith(/common\.TokenValueTooLow/);325 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(10n);326 });327});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();