Skip to content

Commit

Permalink
prevent canceled proposal from executing
Browse files Browse the repository at this point in the history
  • Loading branch information
moodysalem committed Apr 26, 2024
1 parent 6ccf304 commit 7115778
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/governor.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ pub mod Governor {

assert(proposal.proposer.is_non_zero(), 'DOES_NOT_EXIST');
assert(proposal.execution_state.executed.is_zero(), 'ALREADY_EXECUTED');
assert(proposal.execution_state.canceled.is_zero(), 'PROPOSAL_CANCELED');

let timestamp_current = get_block_timestamp();
// we cannot tell if a proposal is executed if it is executed at timestamp 0
Expand Down
27 changes: 27 additions & 0 deletions src/governor_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,33 @@ fn test_execute_valid_proposal() {
assert_eq!(token.balanceOf(recipient()), 100);
}

#[test]
#[should_panic(expected: ('PROPOSAL_CANCELED', 'ENTRYPOINT_FAILED'))]
fn test_canceled_proposal_cannot_be_executed() {
let (staker, token, governor, config) = setup();
let id = create_proposal(governor, token, staker);

token.transfer(governor.contract_address, 100);

token.approve(staker.contract_address, config.quorum.into());
staker.stake(voter1());

advance_time(config.voting_start_delay);
set_contract_address(proposer());
governor.vote(id, true);
set_contract_address(voter1());
governor.vote(id, true);

set_contract_address(proposer());
governor.cancel(id);

advance_time(config.voting_period);

set_contract_address(anyone());

governor.execute(transfer_call(token: token, recipient: recipient(), amount: 100));
}

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

0 comments on commit 7115778

Please sign in to comment.