git.delta.rocks / unique-network / refs/commits / 7c2f408f0bda

difftreelog

tests(parallelization): fix createAccounts failing to catch up on dev node + evm events

Fahrrader2022-10-13parent: #85e2544.patch.diff
in: master

6 files changed

modifiedtests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth
--- a/tests/src/eth/contractSponsoring.test.ts
+++ b/tests/src/eth/contractSponsoring.test.ts
@@ -378,7 +378,7 @@
     // Balance should be taken from flipper instead of caller
     // FIXME the comment is wrong! What check should be here?
     const balanceAfter = await helper.balance.getEthereum(flipper.options.address);
-    expect(balanceAfter).to.be.equals(originalFlipperBalance);
+    expect(balanceAfter).to.be.equal(originalFlipperBalance);
   });
 
   itEth('Sponsoring is set, an address that has UNQ can send a transaction and it works. User balance should not change', async ({helper}) => {
@@ -406,7 +406,7 @@
     const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));
     const callerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));
     expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
-    expect(callerBalanceAfter).to.be.equals(callerBalanceBefore);
+    expect(callerBalanceAfter).to.be.equal(callerBalanceBefore);
   });
 
   itEth('Sponsoring is limited, with setContractRateLimit. The limitation is working if transactions are sent more often, the sender pays the commission.', async ({helper}) => {
@@ -431,23 +431,24 @@
 
     await flipper.methods.flip().send({from: caller});
     expect(await flipper.methods.getValue().call()).to.be.true;
-    expect(await helper.balance.getEthereum(caller)).to.be.equals(originalCallerBalance);
+    expect(await helper.balance.getEthereum(caller)).to.be.equal(originalCallerBalance);
 
     const newFlipperBalance = await helper.balance.getEthereum(sponsor);
-    expect(newFlipperBalance).to.be.not.equals(originalFlipperBalance);
+    expect(newFlipperBalance).to.be.not.equal(originalFlipperBalance);
 
     await flipper.methods.flip().send({from: caller});
+    // todo:playgrounds fails rarely (expected 99893341659775672580n to equal 99912598679356033129n) (again, 99893341659775672580n)
     expect(await helper.balance.getEthereum(sponsor)).to.be.equal(newFlipperBalance);
-    expect(await helper.balance.getEthereum(caller)).to.be.not.equals(originalCallerBalance);
+    expect(await helper.balance.getEthereum(caller)).to.be.not.equal(originalCallerBalance);
   });
 
   // TODO: Find a way to calculate default rate limit
-  itEth('Default rate limit equals 7200', async ({helper}) => {
+  itEth('Default rate limit equal 7200', async ({helper}) => {
     const owner = await helper.eth.createAccountWithBalance(donor);
     const helpers = helper.ethNativeContract.contractHelpers(owner);
     const flipper = await helper.eth.deployFlipper(owner);
 
-    expect(await helpers.methods.sponsoringRateLimit(flipper.options.address).call()).to.be.equals('7200');
+    expect(await helpers.methods.sponsoringRateLimit(flipper.options.address).call()).to.be.equal('7200');
   });
 });
 
@@ -501,7 +502,7 @@
     const helpers = helper.ethNativeContract.contractHelpers(owner);
     const flipper = await helper.eth.deployFlipper(owner);
 
-    expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equals('115792089237316195423570985008687907853269984665640564039457584007913129639935');
+    expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equal('115792089237316195423570985008687907853269984665640564039457584007913129639935');
   });
 
   itEth('Set fee limit', async ({helper}) => {
@@ -510,7 +511,7 @@
     const flipper = await helper.eth.deployFlipper(owner);
 
     await helpers.methods.setSponsoringFeeLimit(flipper.options.address, 100).send();
-    expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equals('100');
+    expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equal('100');
   });
 
   itEth('Negative test - set fee limit by non-owner', async ({helper}) => {
modifiedtests/src/eth/fungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -294,9 +294,11 @@
     contract.events.allEvents((_: any, event: any) => {
       events.push(event);
     });
+    
     await collection.approveTokens(alice, {Ethereum: receiver}, 100n);
+    if (events.length == 0) await helper.wait.newBlocks(1);
+    const event = events[0];
 
-    const event = events[0];
     expect(event.event).to.be.equal('Approval');
     expect(event.address).to.be.equal(collectionAddress);
     expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));
@@ -318,9 +320,11 @@
     contract.events.allEvents((_: any, event: any) => {
       events.push(event);
     });
+
     await collection.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver}, 51n);
+    if (events.length == 0) await helper.wait.newBlocks(1);
+    let event = events[0];
 
-    let event = events[0];
     expect(event.event).to.be.equal('Transfer');
     expect(event.address).to.be.equal(collectionAddress);
     expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));
@@ -347,9 +351,11 @@
     contract.events.allEvents((_: any, event: any) => {
       events.push(event);
     });
+    
     await collection.transfer(alice, {Ethereum:receiver}, 51n);
-
+    if (events.length == 0) await helper.wait.newBlocks(1);
     const event = events[0];
