Skip to content

Commit

Permalink
chore(invariant): remove persist_state config, commit by default (#7819)
Browse files Browse the repository at this point in the history
* chore(invariant): remove persist_state config, commit to backend by default

* Test snekmate fix

* Point to latest snekmate commit
  • Loading branch information
grandizzy committed May 6, 2024
1 parent e7f9b75 commit bfc6549
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 35 deletions.
1 change: 0 additions & 1 deletion crates/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ dictionary_weight = 80
include_storage = true
include_push_bytes = true
shrink_sequence = true
preserve_state = false

[fmt]
line_length = 100
Expand Down
6 changes: 0 additions & 6 deletions crates/config/src/invariant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ pub struct InvariantConfig {
pub shrink_sequence: bool,
/// The maximum number of attempts to shrink the sequence
pub shrink_run_limit: usize,
/// If set to true then VM state is committed and available for next call
/// Useful for handlers that use cheatcodes as roll or warp
/// Use it with caution, introduces performance penalty.
pub preserve_state: bool,
/// The maximum number of rejects via `vm.assume` which can be encountered during a single
/// invariant run.
pub max_assume_rejects: u32,
Expand All @@ -50,7 +46,6 @@ impl Default for InvariantConfig {
dictionary: FuzzDictionaryConfig { dictionary_weight: 80, ..Default::default() },
shrink_sequence: true,
shrink_run_limit: 2usize.pow(18_u32),
preserve_state: false,
max_assume_rejects: 65536,
gas_report_samples: 256,
}
Expand Down Expand Up @@ -81,7 +76,6 @@ impl InlineConfigParser for InvariantConfig {
"fail-on-revert" => conf_clone.fail_on_revert = parse_config_bool(key, value)?,
"call-override" => conf_clone.call_override = parse_config_bool(key, value)?,
"shrink-sequence" => conf_clone.shrink_sequence = parse_config_bool(key, value)?,
"preserve-state" => conf_clone.preserve_state = parse_config_bool(key, value)?,
_ => Err(InlineConfigParserError::InvalidConfigProperty(key.to_string()))?,
}
}
Expand Down
18 changes: 5 additions & 13 deletions crates/evm/evm/src/executors/invariant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use proptest::{
test_runner::{TestCaseError, TestRunner},
};
use result::{assert_invariants, can_continue};
use revm::{primitives::HashMap, DatabaseCommit};
use revm::primitives::HashMap;
use shrink::shrink_sequence;
use std::{cell::RefCell, collections::BTreeMap, sync::Arc};

Expand Down Expand Up @@ -211,16 +211,10 @@ impl<'a> InvariantExecutor<'a> {
while current_run < self.config.depth {
let (sender, (address, calldata)) = inputs.last().expect("no input generated");

// Executes the call from the randomly generated sequence.
let call_result = if self.config.preserve_state {
executor
.call_raw_committing(*sender, *address, calldata.clone(), U256::ZERO)
.expect("could not make raw evm call")
} else {
executor
.call_raw(*sender, *address, calldata.clone(), U256::ZERO)
.expect("could not make raw evm call")
};
// Execute call from the randomly generated sequence and commit state changes.
let call_result = executor
.call_raw_committing(*sender, *address, calldata.clone(), U256::ZERO)
.expect("could not make raw evm call");

if call_result.result.as_ref() == MAGIC_ASSUME {
inputs.pop();
Expand Down Expand Up @@ -252,8 +246,6 @@ impl<'a> InvariantExecutor<'a> {
warn!(target: "forge::test", "{error}");
}
}
// Commit changes to the database.
executor.backend.commit(state_changeset.clone());

fuzz_runs.push(FuzzCase {
calldata: calldata.clone(),
Expand Down
2 changes: 1 addition & 1 deletion crates/forge/tests/cli/ext_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn lil_web3() {
#[test]
#[cfg_attr(windows, ignore = "Windows cannot find installed programs")]
fn snekmate() {
ExtTester::new("pcaversaccio", "snekmate", "ed49a0454393673cdf9a4250dd7051c28e6ac35f")
ExtTester::new("pcaversaccio", "snekmate", "1aa50098720d49e04b257a4aa5138b3d737a0667")
.install_command(&["pnpm", "install", "--prefer-offline"])
// Try npm if pnpm fails / is not installed.
.install_command(&["npm", "install", "--prefer-offline"])
Expand Down
13 changes: 0 additions & 13 deletions crates/forge/tests/it/invariant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,21 +418,8 @@ async fn test_shrink_fail_on_revert() {
async fn test_invariant_preserve_state() {
let filter = Filter::new(".*", ".*", ".*fuzz/invariant/common/InvariantPreserveState.t.sol");
let mut runner = TEST_DATA_DEFAULT.runner();
// Should not fail with default options.
runner.test_options.invariant.fail_on_revert = true;
let results = runner.test_collect(&filter);
assert_multiple(
&results,
BTreeMap::from([(
"default/fuzz/invariant/common/InvariantPreserveState.t.sol:InvariantPreserveState",
vec![("invariant_preserve_state()", true, None, None, None)],
)]),
);

// same test should revert when preserve state enabled
runner.test_options.invariant.fail_on_revert = true;
runner.test_options.invariant.preserve_state = true;
let results = runner.test_collect(&filter);
assert_multiple(
&results,
BTreeMap::from([(
Expand Down
1 change: 0 additions & 1 deletion crates/forge/tests/it/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ impl ForgeTestProfile {
},
shrink_sequence: true,
shrink_run_limit: 2usize.pow(18u32),
preserve_state: false,
max_assume_rejects: 65536,
gas_report_samples: 256,
})
Expand Down

0 comments on commit bfc6549

Please sign in to comment.