Skip to content

Commit

Permalink
fix timelock nits (#39)
Browse files Browse the repository at this point in the history
* - add nice error message for queueing a canceled set of calls
- prevent cancel from being called twice

* revert change to declare script
  • Loading branch information
moodysalem authored May 6, 2024
1 parent ff63998 commit e34d55e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/timelock.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ pub mod Timelock {
let id = to_calls_id(calls);
let execution_state = self.execution_state.read(id);

assert(execution_state.executed.is_zero(), 'ALREADY_EXECUTED');
assert(execution_state.canceled.is_zero(), 'HAS_BEEN_CANCELED');
assert(execution_state.created.is_zero(), 'ALREADY_QUEUED');

Expand All @@ -164,6 +165,7 @@ pub mod Timelock {
let execution_state = self.execution_state.read(id);
assert(execution_state.created.is_non_zero(), 'DOES_NOT_EXIST');
assert(execution_state.executed.is_zero(), 'ALREADY_EXECUTED');
assert(execution_state.canceled.is_zero(), 'ALREADY_CANCELED');

self
.execution_state
Expand Down
17 changes: 17 additions & 0 deletions src/timelock_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,23 @@ fn test_queue_cancel() {
timelock.execute(single_call(transfer_call(token, recipient, 500_u256)));
}

#[test]
#[should_panic(expected: ('ALREADY_CANCELED', 'ENTRYPOINT_FAILED'))]
fn test_queue_cancel_twice() {
set_block_timestamp(1);
let timelock = deploy(get_contract_address(), 86400, 3600);

let token = deploy_token(get_contract_address(), 12345);
token.transfer(timelock.contract_address, 12345);

let recipient = contract_address_const::<12345>();

let id = timelock.queue(single_call(transfer_call(token, recipient, 500_u256)));

timelock.cancel(id);
timelock.cancel(id);
}

#[test]
#[should_panic(expected: ('ALREADY_EXECUTED', 'ENTRYPOINT_FAILED'))]
fn test_queue_execute_twice() {
Expand Down

0 comments on commit e34d55e

Please sign in to comment.