-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(blockifier): gas_for_fee computation (#1804)
- Loading branch information
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
crates/blockifier/src/execution/entry_point_execution_test.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use starknet_api::execution_resources::GasAmount; | ||
|
||
use crate::execution::call_info::{CallExecution, CallInfo, ChargedResources}; | ||
use crate::execution::contract_class::TrackedResource; | ||
use crate::execution::entry_point_execution::to_gas_for_fee; | ||
|
||
#[test] | ||
/// Verifies that every call from the inner most to the outer has the expected gas_for_fee for the | ||
/// following topology (marked as TrackedResource(gas_consumed)): | ||
// Gas(8) -> Gas(3) -> VM(2) -> VM(1) | ||
// \ -> VM(4) | ||
// Expected values are 2 -> 1 -> 0 -> 0. | ||
// \-> 0. | ||
fn test_gas_for_fee() { | ||
// First branch - 3 nested calls. | ||
let mut inner_calls = vec![]; | ||
for (tracked_resource, gas_consumed, expected_gas_for_fee) in [ | ||
(TrackedResource::CairoSteps, 1, 0), | ||
(TrackedResource::CairoSteps, 2, 0), | ||
(TrackedResource::SierraGas, 3, 1), | ||
] { | ||
assert_eq!( | ||
to_gas_for_fee(&tracked_resource, gas_consumed, &inner_calls).0, | ||
expected_gas_for_fee | ||
); | ||
inner_calls = vec![CallInfo { | ||
execution: CallExecution { gas_consumed, ..Default::default() }, | ||
tracked_resource, | ||
inner_calls, | ||
charged_resources: ChargedResources { | ||
gas_for_fee: GasAmount(expected_gas_for_fee), | ||
..Default::default() | ||
}, | ||
..Default::default() | ||
}]; | ||
} | ||
|
||
// Second branch - 1 call. | ||
let (tracked_resource, gas_consumed, expected_gas_for_fee) = | ||
(TrackedResource::CairoSteps, 4, 0); | ||
assert_eq!(to_gas_for_fee(&tracked_resource, gas_consumed, &[]).0, expected_gas_for_fee); | ||
|
||
inner_calls.push(CallInfo { | ||
execution: CallExecution { gas_consumed, ..Default::default() }, | ||
tracked_resource, | ||
charged_resources: ChargedResources { | ||
gas_for_fee: GasAmount(expected_gas_for_fee), | ||
..Default::default() | ||
}, | ||
..Default::default() | ||
}); | ||
|
||
// Outer call. | ||
assert_eq!(to_gas_for_fee(&TrackedResource::SierraGas, 8, &inner_calls).0, 2); | ||
} |