git.delta.rocks / unique-network / refs/commits / 448eded3df3f

difftreelog

source

tests/src/eth/allowlist.test.ts3.0 KiBsourcehistory
1import { expect } from 'chai';2import waitNewBlocks from '../substrate/wait-new-blocks';3import { setContractSponsoringRateLimitExpectFailure } from '../util/helpers';4import { contractHelpers, createEthAccount, createEthAccountWithBalance, deployFlipper, itWeb3, usingWeb3Http } from './util/helpers';56describe('EVM allowlist', () => {7  itWeb3('Contract allowlist can be toggled', async ({ api }) => {8    await usingWeb3Http(async web3Http => {9      const owner = await createEthAccountWithBalance(api, web3Http);10      const flipper = await deployFlipper(web3Http, owner);11      await waitNewBlocks(api, 1);12      const randomUser = createEthAccount(web3Http);1314      const helpers = contractHelpers(web3Http, owner);1516      // Any user is allowed by default17      expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;18      expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.true;19      await waitNewBlocks(api, 1);2021      // Enable22      await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });23      await waitNewBlocks(api, 1);24      expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.true;25      expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.false;2627      // Disable28      await helpers.methods.toggleAllowlist(flipper.options.address, false).send({ from: owner });29      await waitNewBlocks(api, 1);30      expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;31      expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.true;32    });33  });3435  itWeb3.only('Non-whitelisted user can\'t call contract with allowlist enabled', async ({ api }) => {36    await usingWeb3Http(async web3Http => {37      const owner = await createEthAccountWithBalance(api, web3Http);38      const flipper = await deployFlipper(web3Http, owner);39      await waitNewBlocks(api, 1);40      const caller = await createEthAccountWithBalance(api, web3Http);4142      const helpers = contractHelpers(web3Http, owner);4344      // User can flip with allowlist disabled45      await flipper.methods.flip().send({ from: caller });46      await waitNewBlocks(api, 1);47      expect(await flipper.methods.getValue().call()).to.be.true;4849      // Tx will be reverted if user is not in whitelist50      await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });51      await expect(flipper.methods.flip().send({ from: caller })).to.rejected;52      await waitNewBlocks(api, 1);53      expect(await flipper.methods.getValue().call()).to.be.true;5455      // Adding caller to allowlist will make contract callable again56      await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});57      await flipper.methods.flip().send({ from: caller });58      await waitNewBlocks(api, 1);59      expect(await flipper.methods.getValue().call()).to.be.false;60    });61  });62});