Skip to content

Commit 82d77be

Browse files
authoredJan 22, 2025··
fix hash_operation (#1314)
1 parent aadab0f commit 82d77be

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed
 

‎packages/governance/src/tests/test_timelock.cairo

+27
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ fn test_hash_operation() {
178178

179179
// Manually set hash elements
180180
let mut expected_hash = PedersenTrait::new(0)
181+
.update_with(1) // number of calls
181182
.update_with(target.contract_address) // call::to
182183
.update_with(selector!("set_number")) // call::selector
183184
.update_with(1) // call::calldata.len
@@ -228,6 +229,32 @@ fn test_hash_operation_batch() {
228229
assert_eq!(hashed_operation, expected_hash);
229230
}
230231

232+
#[test]
233+
fn test_hash_operation_and_hash_operations() {
234+
let (mut timelock, _) = setup_dispatchers();
235+
let predecessor = 123;
236+
let salt = SALT;
237+
238+
// Setup and hash single call
239+
let to_1 = contract_address_const::<1>();
240+
let selector_1 = 123;
241+
let calldata_1 = array![1, 456].span();
242+
let call_1 = Call { to: to_1, selector: selector_1, calldata: calldata_1 };
243+
244+
let hash_single = timelock.hash_operation(call_1, predecessor, salt);
245+
246+
// Setup and hash batch of single call
247+
let to_2 = contract_address_const::<123>();
248+
let selector_2 = 2;
249+
let calldata_2 = array![456].span();
250+
let call_2 = Call { to: to_2, selector: selector_2, calldata: calldata_2 };
251+
let single_call_batch = array![call_2].span();
252+
253+
let hash_batch = timelock.hash_operation_batch(single_call_batch, predecessor, salt);
254+
255+
assert_ne!(hash_single, hash_batch);
256+
}
257+
231258
//
232259
// schedule
233260
//

‎packages/governance/src/timelock/timelock_controller.cairo

+1-5
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,7 @@ pub mod TimelockControllerComponent {
185185
fn hash_operation(
186186
self: @ComponentState<TContractState>, call: Call, predecessor: felt252, salt: felt252,
187187
) -> felt252 {
188-
PedersenTrait::new(0)
189-
.update_with(call)
190-
.update_with(predecessor)
191-
.update_with(salt)
192-
.finalize()
188+
Self::hash_operation_batch(self, array![call].span(), predecessor, salt)
193189
}
194190

195191
/// Returns the identifier of an operation containing a batch of transactions.

0 commit comments

Comments
 (0)
Please sign in to comment.