+
     expect(event.event).to.be.equal('Transfer');
     expect(event.address).to.be.equal(collectionAddress);
     expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -385,9 +385,11 @@
     contract.events.allEvents((_: any, event: any) => {
       events.push(event);
     });
+
     const {tokenId} = await collection.mintToken(alice);
+    if (events.length == 0) await helper.wait.newBlocks(1);
+    const event = events[0];
 
-    const event = events[0];
     expect(event.event).to.be.equal('Transfer');
     expect(event.address).to.be.equal(collectionAddress);
     expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
@@ -408,8 +410,9 @@
     });
 
     await token.burn(alice);
+    if (events.length == 0) await helper.wait.newBlocks(1);
+    const event = events[0];
 
-    const event = events[0];
     expect(event.event).to.be.equal('Transfer');
     expect(event.address).to.be.equal(collectionAddress);
     expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));
@@ -432,8 +435,9 @@
     });
 
     await token.approve(alice, {Ethereum: receiver});
+    if (events.length == 0) await helper.wait.newBlocks(1);
+    const event = events[0];
 
-    const event = events[0];
     expect(event.event).to.be.equal('Approval');
     expect(event.address).to.be.equal(collectionAddress);
     expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));
@@ -458,8 +462,9 @@
     });
 
     await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver});
-    
+    if (events.length == 0) await helper.wait.newBlocks(1);
     const event = events[0];
+
     expect(event.address).to.be.equal(collectionAddress);
     expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));
     expect(event.returnValues.to).to.be.equal(receiver);
@@ -481,8 +486,9 @@
     });
 
     await token.transfer(alice, {Ethereum: receiver});
-    
+    if (events.length == 0) await helper.wait.newBlocks(1);
     const event = events[0];
+
     expect(event.address).to.be.equal(collectionAddress);
     expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));
     expect(event.returnValues.to).to.be.equal(receiver);
modifiedtests/src/eth/reFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -286,9 +286,11 @@
     contract.events.allEvents((_: any, event: any) => {
       events.push(event);
     });
+
     await tokenContract.methods.transfer(receiver, 1).send();
+    if (events.length == 0) await helper.wait.newBlocks(1);
+    const event = events[0];
 
-    const event = events[0];
     expect(event.address).to.equal(collectionAddress);
     expect(event.returnValues.from).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');
     expect(event.returnValues.to).to.equal(receiver);
@@ -312,9 +314,11 @@
     contract.events.allEvents((_: any, event: any) => {
       events.push(event);
     });
+
     await tokenContract.methods.transfer(receiver, 1).send();
+    if (events.length == 0) await helper.wait.newBlocks(1);
+    const event = events[0];
 
-    const event = events[0];
     expect(event.address).to.equal(collectionAddress);
     expect(event.returnValues.from).to.equal(caller);
     expect(event.returnValues.to).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');
