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
before · tests/src/eth/reFungible.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 {expect, itEth, usingEthPlaygrounds} from './util';19import {IKeyringPair} from '@polkadot/types/types';2021describe('Refungible: Information getting', () => {22  let donor: IKeyringPair;2324  before(async function() {25    await usingEthPlaygrounds(async (helper, privateKey) => {26      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);2728      donor = await privateKey({filename: __filename});29    });30  });3132  itEth('totalSupply', async ({helper}) => {33    const caller = await helper.eth.createAccountWithBalance(donor);34    const {collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'TotalSupply', '6', '6');35    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);36    const nextTokenId = await contract.methods.nextTokenId().call();37    await contract.methods.mint(caller, nextTokenId).send();38    const totalSupply = await contract.methods.totalSupply().call();39    expect(totalSupply).to.equal('1');40  });4142  itEth('balanceOf', async ({helper}) => {43    const caller = await helper.eth.createAccountWithBalance(donor);44    const {collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'BalanceOf', '6', '6');45    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);4647    {48      const nextTokenId = await contract.methods.nextTokenId().call();49      await contract.methods.mint(caller, nextTokenId).send();50    }51    {52      const nextTokenId = await contract.methods.nextTokenId().call();53      await contract.methods.mint(caller, nextTokenId).send();54    }55    {56      const nextTokenId = await contract.methods.nextTokenId().call();57      await contract.methods.mint(caller, nextTokenId).send();58    }5960    const balance = await contract.methods.balanceOf(caller).call();61    expect(balance).to.equal('3');62  });6364  itEth('ownerOf', async ({helper}) => {65    const caller = await helper.eth.createAccountWithBalance(donor);66    const {collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'OwnerOf', '6', '6');67    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);6869    const tokenId = await contract.methods.nextTokenId().call();70    await contract.methods.mint(caller, tokenId).send();7172    const owner = await contract.methods.ownerOf(tokenId).call();73    expect(owner).to.equal(caller);74  });7576  itEth('ownerOf after burn', async ({helper}) => {77    const caller = await helper.eth.createAccountWithBalance(donor);78    const receiver = helper.eth.createAccount();79    const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'OwnerOf-AfterBurn', '6', '6');80    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);8182    const tokenId = await contract.methods.nextTokenId().call();83    await contract.methods.mint(caller, tokenId).send();84    const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);8586    await tokenContract.methods.repartition(2).send();87    await tokenContract.methods.transfer(receiver, 1).send();8889    await tokenContract.methods.burnFrom(caller, 1).send();9091    const owner = await contract.methods.ownerOf(tokenId).call();92    expect(owner).to.equal(receiver);93  });9495  itEth('ownerOf for partial ownership', async ({helper}) => {96    const caller = await helper.eth.createAccountWithBalance(donor);97    const receiver = helper.eth.createAccount();98    const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Partial-OwnerOf', '6', '6');99    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);100101    const tokenId = await contract.methods.nextTokenId().call();102    await contract.methods.mint(caller, tokenId).send();103    const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);104105    await tokenContract.methods.repartition(2).send();106    await tokenContract.methods.transfer(receiver, 1).send();107108    const owner = await contract.methods.ownerOf(tokenId).call();109    expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');110  });111});112113describe('Refungible: Plain calls', () => {114  let donor: IKeyringPair;115116  before(async function() {117    await usingEthPlaygrounds(async (helper, privateKey) => {118      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);119120      donor = await privateKey({filename: __filename});121    });122  });123124  itEth('Can perform mint()', async ({helper}) => {125    const owner = await helper.eth.createAccountWithBalance(donor);126    const receiver = helper.eth.createAccount();127    const {collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Minty', '6', '6');128    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);129    130    const nextTokenId = await contract.methods.nextTokenId().call();131    expect(nextTokenId).to.be.equal('1');132    const result = await contract.methods.mintWithTokenURI(133      receiver,134      nextTokenId,135      'Test URI',136    ).send();137138    const event = result.events.Transfer;139    expect(event.address).to.equal(collectionAddress);140    expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');141    expect(event.returnValues.to).to.equal(receiver);142    expect(event.returnValues.tokenId).to.equal(nextTokenId);143144    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');145  });146147  itEth('Can perform mintBulk()', async ({helper}) => {148    const owner = await helper.eth.createAccountWithBalance(donor);149    const receiver = helper.eth.createAccount();150    const {collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'MintBulky', '6', '6');151    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);152153    {154      const nextTokenId = await contract.methods.nextTokenId().call();155      expect(nextTokenId).to.be.equal('1');156      const result = await contract.methods.mintBulkWithTokenURI(157        receiver,158        [159          [nextTokenId, 'Test URI 0'],160          [+nextTokenId + 1, 'Test URI 1'],161          [+nextTokenId + 2, 'Test URI 2'],162        ],163      ).send();164165      const events = result.events.Transfer;166      for (let i = 0; i < 2; i++) {167        const event = events[i];168        expect(event.address).to.equal(collectionAddress);169        expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');170        expect(event.returnValues.to).to.equal(receiver);171        expect(event.returnValues.tokenId).to.equal(String(+nextTokenId + i));172      }173174      expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');175      expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');176      expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');177    }178  });179180  itEth('Can perform burn()', async ({helper}) => {181    const caller = await helper.eth.createAccountWithBalance(donor);182    const {collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Burny', '6', '6');183    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);184185    const tokenId = await contract.methods.nextTokenId().call();186    await contract.methods.mint(caller, tokenId).send();187    {188      const result = await contract.methods.burn(tokenId).send();189      const event = result.events.Transfer;190      expect(event.address).to.equal(collectionAddress);191      expect(event.returnValues.from).to.equal(caller);192      expect(event.returnValues.to).to.equal('0x0000000000000000000000000000000000000000');193      expect(event.returnValues.tokenId).to.equal(tokenId.toString());194    }195  });196197  itEth('Can perform transferFrom()', async ({helper}) => {198    const caller = await helper.eth.createAccountWithBalance(donor);199    const receiver = helper.eth.createAccount();200    const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'TransferFromy', '6', '6');201    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);202203    const tokenId = await contract.methods.nextTokenId().call();204    const tokenAddress = helper.ethAddress.fromTokenId(collectionId, tokenId);205    await contract.methods.mint(caller, tokenId).send();206207    const tokenContract = helper.ethNativeContract.rftToken(tokenAddress, caller);208    await tokenContract.methods.repartition(15).send();209210    {211      const tokenEvents: any = [];212      tokenContract.events.allEvents((_: any, event: any) => {213        tokenEvents.push(event);214      });215      const result = await contract.methods.transferFrom(caller, receiver, tokenId).send();216217      let event = result.events.Transfer;218      expect(event.address).to.equal(collectionAddress);219      expect(event.returnValues.from).to.equal(caller);220      expect(event.returnValues.to).to.equal(receiver);221      expect(event.returnValues.tokenId).to.equal(tokenId.toString());222223      event = tokenEvents[0];224      expect(event.address).to.equal(tokenAddress);225      expect(event.returnValues.from).to.equal(caller);226      expect(event.returnValues.to).to.equal(receiver);227      expect(event.returnValues.value).to.equal('15');228    }229230    {231      const balance = await contract.methods.balanceOf(receiver).call();232      expect(+balance).to.equal(1);233    }234235    {236      const balance = await contract.methods.balanceOf(caller).call();237      expect(+balance).to.equal(0);238    }239  });240241  itEth('Can perform transfer()', async ({helper}) => {242    const caller = await helper.eth.createAccountWithBalance(donor);243    const receiver = helper.eth.createAccount();244    const {collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Transferry', '6', '6');245    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);246247    const tokenId = await contract.methods.nextTokenId().call();248    await contract.methods.mint(caller, tokenId).send();249250    {251      const result = await contract.methods.transfer(receiver, tokenId).send();252      253      const event = result.events.Transfer;254      expect(event.address).to.equal(collectionAddress);255      expect(event.returnValues.from).to.equal(caller);256      expect(event.returnValues.to).to.equal(receiver);257      expect(event.returnValues.tokenId).to.equal(tokenId.toString());258    }259260    {261      const balance = await contract.methods.balanceOf(caller).call();262      expect(+balance).to.equal(0);263    }264265    {266      const balance = await contract.methods.balanceOf(receiver).call();267      expect(+balance).to.equal(1);268    }269  });270271  itEth('transfer event on transfer from partial ownership to full ownership', async ({helper}) => {272    const caller = await helper.eth.createAccountWithBalance(donor);273    const receiver = helper.eth.createAccount();274    const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Transferry-Partial-to-Full', '6', '6');275    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);276277    const tokenId = await contract.methods.nextTokenId().call();278    await contract.methods.mint(caller, tokenId).send();279280    const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);281282    await tokenContract.methods.repartition(2).send();283    await tokenContract.methods.transfer(receiver, 1).send();284285    const events: any = [];286    contract.events.allEvents((_: any, event: any) => {287      events.push(event);288    });289    await tokenContract.methods.transfer(receiver, 1).send();290291    const event = events[0];292    expect(event.address).to.equal(collectionAddress);293    expect(event.returnValues.from).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');294    expect(event.returnValues.to).to.equal(receiver);295    expect(event.returnValues.tokenId).to.equal(tokenId.toString());296  });297298  itEth('transfer event on transfer from full ownership to partial ownership', async ({helper}) => {299    const caller = await helper.eth.createAccountWithBalance(donor);300    const receiver = helper.eth.createAccount();301    const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Transferry-Full-to-Partial', '6', '6');302    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);303304    const tokenId = await contract.methods.nextTokenId().call();305    await contract.methods.mint(caller, tokenId).send();306307    const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);308309    await tokenContract.methods.repartition(2).send();310311    const events: any = [];312    contract.events.allEvents((_: any, event: any) => {313      events.push(event);314    });315    await tokenContract.methods.transfer(receiver, 1).send();316317    const event = events[0];318    expect(event.address).to.equal(collectionAddress);319    expect(event.returnValues.from).to.equal(caller);320    expect(event.returnValues.to).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');321    expect(event.returnValues.tokenId).to.equal(tokenId.toString());322  });323});324325describe('RFT: Fees', () => {326  let donor: IKeyringPair;327328  before(async function() {329    await usingEthPlaygrounds(async (helper, privateKey) => {330      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);331332      donor = await privateKey({filename: __filename});333    });334  });335336  itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {337    const caller = await helper.eth.createAccountWithBalance(donor);338    const receiver = helper.eth.createAccount();339    const {collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Feeful-Transfer-From', '6', '6');340    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);341342    const tokenId = await contract.methods.nextTokenId().call();343    await contract.methods.mint(caller, tokenId).send();344345    const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transferFrom(caller, receiver, tokenId).send());346    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));347    expect(cost > 0n);348  });349350  itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {351    const caller = await helper.eth.createAccountWithBalance(donor);352    const receiver = helper.eth.createAccount();353    const {collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Feeful-Transfer', '6', '6');354    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);355356    const tokenId = await contract.methods.nextTokenId().call();357    await contract.methods.mint(caller, tokenId).send();358359    const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transfer(receiver, tokenId).send());360    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));361    expect(cost > 0n);362  });363});364365describe('Common metadata', () => {366  let donor: IKeyringPair;367  let alice: IKeyringPair;368369  before(async function() {370    await usingEthPlaygrounds(async (helper, privateKey) => {371      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);372373      donor = await privateKey({filename: __filename});374      [alice] = await helper.arrange.createAccounts([20n], donor);375    });376  });377378  itEth('Returns collection name', async ({helper}) => {379    const caller = helper.eth.createAccount();380    const collection = await helper.rft.mintCollection(alice, {name: 'Leviathan', tokenPrefix: '11'});381    382    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'rft', caller);383    const name = await contract.methods.name().call();384    expect(name).to.equal('Leviathan');385  });386387  itEth('Returns symbol name', async ({helper}) => {388    const caller = await helper.eth.createAccountWithBalance(donor);389    const {collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Leviathan', '', '12');390    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);391    const symbol = await contract.methods.symbol().call();392    expect(symbol).to.equal('12');393  });394});
after · tests/src/eth/reFungible.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 {expect, itEth, usingEthPlaygrounds} from './util';19import {IKeyringPair} from '@polkadot/types/types';2021describe('Refungible: Information getting', () => {22  let donor: IKeyringPair;2324  before(async function() {25    await usingEthPlaygrounds(async (helper, privateKey) => {26      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);2728      donor = await privateKey({filename: __filename});29    });30  });3132  itEth('totalSupply', async ({helper}) => {33    const caller = await helper.eth.createAccountWithBalance(donor);34    const {collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'TotalSupply', '6', '6');35    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);36    const nextTokenId = await contract.methods.nextTokenId().call();37    await contract.methods.mint(caller, nextTokenId).send();38    const totalSupply = await contract.methods.totalSupply().call();39    expect(totalSupply).to.equal('1');40  });4142  itEth('balanceOf', async ({helper}) => {43    const caller = await helper.eth.createAccountWithBalance(donor);44    const {collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'BalanceOf', '6', '6');45    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);4647    {48      const nextTokenId = await contract.methods.nextTokenId().call();49      await contract.methods.mint(caller, nextTokenId).send();50    }51    {52      const nextTokenId = await contract.methods.nextTokenId().call();53      await contract.methods.mint(caller, nextTokenId).send();54    }55    {56      const nextTokenId = await contract.methods.nextTokenId().call();57      await contract.methods.mint(caller, nextTokenId).send();58    }5960    const balance = await contract.methods.balanceOf(caller).call();61    expect(balance).to.equal('3');62  });6364  itEth('ownerOf', async ({helper}) => {65    const caller = await helper.eth.createAccountWithBalance(donor);66    const {collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'OwnerOf', '6', '6');67    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);6869    const tokenId = await contract.methods.nextTokenId().call();70    await contract.methods.mint(caller, tokenId).send();7172    const owner = await contract.methods.ownerOf(tokenId).call();73    expect(owner).to.equal(caller);74  });7576  itEth('ownerOf after burn', async ({helper}) => {77    const caller = await helper.eth.createAccountWithBalance(donor);78    const receiver = helper.eth.createAccount();79    const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'OwnerOf-AfterBurn', '6', '6');80    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);8182    const tokenId = await contract.methods.nextTokenId().call();83    await contract.methods.mint(caller, tokenId).send();84    const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);8586    await tokenContract.methods.repartition(2).send();87    await tokenContract.methods.transfer(receiver, 1).send();8889    await tokenContract.methods.burnFrom(caller, 1).send();9091    const owner = await contract.methods.ownerOf(tokenId).call();92    expect(owner).to.equal(receiver);93  });9495  itEth('ownerOf for partial ownership', async ({helper}) => {96    const caller = await helper.eth.createAccountWithBalance(donor);97    const receiver = helper.eth.createAccount();98    const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Partial-OwnerOf', '6', '6');99    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);100101    const tokenId = await contract.methods.nextTokenId().call();102    await contract.methods.mint(caller, tokenId).send();103    const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);104105    await tokenContract.methods.repartition(2).send();106    await tokenContract.methods.transfer(receiver, 1).send();107108    const owner = await contract.methods.ownerOf(tokenId).call();109    expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');110  });111});112113describe('Refungible: Plain calls', () => {114  let donor: IKeyringPair;115116  before(async function() {117    await usingEthPlaygrounds(async (helper, privateKey) => {118      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);119120      donor = await privateKey({filename: __filename});121    });122  });123124  itEth('Can perform mint()', async ({helper}) => {125    const owner = await helper.eth.createAccountWithBalance(donor);126    const receiver = helper.eth.createAccount();127    const {collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Minty', '6', '6');128    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);129    130    const nextTokenId = await contract.methods.nextTokenId().call();131    expect(nextTokenId).to.be.equal('1');132    const result = await contract.methods.mintWithTokenURI(133      receiver,134      nextTokenId,135      'Test URI',136    ).send();137138    const event = result.events.Transfer;139    expect(event.address).to.equal(collectionAddress);140    expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');141    expect(event.returnValues.to).to.equal(receiver);142    expect(event.returnValues.tokenId).to.equal(nextTokenId);143144    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');145  });146147  itEth('Can perform mintBulk()', async ({helper}) => {148    const owner = await helper.eth.createAccountWithBalance(donor);149    const receiver = helper.eth.createAccount();150    const {collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'MintBulky', '6', '6');151    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);152153    {154      const nextTokenId = await contract.methods.nextTokenId().call();155      expect(nextTokenId).to.be.equal('1');156      const result = await contract.methods.mintBulkWithTokenURI(157        receiver,158        [159          [nextTokenId, 'Test URI 0'],160          [+nextTokenId + 1, 'Test URI 1'],161          [+nextTokenId + 2, 'Test URI 2'],162        ],163      ).send();164165      const events = result.events.Transfer;166      for (let i = 0; i < 2; i++) {167        const event = events[i];168        expect(event.address).to.equal(collectionAddress);169        expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');170        expect(event.returnValues.to).to.equal(receiver);171        expect(event.returnValues.tokenId).to.equal(String(+nextTokenId + i));172      }173174      expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');175      expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');176      expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');177    }178  });179180  itEth('Can perform burn()', async ({helper}) => {181    const caller = await helper.eth.createAccountWithBalance(donor);182    const {collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Burny', '6', '6');183    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);184185    const tokenId = await contract.methods.nextTokenId().call();186    await contract.methods.mint(caller, tokenId).send();187    {188      const result = await contract.methods.burn(tokenId).send();189      const event = result.events.Transfer;190      expect(event.address).to.equal(collectionAddress);191      expect(event.returnValues.from).to.equal(caller);192      expect(event.returnValues.to).to.equal('0x0000000000000000000000000000000000000000');193      expect(event.returnValues.tokenId).to.equal(tokenId.toString());194    }195  });196197  itEth('Can perform transferFrom()', async ({helper}) => {198    const caller = await helper.eth.createAccountWithBalance(donor);199    const receiver = helper.eth.createAccount();200    const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'TransferFromy', '6', '6');201    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);202203    const tokenId = await contract.methods.nextTokenId().call();204    const tokenAddress = helper.ethAddress.fromTokenId(collectionId, tokenId);205    await contract.methods.mint(caller, tokenId).send();206207    const tokenContract = helper.ethNativeContract.rftToken(tokenAddress, caller);208    await tokenContract.methods.repartition(15).send();209210    {211      const tokenEvents: any = [];212      tokenContract.events.allEvents((_: any, event: any) => {213        tokenEvents.push(event);214      });215      const result = await contract.methods.transferFrom(caller, receiver, tokenId).send();216217      let event = result.events.Transfer;218      expect(event.address).to.equal(collectionAddress);219      expect(event.returnValues.from).to.equal(caller);220      expect(event.returnValues.to).to.equal(receiver);221      expect(event.returnValues.tokenId).to.equal(tokenId.toString());222223      event = tokenEvents[0];224      expect(event.address).to.equal(tokenAddress);225      expect(event.returnValues.from).to.equal(caller);226      expect(event.returnValues.to).to.equal(receiver);227      expect(event.returnValues.value).to.equal('15');228    }229230    {231      const balance = await contract.methods.balanceOf(receiver).call();232      expect(+balance).to.equal(1);233    }234235    {236      const balance = await contract.methods.balanceOf(caller).call();237      expect(+balance).to.equal(0);238    }239  });240241  itEth('Can perform transfer()', async ({helper}) => {242    const caller = await helper.eth.createAccountWithBalance(donor);243    const receiver = helper.eth.createAccount();244    const {collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Transferry', '6', '6');245    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);246247    const tokenId = await contract.methods.nextTokenId().call();248    await contract.methods.mint(caller, tokenId).send();249250    {251      const result = await contract.methods.transfer(receiver, tokenId).send();252      253      const event = result.events.Transfer;254      expect(event.address).to.equal(collectionAddress);255      expect(event.returnValues.from).to.equal(caller);256      expect(event.returnValues.to).to.equal(receiver);257      expect(event.returnValues.tokenId).to.equal(tokenId.toString());258    }259260    {261      const balance = await contract.methods.balanceOf(caller).call();262      expect(+balance).to.equal(0);263    }264265    {266      const balance = await contract.methods.balanceOf(receiver).call();267      expect(+balance).to.equal(1);268    }269  });270271  itEth('transfer event on transfer from partial ownership to full ownership', async ({helper}) => {272    const caller = await helper.eth.createAccountWithBalance(donor);273    const receiver = helper.eth.createAccount();274    const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Transferry-Partial-to-Full', '6', '6');275    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);276277    const tokenId = await contract.methods.nextTokenId().call();278    await contract.methods.mint(caller, tokenId).send();279280    const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);281282    await tokenContract.methods.repartition(2).send();283    await tokenContract.methods.transfer(receiver, 1).send();284285    const events: any = [];286    contract.events.allEvents((_: any, event: any) => {287      events.push(event);288    });289290    await tokenContract.methods.transfer(receiver, 1).send();291    if (events.length == 0) await helper.wait.newBlocks(1);292    const event = events[0];293294    expect(event.address).to.equal(collectionAddress);295    expect(event.returnValues.from).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');296    expect(event.returnValues.to).to.equal(receiver);297    expect(event.returnValues.tokenId).to.equal(tokenId.toString());298  });299300  itEth('transfer event on transfer from full ownership to partial ownership', async ({helper}) => {301    const caller = await helper.eth.createAccountWithBalance(donor);302    const receiver = helper.eth.createAccount();303    const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Transferry-Full-to-Partial', '6', '6');304    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);305306    const tokenId = await contract.methods.nextTokenId().call();307    await contract.methods.mint(caller, tokenId).send();308309    const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);310311    await tokenContract.methods.repartition(2).send();312313    const events: any = [];314    contract.events.allEvents((_: any, event: any) => {315      events.push(event);316    });317318    await tokenContract.methods.transfer(receiver, 1).send();319    if (events.length == 0) await helper.wait.newBlocks(1);320    const event = events[0];321322    expect(event.address).to.equal(collectionAddress);323    expect(event.returnValues.from).to.equal(caller);324    expect(event.returnValues.to).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');325    expect(event.returnValues.tokenId).to.equal(tokenId.toString());326  });327});328329describe('RFT: Fees', () => {330  let donor: IKeyringPair;331332  before(async function() {333    await usingEthPlaygrounds(async (helper, privateKey) => {334      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);335336      donor = await privateKey({filename: __filename});337    });338  });339340  itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {341    const caller = await helper.eth.createAccountWithBalance(donor);342    const receiver = helper.eth.createAccount();343    const {collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Feeful-Transfer-From', '6', '6');344    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);345346    const tokenId = await contract.methods.nextTokenId().call();347    await contract.methods.mint(caller, tokenId).send();348349    const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transferFrom(caller, receiver, tokenId).send());350    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));351    expect(cost > 0n);352  });353354  itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {355    const caller = await helper.eth.createAccountWithBalance(donor);356    const receiver = helper.eth.createAccount();357    const {collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Feeful-Transfer', '6', '6');358    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);359360    const tokenId = await contract.methods.nextTokenId().call();361    await contract.methods.mint(caller, tokenId).send();362363    const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transfer(receiver, tokenId).send());364    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));365    expect(cost > 0n);366  });367});368369describe('Common metadata', () => {370  let donor: IKeyringPair;371  let alice: IKeyringPair;372373  before(async function() {374    await usingEthPlaygrounds(async (helper, privateKey) => {375      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);376377      donor = await privateKey({filename: __filename});378      [alice] = await helper.arrange.createAccounts([20n], donor);379    });380  });381382  itEth('Returns collection name', async ({helper}) => {383    const caller = helper.eth.createAccount();384    const collection = await helper.rft.mintCollection(alice, {name: 'Leviathan', tokenPrefix: '11'});385    386    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'rft', caller);387    const name = await contract.methods.name().call();388    expect(name).to.equal('Leviathan');389  });390391  itEth('Returns symbol name', async ({helper}) => {392    const caller = await helper.eth.createAccountWithBalance(donor);393    const {collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Leviathan', '', '12');394    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);395    const symbol = await contract.methods.symbol().call();396    expect(symbol).to.equal('12');397  });398});
modifiedtests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth
--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -311,6 +311,7 @@
     });
     await tokenContract.methods.burnFrom(caller, 1).send();
 
+    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('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');
@@ -399,9 +400,11 @@
     contract.events.allEvents((_: any, event: any) => {
       events.push(event);
     });
-    expect(await token.approve(alice, {Ethereum: receiver}, 100n)).to.be.true;
 
+    expect(await token.approve(alice, {Ethereum: receiver}, 100n)).to.be.true;
+    if (events.length == 0) await helper.wait.newBlocks(1);
     const event = events[0];
+
     expect(event.event).to.be.equal('Approval');
     expect(event.address).to.be.equal(tokenAddress);
     expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));
@@ -425,6 +428,7 @@
     });
 
     expect(await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver},  51n)).to.be.true;
+    if (events.length == 0) await helper.wait.newBlocks(1);
 
     let event = events[0];
     expect(event.event).to.be.equal('Transfer');
@@ -455,8 +459,9 @@
     });
 
     expect(await token.transfer(alice, {Ethereum: receiver},  51n)).to.be.true;
+    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(tokenAddress);
     expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));
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);