Skip to content

Commit f033db8

Browse files
authored
fix: auth minter helper & bound _mint in depositTransaction tests (#17642)
* refactor: auth minter helper tests (#618) * fix: bound _mint correctly in depositTransaction test function (#619)
1 parent bf72a8c commit f033db8

File tree

2 files changed

+26
-31
lines changed

2 files changed

+26
-31
lines changed

packages/contracts-bedrock/test/L1/OptimismPortal2.t.sol

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2565,11 +2565,13 @@ contract OptimismPortal2_DepositTransaction_Test is OptimismPortal2_TestInit {
25652565
external
25662566
{
25672567
// Prevent overflow on an upgrade context
2568-
if (isUsingLockbox()) {
2568+
// Since the value always goes through the portal
2569+
_mint = bound(_mint, 0, type(uint256).max - address(optimismPortal2).balance);
2570+
2571+
if (isUsingLockbox() && address(optimismPortal2).balance > address(ethLockbox).balance) {
25692572
_mint = bound(_mint, 0, type(uint256).max - address(ethLockbox).balance);
2570-
} else {
2571-
_mint = bound(_mint, 0, type(uint256).max - address(optimismPortal2).balance);
25722573
}
2574+
25732575
if (isUsingCustomGasToken()) {
25742576
_mint = 0;
25752577
}
@@ -2585,7 +2587,6 @@ contract OptimismPortal2_DepositTransaction_Test is OptimismPortal2_TestInit {
25852587

25862588
uint256 balanceBefore = address(optimismPortal2).balance;
25872589
uint256 lockboxBalanceBefore = address(ethLockbox).balance;
2588-
_mint = bound(_mint, 0, type(uint256).max - balanceBefore);
25892590

25902591
// EOA emulation
25912592
vm.expectEmit(address(optimismPortal2));

packages/contracts-bedrock/test/L2/LiquidityController.t.sol

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ contract LiquidityController_TestInit is CommonTest {
4747

4848
/// @notice Helper function to authorize a minter.
4949
function _authorizeMinter(address _minter) internal {
50+
assumeNotForgeAddress(_minter);
51+
assumeNotZeroAddress(_minter);
5052
// Authorize the minter
5153
stdstore.target(address(liquidityController)).sig(liquidityController.minters.selector).with_key(_minter)
5254
.checked_write(true);
@@ -114,13 +116,10 @@ contract LiquidityController_AuthorizeMinter_Test is LiquidityController_TestIni
114116
/// @title LiquidityController_DeauthorizeMinter_Test
115117
/// @notice Tests the `deauthorizeMinter` function of the `LiquidityController` contract.
116118
contract LiquidityController_DeauthorizeMinter_Test is LiquidityController_TestInit {
117-
using stdStorage for StdStorage;
118-
119119
/// @notice Tests that the deauthorizeMinter function can be called by the owner.
120120
function testFuzz_deauthorizeMinter_fromOwner_succeeds(address _minter) public {
121121
// Set minter to authorized
122-
stdstore.target(address(liquidityController)).sig(liquidityController.minters.selector).with_key(_minter)
123-
.checked_write(true);
122+
_authorizeMinter(_minter);
124123

125124
// Expect emit MinterDeauthorized event
126125
vm.expectEmit(address(liquidityController));
@@ -138,8 +137,7 @@ contract LiquidityController_DeauthorizeMinter_Test is LiquidityController_TestI
138137
vm.assume(_caller != IProxyAdmin(Predeploys.PROXY_ADMIN).owner());
139138

140139
// Set minter to authorized
141-
stdstore.target(address(liquidityController)).sig(liquidityController.minters.selector).with_key(_minter)
142-
.checked_write(true);
140+
_authorizeMinter(_minter);
143141

144142
// Call the deauthorizeMinter function with non-owner as the caller
145143
vm.prank(_caller);
@@ -154,11 +152,9 @@ contract LiquidityController_DeauthorizeMinter_Test is LiquidityController_TestI
154152
/// @title LiquidityController_Mint_Test
155153
/// @notice Tests the `mint` function of the `LiquidityController` contract.
156154
contract LiquidityController_Mint_Test is LiquidityController_TestInit {
157-
address authorizedMinter = makeAddr("authorizedMinter");
158-
159155
/// @notice Tests that the mint function can be called by an authorized minter.
160-
function testFuzz_mint_fromAuthorizedMinter_succeeds(address _to, uint256 _amount) public {
161-
_authorizeMinter(authorizedMinter);
156+
function testFuzz_mint_fromAuthorizedMinter_succeeds(address _to, uint256 _amount, address _minter) public {
157+
_authorizeMinter(_minter);
162158
vm.assume(_to != address(nativeAssetLiquidity));
163159
_amount = bound(_amount, 1, address(nativeAssetLiquidity).balance);
164160

@@ -171,8 +167,8 @@ contract LiquidityController_Mint_Test is LiquidityController_TestInit {
171167
emit LiquidityWithdrawn(address(liquidityController), _amount);
172168
// Expect emit LiquidityMinted event
173169
vm.expectEmit(address(liquidityController));
174-
emit LiquidityMinted(authorizedMinter, _to, _amount);
175-
vm.prank(authorizedMinter);
170+
emit LiquidityMinted(_minter, _to, _amount);
171+
vm.prank(_minter);
176172
liquidityController.mint(_to, _amount);
177173

178174
// Assert recipient and NativeAssetLiquidity balances are updated correctly
@@ -198,15 +194,15 @@ contract LiquidityController_Mint_Test is LiquidityController_TestInit {
198194
}
199195

200196
/// @notice Tests that the mint function reverts when contract has insufficient balance.
201-
function test_mint_insufficientBalance_fails() public {
202-
_authorizeMinter(authorizedMinter);
197+
function test_mint_insufficientBalance_fails(address _minter) public {
198+
_authorizeMinter(_minter);
203199
// Try to mint more than available balance
204200
uint256 contractBalance = address(nativeAssetLiquidity).balance;
205201
uint256 amount = bound(contractBalance, contractBalance + 1, type(uint256).max);
206202
address to = makeAddr("recipient");
207203

208204
// Call the mint function with insufficient balance
209-
vm.prank(authorizedMinter);
205+
vm.prank(_minter);
210206
// Should revert due to insufficient balance in NativeAssetLiquidity
211207
vm.expectRevert(NativeAssetLiquidity.NativeAssetLiquidity_InsufficientBalance.selector);
212208

@@ -221,36 +217,34 @@ contract LiquidityController_Mint_Test is LiquidityController_TestInit {
221217
/// @title LiquidityController_Burn_Test
222218
/// @notice Tests the `burn` function of the `LiquidityController` contract.
223219
contract LiquidityController_Burn_Test is LiquidityController_TestInit {
224-
address authorizedMinter = makeAddr("authorizedMinter");
225-
226220
/// @notice Tests that the burn function can be called by an authorized minter.
227-
function testFuzz_burn_fromAuthorizedMinter_succeeds(uint256 _amount) public {
228-
_authorizeMinter(authorizedMinter);
221+
function testFuzz_burn_fromAuthorizedMinter_succeeds(uint256 _amount, address _minter) public {
222+
_authorizeMinter(_minter);
229223
_amount = bound(_amount, 0, address(nativeAssetLiquidity).balance);
230224

231225
// Deal the authorized minter with the amount to burn
232-
vm.deal(authorizedMinter, _amount);
226+
vm.deal(_minter, _amount);
233227
uint256 nativeAssetBalanceBefore = address(nativeAssetLiquidity).balance;
234-
uint256 minterBalanceBefore = authorizedMinter.balance;
228+
uint256 minterBalanceBefore = _minter.balance;
235229

236230
// Expect emit LiquidityDeposited event and call the burn function
237231
vm.expectEmit(address(nativeAssetLiquidity));
238232
emit LiquidityDeposited(address(liquidityController), _amount);
239233
// Expect emit LiquidityBurned event
240234
vm.expectEmit(address(liquidityController));
241-
emit LiquidityBurned(authorizedMinter, _amount);
242-
vm.prank(authorizedMinter);
235+
emit LiquidityBurned(_minter, _amount);
236+
vm.prank(_minter);
243237
liquidityController.burn{ value: _amount }();
244238

245239
// Assert minter and NativeAssetLiquidity balances are updated correctly
246-
assertEq(authorizedMinter.balance, minterBalanceBefore - _amount);
240+
assertEq(_minter.balance, minterBalanceBefore - _amount);
247241
assertEq(address(nativeAssetLiquidity).balance, nativeAssetBalanceBefore + _amount);
248242
}
249243

250244
/// @notice Tests that the burn function reverts when called by unauthorized address.
251-
function testFuzz_burn_fromUnauthorizedCaller_fails(address _caller, uint256 _amount) public {
252-
_authorizeMinter(authorizedMinter);
253-
vm.assume(_caller != authorizedMinter);
245+
function testFuzz_burn_fromUnauthorizedCaller_fails(address _caller, uint256 _amount, address _minter) public {
246+
_authorizeMinter(_minter);
247+
vm.assume(_caller != _minter);
254248
_amount = bound(_amount, 0, address(nativeAssetLiquidity).balance);
255249

256250
// Deal the unauthorized caller with the amount to burn

0 commit comments

Comments
 (0)