git.delta.rocks / unique-network / refs/commits / e1baaf9b0769

difftreelog

tests: fix solc has any + revert skipping in transfer

Fahrrader2022-09-09parent: #6069e8a.patch.diff
in: master

3 files changed

addedtests/src/eth/util/playgrounds/unique.dev.d.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/eth/util/playgrounds/unique.dev.d.ts
@@ -0,0 +1,17 @@
+// 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/>.
+
+declare module 'solc';
\ No newline at end of file
modifiedtests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth
--- a/tests/src/eth/util/playgrounds/unique.dev.ts
+++ b/tests/src/eth/util/playgrounds/unique.dev.ts
@@ -2,6 +2,8 @@
 // SPDX-License-Identifier: Apache-2.0
 
 /* eslint-disable function-call-argument-newline */
+// eslint-disable-next-line @typescript-eslint/triple-slash-reference
+/// <reference path="unique.dev.d.ts" />
 
 import {readFile} from 'fs/promises';
 
modifiedtests/src/transfer.test.tsdiffbeforeafterboth
before · tests/src/transfer.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import 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.skip('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.skip('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});