Skip to content

Commit

Permalink
fix hash_operation (#1314)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-fleming authored Jan 22, 2025
1 parent aadab0f commit 82d77be
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
27 changes: 27 additions & 0 deletions packages/governance/src/tests/test_timelock.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ fn test_hash_operation() {

// Manually set hash elements
let mut expected_hash = PedersenTrait::new(0)
.update_with(1) // number of calls
.update_with(target.contract_address) // call::to
.update_with(selector!("set_number")) // call::selector
.update_with(1) // call::calldata.len
Expand Down Expand Up @@ -228,6 +229,32 @@ fn test_hash_operation_batch() {
assert_eq!(hashed_operation, expected_hash);
}

#[test]
fn test_hash_operation_and_hash_operations() {
let (mut timelock, _) = setup_dispatchers();
let predecessor = 123;
let salt = SALT;

// Setup and hash single call
let to_1 = contract_address_const::<1>();
let selector_1 = 123;
let calldata_1 = array![1, 456].span();
let call_1 = Call { to: to_1, selector: selector_1, calldata: calldata_1 };

let hash_single = timelock.hash_operation(call_1, predecessor, salt);

// Setup and hash batch of single call
let to_2 = contract_address_const::<123>();
let selector_2 = 2;
let calldata_2 = array![456].span();
let call_2 = Call { to: to_2, selector: selector_2, calldata: calldata_2 };
let single_call_batch = array![call_2].span();

let hash_batch = timelock.hash_operation_batch(single_call_batch, predecessor, salt);

assert_ne!(hash_single, hash_batch);
}

//
// schedule
//
Expand Down
6 changes: 1 addition & 5 deletions packages/governance/src/timelock/timelock_controller.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,7 @@ pub mod TimelockControllerComponent {
fn hash_operation(
self: @ComponentState<TContractState>, call: Call, predecessor: felt252, salt: felt252,
) -> felt252 {
PedersenTrait::new(0)
.update_with(call)
.update_with(predecessor)
.update_with(salt)
.finalize()
Self::hash_operation_batch(self, array![call].span(), predecessor, salt)
}

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

0 comments on commit 82d77be

Please sign in to comment.