11/* eslint-disable @typescript-eslint/no-unused-expressions */
2- import { ethers , helpers } from "hardhat"
2+ import { ethers } from "hardhat"
33import { smock } from "@defi-wonderland/smock"
44import { expect } from "chai"
55
66import type { FakeContract } from "@defi-wonderland/smock"
7- import type { ContractTransaction } from "ethers"
87import type { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"
98import type { Allowlist , WalletRegistry } from "../typechain"
109
@@ -51,6 +50,15 @@ describe("Allowlist", () => {
5150 allowlist . initialize ( walletRegistry . address )
5251 ) . to . be . revertedWith ( "Initializable: contract is already initialized" )
5352 } )
53+
54+ it ( "should revert if initialized with zero address" , async ( ) => {
55+ const AllowlistFactory = await ethers . getContractFactory ( "Allowlist" )
56+ const newAllowlist = await AllowlistFactory . deploy ( )
57+
58+ await expect ( newAllowlist . initialize ( ZERO_ADDRESS ) ) . to . be . revertedWith (
59+ "ZeroAddress"
60+ )
61+ } )
5462 } )
5563
5664 describe ( "addStakingProvider" , ( ) => {
@@ -100,6 +108,22 @@ describe("Allowlist", () => {
100108 . addStakingProvider ( stakingProvider1 . address , weight )
101109 ) . to . be . reverted
102110 } )
111+
112+ it ( "should revert if staking provider is zero address" , async ( ) => {
113+ const weight = ethers . utils . parseEther ( "40000" )
114+
115+ await expect (
116+ allowlist . connect ( governance ) . addStakingProvider ( ZERO_ADDRESS , weight )
117+ ) . to . be . revertedWith ( "ZeroAddress" )
118+ } )
119+
120+ it ( "should revert if weight is zero" , async ( ) => {
121+ await expect (
122+ allowlist
123+ . connect ( governance )
124+ . addStakingProvider ( stakingProvider1 . address , 0 )
125+ ) . to . be . revertedWith ( "ZeroWeight" )
126+ } )
103127 } )
104128
105129 context ( "when called by non-owner" , ( ) => {
@@ -278,6 +302,20 @@ describe("Allowlist", () => {
278302 . approveAuthorizationDecrease ( stakingProvider2 . address )
279303 ) . to . be . reverted
280304 } )
305+
306+ it ( "should revert if no decrease was requested (bypass protection)" , async ( ) => {
307+ // Add a staking provider but don't request decrease
308+ await allowlist
309+ . connect ( governance )
310+ . addStakingProvider ( stakingProvider2 . address , initialWeight )
311+
312+ // Trying to approve decrease without requesting it first should fail
313+ await expect (
314+ allowlist
315+ . connect ( walletRegistry . wallet )
316+ . approveAuthorizationDecrease ( stakingProvider2 . address )
317+ ) . to . be . revertedWith ( "NoDecreasePending" )
318+ } )
281319 } )
282320
283321 context ( "when called by non-WalletRegistry" , ( ) => {
@@ -330,14 +368,14 @@ describe("Allowlist", () => {
330368 } )
331369
332370 describe ( "seize" , ( ) => {
333- it ( "should emit MaliciousBehaviorIdentified event without seizing tokens " , async ( ) => {
371+ it ( "should emit MaliciousBehaviorIdentified event when called by WalletRegistry " , async ( ) => {
334372 const stakingProviders = [
335373 stakingProvider1 . address ,
336374 stakingProvider2 . address ,
337375 ]
338376
339377 await expect (
340- allowlist . seize (
378+ allowlist . connect ( walletRegistry . wallet ) . seize (
341379 ethers . utils . parseEther ( "1000" ) , // amount (ignored)
342380 100 , // rewardMultiplier (ignored)
343381 thirdParty . address , // notifier
@@ -348,7 +386,7 @@ describe("Allowlist", () => {
348386 . withArgs ( thirdParty . address , stakingProviders )
349387 } )
350388
351- it ( "should be callable by anyone " , async ( ) => {
389+ it ( "should revert when called by non-WalletRegistry " , async ( ) => {
352390 const stakingProviders = [ stakingProvider1 . address ]
353391
354392 await expect (
@@ -360,7 +398,7 @@ describe("Allowlist", () => {
360398 governance . address ,
361399 stakingProviders
362400 )
363- ) . to . not . be . reverted
401+ ) . to . be . revertedWith ( "NotWalletRegistry" )
364402 } )
365403 } )
366404
0 commit comments