Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
lints and fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
tdelabro committed Dec 20, 2023
1 parent 6dab351 commit eae958a
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ fn test_call_contract() {
calldata: calldata.clone(),
..trivial_external_entry_point()
};
let call_info = entry_point_call.clone().execute_directly(&mut state).unwrap();
let call_info = entry_point_call.execute_directly(&mut state).unwrap();

let expected_execution = CallExecution { retdata: retdata![value], ..Default::default() };
let expected_inner_call_info = CallInfo {
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/execution/entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ struct RecursionDepthGuard {

impl RecursionDepthGuard {
fn new(current_depth: Arc<RefCell<usize>>, max_depth: usize) -> Self {
Self { current_depth: current_depth.clone(), max_depth }
Self { current_depth, max_depth }
}

// Tries to increment the current recursion depth and returns an error if the maximum depth
Expand Down
14 changes: 8 additions & 6 deletions crates/blockifier/src/execution/entry_point_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,12 +526,14 @@ fn test_cairo1_entry_point_segment_arena() {
..trivial_external_entry_point()
};

assert!(entry_point_call
.execute_directly(&mut state)
.unwrap()
.vm_resources
.builtin_instance_counter
.contains_key(BuiltinName::segment_arena.name()));
assert!(
entry_point_call
.execute_directly(&mut state)
.unwrap()
.vm_resources
.builtin_instance_counter
.contains_key(BuiltinName::segment_arena.name())
);
}

#[test]
Expand Down
6 changes: 4 additions & 2 deletions crates/blockifier/src/execution/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,10 @@ pub fn keccak(

if remainder != 0 {
return Err(SyscallExecutionError::SyscallError {
error_data: vec![StarkFelt::try_from(INVALID_INPUT_LENGTH_ERROR)
.map_err(SyscallExecutionError::from)?],
error_data: vec![
StarkFelt::try_from(INVALID_INPUT_LENGTH_ERROR)
.map_err(SyscallExecutionError::from)?,
],
});
}

Expand Down
3 changes: 3 additions & 0 deletions crates/blockifier/src/state/cached_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ impl<S: StateReader> StateReader for CachedState<S> {
Ok(*class_hash)
}

#[allow(clippy::map_entry)]
// Clippy solution don't work because it required two mutable ref to self
// Could probably be solved with interior mutability
fn get_compiled_contract_class(&mut self, class_hash: ClassHash) -> StateResult<ContractClass> {
if !self.class_hash_to_class.contains_key(&class_hash) {
let contract_class = self.global_class_hash_to_class().cache_get(&class_hash).cloned();
Expand Down
19 changes: 10 additions & 9 deletions crates/blockifier/src/transaction/account_transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,12 @@ fn test_infinite_recursion(
if success {
assert!(tx_execution_info.revert_error.is_none());
} else {
assert!(tx_execution_info
.revert_error
.unwrap()
.contains("RunResources has no remaining steps."));
assert!(
tx_execution_info
.revert_error
.unwrap()
.contains("RunResources has no remaining steps.")
);
}
}

Expand Down Expand Up @@ -939,10 +941,9 @@ fn test_insufficient_max_fee_reverts(
.unwrap();
assert!(tx_execution_info3.is_reverted());
assert!(tx_execution_info3.actual_fee == actual_fee_depth1);
assert!(tx_execution_info3
.revert_error
.unwrap()
.contains("RunResources has no remaining steps."));
assert!(
tx_execution_info3.revert_error.unwrap().contains("RunResources has no remaining steps.")
);
}

#[rstest]
Expand Down Expand Up @@ -1089,7 +1090,7 @@ fn test_count_actual_storage_changes(
let account_tx = account_invoke_tx(InvokeTxArgs {
nonce: nonce_manager.next(account_address),
calldata: transfer_calldata,
..invoke_args.clone()
..invoke_args
});
let execution_info = account_tx.execute_raw(&mut state, &block_context, true, true).unwrap();

Expand Down
16 changes: 9 additions & 7 deletions crates/blockifier/src/transaction/execution_flavors_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ fn test_simulate_validate_charge_fee_pre_validate(
let result = account_invoke_tx(invoke_tx_args! {
resource_bounds: l1_resource_bounds(MAX_L1_GAS_AMOUNT, gas_price - 1),
nonce: nonce_manager.next(account_address),
..pre_validation_base_args.clone()
..pre_validation_base_args
})
.execute(&mut state, &block_context, charge_fee, validate);
if !charge_fee {
Expand Down Expand Up @@ -480,7 +480,7 @@ fn test_simulate_validate_charge_fee_mid_execution(
resource_bounds: l1_resource_bounds(huge_gas_limit, gas_price),
calldata: recurse_calldata(test_contract_address, false, 10000),
nonce: nonce_manager.next(account_address),
..execution_base_args.clone()
..execution_base_args
})
.execute(&mut state, &low_step_block_context, charge_fee, validate)
.unwrap();
Expand Down Expand Up @@ -616,11 +616,13 @@ fn test_simulate_validate_charge_fee_post_execution(
.unwrap();
assert_eq!(tx_execution_info.is_reverted(), charge_fee);
if charge_fee {
assert!(tx_execution_info
.revert_error
.clone()
.unwrap()
.contains("Insufficient fee token balance."));
assert!(
tx_execution_info
.revert_error
.clone()
.unwrap()
.contains("Insufficient fee token balance.")
);
}
check_gas_and_fee(
&block_context,
Expand Down
12 changes: 5 additions & 7 deletions crates/blockifier/src/transaction/post_execution_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ fn test_revert_on_overdraft(
fee_token_address
),
version,
resource_bounds: max_resource_bounds.clone(),
resource_bounds: max_resource_bounds,
nonce: nonce_manager.next(account_address),
},
)
Expand Down Expand Up @@ -245,7 +245,7 @@ fn test_revert_on_resource_overuse(
&block_context,
invoke_tx_args! {
max_fee,
resource_bounds: max_resource_bounds.clone(),
resource_bounds: max_resource_bounds,
nonce: nonce_manager.next(account_address),
calldata: write_a_lot_calldata(),
..base_args.clone()
Expand Down Expand Up @@ -295,11 +295,9 @@ fn test_revert_on_resource_overuse(

// Assert the transaction was reverted with the correct error.
if is_revertible {
assert!(execution_info_result
.unwrap()
.revert_error
.unwrap()
.starts_with(expected_error_prefix));
assert!(
execution_info_result.unwrap().revert_error.unwrap().starts_with(expected_error_prefix)
);
} else {
assert_matches!(
execution_info_result.unwrap_err(),
Expand Down
18 changes: 8 additions & 10 deletions crates/blockifier/src/transaction/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ fn expected_validate_call_info(
usize::from(entry_point_selector_name == constants::VALIDATE_ENTRY_POINT_NAME)
}
CairoVersion::Cairo1 => {
if entry_point_selector_name == constants::VALIDATE_ENTRY_POINT_NAME {
7
} else {
2
}
if entry_point_selector_name == constants::VALIDATE_ENTRY_POINT_NAME { 7 } else { 2 }
}
};
let n_memory_holes = match cairo_version {
Expand Down Expand Up @@ -1621,7 +1617,7 @@ fn test_only_query_flag(#[case] only_query: bool) {
[
execute_calldata,
expected_block_info.clone().to_vec(),
expected_tx_info.clone(),
expected_tx_info,
expected_call_info,
]
.concat()
Expand Down Expand Up @@ -1754,8 +1750,10 @@ fn test_execute_tx_with_invalid_transaction_version() {
});

let execution_info = account_tx.execute(state, block_context, true, true).unwrap();
assert!(execution_info
.revert_error
.unwrap()
.contains(format!("ASSERT_EQ instruction failed: {} != 1.", invalid_version).as_str()));
assert!(
execution_info
.revert_error
.unwrap()
.contains(format!("ASSERT_EQ instruction failed: {} != 1.", invalid_version).as_str())
);
}

0 comments on commit eae958a

Please sign in to comment.