Skip to content

Commit 1017bac

Browse files
authored
Remove setting unnamed argument in #[available_gas] (#3677)
<!-- Reference any GitHub issues resolved by this PR --> Closes #3109 ## Introduced changes <!-- A brief description of the changes --> - Remove possibility to set unnamed argument in `#[available_gas]`, e.g `#[available_gas(5)]` ## Checklist <!-- Make sure all of these are complete --> - [x] Linked relevant issue - [x] Updated relevant documentation - [ ] Added relevant tests - [x] Performed self-review of the code - [x] Added changes to `CHANGELOG.md`
1 parent 6ee29c9 commit 1017bac

File tree

19 files changed

+141
-443
lines changed

19 files changed

+141
-443
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Forge
11+
12+
#### Removed
13+
14+
- Possibility to use `#[available_gas]` with unnamed argument. Use named arguments instead, e.g. `#[available_gas(l2_gas: 5)]`.
15+
1016
## [0.49.0] - 2025-09-03
1117

1218
### Forge

crates/cheatnet/src/runtime_extensions/forge_config_extension/config.rs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,6 @@ use std::{fmt, num::NonZeroU32};
1010
use url::Url;
1111
// available gas
1212

13-
#[derive(Debug, Clone, Copy, CairoDeserialize, PartialEq)]
14-
pub enum RawAvailableGasConfig {
15-
MaxGas(usize),
16-
MaxResourceBounds(RawAvailableResourceBoundsConfig),
17-
}
18-
19-
impl RawAvailableGasConfig {
20-
#[must_use]
21-
pub fn is_zero(&self) -> bool {
22-
match self {
23-
RawAvailableGasConfig::MaxGas(amount) => *amount == 0,
24-
RawAvailableGasConfig::MaxResourceBounds(bounds) => {
25-
bounds.to_gas_vector() == GasVector::ZERO
26-
}
27-
}
28-
}
29-
}
30-
3113
#[derive(Debug, Clone, Copy, CairoDeserialize, PartialEq)]
3214
pub struct RawAvailableResourceBoundsConfig {
3315
pub l1_gas: usize,
@@ -44,6 +26,11 @@ impl RawAvailableResourceBoundsConfig {
4426
l2_gas: GasAmount(self.l2_gas as u64),
4527
}
4628
}
29+
30+
#[must_use]
31+
pub fn is_zero(&self) -> bool {
32+
self.to_gas_vector() == GasVector::ZERO
33+
}
4734
}
4835

