Skip to content

Commit

Permalink
test(protocol): check LibEIP1559 function results in fuzz tests (#18475)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik authored Nov 11, 2024
1 parent f24a908 commit 06e190c
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions packages/protocol/test/layer2/LibEIP1559.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,37 @@ contract TestLibEIP1559 is TaikoL2Test {

/// forge-config: layer2.fuzz.runs = 1000
/// forge-config: layer2.fuzz.show-logs = true
function test_fuzz_ethQty(uint64 _gasTarget, uint64 _gasExcess) external pure {
function test_fuzz_ethQty(uint64 _gasTarget, uint64 _gasExcess) external {
if (_gasTarget == 0) _gasTarget = 1;
uint256 result = LibEIP1559.ethQty(_gasTarget, _gasExcess);
assertTrue(result > 0);
}

LibEIP1559.ethQty(_gasTarget, _gasExcess);
/// forge-config: layer2.fuzz.runs = 2000
/// forge-config: layer2.fuzz.show-logs = true
function test_fuzz_basefee(uint64 _gasTarget, uint64 _gasExcess) external {
uint256 result = LibEIP1559.basefee(_gasTarget, _gasExcess);
assertTrue(result >= 1);
}

/// forge-config: layer2.fuzz.runs = 2000
/// forge-config: layer2.fuzz.show-logs = true
function test_fuzz_adjustExcess(
uint64 _gasTarget,
uint64 _oldGasTarget,
uint64 _newGasTarget,
uint64 _gasExcess
uint64 _oldGasExcess
)
external
pure
{
if (_gasTarget == 0) _gasTarget = 1;
if (_newGasTarget == 0) _newGasTarget = 1;
LibEIP1559.adjustExcess(_gasTarget, _newGasTarget, _gasExcess);
(uint64 newGasTarget_, uint64 newGasExcess_) =
LibEIP1559.adjustExcess(_oldGasTarget, _newGasTarget, _oldGasExcess);

if (_oldGasTarget == 0 && _newGasTarget == 0) {
assertEq(newGasTarget_, 0);
assertEq(newGasExcess_, _oldGasExcess);
} else {
assertTrue(newGasTarget_ != 0);
}
}

/// forge-config: layer2.fuzz.runs = 2000
Expand Down

0 comments on commit 06e190c

Please sign in to comment.