difftreelog
test fix sponsoring for updated logic
in: master
3 files changed
tests/src/eth/sponsoring.test.tsdiffbeforeafterboth1import { expect } from 'chai';2import privateKey from '../substrate/privateKey';3import waitNewBlocks from '../substrate/wait-new-blocks';4import { contractHelpers, createEthAccount, createEthAccountWithBalance, deployCollector, deployFlipper, itWeb3, transferBalanceToEth, usingWeb3Http } from './util/helpers';56describe('EVM sponsoring', () => {7 itWeb3('Fee is deducted from contract if sponsoring is enabled', async ({api, web3}) => {8 await usingWeb3Http(async web3Http => {9 const alice = privateKey('//Alice');1011 const owner = await createEthAccountWithBalance(api, web3Http);12 const caller = createEthAccount(web3Http);13 const originalCallerBalance = await web3.eth.getBalance(caller);14 expect(originalCallerBalance).to.be.equal('0');1516 const flipper = await deployFlipper(web3Http, owner);17 await waitNewBlocks(api, 1);18 19 const helpers = contractHelpers(web3Http, owner);20 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;21 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});22 await waitNewBlocks(api, 1);23 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;2425 await transferBalanceToEth(api, alice, flipper.options.address);26 await waitNewBlocks(api, 2);2728 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);29 expect(originalFlipperBalance).to.be.not.equal('0');3031 await flipper.methods.flip().send({ from: caller });32 await waitNewBlocks(api, 1);33 expect(await flipper.methods.getValue().call()).to.be.true;3435 // Balance should be taken from flipper instead of caller36 expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);37 expect(await web3.eth.getBalance(flipper.options.address)).to.be.not.equals(originalFlipperBalance);38 });39 });40 itWeb3('...but this doesn\'t applies to payable value', async ({api, web3}) => {41 await usingWeb3Http(async web3Http => {42 const alice = privateKey('//Alice');4344 const owner = await createEthAccountWithBalance(api, web3Http);45 const caller = await createEthAccountWithBalance(api, web3Http);46 await waitNewBlocks(api, 1);47 const originalCallerBalance = await web3.eth.getBalance(caller);48 expect(originalCallerBalance).to.be.not.equal('0');4950 const collector = await deployCollector(web3Http, owner);51 await waitNewBlocks(api, 1);52 53 const helpers = contractHelpers(web3Http, owner);54 expect(await helpers.methods.sponsoringEnabled(collector.options.address).call()).to.be.false;55 await helpers.methods.toggleSponsoring(collector.options.address, true).send({from: owner});56 await waitNewBlocks(api, 1);57 expect(await helpers.methods.sponsoringEnabled(collector.options.address).call()).to.be.true;5859 await transferBalanceToEth(api, alice, collector.options.address);60 await waitNewBlocks(api, 2);6162 const originalCollectorBalance = await web3.eth.getBalance(collector.options.address);63 expect(originalCollectorBalance).to.be.not.equal('0');6465 await collector.methods.giveMoney().send({ from: caller, value: '10000' });66 await waitNewBlocks(api, 1);6768 // Balance will be taken from both caller (value) and from collector (fee)69 expect(await web3.eth.getBalance(caller)).to.be.equals((BigInt(originalCallerBalance) - 10000n).toString());70 expect(await web3.eth.getBalance(collector.options.address)).to.be.not.equals(originalCollectorBalance);71 expect(await collector.methods.getCollected().call()).to.be.equal('10000');72 });73 });74});1import { expect } from 'chai';2import privateKey from '../substrate/privateKey';3import waitNewBlocks from '../substrate/wait-new-blocks';4import { contractHelpers, createEthAccount, createEthAccountWithBalance, deployCollector, deployFlipper, itWeb3, transferBalanceToEth, usingWeb3Http } from './util/helpers';56describe('EVM sponsoring', () => {7 itWeb3('Fee is deducted from contract if sponsoring is enabled', async ({api, web3}) => {8 await usingWeb3Http(async web3Http => {9 const alice = privateKey('//Alice');1011 const owner = await createEthAccountWithBalance(api, web3Http);12 const caller = createEthAccount(web3Http);13 const originalCallerBalance = await web3.eth.getBalance(caller);14 expect(originalCallerBalance).to.be.equal('0');1516 const flipper = await deployFlipper(web3Http, owner);17 await waitNewBlocks(api, 1);18 19 const helpers = contractHelpers(web3Http, owner);20 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });21 await waitNewBlocks(api, 1);22 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({ from: owner });23 await waitNewBlocks(api, 1);2425 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;26 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});27 await waitNewBlocks(api, 1);28 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});29 await waitNewBlocks(api, 1);30 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;3132 await transferBalanceToEth(api, alice, flipper.options.address);33 await waitNewBlocks(api, 2);3435 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);36 expect(originalFlipperBalance).to.be.not.equal('0');3738 await flipper.methods.flip().send({ from: caller });39 await waitNewBlocks(api, 1);40 expect(await flipper.methods.getValue().call()).to.be.true;4142 // Balance should be taken from flipper instead of caller43 expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);44 expect(await web3.eth.getBalance(flipper.options.address)).to.be.not.equals(originalFlipperBalance);45 });46 });47 itWeb3('...but this doesn\'t applies to payable value', async ({api, web3}) => {48 await usingWeb3Http(async web3Http => {49 const alice = privateKey('//Alice');5051 const owner = await createEthAccountWithBalance(api, web3Http);52 const caller = await createEthAccountWithBalance(api, web3Http);53 await waitNewBlocks(api, 1);54 const originalCallerBalance = await web3.eth.getBalance(caller);55 expect(originalCallerBalance).to.be.not.equal('0');5657 const collector = await deployCollector(web3Http, owner);58 await waitNewBlocks(api, 1);59 60 const helpers = contractHelpers(web3Http, owner);61 await helpers.methods.toggleAllowlist(collector.options.address, true).send({ from: owner });62 await waitNewBlocks(api, 1);63 await helpers.methods.toggleAllowed(collector.options.address, caller, true).send({ from: owner });64 await waitNewBlocks(api, 1);6566 expect(await helpers.methods.sponsoringEnabled(collector.options.address).call()).to.be.false;67 await helpers.methods.toggleSponsoring(collector.options.address, true).send({ from: owner });68 await waitNewBlocks(api, 1);69 await helpers.methods.setSponsoringRateLimit(collector.options.address, 0).send({ from: owner });70 await waitNewBlocks(api, 1);71 expect(await helpers.methods.sponsoringEnabled(collector.options.address).call()).to.be.true;7273 await transferBalanceToEth(api, alice, collector.options.address);74 await waitNewBlocks(api, 2);7576 const originalCollectorBalance = await web3.eth.getBalance(collector.options.address);77 expect(originalCollectorBalance).to.be.not.equal('0');7879 await collector.methods.giveMoney().send({ from: caller, value: '10000' });80 await waitNewBlocks(api, 1);8182 // Balance will be taken from both caller (value) and from collector (fee)83 expect(await web3.eth.getBalance(caller)).to.be.equals((BigInt(originalCallerBalance) - 10000n).toString());84 expect(await web3.eth.getBalance(collector.options.address)).to.be.not.equals(originalCollectorBalance);85 expect(await collector.methods.getCollected().call()).to.be.equal('10000');86 });87 });88});tests/src/eth/util/contractHelpersAbi.jsondiffbeforeafterboth--- a/tests/src/eth/util/contractHelpersAbi.json
+++ b/tests/src/eth/util/contractHelpersAbi.json
@@ -138,5 +138,23 @@
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
+ },
+ {
+ "inputs": [
+ {
+ "internalType": "address",
+ "name": "target",
+ "type": "address"
+ },
+ {
+ "internalType": "uint32",
+ "name": "limit",
+ "type": "uint32"
+ }
+ ],
+ "name": "setSponsoringRateLimit",
+ "outputs": [],
+ "stateMutability": "nonpayable",
+ "type": "function"
}
]
\ No newline at end of file
tests/src/eth/util/helpers.tsdiffbeforeafterboth--- a/tests/src/eth/util/helpers.ts
+++ b/tests/src/eth/util/helpers.ts
@@ -18,7 +18,7 @@
import privateKey from '../../substrate/privateKey';
import contractHelpersAbi from './contractHelpersAbi.json';
-export const GAS_ARGS = { gas: 0x10000000, gasPrice: '0x01' };
+export const GAS_ARGS = { gas: 0x1000000, gasPrice: '0x01' };
let web3Connected = false;
export async function usingWeb3<T>(cb: (web3: Web3) => Promise<T> | T): Promise<T> {