modifiedtests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth
before · tests/src/eth/reFungibleToken.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 {Pallets, requirePalletsOrSkip} from '../util';18import {EthUniqueHelper, expect, itEth, usingEthPlaygrounds} from './util';19import {IKeyringPair} from '@polkadot/types/types';20import {Contract} from 'web3-eth-contract';212223describe('Refungible token: Information getting', () => {24  let donor: IKeyringPair;25  let alice: IKeyringPair;2627  before(async function() {28    await usingEthPlaygrounds(async (helper, privateKey) => {29      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);3031      donor = await privateKey({filename: __filename});32      [alice] = await helper.arrange.createAccounts([20n], donor);33    });34  });3536  itEth('totalSupply', async ({helper}) => {37    const caller = await helper.eth.createAccountWithBalance(donor);38    const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'MUON'});39    const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: caller});4041    const contract = helper.ethNativeContract.rftTokenById(collection.collectionId, tokenId, caller);42    const totalSupply = await contract.methods.totalSupply().call();43    expect(totalSupply).to.equal('200');44  });4546  itEth('balanceOf', async ({helper}) => {47    const caller = await helper.eth.createAccountWithBalance(donor);48    const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'MUON'});49    const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: caller});5051    const contract = helper.ethNativeContract.rftTokenById(collection.collectionId, tokenId, caller);52    const balance = await contract.methods.balanceOf(caller).call();53    expect(balance).to.equal('200');54  });5556  itEth('decimals', async ({helper}) => {57    const caller = await helper.eth.createAccountWithBalance(donor);58    const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'MUON'});59    const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: caller});6061    const contract = helper.ethNativeContract.rftTokenById(collection.collectionId, tokenId, caller);62    const decimals = await contract.methods.decimals().call();63    expect(decimals).to.equal('0');64  });65});6667// FIXME: Need erc721 for ReFubgible.68describe('Check ERC721 token URI for ReFungible', () => {69  let donor: IKeyringPair;7071  before(async function() {72    await usingEthPlaygrounds(async (helper, privateKey) => {73      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);7475      donor = await privateKey({filename: __filename});76    });77  });7879  async function setup(helper: EthUniqueHelper, tokenPrefix: string, propertyKey?: string, propertyValue?: string): Promise<{contract: Contract, nextTokenId: string}> {80    const owner = await helper.eth.createAccountWithBalance(donor);81    const receiver = helper.eth.createAccount();8283    const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);84    let result = await collectionHelper.methods.createERC721MetadataCompatibleCollection('Mint collection', 'a', 'b', tokenPrefix).send({value: Number(2n * helper.balance.getOneTokenNominal())});85    const collectionAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);86    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);87    88    const nextTokenId = await contract.methods.nextTokenId().call();89    expect(nextTokenId).to.be.equal('1');90    result = await contract.methods.mint(91      receiver,92      nextTokenId,93    ).send();9495    if (propertyKey && propertyValue) {96      // Set URL or suffix97      await contract.methods.setProperty(nextTokenId, propertyKey, Buffer.from(propertyValue)).send();98    }99100    const event = result.events.Transfer;101    expect(event.address).to.be.equal(collectionAddress);102    expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');103    expect(event.returnValues.to).to.be.equal(receiver);104    expect(event.returnValues.tokenId).to.be.equal(nextTokenId);105106    return {contract, nextTokenId};107  }108109  itEth('Empty tokenURI', async ({helper}) => {110    const {contract, nextTokenId} = await setup(helper, '');111    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');112  });113114  itEth('TokenURI from url', async ({helper}) => {115    const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'url', 'Token URI');116    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');117  });118119  itEth('TokenURI from baseURI + tokenId', async ({helper}) => {120    const {contract, nextTokenId} = await setup(helper, 'BaseURI_');121    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + nextTokenId);122  });123124  itEth('TokenURI from baseURI + suffix', async ({helper}) => {125    const suffix = '/some/suffix';126    const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'suffix', suffix);127    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);128  });129});130131describe('Refungible: Plain calls', () => {132  let donor: IKeyringPair;133  let alice: IKeyringPair;134135  before(async function() {136    await usingEthPlaygrounds(async (helper, privateKey) => {137      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);138139      donor = await privateKey({filename: __filename});140      [alice] = await helper.arrange.createAccounts([50n], donor);141    });142  });143144  itEth('Can perform approve()', async ({helper}) => {145    const owner = await helper.eth.createAccountWithBalance(donor);146    const spender = helper.eth.createAccount();147    const collection = await helper.rft.mintCollection(alice);148    const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner});149150    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);151    const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);152153    {154      const result = await contract.methods.approve(spender, 100).send({from: owner});155      const event = result.events.Approval;156      expect(event.address).to.be.equal(tokenAddress);157      expect(event.returnValues.owner).to.be.equal(owner);158      expect(event.returnValues.spender).to.be.equal(spender);159      expect(event.returnValues.value).to.be.equal('100');160    }161162    {163      const allowance = await contract.methods.allowance(owner, spender).call();164      expect(+allowance).to.equal(100);165    }166  });167168  itEth('Can perform transferFrom()', async ({helper}) => {169    const owner = await helper.eth.createAccountWithBalance(donor);170    const spender = await helper.eth.createAccountWithBalance(donor);171    const receiver = helper.eth.createAccount();172    const collection = await helper.rft.mintCollection(alice);173    const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner});174175    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);176    const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);177178    await contract.methods.approve(spender, 100).send();179180    {181      const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: spender});182      let event = result.events.Transfer;183      expect(event.address).to.be.equal(tokenAddress);184      expect(event.returnValues.from).to.be.equal(owner);185      expect(event.returnValues.to).to.be.equal(receiver);186      expect(event.returnValues.value).to.be.equal('49');187188      event = result.events.Approval;189      expect(event.address).to.be.equal(tokenAddress);190      expect(event.returnValues.owner).to.be.equal(owner);191      expect(event.returnValues.spender).to.be.equal(spender);192      expect(event.returnValues.value).to.be.equal('51');193    }194195    {196      const balance = await contract.methods.balanceOf(receiver).call();197      expect(+balance).to.equal(49);198    }199200    {201      const balance = await contract.methods.balanceOf(owner).call();202      expect(+balance).to.equal(151);203    }204  });205206  itEth('Can perform transfer()', async ({helper}) => {207    const owner = await helper.eth.createAccountWithBalance(donor);208    const receiver = helper.eth.createAccount();209    const collection = await helper.rft.mintCollection(alice);210    const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner});211212    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);213    const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);214215    {216      const result = await contract.methods.transfer(receiver, 50).send({from: owner});217      const event = result.events.Transfer;218      expect(event.address).to.be.equal(tokenAddress);219      expect(event.returnValues.from).to.be.equal(owner);220      expect(event.returnValues.to).to.be.equal(receiver);221      expect(event.returnValues.value).to.be.equal('50');222    }223224    {225      const balance = await contract.methods.balanceOf(owner).call();226      expect(+balance).to.equal(150);227    }228229    {230      const balance = await contract.methods.balanceOf(receiver).call();231      expect(+balance).to.equal(50);232    }233  });234235  itEth('Can perform repartition()', async ({helper}) => {236    const owner = await helper.eth.createAccountWithBalance(donor);237    const receiver = await helper.eth.createAccountWithBalance(donor);238    const collection = await helper.rft.mintCollection(alice);239    const {tokenId} = await collection.mintToken(alice, 100n, {Ethereum: owner});240241    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);242    const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);243244    await contract.methods.repartition(200).send({from: owner});245    expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(200);246    await contract.methods.transfer(receiver, 110).send({from: owner});247    expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(90);248    expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(110);249250    await expect(contract.methods.repartition(80).send({from: owner})).to.eventually.be.rejected; // Transaction is reverted251252    await contract.methods.transfer(receiver, 90).send({from: owner});253    expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(0);254    expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(200);255256    await contract.methods.repartition(150).send({from: receiver});257    await expect(contract.methods.transfer(owner, 160).send({from: receiver})).to.eventually.be.rejected; // Transaction is reverted258    expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(150);259  });260261  itEth('Can repartition with increased amount', async ({helper}) => {262    const owner = await helper.eth.createAccountWithBalance(donor);263    const collection = await helper.rft.mintCollection(alice);264    const {tokenId} = await collection.mintToken(alice, 100n, {Ethereum: owner});265266    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);267    const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);268269    const result = await contract.methods.repartition(200).send();270271    const event = result.events.Transfer;272    expect(event.address).to.be.equal(tokenAddress);273    expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');274    expect(event.returnValues.to).to.be.equal(owner);275    expect(event.returnValues.value).to.be.equal('100');276  });277278  itEth('Can repartition with decreased amount', async ({helper}) => {279    const owner = await helper.eth.createAccountWithBalance(donor);280    const collection = await helper.rft.mintCollection(alice);281    const {tokenId} = await collection.mintToken(alice, 100n, {Ethereum: owner});282283    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);284    const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);285286    const result = await contract.methods.repartition(50).send();287    const event = result.events.Transfer;288    expect(event.address).to.be.equal(tokenAddress);289    expect(event.returnValues.from).to.be.equal(owner);290    expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');291    expect(event.returnValues.value).to.be.equal('50');292  });293294  itEth('Receiving Transfer event on burning into full ownership', async ({helper}) => {295    const caller = await helper.eth.createAccountWithBalance(donor);296    const receiver = await helper.eth.createAccountWithBalance(donor);297    const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Devastation', '6', '6');298    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);299300    const tokenId = await contract.methods.nextTokenId().call();301    await contract.methods.mint(caller, tokenId).send();302    const tokenAddress = helper.ethAddress.fromTokenId(collectionId, tokenId);303    const tokenContract = helper.ethNativeContract.rftToken(tokenAddress, caller);304305    await tokenContract.methods.repartition(2).send();306    await tokenContract.methods.transfer(receiver, 1).send();307308    const events: any = [];309    contract.events.allEvents((_: any, event: any) => {310      events.push(event);311    });312    await tokenContract.methods.burnFrom(caller, 1).send();313314    const event = events[0];315    expect(event.address).to.be.equal(collectionAddress);316    expect(event.returnValues.from).to.be.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');317    expect(event.returnValues.to).to.be.equal(receiver);318    expect(event.returnValues.tokenId).to.be.equal(tokenId);319  });320});321322describe('Refungible: Fees', () => {323  let donor: IKeyringPair;324  let alice: IKeyringPair;325326  before(async function() {327    await usingEthPlaygrounds(async (helper, privateKey) => {328      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);329330      donor = await privateKey({filename: __filename});331      [alice] = await helper.arrange.createAccounts([50n], donor);332    });333  });334335  itEth('approve() call fee is less than 0.2UNQ', async ({helper}) => {336    const owner = await helper.eth.createAccountWithBalance(donor);337    const spender = helper.eth.createAccount();338    const collection = await helper.rft.mintCollection(alice);339    const {tokenId} = await collection.mintToken(alice, 100n, {Ethereum: owner});340341    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);342    const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);343344    const cost = await helper.eth.recordCallFee(owner, () => contract.methods.approve(spender, 100).send({from: owner}));345    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));346  });347348  itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {349    const owner = await helper.eth.createAccountWithBalance(donor);350    const spender = await helper.eth.createAccountWithBalance(donor);351    const collection = await helper.rft.mintCollection(alice);352    const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner});353354    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);355    const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);356357    await contract.methods.approve(spender, 100).send({from: owner});358359    const cost = await helper.eth.recordCallFee(spender, () => contract.methods.transferFrom(owner, spender, 100).send({from: spender}));360    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));361  });362363  itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {364    const owner = await helper.eth.createAccountWithBalance(donor);365    const receiver = helper.eth.createAccount();366    const collection = await helper.rft.mintCollection(alice);367    const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner});368369    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);370    const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);371372    const cost = await helper.eth.recordCallFee(owner, () => contract.methods.transfer(receiver, 100).send({from: owner}));373    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));374  });375});376377describe('Refungible: Substrate calls', () => {378  let donor: IKeyringPair;379  let alice: IKeyringPair;380381  before(async function() {382    await usingEthPlaygrounds(async (helper, privateKey) => {383      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);384385      donor = await privateKey({filename: __filename});386      [alice] = await helper.arrange.createAccounts([50n], donor);387    });388  });389390  itEth('Events emitted for approve()', async ({helper}) => {391    const receiver = helper.eth.createAccount();392    const collection = await helper.rft.mintCollection(alice);393    const token = await collection.mintToken(alice, 200n);394395    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);396    const contract = helper.ethNativeContract.rftToken(tokenAddress);397398    const events: any = [];399    contract.events.allEvents((_: any, event: any) => {400      events.push(event);401    });402    expect(await token.approve(alice, {Ethereum: receiver}, 100n)).to.be.true;403404    const event = events[0];405    expect(event.event).to.be.equal('Approval');406    expect(event.address).to.be.equal(tokenAddress);407    expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));408    expect(event.returnValues.spender).to.be.equal(receiver);409    expect(event.returnValues.value).to.be.equal('100');410  });411412  itEth('Events emitted for transferFrom()', async ({helper}) => {413    const [bob] = await helper.arrange.createAccounts([10n], donor);414    const receiver = helper.eth.createAccount();415    const collection = await helper.rft.mintCollection(alice);416    const token = await collection.mintToken(alice, 200n);417    await token.approve(alice, {Substrate: bob.address}, 100n);418419    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);420    const contract = helper.ethNativeContract.rftToken(tokenAddress);421422    const events: any = [];423    contract.events.allEvents((_: any, event: any) => {424      events.push(event);425    });426427    expect(await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver},  51n)).to.be.true;428429    let event = events[0];430    expect(event.event).to.be.equal('Transfer');431    expect(event.address).to.be.equal(tokenAddress);432    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));433    expect(event.returnValues.to).to.be.equal(receiver);434    expect(event.returnValues.value).to.be.equal('51');435436    event = events[1];437    expect(event.event).to.be.equal('Approval');438    expect(event.address).to.be.equal(tokenAddress);439    expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));440    expect(event.returnValues.spender).to.be.equal(helper.address.substrateToEth(bob.address));441    expect(event.returnValues.value).to.be.equal('49');442  });443444  itEth('Events emitted for transfer()', async ({helper}) => {445    const receiver = helper.eth.createAccount();446    const collection = await helper.rft.mintCollection(alice);447    const token = await collection.mintToken(alice, 200n);448449    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);450    const contract = helper.ethNativeContract.rftToken(tokenAddress);451452    const events: any = [];453    contract.events.allEvents((_: any, event: any) => {454      events.push(event);455    });456457    expect(await token.transfer(alice, {Ethereum: receiver},  51n)).to.be.true;458459    const event = events[0];460    expect(event.event).to.be.equal('Transfer');461    expect(event.address).to.be.equal(tokenAddress);462    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));463    expect(event.returnValues.to).to.be.equal(receiver);464    expect(event.returnValues.value).to.be.equal('51');465  });466});467468describe('ERC 1633 implementation', () => {469  let donor: IKeyringPair;470471  before(async function() {472    await usingEthPlaygrounds(async (helper, privateKey) => {473      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);474475      donor = await privateKey({filename: __filename});476    });477  });478479  itEth('Default parent token address and id', async ({helper}) => {480    const owner = await helper.eth.createAccountWithBalance(donor);481482    const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Sands', '', 'GRAIN');483    const collectionContract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);484    485    const tokenId = await collectionContract.methods.nextTokenId().call();486    await collectionContract.methods.mint(owner, tokenId).send();487    const tokenAddress = helper.ethAddress.fromTokenId(collectionId, tokenId);488    const tokenContract = helper.ethNativeContract.rftToken(tokenAddress, owner);489490    expect(await tokenContract.methods.parentToken().call()).to.be.equal(collectionAddress);491    expect(await tokenContract.methods.parentTokenId().call()).to.be.equal(tokenId);492  });493});
after · tests/src/eth/reFungibleToken.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 {Pallets, requirePalletsOrSkip} from '../util';18import {EthUniqueHelper, expect, itEth, usingEthPlaygrounds} from './util';19import {IKeyringPair} from '@polkadot/types/types';20import {Contract} from 'web3-eth-contract';212223describe('Refungible token: Information getting', () => {24  let donor: IKeyringPair;25  let alice: IKeyringPair;2627  before(async function() {28    await usingEthPlaygrounds(async (helper, privateKey) => {29      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);3031      donor = await privateKey({filename: __filename});32      [alice] = await helper.arrange.createAccounts([20n], donor);33    });34  });3536  itEth('totalSupply', async ({helper}) => {37    const caller = await helper.eth.createAccountWithBalance(donor);38    const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'MUON'});39    const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: caller});4041    const contract = helper.ethNativeContract.rftTokenById(collection.collectionId, tokenId, caller);42    const totalSupply = await contract.methods.totalSupply().call();43    expect(totalSupply).to.equal('200');44  });4546  itEth('balanceOf', async ({helper}) => {47    const caller = await helper.eth.createAccountWithBalance(donor);48    const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'MUON'});49    const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: caller});5051    const contract = helper.ethNativeContract.rftTokenById(collection.collectionId, tokenId, caller);52    const balance = await contract.methods.balanceOf(caller).call();53    expect(balance).to.equal('200');54  });5556  itEth('decimals', async ({helper}) => {57    const caller = await helper.eth.createAccountWithBalance(donor);58    const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'MUON'});59    const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: caller});6061    const contract = helper.ethNativeContract.rftTokenById(collection.collectionId, tokenId, caller);62    const decimals = await contract.methods.decimals().call();63    expect(decimals).to.equal('0');64  });65});6667// FIXME: Need erc721 for ReFubgible.68describe('Check ERC721 token URI for ReFungible', () => {69  let donor: IKeyringPair;7071  before(async function() {72    await usingEthPlaygrounds(async (helper, privateKey) => {73      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);7475      donor = await privateKey({filename: __filename});76    });77  });7879  async function setup(helper: EthUniqueHelper, tokenPrefix: string, propertyKey?: string, propertyValue?: string): Promise<{contract: Contract, nextTokenId: string}> {80    const owner = await helper.eth.createAccountWithBalance(donor);81    const receiver = helper.eth.createAccount();8283    const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);84    let result = await collectionHelper.methods.createERC721MetadataCompatibleCollection('Mint collection', 'a', 'b', tokenPrefix).send({value: Number(2n * helper.balance.getOneTokenNominal())});85    const collectionAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);86    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);87    88    const nextTokenId = await contract.methods.nextTokenId().call();89    expect(nextTokenId).to.be.equal('1');90    result = await contract.methods.mint(91      receiver,92      nextTokenId,93    ).send();9495    if (propertyKey && propertyValue) {96      // Set URL or suffix97      await contract.methods.setProperty(nextTokenId, propertyKey, Buffer.from(propertyValue)).send();98    }99100    const event = result.events.Transfer;101    expect(event.address).to.be.equal(collectionAddress);102    expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');103    expect(event.returnValues.to).to.be.equal(receiver);104    expect(event.returnValues.tokenId).to.be.equal(nextTokenId);105106    return {contract, nextTokenId};107  }108109  itEth('Empty tokenURI', async ({helper}) => {110    const {contract, nextTokenId} = await setup(helper, '');111    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');112  });113114  itEth('TokenURI from url', async ({helper}) => {115    const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'url', 'Token URI');116    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');117  });118119  itEth('TokenURI from baseURI + tokenId', async ({helper}) => {120    const {contract, nextTokenId} = await setup(helper, 'BaseURI_');121    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + nextTokenId);122  });123124  itEth('TokenURI from baseURI + suffix', async ({helper}) => {125    const suffix = '/some/suffix';126    const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'suffix', suffix);127    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);128  });129});130131describe('Refungible: Plain calls', () => {132  let donor: IKeyringPair;133  let alice: IKeyringPair;134135  before(async function() {136    await usingEthPlaygrounds(async (helper, privateKey) => {137      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);138139      donor = await privateKey({filename: __filename});140      [alice] = await helper.arrange.createAccounts([50n], donor);141    });142  });143144  itEth('Can perform approve()', async ({helper}) => {145    const owner = await helper.eth.createAccountWithBalance(donor);146    const spender = helper.eth.createAccount();147    const collection = await helper.rft.mintCollection(alice);148    const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner});149150    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);151    const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);152153    {154      const result = await contract.methods.approve(spender, 100).send({from: owner});155      const event = result.events.Approval;156      expect(event.address).to.be.equal(tokenAddress);157      expect(event.returnValues.owner).to.be.equal(owner);158      expect(event.returnValues.spender).to.be.equal(spender);159      expect(event.returnValues.value).to.be.equal('100');160    }161162    {163      const allowance = await contract.methods.allowance(owner, spender).call();164      expect(+allowance).to.equal(100);165    }166  });167168  itEth('Can perform transferFrom()', async ({helper}) => {169    const owner = await helper.eth.createAccountWithBalance(donor);170    const spender = await helper.eth.createAccountWithBalance(donor);171    const receiver = helper.eth.createAccount();172    const collection = await helper.rft.mintCollection(alice);173    const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner});174175    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);176    const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);177178    await contract.methods.approve(spender, 100).send();179180    {181      const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: spender});182      let event = result.events.Transfer;183      expect(event.address).to.be.equal(tokenAddress);184      expect(event.returnValues.from).to.be.equal(owner);185      expect(event.returnValues.to).to.be.equal(receiver);186      expect(event.returnValues.value).to.be.equal('49');187188      event = result.events.Approval;189      expect(event.address).to.be.equal(tokenAddress);190      expect(event.returnValues.owner).to.be.equal(owner);191      expect(event.returnValues.spender).to.be.equal(spender);192      expect(event.returnValues.value).to.be.equal('51');193    }194195    {196      const balance = await contract.methods.balanceOf(receiver).call();197      expect(+balance).to.equal(49);198    }199200    {201      const balance = await contract.methods.balanceOf(owner).call();202      expect(+balance).to.equal(151);203    }204  });205206  itEth('Can perform transfer()', async ({helper}) => {207    const owner = await helper.eth.createAccountWithBalance(donor);208    const receiver = helper.eth.createAccount();209    const collection = await helper.rft.mintCollection(alice);210    const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner});211212    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);213    const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);214215    {216      const result = await contract.methods.transfer(receiver, 50).send({from: owner});217      const event = result.events.Transfer;218      expect(event.address).to.be.equal(tokenAddress);219      expect(event.returnValues.from).to.be.equal(owner);220      expect(event.returnValues.to).to.be.equal(receiver);221      expect(event.returnValues.value).to.be.equal('50');222    }223224    {225      const balance = await contract.methods.balanceOf(owner).call();226      expect(+balance).to.equal(150);227    }228229    {230      const balance = await contract.methods.balanceOf(receiver).call();231      expect(+balance).to.equal(50);232    }233  });234235  itEth('Can perform repartition()', async ({helper}) => {236    const owner = await helper.eth.createAccountWithBalance(donor);237    const receiver = await helper.eth.createAccountWithBalance(donor);238    const collection = await helper.rft.mintCollection(alice);239    const {tokenId} = await collection.mintToken(alice, 100n, {Ethereum: owner});240241    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);242    const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);243244    await contract.methods.repartition(200).send({from: owner});245    expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(200);246    await contract.methods.transfer(receiver, 110).send({from: owner});247    expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(90);248    expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(110);249250    await expect(contract.methods.repartition(80).send({from: owner})).to.eventually.be.rejected; // Transaction is reverted251252    await contract.methods.transfer(receiver, 90).send({from: owner});253    expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(0);254    expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(200);255256    await contract.methods.repartition(150).send({from: receiver});257    await expect(contract.methods.transfer(owner, 160).send({from: receiver})).to.eventually.be.rejected; // Transaction is reverted258    expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(150);259  });260261  itEth('Can repartition with increased amount', async ({helper}) => {262    const owner = await helper.eth.createAccountWithBalance(donor);263    const collection = await helper.rft.mintCollection(alice);264    const {tokenId} = await collection.mintToken(alice, 100n, {Ethereum: owner});265266    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);267    const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);268269    const result = await contract.methods.repartition(200).send();270271    const event = result.events.Transfer;272    expect(event.address).to.be.equal(tokenAddress);273    expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');274    expect(event.returnValues.to).to.be.equal(owner);275    expect(event.returnValues.value).to.be.equal('100');276  });277278  itEth('Can repartition with decreased amount', async ({helper}) => {279    const owner = await helper.eth.createAccountWithBalance(donor);280    const collection = await helper.rft.mintCollection(alice);281    const {tokenId} = await collection.mintToken(alice, 100n, {Ethereum: owner});282283    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);284    const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);285286    const result = await contract.methods.repartition(50).send();287    const event = result.events.Transfer;288    expect(event.address).to.be.equal(tokenAddress);289    expect(event.returnValues.from).to.be.equal(owner);290    expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');291    expect(event.returnValues.value).to.be.equal('50');292  });293294  itEth('Receiving Transfer event on burning into full ownership', async ({helper}) => {295    const caller = await helper.eth.createAccountWithBalance(donor);296    const receiver = await helper.eth.createAccountWithBalance(donor);297    const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Devastation', '6', '6');298    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);299300    const tokenId = await contract.methods.nextTokenId().call();301    await contract.methods.mint(caller, tokenId).send();302    const tokenAddress = helper.ethAddress.fromTokenId(collectionId, tokenId);303    const tokenContract = helper.ethNativeContract.rftToken(tokenAddress, caller);304305    await tokenContract.methods.repartition(2).send();306    await tokenContract.methods.transfer(receiver, 1).send();307308    const events: any = [];309    contract.events.allEvents((_: any, event: any) => {310      events.push(event);311    });312    await tokenContract.methods.burnFrom(caller, 1).send();313314    if (events.length == 0) await helper.wait.newBlocks(1);315    const event = events[0];316    expect(event.address).to.be.equal(collectionAddress);317    expect(event.returnValues.from).to.be.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');318    expect(event.returnValues.to).to.be.equal(receiver);319    expect(event.returnValues.tokenId).to.be.equal(tokenId);320  });321});322323describe('Refungible: Fees', () => {324  let donor: IKeyringPair;325  let alice: IKeyringPair;326327  before(async function() {328    await usingEthPlaygrounds(async (helper, privateKey) => {329      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);330331      donor = await privateKey({filename: __filename});332      [alice] = await helper.arrange.createAccounts([50n], donor);333    });334  });335336  itEth('approve() call fee is less than 0.2UNQ', async ({helper}) => {337    const owner = await helper.eth.createAccountWithBalance(donor);338    const spender = helper.eth.createAccount();339    const collection = await helper.rft.mintCollection(alice);340    const {tokenId} = await collection.mintToken(alice, 100n, {Ethereum: owner});341342    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);343    const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);344345    const cost = await helper.eth.recordCallFee(owner, () => contract.methods.approve(spender, 100).send({from: owner}));346    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));347  });348349  itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {350    const owner = await helper.eth.createAccountWithBalance(donor);351    const spender = await helper.eth.createAccountWithBalance(donor);352    const collection = await helper.rft.mintCollection(alice);353    const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner});354355    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);356    const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);357358    await contract.methods.approve(spender, 100).send({from: owner});359360    const cost = await helper.eth.recordCallFee(spender, () => contract.methods.transferFrom(owner, spender, 100).send({from: spender}));361    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));362  });363364  itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {365    const owner = await helper.eth.createAccountWithBalance(donor);366    const receiver = helper.eth.createAccount();367    const collection = await helper.rft.mintCollection(alice);368    const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner});369370    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);371    const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);372373    const cost = await helper.eth.recordCallFee(owner, () => contract.methods.transfer(receiver, 100).send({from: owner}));374    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));375  });376});377378describe('Refungible: Substrate calls', () => {379  let donor: IKeyringPair;380  let alice: IKeyringPair;381382  before(async function() {383    await usingEthPlaygrounds(async (helper, privateKey) => {384      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);385386      donor = await privateKey({filename: __filename});387      [alice] = await helper.arrange.createAccounts([50n], donor);388    });389  });390391  itEth('Events emitted for approve()', async ({helper}) => {392    const receiver = helper.eth.createAccount();393    const collection = await helper.rft.mintCollection(alice);394    const token = await collection.mintToken(alice, 200n);395396    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);397    const contract = helper.ethNativeContract.rftToken(tokenAddress);398399    const events: any = [];400    contract.events.allEvents((_: any, event: any) => {401      events.push(event);402    });403404    expect(await token.approve(alice, {Ethereum: receiver}, 100n)).to.be.true;405    if (events.length == 0) await helper.wait.newBlocks(1);406    const event = events[0];407408    expect(event.event).to.be.equal('Approval');409    expect(event.address).to.be.equal(tokenAddress);410    expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));411    expect(event.returnValues.spender).to.be.equal(receiver);412    expect(event.returnValues.value).to.be.equal('100');413  });414415  itEth('Events emitted for transferFrom()', async ({helper}) => {416    const [bob] = await helper.arrange.createAccounts([10n], donor);417    const receiver = helper.eth.createAccount();418    const collection = await helper.rft.mintCollection(alice);419    const token = await collection.mintToken(alice, 200n);420    await token.approve(alice, {Substrate: bob.address}, 100n);421422    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);423    const contract = helper.ethNativeContract.rftToken(tokenAddress);424425    const events: any = [];426    contract.events.allEvents((_: any, event: any) => {427      events.push(event);428    });429430    expect(await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver},  51n)).to.be.true;431    if (events.length == 0) await helper.wait.newBlocks(1);432433    let event = events[0];434    expect(event.event).to.be.equal('Transfer');435    expect(event.address).to.be.equal(tokenAddress);436    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));437    expect(event.returnValues.to).to.be.equal(receiver);438    expect(event.returnValues.value).to.be.equal('51');439440    event = events[1];441    expect(event.event).to.be.equal('Approval');442    expect(event.address).to.be.equal(tokenAddress);443    expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));444    expect(event.returnValues.spender).to.be.equal(helper.address.substrateToEth(bob.address));445    expect(event.returnValues.value).to.be.equal('49');446  });447448  itEth('Events emitted for transfer()', async ({helper}) => {449    const receiver = helper.eth.createAccount();450    const collection = await helper.rft.mintCollection(alice);451    const token = await collection.mintToken(alice, 200n);452453    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);454    const contract = helper.ethNativeContract.rftToken(tokenAddress);455456    const events: any = [];457    contract.events.allEvents((_: any, event: any) => {458      events.push(event);459    });460461    expect(await token.transfer(alice, {Ethereum: receiver},  51n)).to.be.true;462    if (events.length == 0) await helper.wait.newBlocks(1);463    const event = events[0];464465    expect(event.event).to.be.equal('Transfer');466    expect(event.address).to.be.equal(tokenAddress);467    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));468    expect(event.returnValues.to).to.be.equal(receiver);469    expect(event.returnValues.value).to.be.equal('51');470  });471});472473describe('ERC 1633 implementation', () => {474  let donor: IKeyringPair;475476  before(async function() {477    await usingEthPlaygrounds(async (helper, privateKey) => {478      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);479480      donor = await privateKey({filename: __filename});481    });482  });483484  itEth('Default parent token address and id', async ({helper}) => {485    const owner = await helper.eth.createAccountWithBalance(donor);486487    const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Sands', '', 'GRAIN');488    const collectionContract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);489    490    const tokenId = await collectionContract.methods.nextTokenId().call();491    await collectionContract.methods.mint(owner, tokenId).send();492    const tokenAddress = helper.ethAddress.fromTokenId(collectionId, tokenId);493    const tokenContract = helper.ethNativeContract.rftToken(tokenAddress, owner);494495    expect(await tokenContract.methods.parentToken().call()).to.be.equal(collectionAddress);496    expect(await tokenContract.methods.parentTokenId().call()).to.be.equal(tokenId);497  });498});
modifiedtests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.dev.ts
+++ b/tests/src/util/playgrounds/unique.dev.ts
@@ -156,8 +156,9 @@
     };
 
     let accountsCreated = false;
-    // checkBalances retry up to 5 blocks
-    for (let index = 0; index < 5; index++) {
+    const maxBlocksChecked = await this.helper.arrange.isDevNode() ? 50 : 5;
+    // checkBalances retry up to 5-50 blocks
+    for (let index = 0; index < maxBlocksChecked; index++) {
       accountsCreated = await checkBalances();
       if(accountsCreated) break;
       await wait.newBlocks(1);