1234567891011121314151617import {expect} from 'chai';18import {EthUniqueHelper, itSchedEth} from './util';19import {Pallets, usingPlaygrounds} from '../util';2021describe('Scheduing EVM smart contracts', () => {2223 before(async () => {24 await usingPlaygrounds(async (helper) => {25 await helper.testUtils.enable();26 });27 });2829 itSchedEth.ifWithPallets('Successfully schedules and periodically executes an EVM contract', [Pallets.UniqueScheduler], async (scheduleKind, {helper, privateKey}) => {30 const donor = await privateKey({url: import.meta.url});31 const [alice] = await helper.arrange.createAccounts([1000n], donor);3233 const scheduledId = scheduleKind == 'named' ? helper.arrange.makeScheduledId() : undefined;3435 const deployer = await helper.eth.createAccountWithBalance(alice);36 const flipper = await helper.eth.deployFlipper(deployer);3738 const initialValue = await flipper.methods.getValue().call();39 await helper.eth.transferBalanceFromSubstrate(alice, helper.address.substrateToEth(alice.address));4041 const waitForBlocks = 4;42 const periodic = {43 period: 2,44 repetitions: 2,45 };4647 await helper.scheduler.scheduleAfter<EthUniqueHelper>(waitForBlocks, {scheduledId, periodic})48 .eth.sendEVM(49 alice,50 flipper.options.address,51 flipper.methods.flip().encodeABI(),52 '0',53 );5455 expect(await flipper.methods.getValue().call()).to.be.equal(initialValue);5657 await helper.wait.newBlocks(waitForBlocks + 1);58 expect(await flipper.methods.getValue().call()).to.be.not.equal(initialValue);5960 await helper.wait.newBlocks(periodic.period);61 expect(await flipper.methods.getValue().call()).to.be.equal(initialValue);62 });63});