Skip to content

Commit

Permalink
fix(execution): fix bug in get_execution_config_for_block and add test (
Browse files Browse the repository at this point in the history
  • Loading branch information
Yael-Starkware authored Sep 14, 2023
1 parent 1352b14 commit a2ad830
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
55 changes: 54 additions & 1 deletion crates/papyrus_execution/src/execution_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,4 +616,57 @@ fn test_default_execution_config() {
let config_from_file = test_get_default_execution_config();
assert_eq!(expected_config, config_from_file);
}
// TODO(Omri): Test loading of configuration according to the given block number.

fn fill_up_block_execution_config_segment_with_value(value: usize) -> BlockExecutionConfig {
let vm_resource_fee_cost = HashMap::new();
let vm_resource_fee_cost = Arc::new(vm_resource_fee_cost);
BlockExecutionConfig {
fee_contract_address: contract_address!(format!("{:x}", value).as_str()),
invoke_tx_max_n_steps: value as u32,
validate_tx_max_n_steps: value as u32,
max_recursion_depth: value,
step_gas_cost: value as u64,
initial_gas_cost: value as u64,
vm_resource_fee_cost,
}
}

#[test]
/// Test for the get_execution_config_for_block function.
fn test_get_execution_config_for_block() {
let mut execution_config_segments: BTreeMap<BlockNumber, BlockExecutionConfig> =
BTreeMap::new();
let segment_block_numbers = vec![0, 67, 1005, 20369];
for block_number in segment_block_numbers {
execution_config_segments.insert(
BlockNumber(block_number as u64),
fill_up_block_execution_config_segment_with_value(block_number),
);
}
let execution_config_by_block = ExecutionConfigByBlock { execution_config_segments };

assert_eq!(
execution_config_by_block.get_execution_config_for_block(BlockNumber(0)).unwrap(),
&fill_up_block_execution_config_segment_with_value(0),
"Failed to get config for {:?}",
BlockNumber(0),
);
assert_eq!(
execution_config_by_block.get_execution_config_for_block(BlockNumber(67)).unwrap(),
&fill_up_block_execution_config_segment_with_value(67),
"Failed to get config for {:?}",
BlockNumber(67),
);
assert_eq!(
execution_config_by_block.get_execution_config_for_block(BlockNumber(517)).unwrap(),
&fill_up_block_execution_config_segment_with_value(67),
"Failed to get config for {:?}",
BlockNumber(517),
);
assert_eq!(
execution_config_by_block.get_execution_config_for_block(BlockNumber(20400)).unwrap(),
&fill_up_block_execution_config_segment_with_value(20369),
"Failed to get config for {:?}",
BlockNumber(20400),
);
}
6 changes: 3 additions & 3 deletions crates/papyrus_execution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ impl ExecutionConfigByBlock {
// Ok(segments.upper_bound(std::ops::Bound::Included(&block_number)).value().unwrap().
// clone())

for (segment_block_number, segment) in segments.iter() {
if block_number < *segment_block_number {
for (segment_block_number, segment) in segments.iter().rev() {
if block_number >= *segment_block_number {
return Ok(segment);
}
}
return segments.values().last().ok_or(ExecutionError::ConfigContentError);
Err(ExecutionError::ConfigContentError)
}
}

Expand Down

0 comments on commit a2ad830

Please sign in to comment.