Skip to content

Commit

Permalink
Fix snforge-test-collector's default available_gas value (#1057)
Browse files Browse the repository at this point in the history
This needs to be `None` because older versions of snforge would crash on
`u32::max` (which seems to be a default value), with an error that the
attribute is not supported.
  • Loading branch information
Arcticae authored Jan 17, 2024
1 parent c55a25d commit a0fba83
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
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);
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

0 comments on commit a0fba83

Please sign in to comment.