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

difftreelog

source

tests/src/eth/allowlist.test.ts2.8 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {expect} from 'chai';18import {contractHelpers, createEthAccountWithBalance, deployFlipper, itWeb3} from './util/helpers';1920describe('EVM allowlist', () => {21  itWeb3('Contract allowlist can be toggled', async ({api, web3, privateKeyWrapper}) => {22    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);23    const flipper = await deployFlipper(web3, owner);2425    const helpers = contractHelpers(web3, owner);2627    // Any user is allowed by default28    expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;2930    // Enable31    await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});32    expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.true;3334    // Disable35    await helpers.methods.toggleAllowlist(flipper.options.address, false).send({from: owner});36    expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;37  });3839  itWeb3('Non-allowlisted user can\'t call contract with allowlist enabled', async ({api, web3, privateKeyWrapper}) => {40    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);41    const flipper = await deployFlipper(web3, owner);42    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);4344    const helpers = contractHelpers(web3, owner);4546    // User can flip with allowlist disabled47    await flipper.methods.flip().send({from: caller});48    expect(await flipper.methods.getValue().call()).to.be.true;4950    // Tx will be reverted if user is not in allowlist51    await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});52    await expect(flipper.methods.flip().send({from: caller})).to.rejected;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    expect(await flipper.methods.getValue().call()).to.be.false;59  });60});