git.delta.rocks / unique-network / refs/commits / c9e84df54927

difftreelog

source

tests/src/eth/allowlist.test.ts2.0 KiBsourcehistory
1import {expect} from 'chai';2import {contractHelpers, createEthAccountWithBalance, deployFlipper, itWeb3} from './util/helpers';34describe('EVM allowlist', () => {5  itWeb3('Contract allowlist can be toggled', async ({api, web3}) => {6    const owner = await createEthAccountWithBalance(api, web3);7    const flipper = await deployFlipper(web3, owner);89    const helpers = contractHelpers(web3, owner);1011    // Any user is allowed by default12    expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;1314    // Enable15    await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});16    expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.true;1718    // Disable19    await helpers.methods.toggleAllowlist(flipper.options.address, false).send({from: owner});20    expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;21  });2223  itWeb3('Non-allowlisted user can\'t call contract with allowlist enabled', async ({api, web3}) => {24    const owner = await createEthAccountWithBalance(api, web3);25    const flipper = await deployFlipper(web3, owner);26    const caller = await createEthAccountWithBalance(api, web3);2728    const helpers = contractHelpers(web3, owner);2930    // User can flip with allowlist disabled31    await flipper.methods.flip().send({from: caller});32    expect(await flipper.methods.getValue().call()).to.be.true;3334    // Tx will be reverted if user is not in allowlist35    await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});36    await expect(flipper.methods.flip().send({from: caller})).to.rejected;37    expect(await flipper.methods.getValue().call()).to.be.true;3839    // Adding caller to allowlist will make contract callable again40    await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});41    await flipper.methods.flip().send({from: caller});42    expect(await flipper.methods.getValue().call()).to.be.false;43  });44});