difftreelog
tests(parallelization): fix createAccounts failing to catch up on dev node + evm events
in: master
6 files changed
tests/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}) => {
tests/src/eth/fungible.test.tsdiffbeforeafterboth1// 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 {expect, itEth, usingEthPlaygrounds} from './util';18import {IKeyringPair} from '@polkadot/types/types';1920describe('Fungible: Information getting', () => {21 let donor: IKeyringPair;22 let alice: IKeyringPair;2324 before(async function() {25 await usingEthPlaygrounds(async (helper, privateKey) => {26 donor = await privateKey({filename: __filename});27 [alice] = await helper.arrange.createAccounts([20n], donor);28 });29 });3031 itEth('totalSupply', async ({helper}) => {32 const caller = await helper.eth.createAccountWithBalance(donor);33 const collection = await helper.ft.mintCollection(alice);34 await collection.mint(alice, 200n);3536 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'ft', caller);37 const totalSupply = await contract.methods.totalSupply().call();38 expect(totalSupply).to.equal('200');39 });4041 itEth('balanceOf', async ({helper}) => {42 const caller = await helper.eth.createAccountWithBalance(donor);43 const collection = await helper.ft.mintCollection(alice);44 await collection.mint(alice, 200n, {Ethereum: caller});4546 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'ft', caller);47 const balance = await contract.methods.balanceOf(caller).call();48 expect(balance).to.equal('200');49 });50});5152describe('Fungible: Plain calls', () => {53 let donor: IKeyringPair;54 let alice: IKeyringPair;5556 before(async function() {57 await usingEthPlaygrounds(async (helper, privateKey) => {58 donor = await privateKey({filename: __filename});59 [alice] = await helper.arrange.createAccounts([20n], donor);60 });61 });6263 itEth('Can perform mint()', async ({helper}) => {64 const owner = await helper.eth.createAccountWithBalance(donor);65 const receiver = helper.eth.createAccount();66 const collection = await helper.ft.mintCollection(alice);67 await collection.addAdmin(alice, {Ethereum: owner});6869 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);70 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);7172 const result = await contract.methods.mint(receiver, 100).send();73 74 const event = result.events.Transfer;75 expect(event.address).to.equal(collectionAddress);76 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');77 expect(event.returnValues.to).to.equal(receiver);78 expect(event.returnValues.value).to.equal('100');79 });8081 itEth('Can perform mintBulk()', async ({helper}) => {82 const owner = await helper.eth.createAccountWithBalance(donor);83 const bulkSize = 3;84 const receivers = [...new Array(bulkSize)].map(() => helper.eth.createAccount());85 const collection = await helper.ft.mintCollection(alice);86 await collection.addAdmin(alice, {Ethereum: owner});8788 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);89 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);9091 const result = await contract.methods.mintBulk(Array.from({length: bulkSize}, (_, i) => (92 [receivers[i], (i + 1) * 10]93 ))).send();94 const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.value - b.returnValues.value);95 for (let i = 0; i < bulkSize; i++) {96 const event = events[i];97 expect(event.address).to.equal(collectionAddress);98 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');99 expect(event.returnValues.to).to.equal(receivers[i]);100 expect(event.returnValues.value).to.equal(String(10 * (i + 1)));101 }102 });103104 itEth('Can perform burn()', async ({helper}) => {105 const owner = await helper.eth.createAccountWithBalance(donor);106 const receiver = await helper.eth.createAccountWithBalance(donor);107 const collection = await helper.ft.mintCollection(alice);108 await collection.addAdmin(alice, {Ethereum: owner});109110 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);111 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);112 await contract.methods.mint(receiver, 100).send();113114 const result = await contract.methods.burnFrom(receiver, 49).send({from: receiver});115 116 const event = result.events.Transfer;117 expect(event.address).to.equal(collectionAddress);118 expect(event.returnValues.from).to.equal(receiver);119 expect(event.returnValues.to).to.equal('0x0000000000000000000000000000000000000000');120 expect(event.returnValues.value).to.equal('49');121122 const balance = await contract.methods.balanceOf(receiver).call();123 expect(balance).to.equal('51');124 });125126 itEth('Can perform approve()', async ({helper}) => {127 const owner = await helper.eth.createAccountWithBalance(donor);128 const spender = helper.eth.createAccount();129 const collection = await helper.ft.mintCollection(alice);130 await collection.mint(alice, 200n, {Ethereum: owner});131132 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);133 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);134135 {136 const result = await contract.methods.approve(spender, 100).send({from: owner});137138 const event = result.events.Approval;139 expect(event.address).to.be.equal(collectionAddress);140 expect(event.returnValues.owner).to.be.equal(owner);141 expect(event.returnValues.spender).to.be.equal(spender);142 expect(event.returnValues.value).to.be.equal('100');143 }144145 {146 const allowance = await contract.methods.allowance(owner, spender).call();147 expect(+allowance).to.equal(100);148 }149 });150151 itEth('Can perform transferFrom()', async ({helper}) => {152 const owner = await helper.eth.createAccountWithBalance(donor);153 const spender = await helper.eth.createAccountWithBalance(donor);154 const receiver = helper.eth.createAccount();155 const collection = await helper.ft.mintCollection(alice);156 await collection.mint(alice, 200n, {Ethereum: owner});157158 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);159 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);160161 await contract.methods.approve(spender, 100).send();162163 {164 const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: spender});165 166 let event = result.events.Transfer;167 expect(event.address).to.be.equal(collectionAddress);168 expect(event.returnValues.from).to.be.equal(owner);169 expect(event.returnValues.to).to.be.equal(receiver);170 expect(event.returnValues.value).to.be.equal('49');171172 event = result.events.Approval;173 expect(event.address).to.be.equal(collectionAddress);174 expect(event.returnValues.owner).to.be.equal(owner);175 expect(event.returnValues.spender).to.be.equal(spender);176 expect(event.returnValues.value).to.be.equal('51');177 }178179 {180 const balance = await contract.methods.balanceOf(receiver).call();181 expect(+balance).to.equal(49);182 }183184 {185 const balance = await contract.methods.balanceOf(owner).call();186 expect(+balance).to.equal(151);187 }188 });189190 itEth('Can perform transfer()', async ({helper}) => {191 const owner = await helper.eth.createAccountWithBalance(donor);192 const receiver = await helper.eth.createAccountWithBalance(donor);193 const collection = await helper.ft.mintCollection(alice);194 await collection.mint(alice, 200n, {Ethereum: owner});195196 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);197 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);198199 {200 const result = await contract.methods.transfer(receiver, 50).send({from: owner});201 202 const event = result.events.Transfer;203 expect(event.address).to.be.equal(collectionAddress);204 expect(event.returnValues.from).to.be.equal(owner);205 expect(event.returnValues.to).to.be.equal(receiver);206 expect(event.returnValues.value).to.be.equal('50');207 }208209 {210 const balance = await contract.methods.balanceOf(owner).call();211 expect(+balance).to.equal(150);212 }213214 {215 const balance = await contract.methods.balanceOf(receiver).call();216 expect(+balance).to.equal(50);217 }218 });219});220221describe('Fungible: Fees', () => {222 let donor: IKeyringPair;223 let alice: IKeyringPair;224225 before(async function() {226 await usingEthPlaygrounds(async (helper, privateKey) => {227 donor = await privateKey({filename: __filename});228 [alice] = await helper.arrange.createAccounts([20n], donor);229 });230 });231 232 itEth('approve() call fee is less than 0.2UNQ', async ({helper}) => {233 const owner = await helper.eth.createAccountWithBalance(donor);234 const spender = helper.eth.createAccount();235 const collection = await helper.ft.mintCollection(alice);236 await collection.mint(alice, 200n, {Ethereum: owner});237238 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);239 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);240241 const cost = await helper.eth.recordCallFee(owner, () => contract.methods.approve(spender, 100).send({from: owner}));242 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));243 });244245 itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {246 const owner = await helper.eth.createAccountWithBalance(donor);247 const spender = await helper.eth.createAccountWithBalance(donor);248 const collection = await helper.ft.mintCollection(alice);249 await collection.mint(alice, 200n, {Ethereum: owner});250251 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);252 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);253254 await contract.methods.approve(spender, 100).send({from: owner});255256 const cost = await helper.eth.recordCallFee(spender, () => contract.methods.transferFrom(owner, spender, 100).send({from: spender}));257 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));258 });259260 itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {261 const owner = await helper.eth.createAccountWithBalance(donor);262 const receiver = helper.eth.createAccount();263 const collection = await helper.ft.mintCollection(alice);264 await collection.mint(alice, 200n, {Ethereum: owner});265266 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);267 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);268269 const cost = await helper.eth.recordCallFee(owner, () => contract.methods.transfer(receiver, 100).send({from: owner}));270 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));271 });272});273274describe('Fungible: Substrate calls', () => {275 let donor: IKeyringPair;276 let alice: IKeyringPair;277278 before(async function() {279 await usingEthPlaygrounds(async (helper, privateKey) => {280 donor = await privateKey({filename: __filename});281 [alice] = await helper.arrange.createAccounts([20n], donor);282 });283 });284285 itEth('Events emitted for approve()', async ({helper}) => {286 const receiver = helper.eth.createAccount();287 const collection = await helper.ft.mintCollection(alice);288 await collection.mint(alice, 200n);289290 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);291 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft');292293 const events: any = [];294 contract.events.allEvents((_: any, event: any) => {295 events.push(event);296 });297 await collection.approveTokens(alice, {Ethereum: receiver}, 100n);298299 const event = events[0];300 expect(event.event).to.be.equal('Approval');301 expect(event.address).to.be.equal(collectionAddress);302 expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));303 expect(event.returnValues.spender).to.be.equal(receiver);304 expect(event.returnValues.value).to.be.equal('100');305 });306307 itEth('Events emitted for transferFrom()', async ({helper}) => {308 const [bob] = await helper.arrange.createAccounts([10n], donor);309 const receiver = helper.eth.createAccount();310 const collection = await helper.ft.mintCollection(alice);311 await collection.mint(alice, 200n);312 await collection.approveTokens(alice, {Substrate: bob.address}, 100n);313314 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);315 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft');316317 const events: any = [];318 contract.events.allEvents((_: any, event: any) => {319 events.push(event);320 });321 await collection.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver}, 51n);322323 let event = events[0];324 expect(event.event).to.be.equal('Transfer');325 expect(event.address).to.be.equal(collectionAddress);326 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));327 expect(event.returnValues.to).to.be.equal(receiver);328 expect(event.returnValues.value).to.be.equal('51');329330 event = events[1];331 expect(event.event).to.be.equal('Approval');332 expect(event.address).to.be.equal(collectionAddress);333 expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));334 expect(event.returnValues.spender).to.be.equal(helper.address.substrateToEth(bob.address));335 expect(event.returnValues.value).to.be.equal('49');336 });337338 itEth('Events emitted for transfer()', async ({helper}) => {339 const receiver = helper.eth.createAccount();340 const collection = await helper.ft.mintCollection(alice);341 await collection.mint(alice, 200n);342343 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);344 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft');345346 const events: any = [];347 contract.events.allEvents((_: any, event: any) => {348 events.push(event);349 });350 await collection.transfer(alice, {Ethereum:receiver}, 51n);351352 const event = events[0];353 expect(event.event).to.be.equal('Transfer');354 expect(event.address).to.be.equal(collectionAddress);355 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));356 expect(event.returnValues.to).to.be.equal(receiver);357 expect(event.returnValues.value).to.be.equal('51');358 });359});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 {expect, itEth, usingEthPlaygrounds} from './util';18import {IKeyringPair} from '@polkadot/types/types';1920describe('Fungible: Information getting', () => {21 let donor: IKeyringPair;22 let alice: IKeyringPair;2324 before(async function() {25 await usingEthPlaygrounds(async (helper, privateKey) => {26 donor = await privateKey({filename: __filename});27 [alice] = await helper.arrange.createAccounts([20n], donor);28 });29 });3031 itEth('totalSupply', async ({helper}) => {32 const caller = await helper.eth.createAccountWithBalance(donor);33 const collection = await helper.ft.mintCollection(alice);34 await collection.mint(alice, 200n);3536 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'ft', caller);37 const totalSupply = await contract.methods.totalSupply().call();38 expect(totalSupply).to.equal('200');39 });4041 itEth('balanceOf', async ({helper}) => {42 const caller = await helper.eth.createAccountWithBalance(donor);43 const collection = await helper.ft.mintCollection(alice);44 await collection.mint(alice, 200n, {Ethereum: caller});4546 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'ft', caller);47 const balance = await contract.methods.balanceOf(caller).call();48 expect(balance).to.equal('200');49 });50});5152describe('Fungible: Plain calls', () => {53 let donor: IKeyringPair;54 let alice: IKeyringPair;5556 before(async function() {57 await usingEthPlaygrounds(async (helper, privateKey) => {58 donor = await privateKey({filename: __filename});59 [alice] = await helper.arrange.createAccounts([20n], donor);60 });61 });6263 itEth('Can perform mint()', async ({helper}) => {64 const owner = await helper.eth.createAccountWithBalance(donor);65 const receiver = helper.eth.createAccount();66 const collection = await helper.ft.mintCollection(alice);67 await collection.addAdmin(alice, {Ethereum: owner});6869 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);70 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);7172 const result = await contract.methods.mint(receiver, 100).send();73 74 const event = result.events.Transfer;75 expect(event.address).to.equal(collectionAddress);76 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');77 expect(event.returnValues.to).to.equal(receiver);78 expect(event.returnValues.value).to.equal('100');79 });8081 itEth('Can perform mintBulk()', async ({helper}) => {82 const owner = await helper.eth.createAccountWithBalance(donor);83 const bulkSize = 3;84 const receivers = [...new Array(bulkSize)].map(() => helper.eth.createAccount());85 const collection = await helper.ft.mintCollection(alice);86 await collection.addAdmin(alice, {Ethereum: owner});8788 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);89 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);9091 const result = await contract.methods.mintBulk(Array.from({length: bulkSize}, (_, i) => (92 [receivers[i], (i + 1) * 10]93 ))).send();94 const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.value - b.returnValues.value);95 for (let i = 0; i < bulkSize; i++) {96 const event = events[i];97 expect(event.address).to.equal(collectionAddress);98 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');99 expect(event.returnValues.to).to.equal(receivers[i]);100 expect(event.returnValues.value).to.equal(String(10 * (i + 1)));101 }102 });103104 itEth('Can perform burn()', async ({helper}) => {105 const owner = await helper.eth.createAccountWithBalance(donor);106 const receiver = await helper.eth.createAccountWithBalance(donor);107 const collection = await helper.ft.mintCollection(alice);108 await collection.addAdmin(alice, {Ethereum: owner});109110 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);111 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);112 await contract.methods.mint(receiver, 100).send();113114 const result = await contract.methods.burnFrom(receiver, 49).send({from: receiver});115 116 const event = result.events.Transfer;117 expect(event.address).to.equal(collectionAddress);118 expect(event.returnValues.from).to.equal(receiver);119 expect(event.returnValues.to).to.equal('0x0000000000000000000000000000000000000000');120 expect(event.returnValues.value).to.equal('49');121122 const balance = await contract.methods.balanceOf(receiver).call();123 expect(balance).to.equal('51');124 });125126 itEth('Can perform approve()', async ({helper}) => {127 const owner = await helper.eth.createAccountWithBalance(donor);128 const spender = helper.eth.createAccount();129 const collection = await helper.ft.mintCollection(alice);130 await collection.mint(alice, 200n, {Ethereum: owner});131132 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);133 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);134135 {136 const result = await contract.methods.approve(spender, 100).send({from: owner});137138 const event = result.events.Approval;139 expect(event.address).to.be.equal(collectionAddress);140 expect(event.returnValues.owner).to.be.equal(owner);141 expect(event.returnValues.spender).to.be.equal(spender);142 expect(event.returnValues.value).to.be.equal('100');143 }144145 {146 const allowance = await contract.methods.allowance(owner, spender).call();147 expect(+allowance).to.equal(100);148 }149 });150151 itEth('Can perform transferFrom()', async ({helper}) => {152 const owner = await helper.eth.createAccountWithBalance(donor);153 const spender = await helper.eth.createAccountWithBalance(donor);154 const receiver = helper.eth.createAccount();155 const collection = await helper.ft.mintCollection(alice);156 await collection.mint(alice, 200n, {Ethereum: owner});157158 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);159 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);160161 await contract.methods.approve(spender, 100).send();162163 {164 const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: spender});165 166 let event = result.events.Transfer;167 expect(event.address).to.be.equal(collectionAddress);168 expect(event.returnValues.from).to.be.equal(owner);169 expect(event.returnValues.to).to.be.equal(receiver);170 expect(event.returnValues.value).to.be.equal('49');171172 event = result.events.Approval;173 expect(event.address).to.be.equal(collectionAddress);174 expect(event.returnValues.owner).to.be.equal(owner);175 expect(event.returnValues.spender).to.be.equal(spender);176 expect(event.returnValues.value).to.be.equal('51');177 }178179 {180 const balance = await contract.methods.balanceOf(receiver).call();181 expect(+balance).to.equal(49);182 }183184 {185 const balance = await contract.methods.balanceOf(owner).call();186 expect(+balance).to.equal(151);187 }188 });189190 itEth('Can perform transfer()', async ({helper}) => {191 const owner = await helper.eth.createAccountWithBalance(donor);192 const receiver = await helper.eth.createAccountWithBalance(donor);193 const collection = await helper.ft.mintCollection(alice);194 await collection.mint(alice, 200n, {Ethereum: owner});195196 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);197 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);198199 {200 const result = await contract.methods.transfer(receiver, 50).send({from: owner});201 202 const event = result.events.Transfer;203 expect(event.address).to.be.equal(collectionAddress);204 expect(event.returnValues.from).to.be.equal(owner);205 expect(event.returnValues.to).to.be.equal(receiver);206 expect(event.returnValues.value).to.be.equal('50');207 }208209 {210 const balance = await contract.methods.balanceOf(owner).call();211 expect(+balance).to.equal(150);212 }213214 {215 const balance = await contract.methods.balanceOf(receiver).call();216 expect(+balance).to.equal(50);217 }218 });219});220221describe('Fungible: Fees', () => {222 let donor: IKeyringPair;223 let alice: IKeyringPair;224225 before(async function() {226 await usingEthPlaygrounds(async (helper, privateKey) => {227 donor = await privateKey({filename: __filename});228 [alice] = await helper.arrange.createAccounts([20n], donor);229 });230 });231 232 itEth('approve() call fee is less than 0.2UNQ', async ({helper}) => {233 const owner = await helper.eth.createAccountWithBalance(donor);234 const spender = helper.eth.createAccount();235 const collection = await helper.ft.mintCollection(alice);236 await collection.mint(alice, 200n, {Ethereum: owner});237238 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);239 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);240241 const cost = await helper.eth.recordCallFee(owner, () => contract.methods.approve(spender, 100).send({from: owner}));242 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));243 });244245 itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {246 const owner = await helper.eth.createAccountWithBalance(donor);247 const spender = await helper.eth.createAccountWithBalance(donor);248 const collection = await helper.ft.mintCollection(alice);249 await collection.mint(alice, 200n, {Ethereum: owner});250251 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);252 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);253254 await contract.methods.approve(spender, 100).send({from: owner});255256 const cost = await helper.eth.recordCallFee(spender, () => contract.methods.transferFrom(owner, spender, 100).send({from: spender}));257 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));258 });259260 itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {261 const owner = await helper.eth.createAccountWithBalance(donor);262 const receiver = helper.eth.createAccount();263 const collection = await helper.ft.mintCollection(alice);264 await collection.mint(alice, 200n, {Ethereum: owner});265266 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);267 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);268269 const cost = await helper.eth.recordCallFee(owner, () => contract.methods.transfer(receiver, 100).send({from: owner}));270 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));271 });272});273274describe('Fungible: Substrate calls', () => {275 let donor: IKeyringPair;276 let alice: IKeyringPair;277278 before(async function() {279 await usingEthPlaygrounds(async (helper, privateKey) => {280 donor = await privateKey({filename: __filename});281 [alice] = await helper.arrange.createAccounts([20n], donor);282 });283 });284285 itEth('Events emitted for approve()', async ({helper}) => {286 const receiver = helper.eth.createAccount();287 const collection = await helper.ft.mintCollection(alice);288 await collection.mint(alice, 200n);289290 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);291 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft');292293 const events: any = [];294 contract.events.allEvents((_: any, event: any) => {295 events.push(event);296 });297 298 await collection.approveTokens(alice, {Ethereum: receiver}, 100n);299 if (events.length == 0) await helper.wait.newBlocks(1);300 const event = events[0];301302 expect(event.event).to.be.equal('Approval');303 expect(event.address).to.be.equal(collectionAddress);304 expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));305 expect(event.returnValues.spender).to.be.equal(receiver);306 expect(event.returnValues.value).to.be.equal('100');307 });308309 itEth('Events emitted for transferFrom()', async ({helper}) => {310 const [bob] = await helper.arrange.createAccounts([10n], donor);311 const receiver = helper.eth.createAccount();312 const collection = await helper.ft.mintCollection(alice);313 await collection.mint(alice, 200n);314 await collection.approveTokens(alice, {Substrate: bob.address}, 100n);315316 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);317 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft');318319 const events: any = [];320 contract.events.allEvents((_: any, event: any) => {321 events.push(event);322 });323324 await collection.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver}, 51n);325 if (events.length == 0) await helper.wait.newBlocks(1);326 let event = events[0];327328 expect(event.event).to.be.equal('Transfer');329 expect(event.address).to.be.equal(collectionAddress);330 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));331 expect(event.returnValues.to).to.be.equal(receiver);332 expect(event.returnValues.value).to.be.equal('51');333334 event = events[1];335 expect(event.event).to.be.equal('Approval');336 expect(event.address).to.be.equal(collectionAddress);337 expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));338 expect(event.returnValues.spender).to.be.equal(helper.address.substrateToEth(bob.address));339 expect(event.returnValues.value).to.be.equal('49');340 });341342 itEth('Events emitted for transfer()', async ({helper}) => {343 const receiver = helper.eth.createAccount();344 const collection = await helper.ft.mintCollection(alice);345 await collection.mint(alice, 200n);346347 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);348 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft');349350 const events: any = [];351 contract.events.allEvents((_: any, event: any) => {352 events.push(event);353 });354 355 await collection.transfer(alice, {Ethereum:receiver}, 51n);356 if (events.length == 0) await helper.wait.newBlocks(1);357 const event = events[0];358359 expect(event.event).to.be.equal('Transfer');360 expect(event.address).to.be.equal(collectionAddress);361 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));362 expect(event.returnValues.to).to.be.equal(receiver);363 expect(event.returnValues.value).to.be.equal('51');364 });365});tests/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);
tests/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');
tests/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));
tests/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);