1234567891011121314151617import {expect} from 'chai';18import {itSchedEth} from '@unique/test-utils/eth/util.js';19import {EthUniqueHelper} from '@unique/test-utils/eth/index.js';20import {Pallets, usingPlaygrounds} from '@unique/test-utils/util.js';2122describe('Scheduing EVM smart contracts', () => {2324 before(async () => {25 await usingPlaygrounds(async (helper) => {26 await helper.testUtils.enable(Pallets.TestUtils);27 });28 });2930 itSchedEth.ifWithPallets('Successfully schedules and periodically executes an EVM contract', [Pallets.UniqueScheduler], async (scheduleKind, {helper, privateKey}) => {31 const donor = await privateKey({url: import.meta.url});32 const [alice] = await helper.arrange.createAccounts([1000n], donor);3334 const scheduledId = scheduleKind == 'named' ? helper.arrange.makeScheduledId() : undefined;3536 const deployer = await helper.eth.createAccountWithBalance(alice);37 const flipper = await helper.eth.deployFlipper(deployer);3839 const initialValue = await flipper.methods.getValue().call();40 await helper.eth.transferBalanceFromSubstrate(alice, helper.address.substrateToEth(alice.address));4142 const waitForBlocks = 4;43 const periodic = {44 period: 2,45 repetitions: 2,46 };4748 await helper.scheduler.scheduleAfter<EthUniqueHelper>(waitForBlocks, {scheduledId, periodic})49 .eth.sendEVM(50 alice,51 flipper.options.address,52 flipper.methods.flip().encodeABI(),53 '0',54 );5556 expect(await flipper.methods.getValue().call()).to.be.equal(initialValue);5758 await helper.wait.newBlocks(waitForBlocks + 1);59 expect(await flipper.methods.getValue().call()).to.be.not.equal(initialValue);6061 await helper.wait.newBlocks(periodic.period);62 expect(await flipper.methods.getValue().call()).to.be.equal(initialValue);63 });64});