Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit fa6fd36

Browse files
committed
Merge branch 'main' into class-hash-issue
2 parents 8ccab7c + 66a978b commit fa6fd36

File tree

1 file changed

+38
-1
lines changed
  • src/core/transaction_hash

1 file changed

+38
-1
lines changed

src/core/transaction_hash/mod.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ pub fn calculate_declare_transaction_hash(
129129
let class_hash = compute_deprecated_class_hash(contract_class)
130130
.map_err(|_| SyscallHandlerError::FailToComputeHash)?;
131131

132-
let (calldata, additional_data) = if version.is_zero() {
132+
let (calldata, additional_data) = if !version.is_zero() {
133133
(vec![class_hash], vec![nonce])
134134
} else {
135135
(Vec::new(), vec![class_hash])
@@ -183,6 +183,8 @@ mod tests {
183183
use cairo_vm::felt::felt_str;
184184
use coverage_helper::test;
185185

186+
use crate::definitions::block_context::StarknetChainId;
187+
186188
use super::*;
187189

188190
#[test]
@@ -215,4 +217,39 @@ mod tests {
215217

216218
assert_eq!(result, expected);
217219
}
220+
221+
#[test]
222+
fn calculate_declare_hash_test() {
223+
let chain_id = StarknetChainId::MainNet;
224+
let sender_address = Address(felt_str!(
225+
"78963962122521774108119849325604561253807220406669671815499681746608877924"
226+
));
227+
let max_fee = 30580718124600;
228+
let version = 1.into();
229+
let nonce = 3746.into();
230+
let class_hash = felt_str!(
231+
"1935775813346111469198021973672033051732472907985289186515250543849860001197"
232+
);
233+
234+
let (calldata, additional_data) = (vec![class_hash], vec![nonce]);
235+
236+
let tx = calculate_transaction_hash_common(
237+
TransactionHashPrefix::Declare,
238+
version,
239+
&sender_address,
240+
Felt252::zero(),
241+
&calldata,
242+
max_fee,
243+
chain_id.to_felt(),
244+
&additional_data,
245+
)
246+
.unwrap();
247+
248+
assert_eq!(
249+
tx,
250+
felt_str!(
251+
"446404108171603570739811156347043235876209711235222547918688109133687877504"
252+
)
253+
)
254+
}
218255
}

0 commit comments

Comments
 (0)