4936
// fork
@@ -179,7 +166,7 @@ pub struct RawPredeployedContractsConfig {
179166
#[derive(Debug, Default, Clone)]
180167
pub struct RawForgeConfig {
181168
pub fork: Option<RawForkConfig>,
182-
pub available_gas: Option<RawAvailableGasConfig>,
169+
pub available_gas: Option<RawAvailableResourceBoundsConfig>,
183170
pub ignore: Option<RawIgnoreConfig>,
184171
pub should_panic: Option<RawShouldPanicConfig>,
185172
pub fuzzer: Option<RawFuzzerConfig>,

crates/forge-runner/src/gas.rs

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ use blockifier::transaction::objects::HasRelatedFeeType;
1212
use blockifier::utils::u64_from_usize;
1313
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
1414
use cheatnet::runtime_extensions::call_to_blockifier_runtime_extension::rpc::UsedResources;
15-
use cheatnet::runtime_extensions::forge_config_extension::config::RawAvailableGasConfig;
15+
use cheatnet::runtime_extensions::forge_config_extension::config::RawAvailableResourceBoundsConfig;
1616
use cheatnet::state::ExtendedStateReader;
17-
use foundry_ui::UI;
18-
use foundry_ui::components::warning::WarningMessage;
1917
use starknet_api::execution_resources::{GasAmount, GasVector};
2018
use starknet_api::transaction::EventContent;
2119
use starknet_api::transaction::fields::GasVectorComputationMode;
@@ -144,35 +142,20 @@ fn get_state_resources(
144142
}
145143

146144
pub fn check_available_gas(
147-
available_gas: Option<RawAvailableGasConfig>,
145+
available_gas: Option<RawAvailableResourceBoundsConfig>,
148146
summary: TestCaseSummary<Single>,
149-
ui: &UI,
150147
) -> TestCaseSummary<Single> {
151148
match summary {
152149
TestCaseSummary::Passed {
153150
name,
154151
gas_info,
155152
debugging_trace,
156153
..
157-
} if available_gas.is_some_and(|available_gas| match available_gas {
158-
RawAvailableGasConfig::MaxGas(gas) => {
159-
// todo(3109): remove uunnamed argument in available_gas
160-
ui.println(&WarningMessage::new(
161-
"Setting available_gas with unnamed argument is deprecated. \
162-
Consider setting resource bounds (l1_gas, l1_data_gas and l2_gas) explicitly.",
163-
));
164-
// convert resource bounds to classic l1_gas using formula
165-
// l1_gas + l1_data_gas + (l2_gas / 40000)
166-
// because 100 l2_gas = 0.0025 l1_gas
167-
(gas_info.l1_gas + gas_info.l1_data_gas + (gas_info.l2_gas / 40000))
168-
> GasAmount(gas as u64)
169-
}
170-
RawAvailableGasConfig::MaxResourceBounds(bounds) => {
171-
let av_gas = bounds.to_gas_vector();
172-
gas_info.l1_gas > av_gas.l1_gas
173-
|| gas_info.l1_data_gas > av_gas.l1_data_gas
174-
|| gas_info.l2_gas > av_gas.l2_gas
175-
}
154+
} if available_gas.is_some_and(|available_gas| {
155+
let av_gas = available_gas.to_gas_vector();
156+
gas_info.l1_gas > av_gas.l1_gas
157+
|| gas_info.l1_data_gas > av_gas.l1_data_gas
158+
|| gas_info.l2_gas > av_gas.l2_gas
176159
}) =>
177160
{
178161
TestCaseSummary::Failed {

crates/forge-runner/src/lib.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,32 +109,27 @@ pub fn run_for_test_case(
109109
forge_config: Arc<ForgeConfig>,
110110
versioned_program_path: Arc<Utf8PathBuf>,
111111
send: Sender<()>,
112-
ui: &Arc<UI>,
113112
) -> JoinHandle<Result<AnyTestCaseSummary>> {
114113
if case.config.fuzzer_config.is_none() {
115-
let ui = ui.clone();
116114
tokio::task::spawn(async move {
117115
let res = run_test(
118116
case,
119117
casm_program,
120118
forge_config,
121119
versioned_program_path,
122120
send,
123-
ui,
124121
)
125122
.await?;
126123
Ok(AnyTestCaseSummary::Single(res))
127124
})
128125
} else {
129-
let ui = ui.clone();
130126
tokio::task::spawn(async move {
131127
let res = run_with_fuzzing(
132128
case,
133129
casm_program,
134130
forge_config.clone(),
135131
versioned_program_path,
136132
send,
137-
ui,
138133
)
139134
.await??;
140135
Ok(AnyTestCaseSummary::Fuzzing(res))
@@ -148,7 +143,6 @@ fn run_with_fuzzing(
148143
forge_config: Arc<ForgeConfig>,
149144
versioned_program_path: Arc<Utf8PathBuf>,
150145
send: Sender<()>,
151-
ui: Arc<UI>,
152146
) -> JoinHandle<Result<TestCaseSummary<Fuzzing>>> {
153147
tokio::task::spawn(async move {
154148
let test_runner_config = &forge_config.test_runner_config;
@@ -174,7 +168,6 @@ fn run_with_fuzzing(
174168
let mut tasks = FuturesUnordered::new();
175169

176170
for _ in 1..=fuzzer_runs.get() {
177-
let ui = ui.clone();
178171
tasks.push(run_fuzz_test(
179172
case.clone(),
180173
casm_program.clone(),
@@ -183,7 +176,6 @@ fn run_with_fuzzing(
183176
send.clone(),
184177
fuzzing_send.clone(),
185178
rng.clone(),
186-
ui,
187179
));
188180
}
189181

crates/forge-runner/src/package_tests/with_config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::{TestCase, TestTarget};
22
use crate::expected_result::{ExpectedPanicValue, ExpectedTestResult};
33
use cheatnet::runtime_extensions::forge_config_extension::config::{
4-
Expected, RawAvailableGasConfig, RawForgeConfig, RawForkConfig, RawFuzzerConfig,
4+
Expected, RawAvailableResourceBoundsConfig, RawForgeConfig, RawForkConfig, RawFuzzerConfig,
55
RawShouldPanicConfig,
66
};
77
use conversions::serde::serialize::SerializeToFeltVec;
@@ -14,7 +14,7 @@ pub type TestCaseWithConfig = TestCase<TestCaseConfig>;
1414
/// see [`super::with_config_resolved::TestCaseResolvedConfig`] for more info
1515
#[derive(Debug, Clone)]
1616
pub struct TestCaseConfig {
17-
pub available_gas: Option<RawAvailableGasConfig>,
17+
pub available_gas: Option<RawAvailableResourceBoundsConfig>,
1818
pub ignored: bool,
1919
pub expected_result: ExpectedTestResult,
2020
pub fork_config: Option<RawForkConfig>,

crates/forge-runner/src/package_tests/with_config_resolved.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::expected_result::ExpectedTestResult;
33
use anyhow::Result;
44
use cairo_vm::types::program::Program;
55
use cheatnet::runtime_extensions::forge_config_extension::config::{
6-
RawAvailableGasConfig, RawFuzzerConfig,
6+
RawAvailableResourceBoundsConfig, RawFuzzerConfig,
77
};
88
use starknet_api::block::BlockNumber;
99
use universal_sierra_compiler_api::AssembledProgramWithDebugInfo;
@@ -33,7 +33,7 @@ pub struct ResolvedForkConfig {
3333
/// fetches block number
3434
#[derive(Debug, Clone, PartialEq)]
3535
pub struct TestCaseResolvedConfig {
36-
pub available_gas: Option<RawAvailableGasConfig>,
36+
pub available_gas: Option<RawAvailableResourceBoundsConfig>,
3737
pub ignored: bool,
3838
pub expected_result: ExpectedTestResult,
3939
pub fork_config: Option<ResolvedForkConfig>,

crates/forge-runner/src/running.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use cheatnet::state::{
2828
BlockInfoReader, CallTrace, CheatnetState, EncounteredErrors, ExtendedStateReader,
2929
};
3030
use execution::finalize_execution;
31-
use foundry_ui::UI;
3231
use hints::hints_by_representation;
3332
use rand::prelude::StdRng;
3433
use runtime::starknet::context::{build_context, set_max_steps};
@@ -65,7 +64,6 @@ pub fn run_test(
6564
forge_config: Arc<ForgeConfig>,
6665
versioned_program_path: Arc<Utf8PathBuf>,
6766
send: Sender<()>,
68-
ui: Arc<UI>,
6967
) -> JoinHandle<TestCaseSummary<Single>> {
7068
tokio::task::spawn_blocking(move || {
7169
// Due to the inability of spawn_blocking to be abruptly cancelled,
@@ -85,17 +83,10 @@ pub fn run_test(
8583
return TestCaseSummary::Interrupted {};
8684
}
8785

88-
extract_test_case_summary(
89-
run_result,
90-
&case,
91-
&forge_config,
92-
&versioned_program_path,
93-
&ui,
94-
)
86+
extract_test_case_summary(run_result, &case, &forge_config, &versioned_program_path)
9587
})
9688
}
9789

98-
#[expect(clippy::too_many_arguments)]
9990
pub(crate) fn run_fuzz_test(
10091
case: Arc<TestCaseWithResolvedConfig>,
10192
casm_program: Arc<AssembledProgramWithDebugInfo>,
@@ -104,7 +95,6 @@ pub(crate) fn run_fuzz_test(
10495
send: Sender<()>,
10596
fuzzing_send: Sender<()>,
10697
rng: Arc<Mutex<StdRng>>,
107-
ui: Arc<UI>,
10898
) -> JoinHandle<TestCaseSummary<Single>> {
10999
tokio::task::spawn_blocking(move || {
110100
// Due to the inability of spawn_blocking to be abruptly cancelled,
@@ -128,13 +118,7 @@ pub(crate) fn run_fuzz_test(
128118
return TestCaseSummary::Interrupted {};
129119
}
130120

131-
extract_test_case_summary(
132-
run_result,
133-
&case,
134-
&forge_config,
135-
&versioned_program_path,
136-
&ui,
137-
)
121+
extract_test_case_summary(run_result, &case, &forge_config, &versioned_program_path)
138122
})
139123
}
140124

@@ -391,7 +375,6 @@ fn extract_test_case_summary(
391375
case: &TestCaseWithResolvedConfig,
392376
forge_config: &ForgeConfig,
393377
versioned_program_path: &Utf8Path,
394-
ui: &UI,
395378
) -> TestCaseSummary<Single> {
396379
let contracts_data = &forge_config.test_runner_config.contracts_data;
397380
let trace_args = &forge_config.output_config.trace_args;
@@ -403,7 +386,6 @@ fn extract_test_case_summary(
403386
contracts_data,
404387
versioned_program_path,
405388
trace_args,
406-
ui,
407389
),
408390
RunResult::Error(run_error) => {
409391
let mut message = format!(

crates/forge-runner/src/test_case_summary.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use cheatnet::runtime_extensions::call_to_blockifier_runtime_extension::rpc::Use
1111
use cheatnet::runtime_extensions::forge_runtime_extension::contracts_data::ContractsData;
1212
use conversions::byte_array::ByteArray;
1313
use conversions::felt::ToShortString;
14-
use foundry_ui::UI;
1514
use num_traits::Pow;
1615
use shared::utils::build_readable_text;
1716
use starknet_api::execution_resources::GasVector;
@@ -325,7 +324,6 @@ impl TestCaseSummary<Single> {
325324
contracts_data: &ContractsData,
326325
versioned_program_path: &Utf8Path,
327326
trace_args: &TraceArgs,
328-
ui: &UI,
329327
) -> Self {
330328
let name = test_case.name.clone();
331329

@@ -354,7 +352,7 @@ impl TestCaseSummary<Single> {
354352
)),
355353
debugging_trace,
356354
};
357-
check_available_gas(test_case.config.available_gas, summary, ui)
355+
check_available_gas(test_case.config.available_gas, summary)
358356
}
359357
ExpectedTestResult::Panics(expected_panic_value) => TestCaseSummary::Failed {
360358
name,

crates/forge/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const MINIMAL_RECOMMENDED_SCARB_VERSION: Version = Version::new(2, 10, 0);
4242
const MINIMAL_SCARB_VERSION_PREBUILT_PLUGIN: Version = Version::new(2, 10, 0);
4343
const MINIMAL_USC_VERSION: Version = Version::new(2, 0, 0);
4444
const MINIMAL_SCARB_VERSION_FOR_SIERRA_GAS: Version = Version::new(2, 10, 0);
45+
// TODO(#3723) Bump `MINIMAL_SNFORGE_STD_VERSION` to 0.50.0 and `MINIMAL_SNFORGE_STD_DEPRECATED_VERSION` to 0.50.0
4546
const MINIMAL_SNFORGE_STD_VERSION: Version = Version::new(0, 48, 0);
4647
const MINIMAL_SNFORGE_STD_DEPRECATED_VERSION: Version = Version::new(0, 48, 0);
4748
pub const MINIMAL_SCARB_VERSION_FOR_V2_MACROS_REQUIREMENT: Version = Version::new(2, 12, 0);

crates/forge/src/run_tests/test_target.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ pub async fn run_for_test_target(
5757
forge_config.clone(),
5858
tests.sierra_program_path.clone(),
5959
send.clone(),
60-
&ui.clone(),
6160
));
6261
}
6362

0 commit comments

Comments
 (0)