From 7d9b7a6caee3d0f5813fddae569d83755ef36fff Mon Sep 17 00:00:00 2001 From: Santiago Pittella <87827390+SantiagoPittella@users.noreply.github.com> Date: Tue, 11 Jul 2023 16:32:32 -0300 Subject: [PATCH] New methods for tx creation w hash (#805) * add new_with_tx_hash methods for deploy account and invoke * add new_with_tx_hash method for declare * add new_with_tx_hash method for declarev2 * add new_with_tx_hash method for deploy * add doc for declare v2 new method --------- Co-authored-by: Juan Bono --- bench/internals.rs | 5 -- cli/src/main.rs | 5 +- examples/contract_execution/main.rs | 2 +- src/bin/invoke_with_cachedstate.rs | 2 - src/lib.rs | 13 ---- src/syscalls/deprecated_syscall_handler.rs | 1 - src/testing/erc20.rs | 2 - src/testing/state.rs | 64 ++++++++++------ src/transaction/declare.rs | 68 ++++++++++++----- src/transaction/declare_v2.rs | 87 +++++++++++++++++----- src/transaction/deploy.rs | 62 +++++++++------ src/transaction/deploy_account.rs | 62 ++++++++++----- src/transaction/invoke_function.rs | 48 ++++++++---- tests/complex_contracts/utils.rs | 24 ++++-- tests/deploy_account.rs | 2 - tests/internals.rs | 4 - 16 files changed, 293 insertions(+), 158 deletions(-) diff --git a/bench/internals.rs b/bench/internals.rs index fb16bf52d..f116ec94e 100644 --- a/bench/internals.rs +++ b/bench/internals.rs @@ -84,7 +84,6 @@ fn deploy_account() { signature, SALT.clone(), StarknetChainId::TestNet.to_felt(), - None, ) .unwrap(); internal_deploy_account.execute(&mut state_copy, block_context) @@ -116,7 +115,6 @@ fn declare() { 0.into(), vec![], Felt252::zero(), - None, ) .expect("couldn't create transaction"); @@ -153,7 +151,6 @@ fn deploy() { vec![], StarknetChainId::TestNet.to_felt(), 0.into(), - None, ) .unwrap(); internal_deploy.execute(&mut state_copy, block_context) @@ -184,7 +181,6 @@ fn invoke() { vec![], StarknetChainId::TestNet.to_felt(), 0.into(), - None, ) .unwrap(); @@ -207,7 +203,6 @@ fn invoke() { signature, StarknetChainId::TestNet.to_felt(), Some(Felt252::zero()), - None, ) .unwrap(); internal_invoke.execute(&mut state_copy, block_context, 2_000_000) diff --git a/cli/src/main.rs b/cli/src/main.rs index 039846fb1..3b809bc71 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -181,16 +181,15 @@ fn invoke_parser( Some(vec) => vec.iter().map(|&n| n.into()).collect(), None => Vec::new(), }; - let internal_invoke = InvokeFunction::new( + let internal_invoke = InvokeFunction::new_with_tx_hash( contract_address.clone(), entrypoint_selector.clone(), 0, TRANSACTION_VERSION.clone(), calldata.clone(), vec![], - Felt252::zero(), Some(Felt252::zero()), - transaction_hash, + transaction_hash.unwrap(), )?; let _tx_info = internal_invoke.apply(cached_state, &BlockContext::default(), 0)?; diff --git a/examples/contract_execution/main.rs b/examples/contract_execution/main.rs index 3c36b49cf..b735362d4 100644 --- a/examples/contract_execution/main.rs +++ b/examples/contract_execution/main.rs @@ -59,7 +59,7 @@ fn test_contract( //* Declare new contract class //* -------------------------------------------- state - .declare(contract_class.clone(), None) + .declare(contract_class.clone()) .expect("Could not declare the contract class"); //* -------------------------------------------- diff --git a/src/bin/invoke_with_cachedstate.rs b/src/bin/invoke_with_cachedstate.rs index 4cb9d3adf..0175dd6af 100644 --- a/src/bin/invoke_with_cachedstate.rs +++ b/src/bin/invoke_with_cachedstate.rs @@ -62,7 +62,6 @@ fn main() { vec![], StarknetChainId::TestNet.to_felt(), Some(Felt252::from(i * 2)), - None, ) .unwrap() .execute(&mut cached_state, &block_context, 0) @@ -77,7 +76,6 @@ fn main() { vec![], StarknetChainId::TestNet.to_felt(), Some(Felt252::from((i * 2) + 1)), - None, ) .unwrap() .execute(&mut cached_state, &block_context, 0) diff --git a/src/lib.rs b/src/lib.rs index 89d4950cb..383483283 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -273,7 +273,6 @@ mod test { vec![], StarknetChainId::TestNet.to_felt(), Some(0.into()), - None, ) .unwrap(); let transaction = Transaction::InvokeFunction(invoke_function); @@ -415,7 +414,6 @@ mod test { vec![], StarknetChainId::TestNet.to_felt(), None, - None, ) .unwrap(); @@ -506,7 +504,6 @@ mod test { vec![], StarknetChainId::TestNet.to_felt(), Some(1.into()), - None, ) .unwrap(), ); @@ -521,7 +518,6 @@ mod test { vec![], StarknetChainId::TestNet.to_felt(), Some(2.into()), - None, ) .unwrap(), ); @@ -536,7 +532,6 @@ mod test { vec![], StarknetChainId::TestNet.to_felt(), Some(3.into()), - None, ) .unwrap(), ); @@ -634,7 +629,6 @@ mod test { vec![], StarknetChainId::TestNet.to_felt(), Some(1.into()), - None, ) .unwrap(), ); @@ -678,7 +672,6 @@ mod test { vec![], StarknetChainId::TestNet.to_felt(), 0.into(), - None, ) .unwrap(), ); @@ -714,7 +707,6 @@ mod test { 0.into(), vec![], Felt252::zero(), - None, ) .expect("couldn't create transaction"), ); @@ -752,7 +744,6 @@ mod test { vec![], StarknetChainId::TestNet.to_felt(), 0.into(), - None, ) .unwrap(); @@ -775,7 +766,6 @@ mod test { SIGNATURE.clone(), StarknetChainId::TestNet.to_felt(), Some(Felt252::zero()), - None, ) .unwrap(), ); @@ -814,7 +804,6 @@ mod test { SIGNATURE.clone(), SALT.clone(), StarknetChainId::TestNet.to_felt(), - None, ) .unwrap(), ); @@ -964,7 +953,6 @@ mod test { vec![], StarknetChainId::TestNet.to_felt(), 0.into(), - None, ) .unwrap(), ); @@ -986,7 +974,6 @@ mod test { SIGNATURE.clone(), StarknetChainId::TestNet.to_felt(), Some(Felt252::zero()), - None, ) .unwrap(), ); diff --git a/src/syscalls/deprecated_syscall_handler.rs b/src/syscalls/deprecated_syscall_handler.rs index e5b06c02f..149e972d6 100644 --- a/src/syscalls/deprecated_syscall_handler.rs +++ b/src/syscalls/deprecated_syscall_handler.rs @@ -1161,7 +1161,6 @@ mod tests { Vec::new(), 0.into(), Some(0.into()), - None, ) .unwrap(); diff --git a/src/testing/erc20.rs b/src/testing/erc20.rs index 3ee08ef48..4dd0eefe4 100644 --- a/src/testing/erc20.rs +++ b/src/testing/erc20.rs @@ -158,7 +158,6 @@ fn test_erc20_cairo2() { ], contract_address_salt, StarknetChainId::TestNet.to_felt(), - None, ) .unwrap(); @@ -197,7 +196,6 @@ fn test_erc20_cairo2() { ], contract_address_salt, StarknetChainId::TestNet.to_felt(), - None, ) .unwrap(); diff --git a/src/testing/state.rs b/src/testing/state.rs index 3fcf64482..2fb1a12c2 100644 --- a/src/testing/state.rs +++ b/src/testing/state.rs @@ -79,7 +79,6 @@ impl StarknetState { pub fn declare( &mut self, contract_class: ContractClass, - hash_value: Option, ) -> Result<(ClassHash, TransactionExecutionInfo), TransactionError> { let tx = Declare::new( contract_class, @@ -89,7 +88,6 @@ impl StarknetState { 0.into(), Vec::new(), 0.into(), - hash_value, )?; let tx_execution_info = tx.execute(&mut self.state, &self.block_context)?; @@ -176,14 +174,22 @@ impl StarknetState { remaining_gas: u128, ) -> Result<(Address, TransactionExecutionInfo), StarknetStateError> { let chain_id = self.block_context.starknet_os_config.chain_id.to_felt(); - let deploy = Deploy::new( - contract_address_salt, - contract_class.clone(), - constructor_calldata, - chain_id, - TRANSACTION_VERSION.clone(), - hash_value, - )?; + let deploy = match hash_value { + None => Deploy::new( + contract_address_salt, + contract_class.clone(), + constructor_calldata, + chain_id, + TRANSACTION_VERSION.clone(), + )?, + Some(hash_value) => Deploy::new_with_tx_hash( + contract_address_salt, + contract_class.clone(), + constructor_calldata, + TRANSACTION_VERSION.clone(), + hash_value, + )?, + }; let contract_address = deploy.contract_address.clone(); let contract_hash = deploy.contract_hash; let mut tx = Transaction::Deploy(deploy); @@ -277,17 +283,28 @@ impl StarknetState { None => self.state.get_nonce_at(&contract_address)?, }; - InvokeFunction::new( - contract_address, - entry_point_selector, - max_fee, - TRANSACTION_VERSION.clone(), - calldata, - signature, - self.chain_id(), - Some(nonce), - hash_value, - ) + match hash_value { + None => InvokeFunction::new( + contract_address, + entry_point_selector, + max_fee, + TRANSACTION_VERSION.clone(), + calldata, + signature, + self.chain_id(), + Some(nonce), + ), + Some(hash_value) => InvokeFunction::new_with_tx_hash( + contract_address, + entry_point_selector, + max_fee, + TRANSACTION_VERSION.clone(), + calldata, + signature, + Some(nonce), + hash_value, + ), + } } } @@ -455,9 +472,8 @@ mod tests { let fib_contract_class = ContractClass::from_path("starknet_programs/fibonacci.json").unwrap(); - let (ret_class_hash, _exec_info) = starknet_state - .declare(fib_contract_class.clone(), None) - .unwrap(); + let (ret_class_hash, _exec_info) = + starknet_state.declare(fib_contract_class.clone()).unwrap(); //* --------------------------------------- // Expected result diff --git a/src/transaction/declare.rs b/src/transaction/declare.rs index dd877944e..525ff8e1e 100644 --- a/src/transaction/declare.rs +++ b/src/transaction/declare.rs @@ -63,23 +63,60 @@ impl Declare { version: Felt252, signature: Vec, nonce: Felt252, - hash_value: Option, ) -> Result { let hash = compute_deprecated_class_hash(&contract_class)?; let class_hash = felt_to_hash(&hash); - let hash_value = match hash_value { - Some(hash) => hash, - None => calculate_declare_transaction_hash( - &contract_class, - chain_id, - &sender_address, - max_fee, - version.clone(), - nonce.clone(), - )?, + let hash_value = calculate_declare_transaction_hash( + &contract_class, + chain_id, + &sender_address, + max_fee, + version.clone(), + nonce.clone(), + )?; + + let validate_entry_point_selector = VALIDATE_DECLARE_ENTRY_POINT_SELECTOR.clone(); + + let internal_declare = Declare { + class_hash, + sender_address, + tx_type: TransactionType::Declare, + validate_entry_point_selector, + version, + max_fee, + signature, + nonce, + hash_value, + contract_class, + skip_execute: false, + skip_validate: false, + skip_fee_transfer: false, }; + verify_version( + &internal_declare.version, + internal_declare.max_fee, + &internal_declare.nonce, + &internal_declare.signature, + )?; + + Ok(internal_declare) + } + + #[allow(clippy::too_many_arguments)] + pub fn new_with_tx_hash( + contract_class: ContractClass, + sender_address: Address, + max_fee: u128, + version: Felt252, + signature: Vec, + nonce: Felt252, + hash_value: Felt252, + ) -> Result { + let hash = compute_deprecated_class_hash(&contract_class)?; + let class_hash = felt_to_hash(&hash); + let validate_entry_point_selector = VALIDATE_DECLARE_ENTRY_POINT_SELECTOR.clone(); let internal_declare = Declare { @@ -365,7 +402,6 @@ mod tests { 1.into(), Vec::new(), Felt252::zero(), - None, ) .unwrap(); @@ -476,7 +512,6 @@ mod tests { version, Vec::new(), Felt252::from(max_fee), - None, ); // --------------------- @@ -540,7 +575,6 @@ mod tests { version, Vec::new(), nonce, - None, ); // --------------------- @@ -603,7 +637,6 @@ mod tests { 0.into(), signature, Felt252::zero(), - None, ); // --------------------- @@ -665,7 +698,6 @@ mod tests { 1.into(), Vec::new(), Felt252::zero(), - None, ) .unwrap(); @@ -677,7 +709,6 @@ mod tests { 1.into(), Vec::new(), Felt252::one(), - None, ) .unwrap(); @@ -743,7 +774,6 @@ mod tests { 1.into(), Vec::new(), Felt252::zero(), - None, ) .unwrap(); @@ -787,7 +817,6 @@ mod tests { 1.into(), Vec::new(), Felt252::zero(), - None, ) .unwrap(); @@ -849,7 +878,6 @@ mod tests { 1.into(), Vec::new(), Felt252::zero(), - None, ) .unwrap(); diff --git a/src/transaction/declare_v2.rs b/src/transaction/declare_v2.rs index d50afb62f..d195089e1 100644 --- a/src/transaction/declare_v2.rs +++ b/src/transaction/declare_v2.rs @@ -73,7 +73,6 @@ impl DeclareV2 { version: Felt252, signature: Vec, nonce: Felt252, - hash_value: Option, ) -> Result { let validate_entry_point_selector = VALIDATE_DECLARE_ENTRY_POINT_SELECTOR.clone(); @@ -82,17 +81,70 @@ impl DeclareV2 { None => compute_sierra_class_hash(sierra_contract_class)?, }; - let hash_value = match hash_value { - Some(hash) => hash, - None => calculate_declare_v2_transaction_hash( - sierra_class_hash.clone(), - compiled_class_hash.clone(), - chain_id, - &sender_address, - max_fee, - version.clone(), - nonce.clone(), - )?, + let hash_value = calculate_declare_v2_transaction_hash( + sierra_class_hash.clone(), + compiled_class_hash.clone(), + chain_id, + &sender_address, + max_fee, + version.clone(), + nonce.clone(), + )?; + + let internal_declare = DeclareV2 { + sierra_contract_class: sierra_contract_class.to_owned(), + sierra_class_hash, + sender_address, + tx_type: TransactionType::Declare, + validate_entry_point_selector, + version, + max_fee, + signature, + nonce, + compiled_class_hash, + hash_value, + casm_class: Default::default(), + skip_execute: false, + skip_validate: false, + skip_fee_transfer: false, + }; + + verify_version( + &internal_declare.version, + internal_declare.max_fee, + &internal_declare.nonce, + &internal_declare.signature, + )?; + + Ok(internal_declare) + } + + // creates a new instance of a declare but without the computation of the transaction hash. + /// ## Parameters: + /// - sierra_contract_class: The sierra contract class of the contract to declare + /// - compiled_class_hash: the class hash of the contract compiled with Cairo1 or newer. + /// - sender_address: The address of the account declaring the contract. + /// - max_fee: refers to max amount of fee that a declare takes. + /// - version: The version of cairo contract being declare. + /// - signature: Array of felts with the signatures of the contract. + /// - nonce: The nonce of the contract. + #[allow(clippy::too_many_arguments)] + pub fn new_with_tx_hash( + sierra_contract_class: &SierraContractClass, + sierra_class_hash: Option, + compiled_class_hash: Felt252, + sender_address: Address, + max_fee: u128, + version: Felt252, + signature: Vec, + nonce: Felt252, + hash_value: Felt252, + ) -> Result { + let validate_entry_point_selector = VALIDATE_DECLARE_ENTRY_POINT_SELECTOR.clone(); + + let sierra_class_hash = match sierra_class_hash { + Some(h) => h, + None => compute_sierra_class_hash(sierra_contract_class)?, }; let internal_declare = DeclareV2 { @@ -344,8 +396,8 @@ mod tests { use crate::services::api::contract_classes::compiled_class::CompiledClass; use crate::state::state_api::StateReader; use crate::{ - definitions::block_context::StarknetChainId, state::cached_state::CachedState, - state::in_memory_state_reader::InMemoryStateReader, utils::Address, + state::cached_state::CachedState, state::in_memory_state_reader::InMemoryStateReader, + utils::Address, }; use cairo_lang_starknet::casm_contract_class::CasmContractClass; use cairo_vm::felt::Felt252; @@ -373,23 +425,20 @@ mod tests { let sierra_contract_class: cairo_lang_starknet::contract_class::ContractClass = serde_json::from_reader(reader).unwrap(); let sierra_class_hash = compute_sierra_class_hash(&sierra_contract_class).unwrap(); - let chain_id = StarknetChainId::TestNet.to_felt(); - let sender_address = Address(1.into()); // create internal declare v2 - let internal_declare = DeclareV2::new( + let internal_declare = DeclareV2::new_with_tx_hash( &sierra_contract_class, Some(sierra_class_hash), Felt252::one(), - chain_id, sender_address, 0, version, [1.into()].to_vec(), Felt252::zero(), - Some(Felt252::one()), + Felt252::one(), ) .unwrap(); diff --git a/src/transaction/deploy.rs b/src/transaction/deploy.rs index 5d4103c60..6ab07b10e 100644 --- a/src/transaction/deploy.rs +++ b/src/transaction/deploy.rs @@ -51,7 +51,6 @@ impl Deploy { constructor_calldata: Vec, chain_id: Felt252, version: Felt252, - hash_value: Option, ) -> Result { let class_hash = compute_deprecated_class_hash(&contract_class) .map_err(|_| SyscallHandlerError::ErrorComputingHash)?; @@ -64,15 +63,44 @@ impl Deploy { Address(Felt252::zero()), )?); - let hash_value = match hash_value { - Some(hash) => hash, - None => calculate_deploy_transaction_hash( - version.clone(), - &contract_address, - &constructor_calldata, - chain_id, - )?, - }; + let hash_value = calculate_deploy_transaction_hash( + version.clone(), + &contract_address, + &constructor_calldata, + chain_id, + )?; + + Ok(Deploy { + hash_value, + version, + contract_address, + contract_address_salt, + contract_hash, + constructor_calldata, + tx_type: TransactionType::Deploy, + skip_validate: false, + skip_execute: false, + skip_fee_transfer: false, + }) + } + + pub fn new_with_tx_hash( + contract_address_salt: Felt252, + contract_class: ContractClass, + constructor_calldata: Vec, + version: Felt252, + hash_value: Felt252, + ) -> Result { + let class_hash = compute_deprecated_class_hash(&contract_class) + .map_err(|_| SyscallHandlerError::ErrorComputingHash)?; + + let contract_hash: ClassHash = felt_to_hash(&class_hash); + let contract_address = Address(calculate_contract_address( + &contract_address_salt, + &class_hash, + &constructor_calldata, + Address(Felt252::zero()), + )?); Ok(Deploy { hash_value, @@ -276,7 +304,6 @@ mod tests { vec![10.into()], 0.into(), 0.into(), - None, ) .unwrap(); @@ -318,15 +345,8 @@ mod tests { .set_contract_class(&class_hash_bytes, &contract_class) .unwrap(); - let internal_deploy = Deploy::new( - 0.into(), - contract_class, - Vec::new(), - 0.into(), - 0.into(), - None, - ) - .unwrap(); + let internal_deploy = + Deploy::new(0.into(), contract_class, Vec::new(), 0.into(), 0.into()).unwrap(); let block_context = Default::default(); @@ -358,7 +378,6 @@ mod tests { vec![10.into()], 0.into(), 0.into(), - None, ) .unwrap(); @@ -392,7 +411,6 @@ mod tests { Vec::new(), 0.into(), 1.into(), - None, ); assert_matches!( internal_deploy_error.unwrap_err(), diff --git a/src/transaction/deploy_account.rs b/src/transaction/deploy_account.rs index 32cf9d6e8..9ee8e76a8 100644 --- a/src/transaction/deploy_account.rs +++ b/src/transaction/deploy_account.rs @@ -74,7 +74,6 @@ impl DeployAccount { signature: Vec, contract_address_salt: Felt252, chain_id: Felt252, - hash_value: Option, ) -> Result { let contract_address = Address(calculate_contract_address( &contract_address_salt, @@ -83,19 +82,50 @@ impl DeployAccount { Address(Felt252::zero()), )?); - let hash_value = match hash_value { - Some(hash) => hash, - None => calculate_deploy_account_transaction_hash( - version.clone(), - &contract_address, - Felt252::from_bytes_be(&class_hash), - &constructor_calldata, - max_fee, - nonce.clone(), - contract_address_salt.clone(), - chain_id, - )?, - }; + let hash_value = calculate_deploy_account_transaction_hash( + version.clone(), + &contract_address, + Felt252::from_bytes_be(&class_hash), + &constructor_calldata, + max_fee, + nonce.clone(), + contract_address_salt.clone(), + chain_id, + )?; + + Ok(Self { + contract_address, + contract_address_salt, + class_hash, + constructor_calldata, + version, + nonce, + max_fee, + hash_value, + signature, + skip_execute: false, + skip_validate: false, + skip_fee_transfer: false, + }) + } + + #[allow(clippy::too_many_arguments)] + pub fn new_with_tx_hash( + class_hash: ClassHash, + max_fee: u128, + version: Felt252, + nonce: Felt252, + constructor_calldata: Vec, + signature: Vec, + contract_address_salt: Felt252, + hash_value: Felt252, + ) -> Result { + let contract_address = Address(calculate_contract_address( + &contract_address_salt, + &Felt252::from_bytes_be(&class_hash), + &constructor_calldata, + Address(Felt252::zero()), + )?); Ok(Self { contract_address, @@ -423,7 +453,6 @@ mod tests { Vec::new(), 0.into(), StarknetChainId::TestNet2.to_felt(), - None, ) .unwrap(); @@ -460,7 +489,6 @@ mod tests { Vec::new(), 0.into(), StarknetChainId::TestNet2.to_felt(), - None, ) .unwrap(); @@ -473,7 +501,6 @@ mod tests { Vec::new(), 0.into(), StarknetChainId::TestNet2.to_felt(), - None, ) .unwrap(); @@ -514,7 +541,6 @@ mod tests { Vec::new(), 0.into(), StarknetChainId::TestNet2.to_felt(), - None, ) .unwrap(); diff --git a/src/transaction/invoke_function.rs b/src/transaction/invoke_function.rs index b75280031..0e7d704d8 100644 --- a/src/transaction/invoke_function.rs +++ b/src/transaction/invoke_function.rs @@ -61,26 +61,46 @@ impl InvokeFunction { signature: Vec, chain_id: Felt252, nonce: Option, - hash_value: Option, ) -> Result { let (entry_point_selector_field, additional_data) = preprocess_invoke_function_fields( entry_point_selector.clone(), nonce.clone(), version.clone(), )?; - let hash_value = match hash_value { - Some(hash) => hash, - None => calculate_transaction_hash_common( - TransactionHashPrefix::Invoke, - version.clone(), - &contract_address, - entry_point_selector_field, - &calldata, - max_fee, - chain_id, - &additional_data, - )?, - }; + let hash_value = calculate_transaction_hash_common( + TransactionHashPrefix::Invoke, + version.clone(), + &contract_address, + entry_point_selector_field, + &calldata, + max_fee, + chain_id, + &additional_data, + )?; + + InvokeFunction::new_with_tx_hash( + contract_address, + entry_point_selector, + max_fee, + version, + calldata, + signature, + nonce, + hash_value, + ) + } + + #[allow(clippy::too_many_arguments)] + pub fn new_with_tx_hash( + contract_address: Address, + entry_point_selector: Felt252, + max_fee: u128, + version: Felt252, + calldata: Vec, + signature: Vec, + nonce: Option, + hash_value: Felt252, + ) -> Result { let validate_entry_point_selector = VALIDATE_ENTRY_POINT_SELECTOR.clone(); Ok(InvokeFunction { diff --git a/tests/complex_contracts/utils.rs b/tests/complex_contracts/utils.rs index 704b3edd9..d3e640e58 100644 --- a/tests/complex_contracts/utils.rs +++ b/tests/complex_contracts/utils.rs @@ -135,14 +135,22 @@ pub fn deploy( ) -> Result<(Address, [u8; 32]), TransactionError> { let contract_class = ContractClass::from_path(path).unwrap(); - let internal_deploy = Deploy::new( - 0.into(), - contract_class.clone(), - calldata.to_vec(), - StarknetChainId::TestNet.to_felt(), - 0.into(), - hash_value, - )?; + let internal_deploy = match hash_value { + None => Deploy::new( + 0.into(), + contract_class.clone(), + calldata.to_vec(), + StarknetChainId::TestNet.to_felt(), + 0.into(), + )?, + Some(hash_value) => Deploy::new_with_tx_hash( + 0.into(), + contract_class.clone(), + calldata.to_vec(), + 0.into(), + hash_value, + )?, + }; let class_hash = internal_deploy.class_hash(); state.set_contract_class(&class_hash, &contract_class)?; diff --git a/tests/deploy_account.rs b/tests/deploy_account.rs index 309ea0574..b79d3603d 100644 --- a/tests/deploy_account.rs +++ b/tests/deploy_account.rs @@ -62,7 +62,6 @@ fn internal_deploy_account() { ], contract_address_salt.clone(), StarknetChainId::TestNet.to_felt(), - None, ) .unwrap(); @@ -146,7 +145,6 @@ fn internal_deploy_account_cairo1() { ], contract_address_salt, StarknetChainId::TestNet.to_felt(), - None, ) .unwrap(); diff --git a/tests/internals.rs b/tests/internals.rs index b777b2a4d..75bacb1ab 100644 --- a/tests/internals.rs +++ b/tests/internals.rs @@ -550,7 +550,6 @@ fn invoke_tx(calldata: Vec) -> InvokeFunction { vec![], StarknetChainId::TestNet.to_felt(), Some(Felt252::zero()), - None, ) .unwrap() } @@ -1183,7 +1182,6 @@ fn test_deploy_account() { Default::default(), Default::default(), StarknetChainId::TestNet.to_felt(), - None, ) .unwrap(); @@ -1665,7 +1663,6 @@ fn test_invoke_tx_wrong_entrypoint() { vec![], StarknetChainId::TestNet.to_felt(), Some(Felt252::zero()), - None, ) .unwrap(); @@ -1691,7 +1688,6 @@ fn test_deploy_undeclared_account() { Default::default(), Default::default(), StarknetChainId::TestNet.to_felt(), - None, ) .unwrap();