difftreelog
fix PR commets
in: master
4 files changed
tests/src/eth/nativeFungible.test.tsdiffbeforeafterboth1// 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});tests/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 ={
tests/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);
});
tests/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: