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

difftreelog

fix PR commets

Trubnikov Sergey2023-05-17parent: #3429f32.patch.diff
in: master

4 files changed

modifiedtests/src/eth/nativeFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/nativeFungible.test.ts
+++ b/tests/src/eth/nativeFungible.test.ts
@@ -24,7 +24,6 @@
   before(async function() {
     await usingEthPlaygrounds(async (helper, privateKey) => {
       donor = await privateKey({url: import.meta.url});
-      // [alice] = await helper.arrange.createAccounts([30n], donor);
     });
   });
 
@@ -101,7 +100,7 @@
     const balanceReceiverAfter = await helper.balance.getEthereum(receiver);
 
     expect(balanceOwnerBefore - 50n > balanceOwnerAfter).to.be.true;
-    expect(balanceReceiverBefore === balanceReceiverAfter - 50n).to.be.true;
+    expect(balanceReceiverBefore + 50n).to.be.equal(balanceReceiverAfter);
   });
 
   itEth('transferFrom()', async ({helper}) => {
@@ -131,7 +130,6 @@
   before(async function() {
     await usingEthPlaygrounds(async (helper, privateKey) => {
       donor = await privateKey({url: import.meta.url});
-      // [alice] = await helper.arrange.createAccounts([30n], donor);
     });
   });
 
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
@@ -142,7 +142,7 @@
 
   async collection(address: string, mode: TCollectionMode, caller?: string, mergeDeprecated = false) {
     let abi;
-    if (address === '0x17C4e6453cC49aaAAEaCA894E6d9683e00000000') {
+    if (address === this.helper.ethAddress.fromCollectionId(0)) {
       abi = nativeFungibleAbi;
     } else {
       abi ={
modifiedtests/src/sub/nesting/common.test.tsdiffbeforeafterboth
before · tests/src/sub/nesting/common.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 {expect, itSub, Pallets, usingPlaygrounds} from '../../util';19import {UniqueNFTCollection, UniqueRFTCollection} from '../../util/playgrounds/unique';2021let alice: IKeyringPair;22let bob: IKeyringPair;2324before(async () => {25  await usingPlaygrounds(async (helper, privateKey) => {26    const donor = await privateKey({url: import.meta.url});27    [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);28  });29});3031[32  {mode: 'nft' as const, restrictedMode: true, requiredPallets: []},33  {mode: 'nft' as const, restrictedMode: false, requiredPallets: []},34  {mode: 'rft' as const, restrictedMode: true, requiredPallets: [Pallets.ReFungible]},35  {mode: 'rft' as const, restrictedMode: false, requiredPallets: [Pallets.ReFungible]},36].map(testCase => {37  itSub.ifWithPallets(`Token owner can nest ${testCase.mode.toUpperCase()} in NFT if "tokenOwner" permission set ${testCase.restrictedMode ? 'in restricted mode': ''}`, testCase.requiredPallets, async ({helper}) => {38    // Only NFT can be target for nesting in39    const targetNFTCollection = await helper.nft.mintCollection(alice);40    const targetTokenBob = await targetNFTCollection.mintToken(alice, {Substrate: bob.address});4142    const collectionForNesting = await helper[testCase.mode].mintCollection(bob);43    // permissions should be set:44    await targetNFTCollection.setPermissions(alice, {45      nesting: {tokenOwner: true, restricted: testCase.restrictedMode ? [collectionForNesting.collectionId] : null},46    });4748    // 1. Bob can immediately create nested token:49    const nestedToken1 = testCase.mode === 'nft'50      ? await (collectionForNesting as UniqueNFTCollection).mintToken(bob, targetTokenBob.nestingAccount())51      : await (collectionForNesting as UniqueRFTCollection).mintToken(bob, 10n, targetTokenBob.nestingAccount());52    expect(await nestedToken1.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});53    expect(await nestedToken1.getOwner()).to.be.deep.equal(targetTokenBob.nestingAccount().toLowerCase());5455    // 2. Bob can mint and nest token:56    const nestedToken2 = await collectionForNesting.mintToken(bob);57    await nestedToken2.nest(bob, targetTokenBob);58    expect(await nestedToken2.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});59    expect(await nestedToken2.getOwner()).to.be.deep.equal(targetTokenBob.nestingAccount().toLowerCase());60  });61});626364[65  {restrictedMode: true},66  {restrictedMode: false},67].map(testCase => {68  itSub(`Token owner can nest FT in NFT if "tokenOwner" permission set  ${testCase.restrictedMode ? 'in restricted mode': ''}`, async ({helper}) => {69    // Only NFT allows nesting, permissions should be set:70    const targetNFTCollection = await helper.nft.mintCollection(alice);71    const targetTokenBob = await targetNFTCollection.mintToken(alice, {Substrate: bob.address});7273    const collectionForNesting = await helper.ft.mintCollection(bob);74    // permissions should be set:75    await targetNFTCollection.setPermissions(alice, {76      nesting: {tokenOwner: true, restricted: testCase.restrictedMode ? [collectionForNesting.collectionId] : null},77    });7879    // 1. Alice can immediately create nested tokens:80    await collectionForNesting.mint(bob, 100n, targetTokenBob.nestingAccount());81    expect(await collectionForNesting.getTop10Owners()).deep.eq([targetTokenBob.nestingAccount().toLowerCase()]);82    expect(await collectionForNesting.getBalance(targetTokenBob.nestingAccount())).eq(100n);8384    // 2. Alice can mint and nest token:85    await collectionForNesting.mint(bob, 100n);86    await collectionForNesting.transfer(bob, targetTokenBob.nestingAccount(), 50n);87    expect(await collectionForNesting.getBalance(targetTokenBob.nestingAccount())).eq(150n);88  });89});9091[92  {restrictedMode: true},93  {restrictedMode: false},94].map(testCase => {95  itSub(`Token owner can nest Native FT in NFT if "tokenOwner" permission set  ${testCase.restrictedMode ? 'in restricted mode': ''}`, async ({helper}) => {96    // Only NFT allows nesting, permissions should be set:97    const targetNFTCollection = await helper.nft.mintCollection(alice);98    const targetTokenBob = await targetNFTCollection.mintToken(alice, {Substrate: bob.address});99100    const collectionForNesting = helper.ft.getCollectionObject(0);101    // permissions should be set:102    await targetNFTCollection.setPermissions(alice, {103      nesting: {tokenOwner: true, restricted: testCase.restrictedMode ? [collectionForNesting.collectionId] : null},104    });105106    // Alice can mint and nest token:107    await collectionForNesting.transfer(bob, targetTokenBob.nestingAccount(), 50n);108    expect(await collectionForNesting.getBalance(targetTokenBob.nestingAccount())).eq(50n);109  });110});111112113itSub.ifWithPallets('Owner can unnest tokens using transferFrom', [Pallets.ReFungible], async ({helper}) => {114  const collectionToNest = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});115  const tokenA = await collectionToNest.mintToken(alice);116  const tokenB = await collectionToNest.mintToken(alice);117118  // Create a nested token119  const nftCollectionToBeNested = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});120  const rftCollectionToBeNested = await helper.rft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});121  const ftCollectionToBeNested = await helper.ft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});122  const nativeFtCollectionToBeNested = helper.ft.getCollectionObject(0);123124  const nestedNFT = await nftCollectionToBeNested.mintToken(alice, tokenA.nestingAccount());125  const nestedRFT = await rftCollectionToBeNested.mintToken(alice, 100n, tokenA.nestingAccount());126  const _nestedFT = await ftCollectionToBeNested.mint(alice, 100n, tokenA.nestingAccount());127  await nativeFtCollectionToBeNested.transfer(alice, tokenA.nestingAccount(), 100n);128  expect(await nestedNFT.getOwner()).to.be.deep.equal(tokenA.nestingAccount().toLowerCase());129  expect(await nestedRFT.getOwner()).to.be.deep.equal(tokenA.nestingAccount().toLowerCase());130  expect(await ftCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(100n);131  expect(await nativeFtCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(100n);132133  // Transfer the nested token to another token134  await nestedNFT.transferFrom(alice, tokenA.nestingAccount(), tokenB.nestingAccount());135  await nestedRFT.transferFrom(alice, tokenA.nestingAccount(), tokenB.nestingAccount(), 25n);136  await ftCollectionToBeNested.transferFrom(alice, tokenA.nestingAccount(), tokenB.nestingAccount(), 25n);137  await nativeFtCollectionToBeNested.transferFrom(alice, tokenA.nestingAccount(), tokenB.nestingAccount(), 25n);138139  expect(await nestedNFT.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});140  expect(await nestedNFT.getOwner()).to.be.deep.equal(tokenB.nestingAccount().toLowerCase());141142  expect(await nestedRFT.getBalance(tokenB.nestingAccount())).to.equal(25n);143  expect(await nestedRFT.getBalance(tokenA.nestingAccount())).to.equal(75n);144145  expect(await ftCollectionToBeNested.getBalance(tokenB.nestingAccount())).to.equal(25n);146  expect(await ftCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(75n);147148  expect(await nativeFtCollectionToBeNested.getBalance(tokenB.nestingAccount())).to.equal(25n);149  expect(await nativeFtCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(75n);150});
modifiedtests/src/sub/nesting/nesting.negative.test.tsdiffbeforeafterboth
--- a/tests/src/sub/nesting/nesting.negative.test.ts
+++ b/tests/src/sub/nesting/nesting.negative.test.ts
@@ -69,7 +69,7 @@
       ? collectionForNesting.mint(alice, 100n, targetToken.nestingAccount())
       : collectionForNesting.transfer(alice, targetToken.nestingAccount(), 100n)).to.be.rejectedWith('common.UserIsNotAllowedToNest');
 
-    // Alice can mint and nest token:
+    // Alice can't mint and nest tokens:
     if (testCase.mode === 'ft') {
       await collectionForNesting.mint(alice, 100n);
     }
@@ -100,7 +100,7 @@
       case 'nft': nestedTokenBob = await (nestedCollectionBob as UniqueNFTCollection).mintToken(bob); break;
       case 'rft': nestedTokenBob = await (nestedCollectionBob as UniqueRFTCollection).mintToken(bob, 100n); break;
       case 'ft': await (nestedCollectionBob as UniqueFTCollection).mint(bob, 100n); break;
-      case 'native ft': break;
+      case 'native ft': await expect((nestedCollectionBob as UniqueFTCollection).mint(bob, 100n)).to.be.rejectedWith('common.UnsupportedOperation'); break;
     }
 
     // Bob non-owner of targetToken and non admin of targetCollection, so
@@ -109,7 +109,7 @@
       case 'nft': await expect((nestedCollectionBob as UniqueNFTCollection).mintToken(bob, targetToken.nestingAccount())).to.be.rejectedWith('common.UserIsNotAllowedToNest'); break;
       case 'rft': await expect((nestedCollectionBob as UniqueRFTCollection).mintToken(bob, 100n, targetToken.nestingAccount())).to.be.rejectedWith('common.UserIsNotAllowedToNest'); break;
       case 'ft': await expect((nestedCollectionBob as UniqueFTCollection).mint(bob, 100n, targetToken.nestingAccount())).to.be.rejectedWith('common.UserIsNotAllowedToNest'); break;
-      case 'native ft': break;
+      case 'native ft': await expect((nestedCollectionBob as UniqueFTCollection).mint(bob, 100n, targetToken.nestingAccount())).to.be.rejectedWith('common.UnsupportedOperation'); break;
     }
 
     // 2. cannot nest existing token: