|
| 1 | +import hre from 'hardhat'; |
| 2 | + |
| 3 | +import { assertEvent } from '../helpers/utils/test'; |
| 4 | +const { expect } = require('chai'); |
| 5 | + |
| 6 | +describe('BasicWhitelisting', () => { |
| 7 | + let basicWhitelisting: any, owners: any; |
| 8 | + |
| 9 | + beforeEach(async () => { |
| 10 | + owners = await hre.viem.getWalletClients(); |
| 11 | + |
| 12 | + basicWhitelisting = await hre.viem.deployContract('BasicWhitelisting'); |
| 13 | + }); |
| 14 | + |
| 15 | + describe('Deployment', async () => { |
| 16 | + it('Should set the right owner', async () => { |
| 17 | + expect(await basicWhitelisting.read.owner()).to.deep.equal(owners[0].account.address); |
| 18 | + }); |
| 19 | + }); |
| 20 | + |
| 21 | + describe('Whitelisting', async () => { |
| 22 | + it('Should whitelist an address', async () => { |
| 23 | + const addr1 = owners[2].account.address; |
| 24 | + |
| 25 | + await basicWhitelisting.write.addWhitelistedAddress([addr1]); |
| 26 | + expect(await basicWhitelisting.read.isWhitelisted([addr1, 0])).to.be.true; |
| 27 | + }); |
| 28 | + |
| 29 | + it('Should remove an address from whitelist', async () => { |
| 30 | + const addr1 = owners[2].account.address; |
| 31 | + |
| 32 | + await basicWhitelisting.write.addWhitelistedAddress([addr1]); |
| 33 | + await basicWhitelisting.write.removeWhitelistedAddress([addr1]); |
| 34 | + expect(await basicWhitelisting.read.isWhitelisted([addr1, 0])).to.be.false; |
| 35 | + }); |
| 36 | + |
| 37 | + it('Should emit AddressWhitelisted event', async () => { |
| 38 | + const addr1 = owners[2].account.address; |
| 39 | + |
| 40 | + await assertEvent(basicWhitelisting.write.addWhitelistedAddress([addr1]), [ |
| 41 | + { |
| 42 | + contract: basicWhitelisting, |
| 43 | + eventName: 'AddressWhitelisted', |
| 44 | + argNames: ['account'], |
| 45 | + argValuesList: [[addr1]], |
| 46 | + }, |
| 47 | + ]); |
| 48 | + }); |
| 49 | + |
| 50 | + it('Should emit AddressRemovedFromWhitelist event', async () => { |
| 51 | + const addr1 = owners[2].account.address; |
| 52 | + |
| 53 | + await basicWhitelisting.write.addWhitelistedAddress([addr1]); |
| 54 | + |
| 55 | + await assertEvent(basicWhitelisting.write.removeWhitelistedAddress([addr1]), [ |
| 56 | + { |
| 57 | + contract: basicWhitelisting, |
| 58 | + eventName: 'AddressRemovedFromWhitelist', |
| 59 | + argNames: ['account'], |
| 60 | + argValuesList: [[addr1]], |
| 61 | + }, |
| 62 | + ]); |
| 63 | + }); |
| 64 | + |
| 65 | + it('Should only allow the owner to whitelist addresses', async () => { |
| 66 | + const addr1 = owners[2].account.address; |
| 67 | + |
| 68 | + await expect( |
| 69 | + basicWhitelisting.write.addWhitelistedAddress([addr1], { |
| 70 | + account: owners[1].account, |
| 71 | + }), |
| 72 | + ).to.be.rejectedWith('Ownable: caller is not the owner'); |
| 73 | + }); |
| 74 | + |
| 75 | + it('Should only allow the owner to remove addresses from whitelist', async () => { |
| 76 | + const addr1 = owners[2].account.address; |
| 77 | + |
| 78 | + await basicWhitelisting.write.addWhitelistedAddress([addr1]); |
| 79 | + await expect( |
| 80 | + basicWhitelisting.write.removeWhitelistedAddress([addr1], { |
| 81 | + account: owners[1].account, |
| 82 | + }), |
| 83 | + ).to.be.rejectedWith('Ownable: caller is not the owner'); |
| 84 | + }); |
| 85 | + }); |
| 86 | +}); |
0 commit comments