difftreelog
fix contractSponsoring deplyFlipper, remove unneeded comments
in: master
1 file changed
tests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth23 normalizeEvents,23 normalizeEvents,24 CompiledContract,24 CompiledContract,25 GAS_ARGS,25 GAS_ARGS,26 contractHelpers,27 createEthAccountWithBalance,28} from './util/helpers';26} from './util/helpers';29import {itEth, expect} from '../eth/util/playgrounds';27import {itEth, expect} from '../eth/util/playgrounds';3028312932describe.only('Sponsoring EVM contracts', () => {30describe('Sponsoring EVM contracts', () => {33 itEth('Self sponsored can be set by the address that deployed the contract', async ({helper, privateKey}) => {31 itEth('Self sponsored can be set by the address that deployed the contract', async ({helper, privateKey}) => {34 const alice = privateKey('//Alice');32 const alice = privateKey('//Alice');353336 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);37 // const flipper = await deployFlipper(web3, owner);38 // const helpers = contractHelpers(web3, owner);39 const owner = await helper.eth.createAccountWithBalance(alice);34 const owner = await helper.eth.createAccountWithBalance(alice);40 const flipper = await helper.eth.deployFlipper(owner);35 const flipper = await helper.eth.deployFlipper(owner);41 const helpers = helper.ethNativeContract.contractHelpers(owner);36 const helpers = helper.ethNativeContract.contractHelpers(owner);48 itEth('Set self sponsored events', async ({helper, privateKey}) => {43 itEth('Set self sponsored events', async ({helper, privateKey}) => {49 const alice = privateKey('//Alice');44 const alice = privateKey('//Alice');504551 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);52 // const flipper = await deployFlipper(web3, owner);53 // const helpers = contractHelpers(web3, owner);54 const owner = await helper.eth.createAccountWithBalance(alice);46 const owner = await helper.eth.createAccountWithBalance(alice);55 const flipper = await helper.eth.deployFlipper(owner);47 const flipper = await helper.eth.deployFlipper(owner);56 const helpers = helper.ethNativeContract.contractHelpers(owner);48 const helpers = helper.ethNativeContract.contractHelpers(owner);88 itEth('Self sponsored can not be set by the address that did not deployed the contract', async ({helper, privateKey}) => {80 itEth('Self sponsored can not be set by the address that did not deployed the contract', async ({helper, privateKey}) => {89 const alice = privateKey('//Alice');81 const alice = privateKey('//Alice');908291 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);92 // const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);93 // const helpers = contractHelpers(web3, owner);94 // const flipper = await deployFlipper(web3, owner);95 const owner = await helper.eth.createAccountWithBalance(alice);83 const owner = await helper.eth.createAccountWithBalance(alice);96 const notOwner = await helper.eth.createAccountWithBalance(alice);84 const notOwner = await helper.eth.createAccountWithBalance(alice);97 const helpers = helper.ethNativeContract.contractHelpers(owner);85 const helpers = helper.ethNativeContract.contractHelpers(owner);98 const flipper = helper.ethNativeContract.contractHelpers(owner);86 const flipper = await helper.eth.deployFlipper(owner);9987100 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;88 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;101 await expect(helpers.methods.selfSponsoredEnable(flipper.options.address).call({from: notOwner})).to.be.rejectedWith('NoPermission');89 await expect(helpers.methods.selfSponsoredEnable(flipper.options.address).call({from: notOwner})).to.be.rejectedWith('NoPermission');102 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;90 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;103 });91 });10492105 itEth.only('Sponsoring can be set by the address that has deployed the contract', async ({helper, privateKey}) => {93 itEth('Sponsoring can be set by the address that has deployed the contract', async ({helper, privateKey}) => {106 const alice = privateKey('//Alice');94 const alice = privateKey('//Alice');10795108 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);109 // const flipper = await deployFlipper(web3, owner);110 // const helpers = contractHelpers(web3, owner);111 const owner = await helper.eth.createAccountWithBalance(alice);96 const owner = await helper.eth.createAccountWithBalance(alice);112 const helpers = helper.ethNativeContract.contractHelpers(owner);97 const helpers = helper.ethNativeContract.contractHelpers(owner);113 const flipper = await helper.eth.deployFlipper(owner);98 const flipper = await helper.eth.deployFlipper(owner);120 itEth('Sponsoring cannot be set by the address that did not deployed the contract', async ({helper, privateKey}) => {105 itEth('Sponsoring cannot be set by the address that did not deployed the contract', async ({helper, privateKey}) => {121 const alice = privateKey('//Alice');106 const alice = privateKey('//Alice');122107123 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);124 // const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);125 // const flipper = await deployFlipper(web3, owner);126 // const helpers = contractHelpers(web3, owner);127 const owner = await helper.eth.createAccountWithBalance(alice);108 const owner = await helper.eth.createAccountWithBalance(alice);128 const notOwner = await helper.eth.createAccountWithBalance(alice);109 const notOwner = await helper.eth.createAccountWithBalance(alice);129 const helpers = helper.ethNativeContract.contractHelpers(owner);110 const helpers = helper.ethNativeContract.contractHelpers(owner);130 const flipper = helper.ethNativeContract.contractHelpers(owner);111 const flipper = await helper.eth.deployFlipper(owner);131112132 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;113 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;133 await expect(helpers.methods.setSponsoringMode(notOwner, SponsoringMode.Allowlisted).call({from: notOwner})).to.be.rejectedWith('NoPermission');114 await expect(helpers.methods.setSponsoringMode(notOwner, SponsoringMode.Allowlisted).call({from: notOwner})).to.be.rejectedWith('NoPermission');137 itEth('Sponsor can be set by the address that deployed the contract', async ({helper, privateKey}) => {118 itEth('Sponsor can be set by the address that deployed the contract', async ({helper, privateKey}) => {138 const alice = privateKey('//Alice');119 const alice = privateKey('//Alice');139120140 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);141 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);142 // const flipper = await deployFlipper(web3, owner);143 // const helpers = contractHelpers(web3, owner);144 const owner = await helper.eth.createAccountWithBalance(alice);121 const owner = await helper.eth.createAccountWithBalance(alice);145 const sponsor = await helper.eth.createAccountWithBalance(alice);122 const sponsor = await helper.eth.createAccountWithBalance(alice);146 const helpers = helper.ethNativeContract.contractHelpers(owner);123 const helpers = helper.ethNativeContract.contractHelpers(owner);147 const flipper = helper.ethNativeContract.contractHelpers(owner);124 const flipper = await helper.eth.deployFlipper(owner);148125149 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false;126 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false;150 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;127 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;154 itEth('Set sponsor event', async ({helper, privateKey}) => {131 itEth('Set sponsor event', async ({helper, privateKey}) => {155 const alice = privateKey('//Alice');132 const alice = privateKey('//Alice');156133157 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);158 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);159 // const flipper = await deployFlipper(web3, owner);160 // const helpers = contractHelpers(web3, owner);161 const owner = await helper.eth.createAccountWithBalance(alice);134 const owner = await helper.eth.createAccountWithBalance(alice);162 const sponsor = await helper.eth.createAccountWithBalance(alice);135 const sponsor = await helper.eth.createAccountWithBalance(alice);163 const helpers = helper.ethNativeContract.contractHelpers(owner);136 const helpers = helper.ethNativeContract.contractHelpers(owner);164 const flipper = helper.ethNativeContract.contractHelpers(owner);137 const flipper = await helper.eth.deployFlipper(owner);165 138 166 const result = await helpers.methods.setSponsor(flipper.options.address, sponsor).send();139 const result = await helpers.methods.setSponsor(flipper.options.address, sponsor).send();167 const events = normalizeEvents(result.events);140 const events = normalizeEvents(result.events);188 itEth('Sponsor can not be set by the address that did not deployed the contract', async ({helper, privateKey}) => {161 itEth('Sponsor can not be set by the address that did not deployed the contract', async ({helper, privateKey}) => {189 const alice = privateKey('//Alice');162 const alice = privateKey('//Alice');190163191 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);192 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);193 // const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);194 // const flipper = await deployFlipper(web3, owner);195 // const helpers = contractHelpers(web3, owner);196 const owner = await helper.eth.createAccountWithBalance(alice);164 const owner = await helper.eth.createAccountWithBalance(alice);197 const sponsor = await helper.eth.createAccountWithBalance(alice);165 const sponsor = await helper.eth.createAccountWithBalance(alice);198 const notOwner = await helper.eth.createAccountWithBalance(alice);166 const notOwner = await helper.eth.createAccountWithBalance(alice);199 const helpers = helper.ethNativeContract.contractHelpers(owner);167 const helpers = helper.ethNativeContract.contractHelpers(owner);200 const flipper = helper.ethNativeContract.contractHelpers(owner);168 const flipper = await helper.eth.deployFlipper(owner);201169202 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false;170 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false;203 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).call({from: notOwner})).to.be.rejectedWith('NoPermission');171 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).call({from: notOwner})).to.be.rejectedWith('NoPermission');207 itEth('Sponsorship can be confirmed by the address that pending as sponsor', async ({helper, privateKey}) => {175 itEth('Sponsorship can be confirmed by the address that pending as sponsor', async ({helper, privateKey}) => {208 const alice = privateKey('//Alice');176 const alice = privateKey('//Alice');209177210 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);211 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);212 // const flipper = await deployFlipper(web3, owner);213 // const helpers = contractHelpers(web3, owner);214 const owner = await helper.eth.createAccountWithBalance(alice);178 const owner = await helper.eth.createAccountWithBalance(alice);215 const sponsor = await helper.eth.createAccountWithBalance(alice);179 const sponsor = await helper.eth.createAccountWithBalance(alice);216 const helpers = helper.ethNativeContract.contractHelpers(owner);180 const helpers = helper.ethNativeContract.contractHelpers(owner);217 const flipper = helper.ethNativeContract.contractHelpers(owner);181 const flipper = await helper.eth.deployFlipper(owner);218182219 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;183 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;220 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;184 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;225 itEth('Confirm sponsorship event', async ({helper, privateKey}) => {189 itEth('Confirm sponsorship event', async ({helper, privateKey}) => {226 const alice = privateKey('//Alice');190 const alice = privateKey('//Alice');227191228 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);229 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);230 // const flipper = await deployFlipper(web3, owner);231 // const helpers = contractHelpers(web3, owner);232 const owner = await helper.eth.createAccountWithBalance(alice);192 const owner = await helper.eth.createAccountWithBalance(alice);233 const sponsor = await helper.eth.createAccountWithBalance(alice);193 const sponsor = await helper.eth.createAccountWithBalance(alice);234 const helpers = helper.ethNativeContract.contractHelpers(owner);194 const helpers = helper.ethNativeContract.contractHelpers(owner);235 const flipper = helper.ethNativeContract.contractHelpers(owner);195 const flipper = await helper.eth.deployFlipper(owner);236196237 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;197 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;238 const result = await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});198 const result = await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});260 itEth('Sponsorship can not be confirmed by the address that not pending as sponsor', async ({helper, privateKey}) => {220 itEth('Sponsorship can not be confirmed by the address that not pending as sponsor', async ({helper, privateKey}) => {261 const alice = privateKey('//Alice');221 const alice = privateKey('//Alice');262222263 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);264 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);265 // const notSponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);266 // const flipper = await deployFlipper(web3, owner);267 // const helpers = contractHelpers(web3, owner);268 const owner = await helper.eth.createAccountWithBalance(alice);223 const owner = await helper.eth.createAccountWithBalance(alice);269 const sponsor = await helper.eth.createAccountWithBalance(alice);224 const sponsor = await helper.eth.createAccountWithBalance(alice);270 const notSponsor = await helper.eth.createAccountWithBalance(alice);225 const notSponsor = await helper.eth.createAccountWithBalance(alice);271 const helpers = helper.ethNativeContract.contractHelpers(owner);226 const helpers = helper.ethNativeContract.contractHelpers(owner);272 const flipper = helper.ethNativeContract.contractHelpers(owner);227 const flipper = await helper.eth.deployFlipper(owner);273228274 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;229 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;275 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;230 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;280 itEth('Sponsorship can not be confirmed by the address that not set as sponsor', async ({helper, privateKey}) => {235 itEth('Sponsorship can not be confirmed by the address that not set as sponsor', async ({helper, privateKey}) => {281 const alice = privateKey('//Alice');236 const alice = privateKey('//Alice');282237283 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);284 // const notSponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);285 // const flipper = await deployFlipper(web3, owner);286 // const helpers = contractHelpers(web3, owner);287 const owner = await helper.eth.createAccountWithBalance(alice);238 const owner = await helper.eth.createAccountWithBalance(alice);288 const notSponsor = await helper.eth.createAccountWithBalance(alice);239 const notSponsor = await helper.eth.createAccountWithBalance(alice);289 const helpers = helper.ethNativeContract.contractHelpers(owner);240 const helpers = helper.ethNativeContract.contractHelpers(owner);290 const flipper = helper.ethNativeContract.contractHelpers(owner);241 const flipper = await helper.eth.deployFlipper(owner);291242292 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;243 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;293 await expect(helpers.methods.confirmSponsorship(flipper.options.address).call({from: notSponsor})).to.be.rejectedWith('NoPendingSponsor');244 await expect(helpers.methods.confirmSponsorship(flipper.options.address).call({from: notSponsor})).to.be.rejectedWith('NoPendingSponsor');297 itEth('Get self sponsored sponsor', async ({helper, privateKey}) => {248 itEth('Get self sponsored sponsor', async ({helper, privateKey}) => {298 const alice = privateKey('//Alice');249 const alice = privateKey('//Alice');299250300 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);301 // const flipper = await deployFlipper(web3, owner);302 // const helpers = contractHelpers(web3, owner);303 const owner = await helper.eth.createAccountWithBalance(alice);251 const owner = await helper.eth.createAccountWithBalance(alice);304 const flipper = helper.ethNativeContract.contractHelpers(owner);305 const helpers = helper.ethNativeContract.contractHelpers(owner);252 const helpers = helper.ethNativeContract.contractHelpers(owner);253 const flipper = await helper.eth.deployFlipper(owner);306254307 await helpers.methods.selfSponsoredEnable(flipper.options.address).send();255 await helpers.methods.selfSponsoredEnable(flipper.options.address).send();308 256 315 itEth('Get confirmed sponsor', async ({helper, privateKey}) => {263 itEth('Get confirmed sponsor', async ({helper, privateKey}) => {316 const alice = privateKey('//Alice');264 const alice = privateKey('//Alice');317265318 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);319 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);320 // const flipper = await deployFlipper(web3, owner);321 // const helpers = contractHelpers(web3, owner);322 const owner = await helper.eth.createAccountWithBalance(alice);266 const owner = await helper.eth.createAccountWithBalance(alice);323 const sponsor = await helper.eth.createAccountWithBalance(alice);267 const sponsor = await helper.eth.createAccountWithBalance(alice);324 const helpers = helper.ethNativeContract.contractHelpers(owner);268 const helpers = helper.ethNativeContract.contractHelpers(owner);325 const flipper = helper.ethNativeContract.contractHelpers(owner);269 const flipper = await helper.eth.deployFlipper(owner);326270327 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();271 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();328 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});272 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});336 itEth('Sponsor can be removed by the address that deployed the contract', async ({helper, privateKey}) => {280 itEth('Sponsor can be removed by the address that deployed the contract', async ({helper, privateKey}) => {337 const alice = privateKey('//Alice');281 const alice = privateKey('//Alice');338282339 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);340 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);341 // const flipper = await deployFlipper(web3, owner);342 // const helpers = contractHelpers(web3, owner);343 const owner = await helper.eth.createAccountWithBalance(alice);283 const owner = await helper.eth.createAccountWithBalance(alice);344 const sponsor = await helper.eth.createAccountWithBalance(alice);284 const sponsor = await helper.eth.createAccountWithBalance(alice);345 const helpers = helper.ethNativeContract.contractHelpers(owner);285 const helpers = helper.ethNativeContract.contractHelpers(owner);346 const flipper = helper.ethNativeContract.contractHelpers(owner);286 const flipper = await helper.eth.deployFlipper(owner);347287348 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;288 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;349 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();289 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();357 itEth('Remove sponsor event', async ({helper, privateKey}) => {297 itEth('Remove sponsor event', async ({helper, privateKey}) => {358 const alice = privateKey('//Alice');298 const alice = privateKey('//Alice');359299360 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);361 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);362 // const flipper = await deployFlipper(web3, owner);363 // const helpers = contractHelpers(web3, owner);364 const owner = await helper.eth.createAccountWithBalance(alice);300 const owner = await helper.eth.createAccountWithBalance(alice);365 const sponsor = await helper.eth.createAccountWithBalance(alice);301 const sponsor = await helper.eth.createAccountWithBalance(alice);366 const helpers = helper.ethNativeContract.contractHelpers(owner);302 const helpers = helper.ethNativeContract.contractHelpers(owner);367 const flipper = helper.ethNativeContract.contractHelpers(owner);303 const flipper = await helper.eth.deployFlipper(owner);368304369 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();305 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();370 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});306 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});393 itEth('Sponsor can not be removed by the address that did not deployed the contract', async ({helper, privateKey}) => {329 itEth('Sponsor can not be removed by the address that did not deployed the contract', async ({helper, privateKey}) => {394 const alice = privateKey('//Alice');330 const alice = privateKey('//Alice');395331396 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);397 // const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);398 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);399 // const flipper = await deployFlipper(web3, owner);400 // const helpers = contractHelpers(web3, owner);401 const owner = await helper.eth.createAccountWithBalance(alice);332 const owner = await helper.eth.createAccountWithBalance(alice);402 const notOwner = await helper.eth.createAccountWithBalance(alice);333 const notOwner = await helper.eth.createAccountWithBalance(alice);403 const sponsor = await helper.eth.createAccountWithBalance(alice);334 const sponsor = await helper.eth.createAccountWithBalance(alice);404 const helpers = helper.ethNativeContract.contractHelpers(owner);335 const helpers = helper.ethNativeContract.contractHelpers(owner);405 const flipper = helper.ethNativeContract.contractHelpers(owner);336 const flipper = await helper.eth.deployFlipper(owner);406337407 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;338 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;408 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();339 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();416 itEth('In generous mode, non-allowlisted user transaction will be sponsored', async ({helper, privateKey}) => {347 itEth('In generous mode, non-allowlisted user transaction will be sponsored', async ({helper, privateKey}) => {417 const alice = privateKey('//Alice');348 const alice = privateKey('//Alice');418349419 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);420 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);421 // const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);422 // const flipper = await deployFlipper(web3, owner);423 // const helpers = contractHelpers(web3, owner);424 const owner = await helper.eth.createAccountWithBalance(alice);350 const owner = await helper.eth.createAccountWithBalance(alice);425 const sponsor = await helper.eth.createAccountWithBalance(alice);351 const sponsor = await helper.eth.createAccountWithBalance(alice);426 const caller = await helper.eth.createAccountWithBalance(alice);352 const caller = await helper.eth.createAccountWithBalance(alice);427 const helpers = helper.ethNativeContract.contractHelpers(owner);353 const helpers = helper.ethNativeContract.contractHelpers(owner);428 const flipper = helper.ethNativeContract.contractHelpers(owner);354 const flipper = await helper.eth.deployFlipper(owner);429355430 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();356 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();431 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});357 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});449 itEth('In generous mode, non-allowlisted user transaction will be self sponsored', async ({helper, privateKey}) => {375 itEth('In generous mode, non-allowlisted user transaction will be self sponsored', async ({helper, privateKey}) => {450 const alice = privateKey('//Alice');376 const alice = privateKey('//Alice');451377452 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);453 // const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);454 // const flipper = await deployFlipper(web3, owner);455 // const helpers = contractHelpers(web3, owner);456 const owner = await helper.eth.createAccountWithBalance(alice);378 const owner = await helper.eth.createAccountWithBalance(alice);457 const caller = await helper.eth.createAccountWithBalance(alice);379 const caller = await helper.eth.createAccountWithBalance(alice);458 const helpers = helper.ethNativeContract.contractHelpers(owner);380 const helpers = helper.ethNativeContract.contractHelpers(owner);459 const flipper = helper.ethNativeContract.contractHelpers(owner);381 const flipper = await helper.eth.deployFlipper(owner);460382461 await helpers.methods.selfSponsoredEnable(flipper.options.address).send();383 await helpers.methods.selfSponsoredEnable(flipper.options.address).send();462384463 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: owner});385 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: owner});464 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});386 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});465387466 // await transferBalanceToEth(api, alice, flipper.options.address);467 await helper.eth.transferBalanceFromSubstrate(alice, flipper.options.address);388 await helper.eth.transferBalanceFromSubstrate(alice, flipper.options.address);468389469 const contractBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(flipper.options.address));390 const contractBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(flipper.options.address));482 itEth('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should decrease (allowlisted)', async ({helper, privateKey}) => {403 itEth('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should decrease (allowlisted)', async ({helper, privateKey}) => {483 const alice = privateKey('//Alice');404 const alice = privateKey('//Alice');484405485 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);486 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);487 // const caller = createEthAccount(web3);488 // const flipper = await deployFlipper(web3, owner);489 // const helpers = contractHelpers(web3, owner);490 const owner = await helper.eth.createAccountWithBalance(alice);406 const owner = await helper.eth.createAccountWithBalance(alice);491 const sponsor = await helper.eth.createAccountWithBalance(alice);407 const sponsor = await helper.eth.createAccountWithBalance(alice);492 const caller = await helper.eth.createAccountWithBalance(alice);408 const caller = await helper.eth.createAccount();493 const helpers = helper.ethNativeContract.contractHelpers(owner);409 const helpers = helper.ethNativeContract.contractHelpers(owner);494 const flipper = helper.ethNativeContract.contractHelpers(owner);410 const flipper = await helper.eth.deployFlipper(owner);495411496 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});412 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});497 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});413 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});516 itEth('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should not decrease (non-allowlisted)', async ({helper, privateKey}) => {432 itEth('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should not decrease (non-allowlisted)', async ({helper, privateKey}) => {517 const alice = privateKey('//Alice');433 const alice = privateKey('//Alice');518434519 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);520 // const caller = createEthAccount(web3);521 // const flipper = await deployFlipper(web3, owner);522 // const helpers = contractHelpers(web3, owner);523 const owner = await helper.eth.createAccountWithBalance(alice);435 const owner = await helper.eth.createAccountWithBalance(alice);524 const caller = await helper.eth.createAccountWithBalance(alice);436 const caller = await helper.eth.createAccount();525 const helpers = helper.ethNativeContract.contractHelpers(owner);437 const helpers = helper.ethNativeContract.contractHelpers(owner);526 const flipper = helper.ethNativeContract.contractHelpers(owner);438 const flipper = await helper.eth.deployFlipper(owner);527439528 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});440 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});529 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});441 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});530442531 // await transferBalanceToEth(api, alice, flipper.options.address);532 await helper.eth.transferBalanceFromSubstrate(alice, flipper.options.address);443 await helper.eth.transferBalanceFromSubstrate(alice, flipper.options.address);533444534 const originalFlipperBalance = await helper.balance.getEthereum(flipper.options.address); // await web3.eth.getBalance(flipper.options.address);445 const originalFlipperBalance = await helper.balance.getEthereum(flipper.options.address);535 expect(originalFlipperBalance).to.be.not.equal('0');446 expect(originalFlipperBalance).to.be.not.equal('0');536447537 await expect(flipper.methods.flip().send({from: caller})).to.be.rejectedWith(/InvalidTransaction::Payment/);448 await expect(flipper.methods.flip().send({from: caller})).to.be.rejectedWith(/InvalidTransaction::Payment/);538 expect(await flipper.methods.getValue().call()).to.be.false;449 expect(await flipper.methods.getValue().call()).to.be.false;539450540 // Balance should be taken from flipper instead of caller451 // Balance should be taken from flipper instead of caller541 // FIXME the comment is wrong! What check should be here?452 // FIXME the comment is wrong! What check should be here?542 const balanceAfter = await helper.balance.getEthereum(flipper.options.address); // await web3.eth.getBalance(flipper.options.address);453 const balanceAfter = await helper.balance.getEthereum(flipper.options.address);543 expect(balanceAfter).to.be.equals(originalFlipperBalance);454 expect(balanceAfter).to.be.equals(originalFlipperBalance);544 });455 });545456546 itEth('Sponsoring is set, an address that has UNQ can send a transaction and it works. User balance should not change', async ({helper, privateKey}) => {457 itEth('Sponsoring is set, an address that has UNQ can send a transaction and it works. User balance should not change', async ({helper, privateKey}) => {547 const alice = privateKey('//Alice');458 const alice = privateKey('//Alice');548459549 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);550 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);551 // const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);552 // const flipper = await deployFlipper(web3, owner);553 // const helpers = contractHelpers(web3, owner);554 const owner = await helper.eth.createAccountWithBalance(alice);460 const owner = await helper.eth.createAccountWithBalance(alice);555 const sponsor = await helper.eth.createAccountWithBalance(alice);461 const sponsor = await helper.eth.createAccountWithBalance(alice);556 const caller = await helper.eth.createAccountWithBalance(alice);462 const caller = await helper.eth.createAccountWithBalance(alice);557 const helpers = helper.ethNativeContract.contractHelpers(owner);463 const helpers = helper.ethNativeContract.contractHelpers(owner);558 const flipper = helper.ethNativeContract.contractHelpers(owner);464 const flipper = await helper.eth.deployFlipper(owner);559465560 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});466 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});561 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});467 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});581 itEth('Sponsoring is limited, with setContractRateLimit. The limitation is working if transactions are sent more often, the sender pays the commission.', async ({helper, privateKey}) => {487 itEth('Sponsoring is limited, with setContractRateLimit. The limitation is working if transactions are sent more often, the sender pays the commission.', async ({helper, privateKey}) => {582 const alice = privateKey('//Alice');488 const alice = privateKey('//Alice');583489584 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);585 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);586 // const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);587 // const flipper = await deployFlipper(web3, owner);588 // const helpers = contractHelpers(web3, owner);589 const owner = await helper.eth.createAccountWithBalance(alice);490 const owner = await helper.eth.createAccountWithBalance(alice);590 const sponsor = await helper.eth.createAccountWithBalance(alice);491 const sponsor = await helper.eth.createAccountWithBalance(alice);591 const caller = await helper.eth.createAccountWithBalance(alice);492 const caller = await helper.eth.createAccountWithBalance(alice);592 const helpers = helper.ethNativeContract.contractHelpers(owner);493 const helpers = helper.ethNativeContract.contractHelpers(owner);593 const flipper = helper.ethNativeContract.contractHelpers(owner);494 const flipper = await helper.eth.deployFlipper(owner);594 495 595 const originalCallerBalance = await helper.balance.getEthereum(caller); // await web3.eth.getBalance(caller);496 const originalCallerBalance = await helper.balance.getEthereum(caller);596 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});497 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});597 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});498 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});598499602 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();503 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();603 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});504 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});604505605 const originalFlipperBalance = await helper.balance.getEthereum(sponsor); // await web3.eth.getBalance(sponsor);506 const originalFlipperBalance = await helper.balance.getEthereum(sponsor);606 expect(originalFlipperBalance).to.be.not.equal('0');507 expect(originalFlipperBalance).to.be.not.equal('0');607508608 await flipper.methods.flip().send({from: caller});509 await flipper.methods.flip().send({from: caller});621 itEth('Default rate limit equals 7200', async ({helper, privateKey}) => {522 itEth('Default rate limit equals 7200', async ({helper, privateKey}) => {622 const alice = privateKey('//Alice');523 const alice = privateKey('//Alice');623524624 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);625 // const flipper = await deployFlipper(web3, owner);626 // const helpers = contractHelpers(web3, owner);627 const owner = await helper.eth.createAccountWithBalance(alice);525 const owner = await helper.eth.createAccountWithBalance(alice);628 const helpers = helper.ethNativeContract.contractHelpers(owner);526 const helpers = helper.ethNativeContract.contractHelpers(owner);629 const flipper = helper.ethNativeContract.contractHelpers(owner);527 const flipper = await helper.eth.deployFlipper(owner);630528631 expect(await helpers.methods.sponsoringRateLimit(flipper.options.address).call()).to.be.equals('7200');529 expect(await helpers.methods.sponsoringRateLimit(flipper.options.address).call()).to.be.equals('7200');632 });530 });696 itEth('Default fee limit', async ({helper, privateKey}) => {594 itEth('Default fee limit', async ({helper, privateKey}) => {697 const alice = privateKey('//Alice');595 const alice = privateKey('//Alice');698596699 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);700 // const flipper = await deployFlipper(web3, owner);701 // const helpers = contractHelpers(web3, owner);702 const owner = await helper.eth.createAccountWithBalance(alice);597 const owner = await helper.eth.createAccountWithBalance(alice);703 const helpers = helper.ethNativeContract.contractHelpers(owner);598 const helpers = helper.ethNativeContract.contractHelpers(owner);704 const flipper = helper.ethNativeContract.contractHelpers(owner);599 const flipper = await helper.eth.deployFlipper(owner);705600706 expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equals('115792089237316195423570985008687907853269984665640564039457584007913129639935');601 expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equals('115792089237316195423570985008687907853269984665640564039457584007913129639935');707 });602 });708603709 itEth('Set fee limit', async ({helper, privateKey}) => {604 itEth('Set fee limit', async ({helper, privateKey}) => {710 const alice = privateKey('//Alice');605 const alice = privateKey('//Alice');711606712 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);713 // const flipper = await deployFlipper(web3, owner);714 // const helpers = contractHelpers(web3, owner);715 const owner = await helper.eth.createAccountWithBalance(alice);607 const owner = await helper.eth.createAccountWithBalance(alice);716 const helpers = helper.ethNativeContract.contractHelpers(owner);608 const helpers = helper.ethNativeContract.contractHelpers(owner);717 const flipper = helper.ethNativeContract.contractHelpers(owner);609 const flipper = await helper.eth.deployFlipper(owner);718610719 await helpers.methods.setSponsoringFeeLimit(flipper.options.address, 100).send();611 await helpers.methods.setSponsoringFeeLimit(flipper.options.address, 100).send();720 expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equals('100');612 expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equals('100');723 itEth('Negative test - set fee limit by non-owner', async ({helper, privateKey}) => {615 itEth('Negative test - set fee limit by non-owner', async ({helper, privateKey}) => {724 const alice = privateKey('//Alice');616 const alice = privateKey('//Alice');725617726 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);727 // const stranger = await createEthAccountWithBalance(api, web3, privateKeyWrapper);728 // const flipper = await deployFlipper(web3, owner);729 // const helpers = contractHelpers(web3, owner);730 const owner = await helper.eth.createAccountWithBalance(alice);618 const owner = await helper.eth.createAccountWithBalance(alice);731 const stranger = await helper.eth.createAccountWithBalance(alice);619 const stranger = await helper.eth.createAccountWithBalance(alice);732 const helpers = helper.ethNativeContract.contractHelpers(owner);620 const helpers = helper.ethNativeContract.contractHelpers(owner);733 const flipper = helper.ethNativeContract.contractHelpers(owner);621 const flipper = await helper.eth.deployFlipper(owner);734622735 await expect(helpers.methods.setSponsoringFeeLimit(flipper.options.address, 100).send({from: stranger})).to.be.rejected;623 await expect(helpers.methods.setSponsoringFeeLimit(flipper.options.address, 100).send({from: stranger})).to.be.rejected;736 });624 });737625738 itEth('Negative test - check that eth transactions exceeding fee limit are not executed', async ({helper, privateKey}) => {626 itEth('Negative test - check that eth transactions exceeding fee limit are not executed', async ({helper, privateKey}) => {739 const alice = privateKey('//Alice');627 const alice = privateKey('//Alice');740628741 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);742 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);743 // const user = await createEthAccountWithBalance(api, web3, privateKeyWrapper);744 // const helpers = contractHelpers(web3, owner);745 const owner = await helper.eth.createAccountWithBalance(alice);629 const owner = await helper.eth.createAccountWithBalance(alice);746 const sponsor = await helper.eth.createAccountWithBalance(alice);630 const sponsor = await helper.eth.createAccountWithBalance(alice);747 const user = await helper.eth.createAccountWithBalance(alice);631 const user = await helper.eth.createAccountWithBalance(alice);759643760 await helpers.methods.setSponsoringFeeLimit(testContract.options.address, 2_000_000n * gasPrice).send();644 await helpers.methods.setSponsoringFeeLimit(testContract.options.address, 2_000_000n * gasPrice).send();761645762 const originalUserBalance = await helper.balance.getEthereum(user); // await web3.eth.getBalance(user);646 const originalUserBalance = await helper.balance.getEthereum(user);763 await testContract.methods.test(100).send({from: user, gas: 2_000_000});647 await testContract.methods.test(100).send({from: user, gas: 2_000_000});764 expect(await helper.balance.getEthereum(user)).to.be.equal(originalUserBalance);648 expect(await helper.balance.getEthereum(user)).to.be.equal(originalUserBalance);765649770 itEth('Negative test - check that evm.call transactions exceeding fee limit are not executed', async ({helper, privateKey}) => {654 itEth('Negative test - check that evm.call transactions exceeding fee limit are not executed', async ({helper, privateKey}) => {771 const alice = privateKey('//Alice');655 const alice = privateKey('//Alice');772656773 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);774 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);775 // const helpers = contractHelpers(web3, owner);776 const owner = await helper.eth.createAccountWithBalance(alice);657 const owner = await helper.eth.createAccountWithBalance(alice);777 const sponsor = await helper.eth.createAccountWithBalance(alice);658 const sponsor = await helper.eth.createAccountWithBalance(alice);778 const helpers = helper.ethNativeContract.contractHelpers(owner);659 const helpers = helper.ethNativeContract.contractHelpers(owner);789670790 await helpers.methods.setSponsoringFeeLimit(testContract.options.address, 2_000_000n * gasPrice).send();671 await helpers.methods.setSponsoringFeeLimit(testContract.options.address, 2_000_000n * gasPrice).send();791672792 const originalAliceBalance = await helper.balance.getSubstrate(alice.address); // (await api.query.system.account(alice.address)).data.free.toBigInt();673 const originalAliceBalance = await helper.balance.getSubstrate(alice.address);793674794 // await submitTransactionAsync(675 // await submitTransactionAsync(795 // alice,676 // alice,808 await helper.eth.sendEVM(689 await helper.eth.sendEVM(809 alice,690 alice,810 testContract.options.address,691 testContract.options.address,811 testContract.methods.test().encodeABI(),692 testContract.methods.test(100).encodeABI(),812 '100',693 '0',813 );694 );814 // expect((await api.query.system.account(alice.address)).data.free.toBigInt()).to.be.equal(originalAliceBalance);695 // expect((await api.query.system.account(alice.address)).data.free.toBigInt()).to.be.equal(originalAliceBalance);815 expect(await helper.balance.getSubstrate(alice.address)).to.be.equal(originalAliceBalance);696 expect(await helper.balance.getSubstrate(alice.address)).to.be.equal(originalAliceBalance);832 alice,713 alice,833 testContract.options.address,714 testContract.options.address,834 testContract.methods.test().encodeABI(),715 testContract.methods.test().encodeABI(),835 '100',716 '0',836 );717 );837 // expect((await api.query.system.account(alice.address)).data.free.toBigInt()).to.not.be.equal(originalAliceBalance);718 // expect((await api.query.system.account(alice.address)).data.free.toBigInt()).to.not.be.equal(originalAliceBalance);838 expect(await helper.balance.getSubstrate(alice.address)).to.not.be.equal(originalAliceBalance);719 expect(await helper.balance.getSubstrate(alice.address)).to.not.be.equal(originalAliceBalance);