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
387 });387 });
388
388 const {tokenId} = await collection.mintToken(alice);389 const {tokenId} = await collection.mintToken(alice);
389390 if (events.length == 0) await helper.wait.newBlocks(1);
390 const event = events[0];391 const event = events[0];
392
391 expect(event.event).to.be.equal('Transfer');393 expect(event.event).to.be.equal('Transfer');
408 });410 });
409411
410 await token.burn(alice);412 await token.burn(alice);
411413 if (events.length == 0) await helper.wait.newBlocks(1);
412 const event = events[0];414 const event = events[0];
415
413 expect(event.event).to.be.equal('Transfer');416 expect(event.event).to.be.equal('Transfer');
432 });435 });
433436
434 await token.approve(alice, {Ethereum: receiver});437 await token.approve(alice, {Ethereum: receiver});
435438 if (events.length == 0) await helper.wait.newBlocks(1);
436 const event = events[0];439 const event = events[0];
440
437 expect(event.event).to.be.equal('Approval');441 expect(event.event).to.be.equal('Approval');
458 });462 });
459463
460 await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver});464 await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver});
461 465 if (events.length == 0) await helper.wait.newBlocks(1);
462 const event = events[0];466 const event = events[0];
467
463 expect(event.address).to.be.equal(collectionAddress);468 expect(event.address).to.be.equal(collectionAddress);
481 });486 });
482487
483 await token.transfer(alice, {Ethereum: receiver});488 await token.transfer(alice, {Ethereum: receiver});
484 489 if (events.length == 0) await helper.wait.newBlocks(1);
485 const event = events[0];490 const event = events[0];
491
486 expect(event.address).to.be.equal(collectionAddress);492 expect(event.address).to.be.equal(collectionAddress);
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
--- 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);