Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix snforge-test-collector's default available_gas value #1057

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use serde::Serialize;

const FORK_ATTR: &str = "fork";
const FUZZER_ATTR: &str = "fuzzer";

const AVAILABLE_GAS_ATTR: &str = "available_gas";
/// Expectation for a panic case.
#[derive(Debug, Clone, PartialEq, Serialize)]
pub enum ExpectedPanicValue {
Expand Down Expand Up @@ -147,15 +147,26 @@ pub fn forge_try_extract_test_config(

let result = maybe_test_config.map(
|TestConfig {
available_gas,
mut available_gas,
expectation,
ignored,
}| SingleTestConfig {
available_gas,
expected_result: expectation.into(),
ignored,
fork_config,
fuzzer_config,
}| {
// Older versions will crash if the default is passed through
let available_gas_attr = attrs
.iter()
.find(|attr| attr.id.as_str() == AVAILABLE_GAS_ATTR);

if available_gas_attr.is_none() {
available_gas = None
}

SingleTestConfig {
available_gas,
expected_result: expectation.into(),
ignored,
fork_config,
fuzzer_config,
}
},
);
Ok(result)
Expand Down
5 changes: 1 addition & 4 deletions extensions/scarb-snforge-test-collector/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ fn forge_test_locations() {
assert_eq!(&json[1]["test_cases"][0]["name"], "tests::tests::test");
assert_eq!(&json[1]["tests_location"], "Tests");

assert_eq!(
&json[0]["test_cases"][0]["available_gas"],
&Value::Number(Number::from(u32::MAX))
);
assert_eq!(&json[0]["test_cases"][0]["available_gas"], &Value::Null);
war-in marked this conversation as resolved.
Show resolved Hide resolved
assert_eq!(&json[0]["test_cases"][0]["expected_result"], "Success");
assert_eq!(&json[0]["test_cases"][0]["fork_config"], &Value::Null);
assert_eq!(&json[0]["test_cases"][0]["fuzzer_config"], &Value::Null);
Expand Down