1234567891011121314151617import {expect} from 'chai';18import {createEthAccountWithBalance, deployFlipper, GAS_ARGS, itWeb3, subToEth, transferBalanceToEth} from './util/helpers';19import {scheduleExpectSuccess, waitNewBlocks} from '../util/helpers';20import privateKey from '../substrate/privateKey';2122describe('Scheduing EVM smart contracts', () => {23 itWeb3('Successfully schedules and periodically executes an EVM contract', async ({api, web3}) => {24 const deployer = await createEthAccountWithBalance(api, web3);25 const flipper = await deployFlipper(web3, deployer);26 const initialValue = await flipper.methods.getValue().call();27 const alice = privateKey('//Alice');28 await transferBalanceToEth(api, alice, subToEth(alice.address));2930 {31 const tx = api.tx.evm.call(32 subToEth(alice.address),33 flipper.options.address,34 flipper.methods.flip().encodeABI(),35 '0',36 GAS_ARGS.gas,37 await web3.eth.getGasPrice(),38 null,39 null,40 [],41 );42 const waitForBlocks = 4;43 const periodBlocks = 2;4445 await scheduleExpectSuccess(tx, alice, waitForBlocks, '0x' + '0'.repeat(32), periodBlocks, 2);46 expect(await flipper.methods.getValue().call()).to.be.equal(initialValue);47 48 await waitNewBlocks(waitForBlocks - 1);49 expect(await flipper.methods.getValue().call()).to.be.not.equal(initialValue);50 51 await waitNewBlocks(periodBlocks);52 expect(await flipper.methods.getValue().call()).to.be.equal(initialValue);53 }54 });55});