diff --git a/extensions/scarb-snforge-test-collector/src/compilation/test_collector/config.rs b/extensions/scarb-snforge-test-collector/src/compilation/test_collector/config.rs index 68c03c85d..581b65e88 100644 --- a/extensions/scarb-snforge-test-collector/src/compilation/test_collector/config.rs +++ b/extensions/scarb-snforge-test-collector/src/compilation/test_collector/config.rs @@ -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 { @@ -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) diff --git a/extensions/scarb-snforge-test-collector/tests/test.rs b/extensions/scarb-snforge-test-collector/tests/test.rs index 5ee1d46f4..c589f1099 100644 --- a/extensions/scarb-snforge-test-collector/tests/test.rs +++ b/extensions/scarb-snforge-test-collector/tests/test.rs @@ -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);