Skip to content

Commit

Permalink
- add nice error message for queueing a canceled set of calls
Browse files Browse the repository at this point in the history
- prevent cancel from being called twice
  • Loading branch information
moodysalem committed May 6, 2024
1 parent ff63998 commit a85fb29
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion declare-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ echo "Timelock @ $TIMELOCK_CLASS_HASH"
echo "Factory @ $FACTORY_CLASS_HASH"

# starkli deploy --max-fee 0.001 --watch --network "$NETWORK" --keystore-password "$STARKNET_KEYSTORE_PASSWORD" "$AIRDROP_CLAIM_CHECK_CLASS_HASH"
# starkli deploy --max-fee 0.001 --watch --network "$NETWORK" --keystore-password "$STARKNET_KEYSTORE_PASSWORD" "$FACTORY_CLASS_HASH" "$STAKER_CLASS_HASH" "$GOVERNOR_CLASS_HASH" "$TIMELOCK_CLASS_HASH"
starkli deploy --max-fee 0.001 --watch --network "$NETWORK" --keystore-password "$STARKNET_KEYSTORE_PASSWORD" "$FACTORY_CLASS_HASH" $STAKER_CLASS_HASH $GOVERNOR_CLASS_HASH $TIMELOCK_CLASS_HASH
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 a85fb29

Please sign in to comment.