Skip to content

Commit

Permalink
fix: allow for execution of proposals that have closed overrule propo…
Browse files Browse the repository at this point in the history
…sal (same as rejected)
  • Loading branch information
NeverHappened committed Feb 27, 2024
1 parent 09d3f67 commit fdca935
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
7 changes: 4 additions & 3 deletions contracts/subdaos/cwd-subdao-timelock-single/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub fn execute_execute_proposal(
});
}

if !is_overrule_proposal_rejected(&deps, &env, &config.overrule_pre_propose, proposal.id)? {
if !is_overrule_proposal_denied(&deps, &env, &config.overrule_pre_propose, proposal.id)? {
return Err(ContractError::TimeLocked {});
}

Expand Down Expand Up @@ -339,7 +339,7 @@ pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Response, C
Ok(Response::default())
}

fn is_overrule_proposal_rejected(
fn is_overrule_proposal_denied(
deps: &DepsMut,
env: &Env,
overrule_pre_propose: &Addr,
Expand All @@ -363,7 +363,8 @@ fn is_overrule_proposal_rejected(
proposal_id: overrule_proposal_id,
},
)?;
Ok(overrule_proposal.proposal.status == Status::Rejected)
Ok(overrule_proposal.proposal.status == Status::Rejected
|| overrule_proposal.proposal.status == Status::Closed)
}

#[cfg_attr(not(feature = "library"), entry_point)]
Expand Down
34 changes: 34 additions & 0 deletions contracts/subdaos/cwd-subdao-timelock-single/src/testing/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,40 @@ fn test_execute_proposal() {
let updated_prop = PROPOSALS.load(deps.as_mut().storage, 10).unwrap();
assert_eq!(ProposalStatus::Executed, updated_prop.status);

// check execution with close_proposal_on_execution_failure = true and overrule proposal Status == Closed
deps.querier.set_close_proposal_on_execution_failure(true);
let proposal = SingleChoiceProposal {
id: 11,
msgs: vec![correct_proposal_msg()],
status: ProposalStatus::Timelocked,
};
PROPOSALS
.save(deps.as_mut().storage, proposal.id, &proposal)
.unwrap();
// if overrule has Status::Closed that means it was rejected
{
let mut data_mut_ref = overrule_proposal_status.borrow_mut();
*data_mut_ref = Status::Closed;
}
let msg2 = ExecuteMsg::ExecuteProposal { proposal_id: 11 };
let res = execute(deps.as_mut(), env.clone(), info.clone(), msg2.clone()).unwrap();
let expected_attributes = vec![
Attribute::new("action", "execute_proposal"),
Attribute::new("sender", "neutron1unknownsender"),
Attribute::new("proposal_id", "11"),
];
assert_eq!(expected_attributes, res.attributes);
assert_eq!(
proposal
.msgs
.iter()
.map(|msg| SubMsg::reply_on_error(msg.clone(), proposal.id))
.collect::<Vec<SubMsg<NeutronMsg>>>(),
res.messages
);
let updated_prop = PROPOSALS.load(deps.as_mut().storage, 11).unwrap();
assert_eq!(ProposalStatus::Executed, updated_prop.status);

// check that execution fails when there not exactly one message in proposal
let proposal = SingleChoiceProposal {
id: 10,
Expand Down
2 changes: 1 addition & 1 deletion packages/cwd-pre-propose-base/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ where

// Save the deposit.
//
// It is possibe that a malicious proposal hook could run
// It is possible that a malicious proposal hook could run
// before us and update our config! We don't have to worry
// about this though as the only way to be able to update our
// config is to have root on the code module and if someone
Expand Down

0 comments on commit fdca935

Please sign in to comment.