Commit 2d86cab7 authored by smartcontracts's avatar smartcontracts Committed by GitHub

feat: timeout fuzz tests after 10 minutes (#13207)

* feat: timeout fuzz tests after 10 minutes

Uses the new fuzz test timeout feature that we merged into foundry
to limit individual test runs to 10 minutes. Simplifies how we
need to deal with heavy fuzz testing.

* fix: improve bounds for OptimismPortal tests

Improves the fuzz bounds for the OptimismPortal tests so that
they can complete 20000 runs without throwing.
parent b002feab
......@@ -3,7 +3,7 @@ version: 2.1
parameters:
ci_builder_image:
type: string
default: us-docker.pkg.dev/oplabs-tools-artifacts/images/ci-builder:v0.54.0
default: us-docker.pkg.dev/oplabs-tools-artifacts/images/ci-builder:v0.55.0
ci_builder_rust_image:
type: string
default: us-docker.pkg.dev/oplabs-tools-artifacts/images/ci-builder-rust:latest
......
......@@ -83,10 +83,12 @@ depth = 32
[profile.ciheavy.fuzz]
runs = 20000
timeout = 600
[profile.ciheavy.invariant]
runs = 128
depth = 512
timeout = 600
################################################################
# PROFILE: LITE #
......
......@@ -201,7 +201,6 @@ contract OptimismPortal_Test is CommonTest {
}
/// @dev Tests that `depositTransaction` succeeds when msg.sender == tx.origin and non-custom gas is used.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositTransaction_senderIsOrigin_succeeds(
address _to,
uint256 _mint,
......@@ -227,7 +226,6 @@ contract OptimismPortal_Test is CommonTest {
}
/// @dev Tests that `depositTransaction` succeeds when msg.sender != tx.origin and non-custom gas is used.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositTransaction_senderNotOrigin_succeeds(
address _to,
uint256 _mint,
......@@ -310,7 +308,6 @@ contract OptimismPortal_Test is CommonTest {
}
/// @dev Tests that `depositTransaction` succeeds for an EOA.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositTransaction_eoa_succeeds(
address _to,
uint64 _gasLimit,
......@@ -355,7 +352,6 @@ contract OptimismPortal_Test is CommonTest {
}
/// @dev Tests that `depositTransaction` succeeds for a contract.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositTransaction_contract_succeeds(
address _to,
uint64 _gasLimit,
......@@ -1214,7 +1210,6 @@ contract OptimismPortal_FinalizeWithdrawal_Test is CommonTest {
}
/// @dev Tests that `finalizeWithdrawalTransaction` succeeds.
/// forge-config: ciheavy.fuzz.runs = 8192
function testDiff_finalizeWithdrawalTransaction_succeeds(
address _sender,
address _target,
......@@ -1337,7 +1332,6 @@ contract OptimismPortalResourceFuzz_Test is CommonTest {
uint256 constant MAX_GAS_LIMIT = 30_000_000;
/// @dev Test that various values of the resource metering config will not break deposits.
/// forge-config: ciheavy.fuzz.runs = 10000
function testFuzz_systemConfigDeposit_succeeds(
uint32 _maxResourceLimit,
uint8 _elasticityMultiplier,
......@@ -1356,8 +1350,13 @@ contract OptimismPortalResourceFuzz_Test is CommonTest {
uint64 gasLimit = systemConfig.gasLimit();
// Bound resource config
_systemTxMaxGas = uint32(bound(_systemTxMaxGas, 0, gasLimit - 21000));
_maxResourceLimit = uint32(bound(_maxResourceLimit, 21000, MAX_GAS_LIMIT / 8));
_maxResourceLimit = uint32(bound(_maxResourceLimit, 21000, gasLimit - _systemTxMaxGas));
_maximumBaseFee = uint128(bound(_maximumBaseFee, 1, type(uint128).max));
_minimumBaseFee = uint32(bound(_minimumBaseFee, 0, _maximumBaseFee - 1));
_gasLimit = uint64(bound(_gasLimit, 21000, _maxResourceLimit));
_gasLimit = uint64(bound(_gasLimit, 0, gasLimit));
_prevBaseFee = uint128(bound(_prevBaseFee, 0, 3 gwei));
_prevBoughtGas = uint64(bound(_prevBoughtGas, 0, _maxResourceLimit - _gasLimit));
_blockDiff = uint8(bound(_blockDiff, 0, 3));
......@@ -1365,11 +1364,16 @@ contract OptimismPortalResourceFuzz_Test is CommonTest {
_elasticityMultiplier = uint8(bound(_elasticityMultiplier, 1, type(uint8).max));
// Prevent values that would cause reverts
vm.assume(gasLimit >= _gasLimit);
vm.assume(_minimumBaseFee < _maximumBaseFee);
vm.assume(uint256(_maxResourceLimit) + uint256(_systemTxMaxGas) <= gasLimit);
vm.assume(((_maxResourceLimit / _elasticityMultiplier) * _elasticityMultiplier) == _maxResourceLimit);
// Although we typically want to limit the usage of vm.assume, we've constructed the above
// bounds to satisfy the assumptions listed in this specific section. These assumptions
// serve only to act as an additional sanity check on top of the bounds and should not
// result in an unnecessary number of test rejections.
vm.assume(gasLimit >= _gasLimit);
vm.assume(_minimumBaseFee < _maximumBaseFee);
// Base fee can increase quickly and mean that we can't buy the amount of gas we want.
// Here we add a VM assumption to bound the potential increase.
// Compute the maximum possible increase in base fee.
......@@ -1472,7 +1476,6 @@ contract OptimismPortalWithMockERC20_Test is OptimismPortal_FinalizeWithdrawal_T
}
/// @dev Tests that `depositERC20Transaction` succeeds when msg.sender == tx.origin.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositERC20Transaction_senderIsOrigin_succeeds(
address _to,
uint256 _mint,
......@@ -1498,7 +1501,6 @@ contract OptimismPortalWithMockERC20_Test is OptimismPortal_FinalizeWithdrawal_T
}
/// @dev Tests that `depositERC20Transaction` succeeds when msg.sender != tx.origin.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositERC20Transaction_senderNotOrigin_succeeds(
address _to,
uint256 _mint,
......@@ -1697,7 +1699,6 @@ contract OptimismPortalWithMockERC20_Test is OptimismPortal_FinalizeWithdrawal_T
}
/// @dev Tests that `depositTransaction` succeeds when a custom gas token is used but the msg.value is zero.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositTransaction_customGasTokenWithNoValueAndSenderIsOrigin_succeeds(
address _to,
uint256 _value,
......@@ -1721,7 +1722,6 @@ contract OptimismPortalWithMockERC20_Test is OptimismPortal_FinalizeWithdrawal_T
}
/// @dev Tests that `depositTransaction` succeeds when a custom gas token is used but the msg.value is zero.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositTransaction_customGasTokenWithNoValueAndSenderNotOrigin_succeeds(
address _to,
uint256 _value,
......
......@@ -211,7 +211,6 @@ contract OptimismPortal2_Test is CommonTest {
}
/// @dev Tests that `depositTransaction` succeeds for an EOA.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositTransaction_eoa_succeeds(
address _to,
uint64 _gasLimit,
......@@ -256,7 +255,6 @@ contract OptimismPortal2_Test is CommonTest {
}
/// @dev Tests that `depositTransaction` succeeds for a contract.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositTransaction_contract_succeeds(
address _to,
uint64 _gasLimit,
......@@ -1326,7 +1324,6 @@ contract OptimismPortal2_FinalizeWithdrawal_Test is CommonTest {
}
/// @dev Tests that `finalizeWithdrawalTransaction` succeeds.
/// forge-config: ciheavy.fuzz.runs = 8192
function testDiff_finalizeWithdrawalTransaction_succeeds(
address _sender,
address _target,
......@@ -1610,7 +1607,6 @@ contract OptimismPortal2_ResourceFuzz_Test is CommonTest {
}
/// @dev Test that various values of the resource metering config will not break deposits.
/// forge-config: ciheavy.fuzz.runs = 10000
function testFuzz_systemConfigDeposit_succeeds(
uint32 _maxResourceLimit,
uint8 _elasticityMultiplier,
......@@ -1629,8 +1625,13 @@ contract OptimismPortal2_ResourceFuzz_Test is CommonTest {
uint64 gasLimit = systemConfig.gasLimit();
// Bound resource config
_systemTxMaxGas = uint32(bound(_systemTxMaxGas, 0, gasLimit - 21000));
_maxResourceLimit = uint32(bound(_maxResourceLimit, 21000, MAX_GAS_LIMIT / 8));
_maxResourceLimit = uint32(bound(_maxResourceLimit, 21000, gasLimit - _systemTxMaxGas));
_maximumBaseFee = uint128(bound(_maximumBaseFee, 1, type(uint128).max));
_minimumBaseFee = uint32(bound(_minimumBaseFee, 0, _maximumBaseFee - 1));
_gasLimit = uint64(bound(_gasLimit, 21000, _maxResourceLimit));
_gasLimit = uint64(bound(_gasLimit, 0, gasLimit));
_prevBaseFee = uint128(bound(_prevBaseFee, 0, 3 gwei));
_prevBoughtGas = uint64(bound(_prevBoughtGas, 0, _maxResourceLimit - _gasLimit));
_blockDiff = uint8(bound(_blockDiff, 0, 3));
......@@ -1638,12 +1639,16 @@ contract OptimismPortal2_ResourceFuzz_Test is CommonTest {
_elasticityMultiplier = uint8(bound(_elasticityMultiplier, 1, type(uint8).max));
// Prevent values that would cause reverts
vm.assume(gasLimit >= _gasLimit);
vm.assume(_minimumBaseFee < _maximumBaseFee);
vm.assume(_baseFeeMaxChangeDenominator > 1);
vm.assume(uint256(_maxResourceLimit) + uint256(_systemTxMaxGas) <= gasLimit);
vm.assume(((_maxResourceLimit / _elasticityMultiplier) * _elasticityMultiplier) == _maxResourceLimit);
// Although we typically want to limit the usage of vm.assume, we've constructed the above
// bounds to satisfy the assumptions listed in this specific section. These assumptions
// serve only to act as an additional sanity check on top of the bounds and should not
// result in an unnecessary number of test rejections.
vm.assume(gasLimit >= _gasLimit);
vm.assume(_minimumBaseFee < _maximumBaseFee);
// Base fee can increase quickly and mean that we can't buy the amount of gas we want.
// Here we add a VM assumption to bound the potential increase.
// Compute the maximum possible increase in base fee.
......@@ -1746,7 +1751,6 @@ contract OptimismPortal2WithMockERC20_Test is OptimismPortal2_FinalizeWithdrawal
}
/// @dev Tests that `depositERC20Transaction` succeeds when msg.sender == tx.origin.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositERC20Transaction_senderIsOrigin_succeeds(
address _to,
uint256 _mint,
......@@ -1772,7 +1776,6 @@ contract OptimismPortal2WithMockERC20_Test is OptimismPortal2_FinalizeWithdrawal
}
/// @dev Tests that `depositERC20Transaction` succeeds when msg.sender != tx.origin.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositERC20Transaction_senderNotOrigin_succeeds(
address _to,
uint256 _mint,
......@@ -1980,7 +1983,6 @@ contract OptimismPortal2WithMockERC20_Test is OptimismPortal2_FinalizeWithdrawal
}
/// @dev Tests that `depositTransaction` succeeds when a custom gas token is used but the msg.value is zero.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositTransaction_customGasTokenWithNoValueAndSenderIsOrigin_succeeds(
address _to,
uint256 _value,
......@@ -2004,7 +2006,6 @@ contract OptimismPortal2WithMockERC20_Test is OptimismPortal2_FinalizeWithdrawal
}
/// @dev Tests that `depositTransaction` succeeds when a custom gas token is used but the msg.value is zero.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositTransaction_customGasTokenWithNoValueAndSenderNotOrigin_succeeds(
address _to,
uint256 _value,
......
......@@ -889,7 +889,6 @@ contract PreimageOracle_LargePreimageProposals_Test is Test {
/// @notice Tests that squeezing a large preimage proposal after the challenge period has passed always succeeds and
/// persists the correct data.
/// forge-config: ciheavy.fuzz.runs = 512
function testFuzz_squeezeLPP_succeeds(uint256 _numBlocks, uint32 _partOffset) public {
_numBlocks = bound(_numBlocks, 1, 2 ** 8);
_partOffset = uint32(bound(_partOffset, 0, _numBlocks * LibKeccak.BLOCK_SIZE_BYTES + 8 - 1));
......@@ -1087,7 +1086,6 @@ contract PreimageOracle_LargePreimageProposals_Test is Test {
/// @notice Tests that challenging the first divergence in a large preimage proposal at an arbitrary location
/// in the leaf values always succeeds.
/// forge-config: ciheavy.fuzz.runs = 512
function testFuzz_challenge_arbitraryLocation_succeeds(uint256 _lastCorrectLeafIdx, uint256 _numBlocks) public {
_numBlocks = bound(_numBlocks, 1, 2 ** 8);
_lastCorrectLeafIdx = bound(_lastCorrectLeafIdx, 0, _numBlocks - 1);
......@@ -1140,7 +1138,6 @@ contract PreimageOracle_LargePreimageProposals_Test is Test {
}
/// @notice Tests that challenging the a divergence in a large preimage proposal at the first leaf always succeeds.
/// forge-config: ciheavy.fuzz.runs = 1024
function testFuzz_challengeFirst_succeeds(uint256 _numBlocks) public {
_numBlocks = bound(_numBlocks, 1, 2 ** 8);
......
......@@ -228,7 +228,6 @@ contract LivenessGuard_FuzzOwnerManagement_Test is StdCheats, StdUtils, Liveness
mapping(address => uint256) privateKeys;
/// @dev Tests that the guard correctly manages the lastLive mapping when owners are added, removed, or swapped
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_ownerManagement_works(
uint256 initialOwners,
uint256 threshold,
......
......@@ -22,7 +22,6 @@ contract DeployVariations_Test is CommonTest {
}
}
/// forge-config: ciheavy.fuzz.runs = 512
/// @dev It should be possible to enable Fault Proofs with any mix of CGT and Alt-DA.
function testFuzz_enableFaultProofs_succeeds(bool _enableCGT, bool _enableAltDa) public virtual {
enableAddOns(_enableCGT, _enableAltDa);
......@@ -30,7 +29,6 @@ contract DeployVariations_Test is CommonTest {
super.setUp();
}
/// forge-config: ciheavy.fuzz.runs = 512
/// @dev It should be possible to enable Fault Proofs and Interop with any mix of CGT and Alt-DA.
function test_enableInteropAndFaultProofs_succeeds(bool _enableCGT, bool _enableAltDa) public virtual {
enableAddOns(_enableCGT, _enableAltDa);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment