difftreelog
fix draft fix of contractSponsoring
in: master
1 file changed
tests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import * as solc from 'solc';17import * as solc from 'solc';18import {expect} from 'chai';19import {expectSubstrateEventsAtBlock} from '../util/helpers';18import {expectSubstrateEventsAtBlock} from '../util/helpers';20import Web3 from 'web3';19import Web3 from 'web3';212022import {21import {23 contractHelpers,24 createEthAccountWithBalance,25 transferBalanceToEth,26 deployFlipper,27 itWeb3,28 SponsoringMode,22 SponsoringMode,29 createEthAccount,30 ethBalanceViaSub,31 normalizeEvents,23 normalizeEvents,32 CompiledContract,24 CompiledContract,33 GAS_ARGS,25 GAS_ARGS,34 subToEth,26 contractHelpers,27 createEthAccountWithBalance,35} from './util/helpers';28} from './util/helpers';36import {submitTransactionAsync} from '../substrate/substrate-api';29import {itEth, expect} from '../eth/util/playgrounds';37303138describe('Sponsoring EVM contracts', () => {32describe.only('Sponsoring EVM contracts', () => {39 itWeb3('Self sponsored can be set by the address that deployed the contract', async ({api, web3, privateKeyWrapper}) => {33 itEth('Self sponsored can be set by the address that deployed the contract', async ({helper, privateKey}) => {40 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);34 const alice = privateKey('//Alice');3536 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);41 const flipper = await deployFlipper(web3, owner);37 // const flipper = await deployFlipper(web3, owner);42 const helpers = contractHelpers(web3, owner);38 // const helpers = contractHelpers(web3, owner);39 const owner = await helper.eth.createAccountWithBalance(alice);40 const flipper = await helper.eth.deployFlipper(owner);41 const helpers = helper.ethNativeContract.contractHelpers(owner);4243 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;43 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;44 await expect(helpers.methods.selfSponsoredEnable(flipper.options.address).send()).to.be.not.rejected;44 await expect(helpers.methods.selfSponsoredEnable(flipper.options.address).send()).to.be.not.rejected;45 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;45 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;46 });46 });474748 itWeb3('Set self sponsored events', async ({api, web3, privateKeyWrapper}) => {48 itEth('Set self sponsored events', async ({helper, privateKey}) => {49 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);49 const alice = privateKey('//Alice');5051 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);50 const flipper = await deployFlipper(web3, owner);52 // const flipper = await deployFlipper(web3, owner);51 const helpers = contractHelpers(web3, owner);53 // const helpers = contractHelpers(web3, owner);54 const owner = await helper.eth.createAccountWithBalance(alice);55 const flipper = await helper.eth.deployFlipper(owner);56 const helpers = helper.ethNativeContract.contractHelpers(owner);52 57 53 const result = await helpers.methods.selfSponsoredEnable(flipper.options.address).send();58 const result = await helpers.methods.selfSponsoredEnable(flipper.options.address).send();54 // console.log(result);55 const ethEvents = normalizeEvents(result.events);59 const ethEvents = normalizeEvents(result.events);56 expect(ethEvents).to.be.deep.equal([60 expect(ethEvents).to.be.deep.equal([57 {61 {72 },76 },73 ]);77 ]);747879 // TODO use helper.getApi() from the sceduler PR75 await expectSubstrateEventsAtBlock(80 await expectSubstrateEventsAtBlock(76 api, 81 helper.api!,77 result.blockNumber,82 result.blockNumber,78 'evmContractHelpers',83 'evmContractHelpers',79 ['ContractSponsorSet','ContractSponsorshipConfirmed'],84 ['ContractSponsorSet','ContractSponsorshipConfirmed'],80 );85 );81 });86 });828783 itWeb3('Self sponsored can not be set by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => {88 itEth('Self sponsored can not be set by the address that did not deployed the contract', async ({helper, privateKey}) => {84 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);89 const alice = privateKey('//Alice');9091 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);85 const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);92 // const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);86 const flipper = await deployFlipper(web3, owner);93 // const helpers = contractHelpers(web3, owner);94 // const flipper = await deployFlipper(web3, owner);87 const helpers = contractHelpers(web3, owner);95 const owner = await helper.eth.createAccountWithBalance(alice);96 const notOwner = await helper.eth.createAccountWithBalance(alice);97 const helpers = helper.ethNativeContract.contractHelpers(owner);98 const flipper = helper.ethNativeContract.contractHelpers(owner);9988 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;100 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;89 await expect(helpers.methods.selfSponsoredEnable(flipper.options.address).call({from: notOwner})).to.be.rejectedWith('NoPermission');101 await expect(helpers.methods.selfSponsoredEnable(flipper.options.address).call({from: notOwner})).to.be.rejectedWith('NoPermission');90 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;102 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;91 });103 });9210493 itWeb3('Sponsoring can be set by the address that has deployed the contract', async ({api, web3, privateKeyWrapper}) => {105 itEth.only('Sponsoring can be set by the address that has deployed the contract', async ({helper, privateKey}) => {94 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);106 const alice = privateKey('//Alice');107108 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);95 const flipper = await deployFlipper(web3, owner);109 // const flipper = await deployFlipper(web3, owner);96 const helpers = contractHelpers(web3, owner);110 // const helpers = contractHelpers(web3, owner);111 const owner = await helper.eth.createAccountWithBalance(alice);112 const helpers = helper.ethNativeContract.contractHelpers(owner);113 const flipper = await helper.eth.deployFlipper(owner);11497 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;115 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;98 await expect(helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner})).to.be.not.rejected;116 await expect(helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner})).to.be.not.rejected;99 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;117 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;100 });118 });101119102 itWeb3('Sponsoring cannot be set by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => {120 itEth('Sponsoring cannot be set by the address that did not deployed the contract', async ({helper, privateKey}) => {103 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);121 const alice = privateKey('//Alice');122123 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);104 const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);124 // const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);105 const flipper = await deployFlipper(web3, owner);125 // const flipper = await deployFlipper(web3, owner);106 const helpers = contractHelpers(web3, owner);126 // const helpers = contractHelpers(web3, owner);127 const owner = await helper.eth.createAccountWithBalance(alice);128 const notOwner = await helper.eth.createAccountWithBalance(alice);129 const helpers = helper.ethNativeContract.contractHelpers(owner);130 const flipper = helper.ethNativeContract.contractHelpers(owner);131107 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;132 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;108 await expect(helpers.methods.setSponsoringMode(notOwner, SponsoringMode.Allowlisted).call({from: notOwner})).to.be.rejectedWith('NoPermission');133 await expect(helpers.methods.setSponsoringMode(notOwner, SponsoringMode.Allowlisted).call({from: notOwner})).to.be.rejectedWith('NoPermission');109 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;134 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;110 });135 });111 136 112 itWeb3('Sponsor can be set by the address that deployed the contract', async ({api, web3, privateKeyWrapper}) => {137 itEth('Sponsor can be set by the address that deployed the contract', async ({helper, privateKey}) => {113 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);138 const alice = privateKey('//Alice');139140 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);114 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);141 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);115 const flipper = await deployFlipper(web3, owner);142 // const flipper = await deployFlipper(web3, owner);116 const helpers = contractHelpers(web3, owner);143 // const helpers = contractHelpers(web3, owner);144 const owner = await helper.eth.createAccountWithBalance(alice);145 const sponsor = await helper.eth.createAccountWithBalance(alice);146 const helpers = helper.ethNativeContract.contractHelpers(owner);147 const flipper = helper.ethNativeContract.contractHelpers(owner);148117 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false;149 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false;118 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;150 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;119 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.true;151 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.true;120 });152 });121 153 122 itWeb3('Set sponsor event', async ({api, web3, privateKeyWrapper}) => {154 itEth('Set sponsor event', async ({helper, privateKey}) => {123 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);155 const alice = privateKey('//Alice');156157 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);124 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);158 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);125 const flipper = await deployFlipper(web3, owner);159 // const flipper = await deployFlipper(web3, owner);126 const helpers = contractHelpers(web3, owner);160 // const helpers = contractHelpers(web3, owner);161 const owner = await helper.eth.createAccountWithBalance(alice);162 const sponsor = await helper.eth.createAccountWithBalance(alice);163 const helpers = helper.ethNativeContract.contractHelpers(owner);164 const flipper = helper.ethNativeContract.contractHelpers(owner);127 165 128 const result = await helpers.methods.setSponsor(flipper.options.address, sponsor).send();166 const result = await helpers.methods.setSponsor(flipper.options.address, sponsor).send();129 const events = normalizeEvents(result.events);167 const events = normalizeEvents(result.events);138 },176 },139 ]);177 ]);140178179 // TODO use helper.getApi() from the sceduler PR141 await expectSubstrateEventsAtBlock(180 await expectSubstrateEventsAtBlock(142 api, 181 helper.api!, 143 result.blockNumber,182 result.blockNumber,144 'evmContractHelpers',183 'evmContractHelpers',145 ['ContractSponsorSet'],184 ['ContractSponsorSet'],146 );185 );147 });186 });148 187 149 itWeb3('Sponsor can not be set by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => {188 itEth('Sponsor can not be set by the address that did not deployed the contract', async ({helper, privateKey}) => {150 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);189 const alice = privateKey('//Alice');190191 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);151 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);192 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);152 const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);193 // const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);153 const flipper = await deployFlipper(web3, owner);194 // const flipper = await deployFlipper(web3, owner);154 const helpers = contractHelpers(web3, owner);195 // const helpers = contractHelpers(web3, owner);196 const owner = await helper.eth.createAccountWithBalance(alice);197 const sponsor = await helper.eth.createAccountWithBalance(alice);198 const notOwner = await helper.eth.createAccountWithBalance(alice);199 const helpers = helper.ethNativeContract.contractHelpers(owner);200 const flipper = helper.ethNativeContract.contractHelpers(owner);201155 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false;202 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false;156 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).call({from: notOwner})).to.be.rejectedWith('NoPermission');203 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).call({from: notOwner})).to.be.rejectedWith('NoPermission');157 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false;204 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false;158 });205 });159206160 itWeb3('Sponsorship can be confirmed by the address that pending as sponsor', async ({api, web3, privateKeyWrapper}) => {207 itEth('Sponsorship can be confirmed by the address that pending as sponsor', async ({helper, privateKey}) => {161 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);208 const alice = privateKey('//Alice');209210 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);162 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);211 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);163 const flipper = await deployFlipper(web3, owner);212 // const flipper = await deployFlipper(web3, owner);164 const helpers = contractHelpers(web3, owner);213 // const helpers = contractHelpers(web3, owner);214 const owner = await helper.eth.createAccountWithBalance(alice);215 const sponsor = await helper.eth.createAccountWithBalance(alice);216 const helpers = helper.ethNativeContract.contractHelpers(owner);217 const flipper = helper.ethNativeContract.contractHelpers(owner);218165 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;219 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;166 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;220 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;167 await expect(helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor})).to.be.not.rejected;221 await expect(helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor})).to.be.not.rejected;168 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;222 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;169 });223 });170224171 itWeb3('Confirm sponsorship event', async ({api, web3, privateKeyWrapper}) => {225 itEth('Confirm sponsorship event', async ({helper, privateKey}) => {172 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);226 const alice = privateKey('//Alice');227228 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);173 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);229 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);174 const flipper = await deployFlipper(web3, owner);230 // const flipper = await deployFlipper(web3, owner);175 const helpers = contractHelpers(web3, owner);231 // const helpers = contractHelpers(web3, owner);232 const owner = await helper.eth.createAccountWithBalance(alice);233 const sponsor = await helper.eth.createAccountWithBalance(alice);234 const helpers = helper.ethNativeContract.contractHelpers(owner);235 const flipper = helper.ethNativeContract.contractHelpers(owner);236176 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;237 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;177 const result = await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});238 const result = await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});187 },248 },188 ]);249 ]);189250251 // TODO use helper.getApi() from the sceduler PR190 await expectSubstrateEventsAtBlock(252 await expectSubstrateEventsAtBlock(191 api, 253 helper.api!, 192 result.blockNumber,254 result.blockNumber,193 'evmContractHelpers',255 'evmContractHelpers',194 ['ContractSponsorshipConfirmed'],256 ['ContractSponsorshipConfirmed'],195 );257 );196 });258 });197259198 itWeb3('Sponsorship can not be confirmed by the address that not pending as sponsor', async ({api, web3, privateKeyWrapper}) => {260 itEth('Sponsorship can not be confirmed by the address that not pending as sponsor', async ({helper, privateKey}) => {199 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);261 const alice = privateKey('//Alice');262263 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);200 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);264 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);201 const notSponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);265 // const notSponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);202 const flipper = await deployFlipper(web3, owner);266 // const flipper = await deployFlipper(web3, owner);203 const helpers = contractHelpers(web3, owner);267 // const helpers = contractHelpers(web3, owner);268 const owner = await helper.eth.createAccountWithBalance(alice);269 const sponsor = await helper.eth.createAccountWithBalance(alice);270 const notSponsor = await helper.eth.createAccountWithBalance(alice);271 const helpers = helper.ethNativeContract.contractHelpers(owner);272 const flipper = helper.ethNativeContract.contractHelpers(owner);273204 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;274 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;205 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;275 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;206 await expect(helpers.methods.confirmSponsorship(flipper.options.address).call({from: notSponsor})).to.be.rejectedWith('NoPermission');276 await expect(helpers.methods.confirmSponsorship(flipper.options.address).call({from: notSponsor})).to.be.rejectedWith('NoPermission');207 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;277 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;208 });278 });209279210 itWeb3('Sponsorship can not be confirmed by the address that not set as sponsor', async ({api, web3, privateKeyWrapper}) => {280 itEth('Sponsorship can not be confirmed by the address that not set as sponsor', async ({helper, privateKey}) => {211 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);281 const alice = privateKey('//Alice');282283 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);212 const notSponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);284 // const notSponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);213 const flipper = await deployFlipper(web3, owner);285 // const flipper = await deployFlipper(web3, owner);214 const helpers = contractHelpers(web3, owner);286 // const helpers = contractHelpers(web3, owner);287 const owner = await helper.eth.createAccountWithBalance(alice);288 const notSponsor = await helper.eth.createAccountWithBalance(alice);289 const helpers = helper.ethNativeContract.contractHelpers(owner);290 const flipper = helper.ethNativeContract.contractHelpers(owner);291215 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;292 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;216 await expect(helpers.methods.confirmSponsorship(flipper.options.address).call({from: notSponsor})).to.be.rejectedWith('NoPendingSponsor');293 await expect(helpers.methods.confirmSponsorship(flipper.options.address).call({from: notSponsor})).to.be.rejectedWith('NoPendingSponsor');217 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;294 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;218 });295 });219296220 itWeb3('Get self sponsored sponsor', async ({api, web3, privateKeyWrapper}) => {297 itEth('Get self sponsored sponsor', async ({helper, privateKey}) => {221 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);298 const alice = privateKey('//Alice');299300 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);222 const flipper = await deployFlipper(web3, owner);301 // const flipper = await deployFlipper(web3, owner);223 const helpers = contractHelpers(web3, owner);302 // const helpers = contractHelpers(web3, owner);303 const owner = await helper.eth.createAccountWithBalance(alice);304 const flipper = helper.ethNativeContract.contractHelpers(owner);305 const helpers = helper.ethNativeContract.contractHelpers(owner);306224 await helpers.methods.selfSponsoredEnable(flipper.options.address).send();307 await helpers.methods.selfSponsoredEnable(flipper.options.address).send();225 308 229 expect(result[1]).to.be.eq('0');312 expect(result[1]).to.be.eq('0');230 });313 });231314232 itWeb3('Get confirmed sponsor', async ({api, web3, privateKeyWrapper}) => {315 itEth('Get confirmed sponsor', async ({helper, privateKey}) => {233 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);316 const alice = privateKey('//Alice');317318 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);234 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);319 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);235 const flipper = await deployFlipper(web3, owner);320 // const flipper = await deployFlipper(web3, owner);236 const helpers = contractHelpers(web3, owner);321 // const helpers = contractHelpers(web3, owner);322 const owner = await helper.eth.createAccountWithBalance(alice);323 const sponsor = await helper.eth.createAccountWithBalance(alice);324 const helpers = helper.ethNativeContract.contractHelpers(owner);325 const flipper = helper.ethNativeContract.contractHelpers(owner);326237 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();327 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();238 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});328 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});243 expect(result[1]).to.be.eq('0');333 expect(result[1]).to.be.eq('0');244 });334 });245335246 itWeb3('Sponsor can be removed by the address that deployed the contract', async ({api, web3, privateKeyWrapper}) => {336 itEth('Sponsor can be removed by the address that deployed the contract', async ({helper, privateKey}) => {247 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);337 const alice = privateKey('//Alice');248 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);249 const flipper = await deployFlipper(web3, owner);250 const helpers = contractHelpers(web3, owner);251338339 // 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);344 const sponsor = await helper.eth.createAccountWithBalance(alice);345 const helpers = helper.ethNativeContract.contractHelpers(owner);346 const flipper = helper.ethNativeContract.contractHelpers(owner);347252 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;348 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;253 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();349 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();254 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});350 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});258 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;354 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;259 });355 });260356261 itWeb3('Remove sponsor event', async ({api, web3, privateKeyWrapper}) => {357 itEth('Remove sponsor event', async ({helper, privateKey}) => {262 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);358 const alice = privateKey('//Alice');263 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);264 const flipper = await deployFlipper(web3, owner);265 const helpers = contractHelpers(web3, owner);266359360 // 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);365 const sponsor = await helper.eth.createAccountWithBalance(alice);366 const helpers = helper.ethNativeContract.contractHelpers(owner);367 const flipper = helper.ethNativeContract.contractHelpers(owner);368267 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();369 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();268 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});370 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});269 371 279 },381 },280 ]);382 ]);281383384 // TODO use helper.getApi() from the sceduler PR282 await expectSubstrateEventsAtBlock(385 await expectSubstrateEventsAtBlock(283 api, 386 helper.api!, 284 result.blockNumber,387 result.blockNumber,285 'evmContractHelpers',388 'evmContractHelpers',286 ['ContractSponsorRemoved'],389 ['ContractSponsorRemoved'],287 );390 );288 });391 });289392290 itWeb3('Sponsor can not be removed by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => {393 itEth('Sponsor can not be removed by the address that did not deployed the contract', async ({helper, privateKey}) => {291 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);394 const alice = privateKey('//Alice');292 const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);293 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);294 const flipper = await deployFlipper(web3, owner);295 const helpers = contractHelpers(web3, owner);296395396 // 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);402 const notOwner = await helper.eth.createAccountWithBalance(alice);403 const sponsor = await helper.eth.createAccountWithBalance(alice);404 const helpers = helper.ethNativeContract.contractHelpers(owner);405 const flipper = helper.ethNativeContract.contractHelpers(owner);406297 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;407 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;298 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();408 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();299 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});409 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});303 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;413 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;304 });414 });305415306 itWeb3('In generous mode, non-allowlisted user transaction will be sponsored', async ({api, web3, privateKeyWrapper}) => {416 itEth('In generous mode, non-allowlisted user transaction will be sponsored', async ({helper, privateKey}) => {307 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);417 const alice = privateKey('//Alice');308 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);309 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);310418311 const flipper = await deployFlipper(web3, owner);419 // 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);425 const sponsor = await helper.eth.createAccountWithBalance(alice);426 const caller = await helper.eth.createAccountWithBalance(alice);427 const helpers = helper.ethNativeContract.contractHelpers(owner);428 const flipper = helper.ethNativeContract.contractHelpers(owner);312429313 const helpers = contractHelpers(web3, owner);314315 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();430 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();316 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});431 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});317432318 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: owner});433 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: owner});319 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});434 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});320435321 const sponsorBalanceBefore = await ethBalanceViaSub(api, sponsor);436 const sponsorBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));322 const callerBalanceBefore = await ethBalanceViaSub(api, caller);437 const callerBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));323438324 await flipper.methods.flip().send({from: caller});439 await flipper.methods.flip().send({from: caller});325 expect(await flipper.methods.getValue().call()).to.be.true;440 expect(await flipper.methods.getValue().call()).to.be.true;326441327 // Balance should be taken from sponsor instead of caller442 // Balance should be taken from sponsor instead of caller328 const sponsorBalanceAfter = await ethBalanceViaSub(api, sponsor);443 const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));329 const callerBalanceAfter = await ethBalanceViaSub(api, caller);444 const callerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));330 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;445 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;331 expect(callerBalanceAfter).to.be.eq(callerBalanceBefore);446 expect(callerBalanceAfter).to.be.eq(callerBalanceBefore);332 });447 });333448334 itWeb3('In generous mode, non-allowlisted user transaction will be self sponsored', async ({api, web3, privateKeyWrapper}) => {449 itEth('In generous mode, non-allowlisted user transaction will be self sponsored', async ({helper, privateKey}) => {335 const alice = privateKeyWrapper('//Alice');450 const alice = privateKey('//Alice');336451337 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);452 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);338 const caller = 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);457 const caller = await helper.eth.createAccountWithBalance(alice);458 const helpers = helper.ethNativeContract.contractHelpers(owner);459 const flipper = helper.ethNativeContract.contractHelpers(owner);339460340 const flipper = await deployFlipper(web3, owner);341342 const helpers = contractHelpers(web3, owner);343344 await helpers.methods.selfSponsoredEnable(flipper.options.address).send();461 await helpers.methods.selfSponsoredEnable(flipper.options.address).send();345462346 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: owner});463 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: owner});347 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});464 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});348465349 await transferBalanceToEth(api, alice, flipper.options.address);466 // await transferBalanceToEth(api, alice, flipper.options.address);467 await helper.eth.transferBalanceFromSubstrate(alice, flipper.options.address);350468351 const contractBalanceBefore = await ethBalanceViaSub(api, flipper.options.address);469 const contractBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(flipper.options.address));352 const callerBalanceBefore = await ethBalanceViaSub(api, caller);470 const callerBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));353471354 await flipper.methods.flip().send({from: caller});472 await flipper.methods.flip().send({from: caller});355 expect(await flipper.methods.getValue().call()).to.be.true;473 expect(await flipper.methods.getValue().call()).to.be.true;356474357 // Balance should be taken from sponsor instead of caller475 // Balance should be taken from sponsor instead of caller358 const contractBalanceAfter = await ethBalanceViaSub(api, flipper.options.address);476 const contractBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(flipper.options.address));359 const callerBalanceAfter = await ethBalanceViaSub(api, caller);477 const callerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));360 expect(contractBalanceAfter < contractBalanceBefore).to.be.true;478 expect(contractBalanceAfter < contractBalanceBefore).to.be.true;361 expect(callerBalanceAfter).to.be.eq(callerBalanceBefore);479 expect(callerBalanceAfter).to.be.eq(callerBalanceBefore);362 });480 });363481364 itWeb3('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should decrease (allowlisted)', async ({api, web3, privateKeyWrapper}) => {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}) => {365 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);483 const alice = privateKey('//Alice');366 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);367 const caller = createEthAccount(web3);368484369 const flipper = await deployFlipper(web3, owner);485 // 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);491 const sponsor = await helper.eth.createAccountWithBalance(alice);492 const caller = await helper.eth.createAccountWithBalance(alice);493 const helpers = helper.ethNativeContract.contractHelpers(owner);494 const flipper = helper.ethNativeContract.contractHelpers(owner);370495371 const helpers = contractHelpers(web3, owner);372 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});496 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});373 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});497 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});374498378 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();502 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();379 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});503 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});380504381 const sponsorBalanceBefore = await ethBalanceViaSub(api, sponsor);505 const sponsorBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));382 expect(sponsorBalanceBefore).to.be.not.equal('0');506 expect(sponsorBalanceBefore).to.be.not.equal('0');383507384 await flipper.methods.flip().send({from: caller});508 await flipper.methods.flip().send({from: caller});385 expect(await flipper.methods.getValue().call()).to.be.true;509 expect(await flipper.methods.getValue().call()).to.be.true;386510387 // Balance should be taken from flipper instead of caller511 // Balance should be taken from flipper instead of caller388 const sponsorBalanceAfter = await ethBalanceViaSub(api, sponsor);512 const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));389 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;513 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;390 });514 });391515392 itWeb3('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should not decrease (non-allowlisted)', async ({api, web3, privateKeyWrapper}) => {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}) => {393 const alice = privateKeyWrapper('//Alice');517 const alice = privateKey('//Alice');394518395 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);519 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);396 const caller = createEthAccount(web3);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);524 const caller = await helper.eth.createAccountWithBalance(alice);525 const helpers = helper.ethNativeContract.contractHelpers(owner);526 const flipper = helper.ethNativeContract.contractHelpers(owner);397527398 const flipper = await deployFlipper(web3, owner);399400 const helpers = contractHelpers(web3, owner);401402 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});528 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});403 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});529 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});404530405 await transferBalanceToEth(api, alice, flipper.options.address);531 // await transferBalanceToEth(api, alice, flipper.options.address);532 await helper.eth.transferBalanceFromSubstrate(alice, flipper.options.address);406533407 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);534 const originalFlipperBalance = await helper.balance.getEthereum(flipper.options.address); // await web3.eth.getBalance(flipper.options.address);408 expect(originalFlipperBalance).to.be.not.equal('0');535 expect(originalFlipperBalance).to.be.not.equal('0');409536410 await expect(flipper.methods.flip().send({from: caller})).to.be.rejectedWith(/InvalidTransaction::Payment/);537 await expect(flipper.methods.flip().send({from: caller})).to.be.rejectedWith(/InvalidTransaction::Payment/);411 expect(await flipper.methods.getValue().call()).to.be.false;538 expect(await flipper.methods.getValue().call()).to.be.false;412539413 // Balance should be taken from flipper instead of caller540 // Balance should be taken from flipper instead of caller414 const balanceAfter = await web3.eth.getBalance(flipper.options.address);541 // 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);415 expect(+balanceAfter).to.be.equals(+originalFlipperBalance);543 expect(balanceAfter).to.be.equals(originalFlipperBalance);416 });544 });417545418 itWeb3('Sponsoring is set, an address that has UNQ can send a transaction and it works. User balance should not change', async ({api, web3, privateKeyWrapper}) => {546 itEth('Sponsoring is set, an address that has UNQ can send a transaction and it works. User balance should not change', async ({helper, privateKey}) => {419 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);547 const alice = privateKey('//Alice');420 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);421 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);422548423 const flipper = await deployFlipper(web3, owner);549 // 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);555 const sponsor = await helper.eth.createAccountWithBalance(alice);556 const caller = await helper.eth.createAccountWithBalance(alice);557 const helpers = helper.ethNativeContract.contractHelpers(owner);558 const flipper = helper.ethNativeContract.contractHelpers(owner);424559425 const helpers = contractHelpers(web3, owner);426 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});560 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});427 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});561 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});428562432 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();566 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();433 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});567 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});434568435 const sponsorBalanceBefore = await ethBalanceViaSub(api, sponsor);569 const sponsorBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));436 const callerBalanceBefore = await ethBalanceViaSub(api, caller);570 const callerBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));437571438 await flipper.methods.flip().send({from: caller});572 await flipper.methods.flip().send({from: caller});439 expect(await flipper.methods.getValue().call()).to.be.true;573 expect(await flipper.methods.getValue().call()).to.be.true;440574441 const sponsorBalanceAfter = await ethBalanceViaSub(api, sponsor);575 const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));442 const callerBalanceAfter = await ethBalanceViaSub(api, caller);576 const callerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));443 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;577 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;444 expect(callerBalanceAfter).to.be.equals(callerBalanceBefore);578 expect(callerBalanceAfter).to.be.equals(callerBalanceBefore);445 });579 });446580447 itWeb3('Sponsoring is limited, with setContractRateLimit. The limitation is working if transactions are sent more often, the sender pays the commission.', async ({api, web3, privateKeyWrapper}) => {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}) => {448 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);582 const alice = privateKey('//Alice');449 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);450 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);451 const originalCallerBalance = await web3.eth.getBalance(caller);452583453 const flipper = await deployFlipper(web3, owner);584 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);454585 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);586 // const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);587 // const flipper = await deployFlipper(web3, owner);455 const helpers = contractHelpers(web3, owner);588 // const helpers = contractHelpers(web3, owner);589 const owner = await helper.eth.createAccountWithBalance(alice);590 const sponsor = await helper.eth.createAccountWithBalance(alice);591 const caller = await helper.eth.createAccountWithBalance(alice);592 const helpers = helper.ethNativeContract.contractHelpers(owner);593 const flipper = helper.ethNativeContract.contractHelpers(owner);594 595 const originalCallerBalance = await helper.balance.getEthereum(caller); // await web3.eth.getBalance(caller);456 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});596 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});457 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});597 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});458598462 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();602 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();463 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});603 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});464604465 const originalFlipperBalance = await web3.eth.getBalance(sponsor);605 const originalFlipperBalance = await helper.balance.getEthereum(sponsor); // await web3.eth.getBalance(sponsor);466 expect(originalFlipperBalance).to.be.not.equal('0');606 expect(originalFlipperBalance).to.be.not.equal('0');467607468 await flipper.methods.flip().send({from: caller});608 await flipper.methods.flip().send({from: caller});469 expect(await flipper.methods.getValue().call()).to.be.true;609 expect(await flipper.methods.getValue().call()).to.be.true;470 expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);610 expect(await helper.balance.getEthereum(caller)).to.be.equals(originalCallerBalance);471611472 const newFlipperBalance = await web3.eth.getBalance(sponsor);612 const newFlipperBalance = await helper.balance.getEthereum(sponsor);473 expect(newFlipperBalance).to.be.not.equals(originalFlipperBalance);613 expect(newFlipperBalance).to.be.not.equals(originalFlipperBalance);474614475 await flipper.methods.flip().send({from: caller});615 await flipper.methods.flip().send({from: caller});476 expect(await web3.eth.getBalance(sponsor)).to.be.equal(newFlipperBalance);616 expect(await helper.balance.getEthereum(sponsor)).to.be.equal(newFlipperBalance);477 expect(await web3.eth.getBalance(caller)).to.be.not.equals(originalCallerBalance);617 expect(await helper.balance.getEthereum(caller)).to.be.not.equals(originalCallerBalance);478 });618 });479619480 // TODO: Find a way to calculate default rate limit620 // TODO: Find a way to calculate default rate limit481 itWeb3('Default rate limit equals 7200', async ({api, web3, privateKeyWrapper}) => {621 itEth('Default rate limit equals 7200', async ({helper, privateKey}) => {482 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);622 const alice = privateKey('//Alice');623624 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);483 const flipper = await deployFlipper(web3, owner);625 // const flipper = await deployFlipper(web3, owner);484 const helpers = contractHelpers(web3, owner);626 // const helpers = contractHelpers(web3, owner);627 const owner = await helper.eth.createAccountWithBalance(alice);628 const helpers = helper.ethNativeContract.contractHelpers(owner);629 const flipper = helper.ethNativeContract.contractHelpers(owner);630485 expect(await helpers.methods.sponsoringRateLimit(flipper.options.address).call()).to.be.equals('7200');631 expect(await helpers.methods.sponsoringRateLimit(flipper.options.address).call()).to.be.equals('7200');486 });632 });547 return await testContract.deploy({data: compiled.object}).send({from: owner});693 return await testContract.deploy({data: compiled.object}).send({from: owner});548 }694 }549695550 itWeb3('Default fee limit', async ({api, web3, privateKeyWrapper}) => {696 itEth('Default fee limit', async ({helper, privateKey}) => {551 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);697 const alice = privateKey('//Alice');698699 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);552 const flipper = await deployFlipper(web3, owner);700 // const flipper = await deployFlipper(web3, owner);553 const helpers = contractHelpers(web3, owner);701 // const helpers = contractHelpers(web3, owner);702 const owner = await helper.eth.createAccountWithBalance(alice);703 const helpers = helper.ethNativeContract.contractHelpers(owner);704 const flipper = helper.ethNativeContract.contractHelpers(owner);705554 expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equals('115792089237316195423570985008687907853269984665640564039457584007913129639935');706 expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equals('115792089237316195423570985008687907853269984665640564039457584007913129639935');555 });707 });556708557 itWeb3('Set fee limit', async ({api, web3, privateKeyWrapper}) => {709 itEth('Set fee limit', async ({helper, privateKey}) => {558 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);710 const alice = privateKey('//Alice');711712 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);559 const flipper = await deployFlipper(web3, owner);713 // const flipper = await deployFlipper(web3, owner);560 const helpers = contractHelpers(web3, owner);714 // const helpers = contractHelpers(web3, owner);715 const owner = await helper.eth.createAccountWithBalance(alice);716 const helpers = helper.ethNativeContract.contractHelpers(owner);717 const flipper = helper.ethNativeContract.contractHelpers(owner);718561 await helpers.methods.setSponsoringFeeLimit(flipper.options.address, 100).send();719 await helpers.methods.setSponsoringFeeLimit(flipper.options.address, 100).send();562 expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equals('100');720 expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equals('100');563 });721 });564722565 itWeb3('Negative test - set fee limit by non-owner', async ({api, web3, privateKeyWrapper}) => {723 itEth('Negative test - set fee limit by non-owner', async ({helper, privateKey}) => {566 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);724 const alice = privateKey('//Alice');725726 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);567 const stranger = await createEthAccountWithBalance(api, web3, privateKeyWrapper);727 // const stranger = await createEthAccountWithBalance(api, web3, privateKeyWrapper);568 const flipper = await deployFlipper(web3, owner);728 // const flipper = await deployFlipper(web3, owner);569 const helpers = contractHelpers(web3, owner);729 // const helpers = contractHelpers(web3, owner);730 const owner = await helper.eth.createAccountWithBalance(alice);731 const stranger = await helper.eth.createAccountWithBalance(alice);732 const helpers = helper.ethNativeContract.contractHelpers(owner);733 const flipper = helper.ethNativeContract.contractHelpers(owner);734570 await expect(helpers.methods.setSponsoringFeeLimit(flipper.options.address, 100).send({from: stranger})).to.be.rejected;735 await expect(helpers.methods.setSponsoringFeeLimit(flipper.options.address, 100).send({from: stranger})).to.be.rejected;571 });736 });572737573 itWeb3('Negative test - check that eth transactions exceeding fee limit are not executed', async ({api, web3, privateKeyWrapper}) => {738 itEth('Negative test - check that eth transactions exceeding fee limit are not executed', async ({helper, privateKey}) => {574 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);739 const alice = privateKey('//Alice');575 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);576 const user = await createEthAccountWithBalance(api, web3, privateKeyWrapper);577740578 const testContract = await deployTestContract(web3, owner);741 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);742 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);579 const helpers = contractHelpers(web3, owner);743 // const user = await createEthAccountWithBalance(api, web3, privateKeyWrapper);744 // const helpers = contractHelpers(web3, owner);745 const owner = await helper.eth.createAccountWithBalance(alice);746 const sponsor = await helper.eth.createAccountWithBalance(alice);747 const user = await helper.eth.createAccountWithBalance(alice);748 const helpers = helper.ethNativeContract.contractHelpers(owner);749750 const testContract = await deployTestContract(helper.getWeb3(), owner);580 751 581 await helpers.methods.setSponsoringMode(testContract.options.address, SponsoringMode.Generous).send({from: owner});752 await helpers.methods.setSponsoringMode(testContract.options.address, SponsoringMode.Generous).send({from: owner});582 await helpers.methods.setSponsoringRateLimit(testContract.options.address, 0).send({from: owner});753 await helpers.methods.setSponsoringRateLimit(testContract.options.address, 0).send({from: owner});583 754 584 await helpers.methods.setSponsor(testContract.options.address, sponsor).send();755 await helpers.methods.setSponsor(testContract.options.address, sponsor).send();585 await helpers.methods.confirmSponsorship(testContract.options.address).send({from: sponsor});756 await helpers.methods.confirmSponsorship(testContract.options.address).send({from: sponsor});586757587 const gasPrice = BigInt(await web3.eth.getGasPrice());758 const gasPrice = BigInt(await helper.getWeb3().eth.getGasPrice());588759589 await helpers.methods.setSponsoringFeeLimit(testContract.options.address, 2_000_000n * gasPrice).send();760 await helpers.methods.setSponsoringFeeLimit(testContract.options.address, 2_000_000n * gasPrice).send();590761591 const originalUserBalance = await web3.eth.getBalance(user);762 const originalUserBalance = await helper.balance.getEthereum(user); // await web3.eth.getBalance(user);592 await testContract.methods.test(100).send({from: user, gas: 2_000_000});763 await testContract.methods.test(100).send({from: user, gas: 2_000_000});593 expect(await web3.eth.getBalance(user)).to.be.equal(originalUserBalance);764 expect(await helper.balance.getEthereum(user)).to.be.equal(originalUserBalance);594765595 await testContract.methods.test(100).send({from: user, gas: 2_100_000});766 await testContract.methods.test(100).send({from: user, gas: 2_100_000});596 expect(await web3.eth.getBalance(user)).to.not.be.equal(originalUserBalance);767 expect(await helper.balance.getEthereum(user)).to.not.be.equal(originalUserBalance);597 });768 });598769599 itWeb3('Negative test - check that evm.call transactions exceeding fee limit are not executed', async ({api, web3, privateKeyWrapper}) => {770 itEth('Negative test - check that evm.call transactions exceeding fee limit are not executed', async ({helper, privateKey}) => {600 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);771 const alice = privateKey('//Alice');601 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);602772603 const testContract = await deployTestContract(web3, owner);773 // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);774 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);604 const helpers = contractHelpers(web3, owner);775 // const helpers = contractHelpers(web3, owner);776 const owner = await helper.eth.createAccountWithBalance(alice);777 const sponsor = await helper.eth.createAccountWithBalance(alice);778 const helpers = helper.ethNativeContract.contractHelpers(owner);779780 const testContract = await deployTestContract(helper.getWeb3(), owner);605 781 606 await helpers.methods.setSponsoringMode(testContract.options.address, SponsoringMode.Generous).send({from: owner});782 await helpers.methods.setSponsoringMode(testContract.options.address, SponsoringMode.Generous).send({from: owner});607 await helpers.methods.setSponsoringRateLimit(testContract.options.address, 0).send({from: owner});783 await helpers.methods.setSponsoringRateLimit(testContract.options.address, 0).send({from: owner});608 784 609 await helpers.methods.setSponsor(testContract.options.address, sponsor).send();785 await helpers.methods.setSponsor(testContract.options.address, sponsor).send();610 await helpers.methods.confirmSponsorship(testContract.options.address).send({from: sponsor});786 await helpers.methods.confirmSponsorship(testContract.options.address).send({from: sponsor});611787612 const gasPrice = BigInt(await web3.eth.getGasPrice());788 const gasPrice = BigInt(await helper.getWeb3().eth.getGasPrice());613789614 await helpers.methods.setSponsoringFeeLimit(testContract.options.address, 2_000_000n * gasPrice).send();790 await helpers.methods.setSponsoringFeeLimit(testContract.options.address, 2_000_000n * gasPrice).send();615791616 const alice = privateKeyWrapper('//Alice');792 const originalAliceBalance = await helper.balance.getSubstrate(alice.address); // (await api.query.system.account(alice.address)).data.free.toBigInt();617 const originalAliceBalance = (await api.query.system.account(alice.address)).data.free.toBigInt();793618 794 // await submitTransactionAsync(619 await submitTransactionAsync(795 // alice,796 // api.tx.evm.call(797 // subToEth(alice.address),798 // testContract.options.address,799 // testContract.methods.test(100).encodeABI(),800 // Uint8Array.from([]),801 // 2_000_000n,802 // gasPrice,803 // null,804 // null,805 // [],806 // ),807 // );808 await helper.eth.sendEVM(620 alice,809 alice,621 api.tx.evm.call(810 testContract.options.address,622 subToEth(alice.address),623 testContract.options.address,624 testContract.methods.test(100).encodeABI(),811 testContract.methods.test().encodeABI(),625 Uint8Array.from([]),812 '100',626 2_000_000n,627 gasPrice,628 null,629 null,630 [],631 ),632 );813 );633 expect((await api.query.system.account(alice.address)).data.free.toBigInt()).to.be.equal(originalAliceBalance);814 // 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);634 816 635 await submitTransactionAsync(817 // await submitTransactionAsync(818 // alice,819 // api.tx.evm.call(820 // subToEth(alice.address),821 // testContract.options.address,822 // testContract.methods.test(100).encodeABI(),823 // Uint8Array.from([]),824 // 2_100_000n,825 // gasPrice,826 // null,827 // null,828 // [],829 // ),830 // );831 await helper.eth.sendEVM(636 alice,832 alice,637 api.tx.evm.call(833 testContract.options.address,638 subToEth(alice.address),639 testContract.options.address,640 testContract.methods.test(100).encodeABI(),834 testContract.methods.test().encodeABI(),641 Uint8Array.from([]),835 '100',642 2_100_000n,643 gasPrice,644 null,645 null,646 [],647 ),648 );836 );649 expect((await api.query.system.account(alice.address)).data.free.toBigInt()).to.not.be.equal(originalAliceBalance);837 // 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);650 });839 });651});840});652841