git.delta.rocks / unique-network / refs/commits / 6b16ace53bf5

difftreelog

source

tests/src/eth/allowlist.test.ts2.9 KiBsourcehistory
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      // Any user is allowed by default16      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      // Enable21      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      // Disable27      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      // User can flip with allowlist disabled44      await flipper.methods.flip().send({ from: caller });45      await waitNewBlocks(api, 1);46      expect(await flipper.methods.getValue().call()).to.be.true;4748      // Tx will be reverted if user is not in whitelist49      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      // Adding caller to allowlist will make contract callable again55      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});