diff --git a/crates/blockifier/src/blockifier/stateful_validator_test.rs b/crates/blockifier/src/blockifier/stateful_validator_test.rs index 4b030cd683..49d172758a 100644 --- a/crates/blockifier/src/blockifier/stateful_validator_test.rs +++ b/crates/blockifier/src/blockifier/stateful_validator_test.rs @@ -1,12 +1,10 @@ use rstest::rstest; -use starknet_api::core::Nonce; -use starknet_api::hash::StarkFelt; -use starknet_api::stark_felt; use starknet_api::transaction::{Fee, TransactionVersion}; use crate::blockifier::stateful_validator::StatefulValidator; use crate::bouncer::BouncerConfig; use crate::context::BlockContext; +use crate::nonce; use crate::test_utils::contracts::FeatureContract; use crate::test_utils::initial_test_state::{fund_account, test_state}; use crate::test_utils::{CairoVersion, NonceManager, BALANCE}; @@ -70,7 +68,7 @@ fn test_transaction_validator( let mut stateful_validator = StatefulValidator::create( state, block_context, - Nonce(stark_felt!(0_u32)), + nonce!(0_u32), BouncerConfig::create_for_testing(), ); diff --git a/crates/blockifier/src/bouncer_test.rs b/crates/blockifier/src/bouncer_test.rs index 11041d420a..fae71308da 100644 --- a/crates/blockifier/src/bouncer_test.rs +++ b/crates/blockifier/src/bouncer_test.rs @@ -2,9 +2,9 @@ use std::collections::{HashMap, HashSet}; use cairo_vm::serde::deserialize_program::BuiltinName; use rstest::rstest; -use starknet_api::core::{ClassHash, ContractAddress}; -use starknet_api::hash::StarkFelt; -use starknet_api::state::StorageKey; +use starknet_api::core::{ClassHash, ContractAddress, PatriciaKey}; +use starknet_api::hash::StarkHash; +use starknet_api::{class_hash, contract_address, patricia_key}; use super::BouncerConfig; use crate::blockifier::transaction_executor::{ @@ -14,6 +14,7 @@ use crate::bouncer::{Bouncer, BouncerWeights, BuiltinCount}; use crate::context::BlockContext; use crate::execution::call_info::ExecutionSummary; use crate::state::cached_state::{CachedState, StateChangesKeys}; +use crate::storage_key; use crate::test_utils::initial_test_state::test_state; use crate::transaction::errors::TransactionExecutionError; @@ -78,10 +79,10 @@ fn test_block_weights_has_room() { #[rstest] #[case::empty_initial_bouncer(Bouncer::new(BouncerConfig::default()))] #[case::non_empty_initial_bouncer(Bouncer { - executed_class_hashes: HashSet::from([ClassHash(StarkFelt::from(0_u128))]), + executed_class_hashes: HashSet::from([class_hash!(0_u128)]), visited_storage_entries: HashSet::from([( - ContractAddress::from(0_u128), - StorageKey::from(0_u128), + contract_address!(0_u128), + storage_key!(0_u128), )]), state_changes_keys: StateChangesKeys::create_for_testing(HashSet::from([ ContractAddress::from(0_u128), @@ -106,13 +107,10 @@ fn test_block_weights_has_room() { })] fn test_bouncer_update(#[case] initial_bouncer: Bouncer) { let execution_summary_to_update = ExecutionSummary { - executed_class_hashes: HashSet::from([ - ClassHash(StarkFelt::from(1_u128)), - ClassHash(StarkFelt::from(2_u128)), - ]), + executed_class_hashes: HashSet::from([class_hash!(1_u128), class_hash!(2_u128)]), visited_storage_entries: HashSet::from([ - (ContractAddress::from(1_u128), StorageKey::from(1_u128)), - (ContractAddress::from(2_u128), StorageKey::from(2_u128)), + (ContractAddress::from(1_u128), storage_key!(1_u128)), + (ContractAddress::from(2_u128), storage_key!(2_u128)), ]), ..Default::default() }; diff --git a/crates/blockifier/src/concurrency/versioned_state_proxy_test.rs b/crates/blockifier/src/concurrency/versioned_state_proxy_test.rs index 54c2a65422..240abb33b0 100644 --- a/crates/blockifier/src/concurrency/versioned_state_proxy_test.rs +++ b/crates/blockifier/src/concurrency/versioned_state_proxy_test.rs @@ -2,20 +2,16 @@ use std::collections::HashMap; use std::sync::{Arc, Mutex}; use std::thread; -use starknet_api::core::{ - calculate_contract_address, ClassHash, CompiledClassHash, ContractAddress, Nonce, PatriciaKey, -}; +use starknet_api::core::{calculate_contract_address, ClassHash, ContractAddress, PatriciaKey}; use starknet_api::hash::{StarkFelt, StarkHash}; -use starknet_api::state::StorageKey; use starknet_api::transaction::{Calldata, ContractAddressSalt, Fee, TransactionVersion}; -use starknet_api::{calldata, contract_address, patricia_key, stark_felt}; +use starknet_api::{calldata, class_hash, contract_address, patricia_key, stark_felt}; use crate::abi::abi_utils::{get_fee_token_var_address, get_storage_var_address}; use crate::concurrency::versioned_state_proxy::{ ThreadSafeVersionedState, VersionedState, VersionedStateProxy, }; use crate::context::BlockContext; -use crate::deploy_account_tx_args; use crate::state::cached_state::CachedState; use crate::state::state_api::{State, StateReader}; use crate::test_utils::contracts::FeatureContract; @@ -27,17 +23,18 @@ use crate::transaction::account_transaction::AccountTransaction; use crate::transaction::objects::{FeeType, TransactionInfoCreator}; use crate::transaction::test_utils::l1_resource_bounds; use crate::transaction::transactions::ExecutableTransaction; +use crate::{compiled_class_hash, deploy_account_tx_args, nonce, storage_key}; #[test] fn test_versioned_state_proxy() { // Test data let test_contract = FeatureContract::TestContract(CairoVersion::Cairo0); let contract_address = contract_address!("0x1"); - let key = StorageKey(patricia_key!("0x10")); + let key = storage_key!("0x10"); let stark_felt = stark_felt!(13_u8); - let nonce = Nonce(stark_felt!(2_u8)); - let class_hash = ClassHash(stark_felt!(27_u8)); - let compiled_class_hash = CompiledClassHash(stark_felt!(29_u8)); + let nonce = nonce!(2_u8); + let class_hash = class_hash!(27_u8); + let compiled_class_hash = compiled_class_hash!(29_u8); let contract_class = test_contract.get_class(); // Create the verioned state @@ -73,12 +70,12 @@ fn test_versioned_state_proxy() { ); // Write to the state. - let new_key = StorageKey(patricia_key!("0x11")); + let new_key = storage_key!("0x11"); let stark_felt_v3 = stark_felt!(14_u8); - let nonce_v4 = Nonce(stark_felt!(3_u8)); - let class_hash_v7 = ClassHash(stark_felt!(28_u8)); - let class_hash_v10 = ClassHash(stark_felt!(29_u8)); - let compiled_class_hash_v18 = CompiledClassHash(stark_felt!(30_u8)); + let nonce_v4 = nonce!(3_u8); + let class_hash_v7 = class_hash!(28_u8); + let class_hash_v10 = class_hash!(29_u8); + let compiled_class_hash_v18 = compiled_class_hash!(30_u8); let contract_class_v11 = FeatureContract::TestContract(CairoVersion::Cairo1).get_class(); versioned_state_proxys[3].set_storage_at(contract_address, new_key, stark_felt_v3).unwrap(); diff --git a/crates/blockifier/src/execution/deprecated_syscalls/deprecated_syscalls_test.rs b/crates/blockifier/src/execution/deprecated_syscalls/deprecated_syscalls_test.rs index d657f76bb4..7fd5198f68 100644 --- a/crates/blockifier/src/execution/deprecated_syscalls/deprecated_syscalls_test.rs +++ b/crates/blockifier/src/execution/deprecated_syscalls/deprecated_syscalls_test.rs @@ -6,14 +6,14 @@ use cairo_vm::vm::runners::cairo_runner::ExecutionResources; use num_traits::Pow; use pretty_assertions::assert_eq; use rstest::rstest; -use starknet_api::core::{calculate_contract_address, ChainId, Nonce, PatriciaKey}; +use starknet_api::core::{calculate_contract_address, ChainId, PatriciaKey}; use starknet_api::hash::{StarkFelt, StarkHash}; use starknet_api::state::StorageKey; use starknet_api::transaction::{ Calldata, ContractAddressSalt, EventContent, EventData, EventKey, Fee, TransactionHash, TransactionVersion, }; -use starknet_api::{calldata, patricia_key, stark_felt}; +use starknet_api::{calldata, stark_felt}; use test_case::test_case; use crate::abi::abi_utils::selector_from_name; @@ -38,7 +38,7 @@ use crate::transaction::objects::{ CommonAccountFields, DeprecatedTransactionInfo, TransactionInfo, }; use crate::versioned_constants::VersionedConstants; -use crate::{check_entry_point_execution_error_for_custom_hint, retdata}; +use crate::{check_entry_point_execution_error_for_custom_hint, nonce, retdata, storage_key}; #[test] fn test_storage_read_write() { @@ -147,7 +147,7 @@ fn test_nested_library_call() { execution: CallExecution::from_retdata(retdata![stark_felt!(value + 1)]), resources: storage_entry_point_resources.clone(), storage_read_values: vec![stark_felt!(0_u8), stark_felt!(value + 1)], - accessed_storage_keys: HashSet::from([StorageKey(patricia_key!(key + 1))]), + accessed_storage_keys: HashSet::from([storage_key!(key + 1)]), ..Default::default() }; let mut library_call_resources = &get_syscall_resources(DeprecatedSyscallSelector::LibraryCall) @@ -169,7 +169,7 @@ fn test_nested_library_call() { execution: CallExecution::from_retdata(retdata![stark_felt!(value)]), resources: storage_entry_point_resources.clone(), storage_read_values: vec![stark_felt!(0_u8), stark_felt!(value)], - accessed_storage_keys: HashSet::from([StorageKey(patricia_key!(key))]), + accessed_storage_keys: HashSet::from([storage_key!(key)]), ..Default::default() }; @@ -234,7 +234,7 @@ fn test_call_contract() { builtin_instance_counter: HashMap::from([(RANGE_CHECK_BUILTIN_NAME.to_string(), 2)]), }, storage_read_values: vec![StarkFelt::ZERO, stark_felt!(value)], - accessed_storage_keys: HashSet::from([StorageKey(patricia_key!(key))]), + accessed_storage_keys: HashSet::from([storage_key!(key)]), ..Default::default() }; let expected_call_info = CallInfo { @@ -451,7 +451,7 @@ fn test_tx_info(#[values(false, true)] only_query: bool) { } let tx_hash = TransactionHash(stark_felt!(1991_u16)); let max_fee = Fee(0); - let nonce = Nonce(stark_felt!(3_u16)); + let nonce = nonce!(3_u16); let sender_address = test_contract.get_instance_address(0); let expected_tx_info = calldata![ felt_to_stark_felt(&version), // Transaction version. diff --git a/crates/blockifier/src/execution/entry_point_test.rs b/crates/blockifier/src/execution/entry_point_test.rs index 5fd8ab2918..e3fe7f7f0a 100644 --- a/crates/blockifier/src/execution/entry_point_test.rs +++ b/crates/blockifier/src/execution/entry_point_test.rs @@ -8,9 +8,8 @@ use rstest::rstest; use starknet_api::core::{EntryPointSelector, PatriciaKey}; use starknet_api::deprecated_contract_class::{EntryPointOffset, EntryPointType}; use starknet_api::hash::{StarkFelt, StarkHash}; -use starknet_api::state::StorageKey; use starknet_api::transaction::{Calldata, TransactionVersion}; -use starknet_api::{calldata, patricia_key, stark_felt}; +use starknet_api::{calldata, stark_felt}; use crate::abi::abi_utils::{get_storage_var_address, selector_from_name}; use crate::context::{BlockContext, ChainInfo}; @@ -36,7 +35,7 @@ use crate::transaction::test_utils::{ use crate::transaction::transaction_types::TransactionType; use crate::transaction::transactions::ExecutableTransaction; use crate::versioned_constants::VersionedConstants; -use crate::{invoke_tx_args, retdata}; +use crate::{invoke_tx_args, retdata, storage_key}; const INNER_CALL_CONTRACT_IN_CALL_CHAIN_OFFSET: usize = 117; @@ -539,10 +538,7 @@ fn test_storage_related_members() { }; let actual_call_info = entry_point_call.execute_directly(&mut state).unwrap(); assert_eq!(actual_call_info.storage_read_values, vec![stark_felt!(0_u8), value]); - assert_eq!( - actual_call_info.accessed_storage_keys, - HashSet::from([StorageKey(patricia_key!(key))]) - ); + assert_eq!(actual_call_info.accessed_storage_keys, HashSet::from([storage_key!(key)])); } #[test] diff --git a/crates/blockifier/src/execution/syscalls/syscalls_test.rs b/crates/blockifier/src/execution/syscalls/syscalls_test.rs index 98a424a23b..864827afa4 100644 --- a/crates/blockifier/src/execution/syscalls/syscalls_test.rs +++ b/crates/blockifier/src/execution/syscalls/syscalls_test.rs @@ -9,7 +9,7 @@ use num_traits::Pow; use pretty_assertions::assert_eq; use rstest::rstest; use starknet_api::core::{ - calculate_contract_address, ChainId, ContractAddress, EthAddress, Nonce, PatriciaKey, + calculate_contract_address, ChainId, ContractAddress, EthAddress, PatriciaKey, }; use starknet_api::data_availability::DataAvailabilityMode; use starknet_api::hash::{StarkFelt, StarkHash}; @@ -19,7 +19,7 @@ use starknet_api::transaction::{ L2ToL1Payload, PaymasterData, Resource, ResourceBounds, ResourceBoundsMapping, Tip, TransactionHash, TransactionVersion, }; -use starknet_api::{calldata, patricia_key, stark_felt}; +use starknet_api::{calldata, stark_felt}; use test_case::test_case; use crate::abi::abi_utils::selector_from_name; @@ -50,8 +50,7 @@ use crate::transaction::objects::{ CommonAccountFields, CurrentTransactionInfo, DeprecatedTransactionInfo, TransactionInfo, }; use crate::versioned_constants::VersionedConstants; -use crate::{check_entry_point_execution_error_for_custom_hint, retdata}; - +use crate::{check_entry_point_execution_error_for_custom_hint, nonce, retdata, storage_key}; pub const REQUIRED_GAS_STORAGE_READ_WRITE_TEST: u64 = 27150; pub const REQUIRED_GAS_CALL_CONTRACT_TEST: u64 = 105680; pub const REQUIRED_GAS_LIBRARY_CALL_TEST: u64 = REQUIRED_GAS_CALL_CONTRACT_TEST; @@ -374,7 +373,7 @@ fn test_get_execution_info( let tx_hash = TransactionHash(stark_felt!(1991_u16)); let max_fee = Fee(42); - let nonce = Nonce(stark_felt!(3_u16)); + let nonce = nonce!(3_u16); let sender_address = test_contract_address; let expected_tx_info: Vec; @@ -622,7 +621,7 @@ fn test_nested_library_call() { }, resources: storage_entry_point_resources.clone(), storage_read_values: vec![stark_felt!(value + 1)], - accessed_storage_keys: HashSet::from([StorageKey(patricia_key!(key + 1))]), + accessed_storage_keys: HashSet::from([storage_key!(key + 1)]), ..Default::default() }; let library_call_resources = &get_syscall_resources(SyscallSelector::LibraryCall) @@ -651,7 +650,7 @@ fn test_nested_library_call() { }, resources: storage_entry_point_resources, storage_read_values: vec![stark_felt!(value)], - accessed_storage_keys: HashSet::from([StorageKey(patricia_key!(key))]), + accessed_storage_keys: HashSet::from([storage_key!(key)]), ..Default::default() }; diff --git a/crates/blockifier/src/fee/actual_cost_test.rs b/crates/blockifier/src/fee/actual_cost_test.rs index 2f534d0674..a8c5dbce0a 100644 --- a/crates/blockifier/src/fee/actual_cost_test.rs +++ b/crates/blockifier/src/fee/actual_cost_test.rs @@ -1,5 +1,4 @@ use rstest::{fixture, rstest}; -use starknet_api::core::Nonce; use starknet_api::hash::StarkFelt; use starknet_api::stark_felt; use starknet_api::transaction::{Fee, L2ToL1Payload, TransactionVersion}; @@ -11,7 +10,6 @@ use crate::fee::gas_usage::{ get_consumed_message_to_l2_emissions_cost, get_log_message_to_l1_emissions_cost, get_message_segment_length, }; -use crate::invoke_tx_args; use crate::state::cached_state::StateChangesCount; use crate::test_utils::contracts::FeatureContract; use crate::test_utils::initial_test_state::test_state; @@ -22,7 +20,7 @@ use crate::transaction::test_utils::{account_invoke_tx, calculate_class_info_for use crate::transaction::transactions::ExecutableTransaction; use crate::utils::{u128_from_usize, usize_from_u128}; use crate::versioned_constants::VersionedConstants; - +use crate::{invoke_tx_args, nonce}; #[fixture] fn versioned_constants() -> &'static VersionedConstants { VersionedConstants::latest_constants() @@ -344,7 +342,7 @@ fn test_calculate_tx_gas_usage(#[values(false, true)] use_kzg_da: bool) { sender_address: account_contract_address, calldata: execute_calldata, version: TransactionVersion::ONE, - nonce: Nonce(stark_felt!(1_u8)), + nonce: nonce!(1_u8), }); let calldata_length = account_tx.calldata_length(); diff --git a/crates/blockifier/src/state/cached_state_test.rs b/crates/blockifier/src/state/cached_state_test.rs index 71dd1054bd..8854b4f58a 100644 --- a/crates/blockifier/src/state/cached_state_test.rs +++ b/crates/blockifier/src/state/cached_state_test.rs @@ -14,7 +14,7 @@ use crate::test_utils::contracts::FeatureContract; use crate::test_utils::dict_state_reader::DictStateReader; use crate::test_utils::initial_test_state::test_state; use crate::test_utils::CairoVersion; - +use crate::{compiled_class_hash, nonce, storage_key}; const CONTRACT_ADDRESS: &str = "0x100"; fn set_initial_state_values( @@ -36,7 +36,7 @@ fn set_initial_state_values( fn get_uninitialized_storage_value() { let state: CachedState = CachedState::default(); let contract_address = contract_address!("0x1"); - let key = StorageKey(patricia_key!("0x10")); + let key = storage_key!("0x10"); assert_eq!(state.get_storage_at(contract_address, key).unwrap(), StarkFelt::default()); } @@ -45,8 +45,8 @@ fn get_uninitialized_storage_value() { fn get_and_set_storage_value() { let contract_address0 = contract_address!("0x100"); let contract_address1 = contract_address!("0x200"); - let key0 = StorageKey(patricia_key!("0x10")); - let key1 = StorageKey(patricia_key!("0x20")); + let key0 = storage_key!("0x10"); + let key1 = storage_key!("0x20"); let storage_val0: StarkFelt = stark_felt!("0x1"); let storage_val1: StarkFelt = stark_felt!("0x5"); @@ -78,8 +78,8 @@ fn cast_between_storage_mapping_types() { let contract_address0 = contract_address!("0x100"); let contract_address1 = contract_address!("0x200"); - let key0 = StorageKey(patricia_key!("0x10")); - let key1 = StorageKey(patricia_key!("0x20")); + let key0 = storage_key!("0x10"); + let key1 = storage_key!("0x20"); let storage_val0: StarkFelt = stark_felt!("0x1"); let storage_val1: StarkFelt = stark_felt!("0x5"); let storage_val2: StarkFelt = stark_felt!("0xa"); @@ -134,7 +134,7 @@ fn declare_contract() { fn get_and_increment_nonce() { let contract_address1 = contract_address!("0x100"); let contract_address2 = contract_address!("0x200"); - let initial_nonce = Nonce(stark_felt!("0x1")); + let initial_nonce = nonce!("0x1"); let mut state = CachedState::from(DictStateReader { address_to_nonce: HashMap::from([ @@ -147,17 +147,17 @@ fn get_and_increment_nonce() { assert_eq!(state.get_nonce_at(contract_address2).unwrap(), initial_nonce); assert!(state.increment_nonce(contract_address1).is_ok()); - let nonce1_plus_one = Nonce(stark_felt!("0x2")); + let nonce1_plus_one = nonce!("0x2"); assert_eq!(state.get_nonce_at(contract_address1).unwrap(), nonce1_plus_one); assert_eq!(state.get_nonce_at(contract_address2).unwrap(), initial_nonce); assert!(state.increment_nonce(contract_address1).is_ok()); - let nonce1_plus_two = Nonce(stark_felt!("0x3")); + let nonce1_plus_two = nonce!("0x3"); assert_eq!(state.get_nonce_at(contract_address1).unwrap(), nonce1_plus_two); assert_eq!(state.get_nonce_at(contract_address2).unwrap(), initial_nonce); assert!(state.increment_nonce(contract_address2).is_ok()); - let nonce2_plus_one = Nonce(stark_felt!("0x2")); + let nonce2_plus_one = nonce!("0x2"); assert_eq!(state.get_nonce_at(contract_address1).unwrap(), nonce1_plus_two); assert_eq!(state.get_nonce_at(contract_address2).unwrap(), nonce2_plus_one); } @@ -232,8 +232,8 @@ fn cached_state_state_diff_conversion() { // key_x will not be changed. // key_y will be changed, but only with contract_address2 the value ends up being different, so // should only appear with contract_address2. - let key_x = StorageKey(patricia_key!("0x10")); - let key_y = StorageKey(patricia_key!("0x20")); + let key_x = storage_key!("0x10"); + let key_y = storage_key!("0x20"); let storage_val0: StarkFelt = stark_felt!("0x1"); let storage_val1: StarkFelt = stark_felt!("0x5"); let storage_val2: StarkFelt = stark_felt!("0x6"); @@ -260,7 +260,7 @@ fn cached_state_state_diff_conversion() { // Declare a new class. let class_hash = FeatureContract::Empty(CairoVersion::Cairo0).get_class_hash(); // Some unused class hash. - let compiled_class_hash = CompiledClassHash(stark_felt!(1_u8)); + let compiled_class_hash = compiled_class_hash!(1_u8); state.set_compiled_class_hash(class_hash, compiled_class_hash).unwrap(); // Write the initial value using key contract_address1. @@ -279,7 +279,7 @@ fn cached_state_state_diff_conversion() { address_to_class_hash: IndexMap::from_iter([(contract_address2, new_class_hash)]), storage_updates: IndexMap::from_iter([(contract_address2, indexmap! {key_y => new_value})]), class_hash_to_compiled_class_hash: IndexMap::from_iter([(class_hash, compiled_class_hash)]), - address_to_nonce: IndexMap::from_iter([(contract_address2, Nonce(StarkFelt::from(1_u64)))]), + address_to_nonce: IndexMap::from_iter([(contract_address2, nonce!(1_u64))]), }; assert_eq!(expected_state_diff, state.to_state_diff()); @@ -293,8 +293,8 @@ fn create_state_changes_for_test( let contract_address = contract_address!(CONTRACT_ADDRESS); let contract_address2 = contract_address!("0x101"); let class_hash = class_hash!("0x10"); - let compiled_class_hash = CompiledClassHash(stark_felt!("0x11")); - let key = StorageKey(patricia_key!("0x10")); + let compiled_class_hash = compiled_class_hash!("0x11"); + let key = storage_key!("0x10"); let storage_val: StarkFelt = stark_felt!("0x1"); state.set_class_hash_at(contract_address, class_hash).unwrap(); @@ -447,23 +447,20 @@ fn test_cache_get_write_keys() { (contract_address2, some_class_hash), ]), storage_updates: HashMap::from([ - ((contract_address1, StorageKey(patricia_key!("0x300"))), some_felt), - ((contract_address1, StorageKey(patricia_key!("0x600"))), some_felt), - ((contract_address3, StorageKey(patricia_key!("0x600"))), some_felt), + ((contract_address1, storage_key!("0x300")), some_felt), + ((contract_address1, storage_key!("0x600")), some_felt), + ((contract_address3, storage_key!("0x600")), some_felt), ]), - compiled_class_hash_updates: HashMap::from([( - class_hash0, - CompiledClassHash(stark_felt!("0x3")), - )]), + compiled_class_hash_updates: HashMap::from([(class_hash0, compiled_class_hash!("0x3"))]), }; let expected_keys = StateChangesKeys { nonce_keys: HashSet::from([contract_address0]), class_hash_keys: HashSet::from([contract_address1, contract_address2]), storage_keys: HashSet::from([ - (contract_address1, StorageKey(patricia_key!("0x300"))), - (contract_address1, StorageKey(patricia_key!("0x600"))), - (contract_address3, StorageKey(patricia_key!("0x600"))), + (contract_address1, storage_key!("0x300")), + (contract_address1, storage_key!("0x600")), + (contract_address3, storage_key!("0x600")), ]), compiled_class_hash_keys: HashSet::from([class_hash0]), modified_contracts: HashSet::from([ @@ -492,8 +489,8 @@ fn test_state_changes_keys() { nonce_keys: HashSet::from([contract_address0]), class_hash_keys: HashSet::from([contract_address1]), storage_keys: HashSet::from([ - (contract_address2, StorageKey(patricia_key!("0x300"))), - (contract_address2, StorageKey(patricia_key!("0x200"))), + (contract_address2, storage_key!("0x300")), + (contract_address2, storage_key!("0x200")), ]), compiled_class_hash_keys: HashSet::from([class_hash0, class_hash1]), modified_contracts: HashSet::from([contract_address1, contract_address2]), @@ -526,7 +523,7 @@ fn test_state_changes_keys() { let mut keys1 = StateChangesKeys { nonce_keys: HashSet::from([contract_address1]), class_hash_keys: HashSet::from([contract_address1, contract_address2]), - storage_keys: HashSet::from([(contract_address2, StorageKey(patricia_key!("0x300")))]), + storage_keys: HashSet::from([(contract_address2, storage_key!("0x300"))]), compiled_class_hash_keys: HashSet::from([class_hash0]), modified_contracts: HashSet::from([contract_address1, contract_address3]), }; @@ -536,7 +533,7 @@ fn test_state_changes_keys() { StateChangesKeys { nonce_keys: HashSet::from([contract_address0]), class_hash_keys: HashSet::new(), - storage_keys: HashSet::from([(contract_address2, StorageKey(patricia_key!("0x200")),)]), + storage_keys: HashSet::from([(contract_address2, storage_key!("0x200"),)]), compiled_class_hash_keys: HashSet::from([class_hash1]), modified_contracts: HashSet::from([contract_address2]), } @@ -562,8 +559,8 @@ fn test_state_changes_keys() { nonce_keys: HashSet::from([contract_address0, contract_address1]), class_hash_keys: HashSet::from([contract_address1, contract_address2]), storage_keys: HashSet::from([ - (contract_address2, StorageKey(patricia_key!("0x300"))), - (contract_address2, StorageKey(patricia_key!("0x200"))), + (contract_address2, storage_key!("0x300")), + (contract_address2, storage_key!("0x200")), ]), compiled_class_hash_keys: HashSet::from([class_hash0, class_hash1]), modified_contracts: HashSet::from([ @@ -578,10 +575,10 @@ fn test_state_changes_keys() { #[rstest] fn test_state_maps() { let contract_address1 = contract_address!("0x101"); - let storage_key1 = StorageKey(patricia_key!("0x102")); - let class_hash1 = ClassHash(stark_felt!("0x103")); - let nonce1 = Nonce(stark_felt!("0x104")); - let compiled_class_hash1 = CompiledClassHash(stark_felt!("0x105")); + let storage_key1 = storage_key!("0x102"); + let class_hash1 = class_hash!("0x103"); + let nonce1 = nonce!("0x104"); + let compiled_class_hash1 = compiled_class_hash!("0x105"); let some_felt1 = stark_felt!("0x106"); let maps = StateMaps { nonces: HashMap::from([(contract_address1, nonce1)]), diff --git a/crates/blockifier/src/test_utils.rs b/crates/blockifier/src/test_utils.rs index 4140d1a477..35b7de8876 100644 --- a/crates/blockifier/src/test_utils.rs +++ b/crates/blockifier/src/test_utils.rs @@ -138,6 +138,25 @@ macro_rules! nonce { }; } +// TODO(Yoni, 1/1/2025): move to SN API. +/// A utility macro to create a [`StorageKey`] from a hex string / unsigned integer representation. +#[macro_export] +macro_rules! storage_key { + ($s:expr) => { + starknet_api::state::StorageKey(starknet_api::patricia_key!($s)) + }; +} + +// TODO(Yoni, 1/1/2025): move to SN API. +/// A utility macro to create a [`CompiledClassHash`] from a hex string / unsigned integer +/// representation. +#[macro_export] +macro_rules! compiled_class_hash { + ($s:expr) => { + starknet_api::core::CompiledClassHash(starknet_api::hash::StarkHash::try_from($s).unwrap()) + }; +} + #[derive(Default)] pub struct SaltManager { next_salt: u8, diff --git a/crates/blockifier/src/transaction/account_transactions_test.rs b/crates/blockifier/src/transaction/account_transactions_test.rs index b2b51e767b..fc60d8fb2e 100644 --- a/crates/blockifier/src/transaction/account_transactions_test.rs +++ b/crates/blockifier/src/transaction/account_transactions_test.rs @@ -5,9 +5,7 @@ use cairo_felt::Felt252; use cairo_vm::vm::runners::cairo_runner::ResourceTracker; use pretty_assertions::assert_eq; use rstest::rstest; -use starknet_api::core::{ - calculate_contract_address, ClassHash, ContractAddress, Nonce, PatriciaKey, -}; +use starknet_api::core::{calculate_contract_address, ClassHash, ContractAddress, PatriciaKey}; use starknet_api::hash::{StarkFelt, StarkHash}; use starknet_api::state::StorageKey; use starknet_api::transaction::{ @@ -52,7 +50,7 @@ use crate::transaction::transaction_types::TransactionType; use crate::transaction::transactions::{DeclareTransaction, ExecutableTransaction}; use crate::{ check_transaction_execution_error_for_invalid_scenario, declare_tx_args, - deploy_account_tx_args, invoke_tx_args, + deploy_account_tx_args, invoke_tx_args, nonce, storage_key, }; #[rstest] @@ -575,7 +573,7 @@ fn test_fail_deploy_account( check_transaction_execution_error_for_invalid_scenario!(cairo_version, error, false); // Assert nonce and balance are unchanged, and that no contract was deployed at the address. - assert_eq!(state.get_nonce_at(deploy_address).unwrap(), Nonce(stark_felt!(0_u8))); + assert_eq!(state.get_nonce_at(deploy_address).unwrap(), nonce!(0_u8)); assert_eq!( state.get_fee_token_balance(deploy_address, fee_token_address).unwrap(), initial_balance @@ -1105,8 +1103,7 @@ fn test_count_actual_storage_changes( let fee_1 = execution_info.actual_fee; let state_changes_1 = state.get_actual_state_changes().unwrap(); - let cell_write_storage_change = - ((contract_address, StorageKey(patricia_key!(15_u8))), stark_felt!(1_u8)); + let cell_write_storage_change = ((contract_address, storage_key!(15_u8)), stark_felt!(1_u8)); let mut expected_sequencer_total_fee = initial_sequencer_balance + Felt252::from(fee_1.0); let mut expected_sequencer_fee_update = ( (fee_token_address, sequencer_fee_token_var_address), diff --git a/crates/blockifier/src/transaction/execution_flavors_test.rs b/crates/blockifier/src/transaction/execution_flavors_test.rs index d5041a087a..019e8ae376 100644 --- a/crates/blockifier/src/transaction/execution_flavors_test.rs +++ b/crates/blockifier/src/transaction/execution_flavors_test.rs @@ -2,7 +2,7 @@ use assert_matches::assert_matches; use cairo_felt::Felt252; use pretty_assertions::assert_eq; use rstest::rstest; -use starknet_api::core::{ContractAddress, Nonce}; +use starknet_api::core::ContractAddress; use starknet_api::hash::StarkFelt; use starknet_api::stark_felt; use starknet_api::transaction::{Calldata, Fee, TransactionSignature, TransactionVersion}; @@ -11,7 +11,6 @@ use crate::context::{BlockContext, ChainInfo}; use crate::execution::execution_utils::{felt_to_stark_felt, stark_felt_to_felt}; use crate::execution::syscalls::SyscallSelector; use crate::fee::fee_utils::{calculate_tx_fee, get_fee_by_gas_vector}; -use crate::invoke_tx_args; use crate::state::cached_state::CachedState; use crate::state::state_api::StateReader; use crate::test_utils::contracts::FeatureContract; @@ -29,6 +28,7 @@ use crate::transaction::objects::{FeeType, GasVector, TransactionExecutionInfo}; use crate::transaction::test_utils::{account_invoke_tx, l1_resource_bounds, INVALID}; use crate::transaction::transaction_types::TransactionType; use crate::transaction::transactions::ExecutableTransaction; +use crate::{invoke_tx_args, nonce}; const VALIDATE_GAS_OVERHEAD: u64 = 21; struct FlavorTestInitialState { @@ -173,7 +173,7 @@ fn test_simulate_validate_charge_fee_pre_validate( }; // First scenario: invalid nonce. Regardless of flags, should fail. - let invalid_nonce = Nonce(stark_felt!(7_u8)); + let invalid_nonce = nonce!(7_u8); let account_nonce = state.get_nonce_at(account_address).unwrap(); let result = account_invoke_tx( invoke_tx_args! {nonce: invalid_nonce, ..pre_validation_base_args.clone()}, diff --git a/crates/blockifier/src/transaction/objects_test.rs b/crates/blockifier/src/transaction/objects_test.rs index 67330bfbcc..0e37a8994c 100644 --- a/crates/blockifier/src/transaction/objects_test.rs +++ b/crates/blockifier/src/transaction/objects_test.rs @@ -1,7 +1,7 @@ use rstest::rstest; +use starknet_api::class_hash; use starknet_api::core::ClassHash; -use starknet_api::hash::StarkFelt; -use starknet_api::stark_felt; +use starknet_api::hash::StarkHash; use crate::execution::call_info::{ CallExecution, CallInfo, ExecutionSummary, OrderedEvent, TestExecutionSummary, @@ -11,10 +11,7 @@ use crate::transaction::objects::TransactionExecutionInfo; fn shared_call_info() -> CallInfo { CallInfo { - call: CallEntryPoint { - class_hash: Some(ClassHash(stark_felt!("0x1"))), - ..Default::default() - }, + call: CallEntryPoint { class_hash: Some(class_hash!("0x1")), ..Default::default() }, ..Default::default() } } @@ -114,9 +111,9 @@ fn test_events_counter_in_transaction_execution_info_with_inner_call_info( #[rstest] #[case( - TestExecutionSummary::new(1, 2, ClassHash(stark_felt!("0x1")), "0x1", "0x1"), - TestExecutionSummary::new(2, 3, ClassHash(stark_felt!("0x2")), "0x2", "0x2"), - TestExecutionSummary::new(3, 4, ClassHash(stark_felt!("0x3")), "0x3", "0x3") + TestExecutionSummary::new(1, 2, class_hash!("0x1"), "0x1", "0x1"), + TestExecutionSummary::new(2, 3, class_hash!("0x2"), "0x2", "0x2"), + TestExecutionSummary::new(3, 4, class_hash!("0x3"), "0x3", "0x3") )] fn test_summarize( #[case] validate_params: TestExecutionSummary, diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index 796f3964c9..77e2d5bc47 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -76,7 +76,7 @@ use crate::versioned_constants::VersionedConstants; use crate::{ check_transaction_execution_error_for_custom_hint, check_transaction_execution_error_for_invalid_scenario, declare_tx_args, - deploy_account_tx_args, invoke_tx_args, retdata, + deploy_account_tx_args, invoke_tx_args, nonce, retdata, }; static VERSIONED_CONSTANTS: Lazy = @@ -484,7 +484,7 @@ fn test_invoke_tx( // Test nonce update. let nonce_from_state = state.get_nonce_at(sender_address).unwrap(); - assert_eq!(nonce_from_state, Nonce(stark_felt!(1_u8))); + assert_eq!(nonce_from_state, nonce!(1_u8)); // Test final balances. validate_final_balances( @@ -989,7 +989,7 @@ fn test_invalid_nonce( let mut transactional_state = CachedState::create_transactional(state); // Strict, negative flow: account nonce = 0, incoming tx nonce = 1. - let invalid_nonce = Nonce(stark_felt!(1_u8)); + let invalid_nonce = nonce!(1_u8); let invalid_tx = account_invoke_tx(invoke_tx_args! { nonce: invalid_nonce, ..valid_invoke_tx_args.clone() }); let invalid_tx_context = block_context.to_tx_context(&invalid_tx); @@ -1008,7 +1008,7 @@ fn test_invalid_nonce( // Non-strict. // Positive flow: account nonce = 0, incoming tx nonce = 1. - let valid_nonce = Nonce(stark_felt!(1_u8)); + let valid_nonce = nonce!(1_u8); let valid_tx = account_invoke_tx(invoke_tx_args! { nonce: valid_nonce, ..valid_invoke_tx_args.clone() }); @@ -1018,7 +1018,7 @@ fn test_invalid_nonce( .unwrap(); // Negative flow: account nonce = 1, incoming tx nonce = 0. - let invalid_nonce = Nonce(stark_felt!(0_u8)); + let invalid_nonce = nonce!(0_u8); let invalid_tx = account_invoke_tx(invoke_tx_args! { nonce: invalid_nonce, ..valid_invoke_tx_args.clone() }); let invalid_tx_context = block_context.to_tx_context(&invalid_tx); @@ -1031,7 +1031,7 @@ fn test_invalid_nonce( pre_validation_err, TransactionPreValidationError::InvalidNonce {address, account_nonce, incoming_tx_nonce} if (address, account_nonce, incoming_tx_nonce) == - (valid_invoke_tx_args.sender_address, Nonce(stark_felt!(1_u8)), invalid_nonce) + (valid_invoke_tx_args.sender_address, nonce!(1_u8), invalid_nonce) ); } @@ -1184,8 +1184,7 @@ fn test_declare_tx( assert_eq!(actual_execution_info, expected_execution_info); // Test nonce update. V0 transactions do not update nonce. - let expected_nonce = - Nonce(stark_felt!(if tx_version == TransactionVersion::ZERO { 0_u8 } else { 1_u8 })); + let expected_nonce = nonce!(if tx_version == TransactionVersion::ZERO { 0_u8 } else { 1_u8 }); let nonce_from_state = state.get_nonce_at(sender_address).unwrap(); assert_eq!(nonce_from_state, expected_nonce); @@ -1327,7 +1326,7 @@ fn test_deploy_account_tx( // Test nonce update. let nonce_from_state = state.get_nonce_at(deployed_account_address).unwrap(); - assert_eq!(nonce_from_state, Nonce(stark_felt!(1_u8))); + assert_eq!(nonce_from_state, nonce!(1_u8)); // Test final balances. validate_final_balances( @@ -1966,7 +1965,7 @@ fn test_emit_event_exceeds_limit( sender_address: account_contract.get_instance_address(0), calldata: execute_calldata, version: TransactionVersion::ONE, - nonce: Nonce(stark_felt!(0_u8)), + nonce: nonce!(0_u8), }); let execution_info = account_tx.execute(state, block_context, true, true).unwrap(); match &expected_error {