1import { expect } from 'chai';2import waitNewBlocks from '../substrate/wait-new-blocks';3import { contractHelpers, createEthAccount, createEthAccountWithBalance, deployFlipper, itWeb3, usingWeb3Http } from './util/helpers';45describe('EVM allowlist', () => {6 itWeb3('Contract allowlist can be toggled', async ({ api }) => {7 await usingWeb3Http(async web3Http => {8 const owner = await createEthAccountWithBalance(api, web3Http);9 const flipper = await deployFlipper(web3Http, owner);10 await waitNewBlocks(api, 1);11 const randomUser = createEthAccount(web3Http);1213 const helpers = contractHelpers(web3Http, owner);1415 16 expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;17 expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.true;18 await waitNewBlocks(api, 1);1920 21 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });22 await waitNewBlocks(api, 1);23 expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.true;24 expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.false;2526 27 await helpers.methods.toggleAllowlist(flipper.options.address, false).send({ from: owner });28 await waitNewBlocks(api, 1);29 expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;30 expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.true;31 });32 });3334 itWeb3('Non-whitelisted user can\'t call contract with allowlist enabled', async ({ api }) => {35 await usingWeb3Http(async web3Http => {36 const owner = await createEthAccountWithBalance(api, web3Http);37 const flipper = await deployFlipper(web3Http, owner);38 await waitNewBlocks(api, 1);39 const caller = await createEthAccountWithBalance(api, web3Http);4041 const helpers = contractHelpers(web3Http, owner);4243 44 await flipper.methods.flip().send({ from: caller });45 await waitNewBlocks(api, 1);46 expect(await flipper.methods.getValue().call()).to.be.true;4748 49 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });50 await expect(flipper.methods.flip().send({ from: caller })).to.rejected;51 await waitNewBlocks(api, 1);52 expect(await flipper.methods.getValue().call()).to.be.true;5354 55 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});56 await flipper.methods.flip().send({ from: caller });57 await waitNewBlocks(api, 1);58 expect(await flipper.methods.getValue().call()).to.be.false;59 });60 });61});