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
before · tests/src/eth/nativeFungible.test.ts
1// Copyright 2019-2023 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, itEth, usingEthPlaygrounds} from './util';19import {UniqueHelper} from '../util/playgrounds/unique';2021describe('NativeFungible: ERC20 calls', () => {22  let donor: IKeyringPair;2324  before(async function() {25    await usingEthPlaygrounds(async (helper, privateKey) => {26      donor = await privateKey({url: import.meta.url});27      // [alice] = await helper.arrange.createAccounts([30n], donor);28    });29  });3031  itEth('approve()', async ({helper}) => {32    const owner = await helper.eth.createAccountWithBalance(donor);33    const spender = helper.eth.createAccount();34    const collectionAddress = helper.ethAddress.fromCollectionId(0);35    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);3637    await expect(contract.methods.approve(spender, 100).call({from: owner})).to.be.rejectedWith('Approve not supported');38  });3940  itEth('balanceOf()', async ({helper}) => {41    const owner = await helper.eth.createAccountWithBalance(donor, 123n);42    const collectionAddress = helper.ethAddress.fromCollectionId(0);43    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);4445    const balance = await contract.methods.balanceOf(owner).call({from: owner});46    expect(balance).to.be.eq('123000000000000000000');47  });4849  itEth('decimals()', async ({helper}) => {50    const owner = await helper.eth.createAccountWithBalance(donor);51    const collectionAddress = helper.ethAddress.fromCollectionId(0);52    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);5354    const realDecimals = (await helper.chain.getChainProperties().tokenDecimals)[0].toString();55    const decimals = await contract.methods.decimals().call({from: owner});56    expect(decimals).to.be.eq(realDecimals);57  });5859  itEth('name()', async ({helper}) => {60    const owner = await helper.eth.createAccountWithBalance(donor);61    const collectionAddress = helper.ethAddress.fromCollectionId(0);62    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);6364    const realName = await UniqueHelper.detectNetwork(helper.getApi());65    const name = await contract.methods.name().call({from: owner});66    expect(name).to.be.eq(realName);67  });6869  itEth('symbol()', async ({helper}) => {70    const owner = await helper.eth.createAccountWithBalance(donor);71    const collectionAddress = helper.ethAddress.fromCollectionId(0);72    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);7374    const realName = (await helper.chain.getChainProperties().tokenSymbol)[0];75    const name = await contract.methods.symbol().call({from: owner});76    expect(name).to.be.eq(realName);77  });7879  itEth('totalSupply()', async ({helper}) => {80    const owner = await helper.eth.createAccountWithBalance(donor);81    const collectionAddress = helper.ethAddress.fromCollectionId(0);82    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);8384    const totalSupplyEth = BigInt(await contract.methods.totalSupply().call({from: owner}));85    const totalSupplySub = await helper.balance.getTotalIssuance();86    expect(totalSupplyEth).to.be.eq(totalSupplySub);87  });8889  itEth('transfer()', async ({helper}) => {90    const owner = await helper.eth.createAccountWithBalance(donor);91    const receiver = await helper.eth.createAccountWithBalance(donor);92    const collectionAddress = helper.ethAddress.fromCollectionId(0);93    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);9495    const balanceOwnerBefore = await helper.balance.getEthereum(owner);96    const balanceReceiverBefore = await helper.balance.getEthereum(receiver);9798    await contract.methods.transfer(receiver, 50).send({from: owner});99100    const balanceOwnerAfter = await helper.balance.getEthereum(owner);101    const balanceReceiverAfter = await helper.balance.getEthereum(receiver);102103    expect(balanceOwnerBefore - 50n > balanceOwnerAfter).to.be.true;104    expect(balanceReceiverBefore === balanceReceiverAfter - 50n).to.be.true;105  });106107  itEth('transferFrom()', async ({helper}) => {108    const owner = await helper.eth.createAccountWithBalance(donor);109    const receiver = await helper.eth.createAccountWithBalance(donor);110    const collectionAddress = helper.ethAddress.fromCollectionId(0);111    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);112113    const balanceOwnerBefore = await helper.balance.getEthereum(owner);114    const balanceReceiverBefore = await helper.balance.getEthereum(receiver);115116    await contract.methods.transferFrom(owner, receiver, 50).send({from: owner});117118    const balanceOwnerAfter = await helper.balance.getEthereum(owner);119    const balanceReceiverAfter = await helper.balance.getEthereum(receiver);120121    expect(balanceOwnerBefore - 50n > balanceOwnerAfter).to.be.true;122    expect(balanceReceiverBefore === balanceReceiverAfter - 50n).to.be.true;123124    await expect(contract.methods.transferFrom(receiver, receiver, 50).call({from: owner})).to.be.rejectedWith('ApprovedValueTooLow');125  });126});127128describe('NativeFungible: ERC20UniqueExtensions calls', () => {129  let donor: IKeyringPair;130131  before(async function() {132    await usingEthPlaygrounds(async (helper, privateKey) => {133      donor = await privateKey({url: import.meta.url});134      // [alice] = await helper.arrange.createAccounts([30n], donor);135    });136  });137138  itEth('transferCross()', async ({helper}) => {139    const owner = await helper.eth.createAccountWithBalance(donor);140    const receiver = await helper.ethCrossAccount.createAccountWithBalance(donor);141    const collectionAddress = helper.ethAddress.fromCollectionId(0);142    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);143144    const balanceOwnerBefore = await helper.balance.getEthereum(owner);145    const balanceReceiverBefore = await helper.balance.getEthereum(receiver.eth);146147    await contract.methods.transferCross(receiver, 50).send({from: owner});148149    const balanceOwnerAfter = await helper.balance.getEthereum(owner);150    const balanceReceiverAfter = await helper.balance.getEthereum(receiver.eth);151152    expect(balanceOwnerBefore - 50n > balanceOwnerAfter).to.be.true;153    expect(balanceReceiverBefore === balanceReceiverAfter - 50n).to.be.true;154  });155156  itEth('transferFromCross()', async ({helper}) => {157    const owner = await helper.ethCrossAccount.createAccountWithBalance(donor);158    const receiver = await helper.ethCrossAccount.createAccountWithBalance(donor);159    const collectionAddress = helper.ethAddress.fromCollectionId(0);160    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner.eth);161162    const balanceOwnerBefore = await helper.balance.getEthereum(owner.eth);163    const balanceReceiverBefore = await helper.balance.getEthereum(receiver.eth);164165    await contract.methods.transferFromCross(owner, receiver, 50).send({from: owner.eth});166167    const balanceOwnerAfter = await helper.balance.getEthereum(owner.eth);168    const balanceReceiverAfter = await helper.balance.getEthereum(receiver.eth);169170    expect(balanceOwnerBefore - 50n > balanceOwnerAfter).to.be.true;171    expect(balanceReceiverBefore === balanceReceiverAfter - 50n).to.be.true;172173    await expect(contract.methods.transferFromCross(receiver, receiver, 50).call({from: owner.eth})).to.be.rejectedWith('no permission');174  });175});
after · tests/src/eth/nativeFungible.test.ts
1// Copyright 2019-2023 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, itEth, usingEthPlaygrounds} from './util';19import {UniqueHelper} from '../util/playgrounds/unique';2021describe('NativeFungible: ERC20 calls', () => {22  let donor: IKeyringPair;2324  before(async function() {25    await usingEthPlaygrounds(async (helper, privateKey) => {26      donor = await privateKey({url: import.meta.url});27    });28  });2930  itEth('approve()', async ({helper}) => {31    const owner = await helper.eth.createAccountWithBalance(donor);32    const spender = helper.eth.createAccount();33    const collectionAddress = helper.ethAddress.fromCollectionId(0);34    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);3536    await expect(contract.methods.approve(spender, 100).call({from: owner})).to.be.rejectedWith('Approve not supported');37  });3839  itEth('balanceOf()', async ({helper}) => {40    const owner = await helper.eth.createAccountWithBalance(donor, 123n);41    const collectionAddress = helper.ethAddress.fromCollectionId(0);42    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);4344    const balance = await contract.methods.balanceOf(owner).call({from: owner});45    expect(balance).to.be.eq('123000000000000000000');46  });4748  itEth('decimals()', async ({helper}) => {49    const owner = await helper.eth.createAccountWithBalance(donor);50    const collectionAddress = helper.ethAddress.fromCollectionId(0);51    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);5253    const realDecimals = (await helper.chain.getChainProperties().tokenDecimals)[0].toString();54    const decimals = await contract.methods.decimals().call({from: owner});55    expect(decimals).to.be.eq(realDecimals);56  });5758  itEth('name()', async ({helper}) => {59    const owner = await helper.eth.createAccountWithBalance(donor);60    const collectionAddress = helper.ethAddress.fromCollectionId(0);61    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);6263    const realName = await UniqueHelper.detectNetwork(helper.getApi());64    const name = await contract.methods.name().call({from: owner});65    expect(name).to.be.eq(realName);66  });6768  itEth('symbol()', async ({helper}) => {69    const owner = await helper.eth.createAccountWithBalance(donor);70    const collectionAddress = helper.ethAddress.fromCollectionId(0);71    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);7273    const realName = (await helper.chain.getChainProperties().tokenSymbol)[0];74    const name = await contract.methods.symbol().call({from: owner});75    expect(name).to.be.eq(realName);76  });7778  itEth('totalSupply()', async ({helper}) => {79    const owner = await helper.eth.createAccountWithBalance(donor);80    const collectionAddress = helper.ethAddress.fromCollectionId(0);81    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);8283    const totalSupplyEth = BigInt(await contract.methods.totalSupply().call({from: owner}));84    const totalSupplySub = await helper.balance.getTotalIssuance();85    expect(totalSupplyEth).to.be.eq(totalSupplySub);86  });8788  itEth('transfer()', async ({helper}) => {89    const owner = await helper.eth.createAccountWithBalance(donor);90    const receiver = await helper.eth.createAccountWithBalance(donor);91    const collectionAddress = helper.ethAddress.fromCollectionId(0);92    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);9394    const balanceOwnerBefore = await helper.balance.getEthereum(owner);95    const balanceReceiverBefore = await helper.balance.getEthereum(receiver);9697    await contract.methods.transfer(receiver, 50).send({from: owner});9899    const balanceOwnerAfter = await helper.balance.getEthereum(owner);100    const balanceReceiverAfter = await helper.balance.getEthereum(receiver);101102    expect(balanceOwnerBefore - 50n > balanceOwnerAfter).to.be.true;103    expect(balanceReceiverBefore + 50n).to.be.equal(balanceReceiverAfter);104  });105106  itEth('transferFrom()', async ({helper}) => {107    const owner = await helper.eth.createAccountWithBalance(donor);108    const receiver = await helper.eth.createAccountWithBalance(donor);109    const collectionAddress = helper.ethAddress.fromCollectionId(0);110    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);111112    const balanceOwnerBefore = await helper.balance.getEthereum(owner);113    const balanceReceiverBefore = await helper.balance.getEthereum(receiver);114115    await contract.methods.transferFrom(owner, receiver, 50).send({from: owner});116117    const balanceOwnerAfter = await helper.balance.getEthereum(owner);118    const balanceReceiverAfter = await helper.balance.getEthereum(receiver);119120    expect(balanceOwnerBefore - 50n > balanceOwnerAfter).to.be.true;121    expect(balanceReceiverBefore === balanceReceiverAfter - 50n).to.be.true;122123    await expect(contract.methods.transferFrom(receiver, receiver, 50).call({from: owner})).to.be.rejectedWith('ApprovedValueTooLow');124  });125});126127describe('NativeFungible: ERC20UniqueExtensions calls', () => {128  let donor: IKeyringPair;129130  before(async function() {131    await usingEthPlaygrounds(async (helper, privateKey) => {132      donor = await privateKey({url: import.meta.url});133    });134  });135136  itEth('transferCross()', async ({helper}) => {137    const owner = await helper.eth.createAccountWithBalance(donor);138    const receiver = await helper.ethCrossAccount.createAccountWithBalance(donor);139    const collectionAddress = helper.ethAddress.fromCollectionId(0);140    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);141142    const balanceOwnerBefore = await helper.balance.getEthereum(owner);143    const balanceReceiverBefore = await helper.balance.getEthereum(receiver.eth);144145    await contract.methods.transferCross(receiver, 50).send({from: owner});146147    const balanceOwnerAfter = await helper.balance.getEthereum(owner);148    const balanceReceiverAfter = await helper.balance.getEthereum(receiver.eth);149150    expect(balanceOwnerBefore - 50n > balanceOwnerAfter).to.be.true;151    expect(balanceReceiverBefore === balanceReceiverAfter - 50n).to.be.true;152  });153154  itEth('transferFromCross()', async ({helper}) => {155    const owner = await helper.ethCrossAccount.createAccountWithBalance(donor);156    const receiver = await helper.ethCrossAccount.createAccountWithBalance(donor);157    const collectionAddress = helper.ethAddress.fromCollectionId(0);158    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner.eth);159160    const balanceOwnerBefore = await helper.balance.getEthereum(owner.eth);161    const balanceReceiverBefore = await helper.balance.getEthereum(receiver.eth);162163    await contract.methods.transferFromCross(owner, receiver, 50).send({from: owner.eth});164165    const balanceOwnerAfter = await helper.balance.getEthereum(owner.eth);166    const balanceReceiverAfter = await helper.balance.getEthereum(receiver.eth);167168    expect(balanceOwnerBefore - 50n > balanceOwnerAfter).to.be.true;169    expect(balanceReceiverBefore === balanceReceiverAfter - 50n).to.be.true;170171    await expect(contract.methods.transferFromCross(receiver, receiver, 50).call({from: owner.eth})).to.be.rejectedWith('no permission');172  });173});
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
--- a/tests/src/sub/nesting/common.test.ts
+++ b/tests/src/sub/nesting/common.test.ts
@@ -103,7 +103,7 @@
       nesting: {tokenOwner: true, restricted: testCase.restrictedMode ? [collectionForNesting.collectionId] : null},
     });
 
-    // Alice can mint and nest token:
+    // Bob can nest Native FT into their NFT:
     await collectionForNesting.transfer(bob, targetTokenBob.nestingAccount(), 50n);
     expect(await collectionForNesting.getBalance(targetTokenBob.nestingAccount())).eq(50n);
   });
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: