1234567891011121314151617import {expect} from 'chai';18import {createEthAccountWithBalance, deployFlipper, GAS_ARGS, itWeb3, subToEth, transferBalanceToEth} from './util/helpers';19import {scheduleExpectSuccess, waitNewBlocks, requirePallets, Pallets} from '../util/helpers';2021describe('Scheduing EVM smart contracts', () => {22 before(async function() {23 await requirePallets(this, [Pallets.Scheduler]);24 });2526 itWeb3('Successfully schedules and periodically executes an EVM contract', async ({api, web3, privateKeyWrapper}) => {27 const deployer = await createEthAccountWithBalance(api, web3, privateKeyWrapper);28 const flipper = await deployFlipper(web3, deployer);29 const initialValue = await flipper.methods.getValue().call();30 const alice = privateKeyWrapper('//Alice');31 await transferBalanceToEth(api, alice, subToEth(alice.address));3233 {34 const tx = api.tx.evm.call(35 subToEth(alice.address),36 flipper.options.address,37 flipper.methods.flip().encodeABI(),38 '0',39 GAS_ARGS.gas,40 await web3.eth.getGasPrice(),41 null,42 null,43 [],44 );45 const waitForBlocks = 4;46 const periodBlocks = 2;4748 await scheduleExpectSuccess(tx, alice, waitForBlocks, '0x' + '0'.repeat(32), periodBlocks, 2);49 expect(await flipper.methods.getValue().call()).to.be.equal(initialValue);50 51 await waitNewBlocks(waitForBlocks - 1);52 expect(await flipper.methods.getValue().call()).to.be.not.equal(initialValue);53 54 await waitNewBlocks(periodBlocks);55 expect(await flipper.methods.getValue().call()).to.be.equal(initialValue);56 }57 });58});