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
378 // Balance should be taken from flipper instead of caller378 // Balance should be taken from flipper instead of caller
379 // FIXME the comment is wrong! What check should be here?379 // FIXME the comment is wrong! What check should be here?
380 const balanceAfter = await helper.balance.getEthereum(flipper.options.address);380 const balanceAfter = await helper.balance.getEthereum(flipper.options.address);
381 expect(balanceAfter).to.be.equals(originalFlipperBalance);381 expect(balanceAfter).to.be.equal(originalFlipperBalance);
382 });382 });
383383
384 itEth('Sponsoring is set, an address that has UNQ can send a transaction and it works. User balance should not change', async ({helper}) => {384 itEth('Sponsoring is set, an address that has UNQ can send a transaction and it works. User balance should not change', async ({helper}) => {
406 const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));406 const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));
407 const callerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));407 const callerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));
408 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;408 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
409 expect(callerBalanceAfter).to.be.equals(callerBalanceBefore);409 expect(callerBalanceAfter).to.be.equal(callerBalanceBefore);
410 });410 });
411411
412 itEth('Sponsoring is limited, with setContractRateLimit. The limitation is working if transactions are sent more often, the sender pays the commission.', async ({helper}) => {412 itEth('Sponsoring is limited, with setContractRateLimit. The limitation is working if transactions are sent more often, the sender pays the commission.', async ({helper}) => {
431431
432 await flipper.methods.flip().send({from: caller});432 await flipper.methods.flip().send({from: caller});
433 expect(await flipper.methods.getValue().call()).to.be.true;433 expect(await flipper.methods.getValue().call()).to.be.true;
434 expect(await helper.balance.getEthereum(caller)).to.be.equals(originalCallerBalance);434 expect(await helper.balance.getEthereum(caller)).to.be.equal(originalCallerBalance);
435435
436 const newFlipperBalance = await helper.balance.getEthereum(sponsor);436 const newFlipperBalance = await helper.balance.getEthereum(sponsor);
437 expect(newFlipperBalance).to.be.not.equals(originalFlipperBalance);437 expect(newFlipperBalance).to.be.not.equal(originalFlipperBalance);
438438
439 await flipper.methods.flip().send({from: caller});439 await flipper.methods.flip().send({from: caller});
440 // todo:playgrounds fails rarely (expected 99893341659775672580n to equal 99912598679356033129n) (again, 99893341659775672580n)
440 expect(await helper.balance.getEthereum(sponsor)).to.be.equal(newFlipperBalance);441 expect(await helper.balance.getEthereum(sponsor)).to.be.equal(newFlipperBalance);
441 expect(await helper.balance.getEthereum(caller)).to.be.not.equals(originalCallerBalance);442 expect(await helper.balance.getEthereum(caller)).to.be.not.equal(originalCallerBalance);
442 });443 });
443444
444 // TODO: Find a way to calculate default rate limit445 // TODO: Find a way to calculate default rate limit
445 itEth('Default rate limit equals 7200', async ({helper}) => {446 itEth('Default rate limit equal 7200', async ({helper}) => {
446 const owner = await helper.eth.createAccountWithBalance(donor);447 const owner = await helper.eth.createAccountWithBalance(donor);
447 const helpers = helper.ethNativeContract.contractHelpers(owner);448 const helpers = helper.ethNativeContract.contractHelpers(owner);
448 const flipper = await helper.eth.deployFlipper(owner);449 const flipper = await helper.eth.deployFlipper(owner);
449450
450 expect(await helpers.methods.sponsoringRateLimit(flipper.options.address).call()).to.be.equals('7200');451 expect(await helpers.methods.sponsoringRateLimit(flipper.options.address).call()).to.be.equal('7200');
451 });452 });
452});453});
453454
501 const helpers = helper.ethNativeContract.contractHelpers(owner);502 const helpers = helper.ethNativeContract.contractHelpers(owner);
502 const flipper = await helper.eth.deployFlipper(owner);503 const flipper = await helper.eth.deployFlipper(owner);
503504
504 expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equals('115792089237316195423570985008687907853269984665640564039457584007913129639935');505 expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equal('115792089237316195423570985008687907853269984665640564039457584007913129639935');
505 });506 });
506507
507 itEth('Set fee limit', async ({helper}) => {508 itEth('Set fee limit', async ({helper}) => {
510 const flipper = await helper.eth.deployFlipper(owner);511 const flipper = await helper.eth.deployFlipper(owner);
511512
512 await helpers.methods.setSponsoringFeeLimit(flipper.options.address, 100).send();513 await helpers.methods.setSponsoringFeeLimit(flipper.options.address, 100).send();
513 expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equals('100');514 expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equal('100');
514 });515 });
515516
516 itEth('Negative test - set fee limit by non-owner', async ({helper}) => {517 itEth('Negative test - set fee limit by non-owner', async ({helper}) => {
modifiedtests/src/eth/fungible.test.tsdiffbeforeafterboth
296 });296 });
297
297 await collection.approveTokens(alice, {Ethereum: receiver}, 100n);298 await collection.approveTokens(alice, {Ethereum: receiver}, 100n);
298299 if (events.length == 0) await helper.wait.newBlocks(1);
299 const event = events[0];300 const event = events[0];
301
300 expect(event.event).to.be.equal('Approval');302 expect(event.event).to.be.equal('Approval');
320 });322 });
323
321 await collection.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver}, 51n);324 await collection.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver}, 51n);
322325 if (events.length == 0) await helper.wait.newBlocks(1);
323 let event = events[0];326 let event = events[0];
327
324 expect(event.event).to.be.equal('Transfer');328 expect(event.event).to.be.equal('Transfer');
349 });353 });
354
350 await collection.transfer(alice, {Ethereum:receiver}, 51n);355 await collection.transfer(alice, {Ethereum:receiver}, 51n);
351356 if (events.length == 0) await helper.wait.newBlocks(1);
352 const event = events[0];357 const event = events[0];
358
353 expect(event.event).to.be.equal('Transfer');359 expect(event.event).to.be.equal('Transfer');
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
288 });288 });
289
289 await tokenContract.methods.transfer(receiver, 1).send();290 await tokenContract.methods.transfer(receiver, 1).send();
290291 if (events.length == 0) await helper.wait.newBlocks(1);
291 const event = events[0];292 const event = events[0];
293
292 expect(event.address).to.equal(collectionAddress);294 expect(event.address).to.equal(collectionAddress);
314 });316 });
317
315 await tokenContract.methods.transfer(receiver, 1).send();318 await tokenContract.methods.transfer(receiver, 1).send();
316319 if (events.length == 0) await helper.wait.newBlocks(1);
317 const event = events[0];320 const event = events[0];
321
318 expect(event.address).to.equal(collectionAddress);322 expect(event.address).to.equal(collectionAddress);
modifiedtests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth
311 });311 });
312 await tokenContract.methods.burnFrom(caller, 1).send();312 await tokenContract.methods.burnFrom(caller, 1).send();
313313
314 if (events.length == 0) await helper.wait.newBlocks(1);
314 const event = events[0];315 const event = events[0];
315 expect(event.address).to.be.equal(collectionAddress);316 expect(event.address).to.be.equal(collectionAddress);
316 expect(event.returnValues.from).to.be.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');317 expect(event.returnValues.from).to.be.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');
401 });402 });
403
402 expect(await token.approve(alice, {Ethereum: receiver}, 100n)).to.be.true;404 expect(await token.approve(alice, {Ethereum: receiver}, 100n)).to.be.true;
403405 if (events.length == 0) await helper.wait.newBlocks(1);
404 const event = events[0];406 const event = events[0];
407
405 expect(event.event).to.be.equal('Approval');408 expect(event.event).to.be.equal('Approval');
425 });428 });
426429
427 expect(await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver}, 51n)).to.be.true;430 expect(await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver}, 51n)).to.be.true;
431 if (events.length == 0) await helper.wait.newBlocks(1);
428432
429 let event = events[0];433 let event = events[0];
430 expect(event.event).to.be.equal('Transfer');434 expect(event.event).to.be.equal('Transfer');
455 });459 });
456460
457 expect(await token.transfer(alice, {Ethereum: receiver}, 51n)).to.be.true;461 expect(await token.transfer(alice, {Ethereum: receiver}, 51n)).to.be.true;
458462 if (events.length == 0) await helper.wait.newBlocks(1);
459 const event = events[0];463 const event = events[0];
464
460 expect(event.event).to.be.equal('Transfer');465 expect(event.event).to.be.equal('Transfer');
modifiedtests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth
156 };156 };
157157
158 let accountsCreated = false;158 let accountsCreated = false;
159 const maxBlocksChecked = await this.helper.arrange.isDevNode() ? 50 : 5;
159 // checkBalances retry up to 5 blocks160 // checkBalances retry up to 5-50 blocks
160 for (let index = 0; index < 5; index++) {161 for (let index = 0; index < maxBlocksChecked; index++) {
161 accountsCreated = await checkBalances();162 accountsCreated = await checkBalances();
162 if(accountsCreated) break;163 if(accountsCreated) break;
163 await wait.newBlocks(1);164 await wait.newBlocks(1);