Skip to content

Commit

Permalink
Fixed veto expiration calculation and removed timelock duration valid…
Browse files Browse the repository at this point in the history
…ation.
  • Loading branch information
NoahSaso committed Dec 4, 2023
1 parent 2d333ae commit 13498d6
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 263 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@
"type": "boolean"
},
"timelock_duration": {
"description": "The time duration to delay proposal execution for.",
"description": "The time duration to lock a proposal for after its expiration to allow the vetoer to veto.",
"allOf": [
{
"$ref": "#/definitions/Duration"
Expand Down Expand Up @@ -1540,7 +1540,7 @@
"type": "boolean"
},
"timelock_duration": {
"description": "The time duration to delay proposal execution for.",
"description": "The time duration to lock a proposal for after its expiration to allow the vetoer to veto.",
"allOf": [
{
"$ref": "#/definitions/Duration"
Expand Down Expand Up @@ -2304,7 +2304,7 @@
"type": "boolean"
},
"timelock_duration": {
"description": "The time duration to delay proposal execution for.",
"description": "The time duration to lock a proposal for after its expiration to allow the vetoer to veto.",
"allOf": [
{
"$ref": "#/definitions/Duration"
Expand Down Expand Up @@ -2489,7 +2489,7 @@
"type": "boolean"
},
"timelock_duration": {
"description": "The time duration to delay proposal execution for.",
"description": "The time duration to lock a proposal for after its expiration to allow the vetoer to veto.",
"allOf": [
{
"$ref": "#/definitions/Duration"
Expand Down Expand Up @@ -3624,7 +3624,7 @@
"type": "boolean"
},
"timelock_duration": {
"description": "The time duration to delay proposal execution for.",
"description": "The time duration to lock a proposal for after its expiration to allow the vetoer to veto.",
"allOf": [
{
"$ref": "#/definitions/Duration"
Expand Down Expand Up @@ -4894,7 +4894,7 @@
"type": "boolean"
},
"timelock_duration": {
"description": "The time duration to delay proposal execution for.",
"description": "The time duration to lock a proposal for after its expiration to allow the vetoer to veto.",
"allOf": [
{
"$ref": "#/definitions/Duration"
Expand Down Expand Up @@ -6159,7 +6159,7 @@
"type": "boolean"
},
"timelock_duration": {
"description": "The time duration to delay proposal execution for.",
"description": "The time duration to lock a proposal for after its expiration to allow the vetoer to veto.",
"allOf": [
{
"$ref": "#/definitions/Duration"
Expand Down
12 changes: 6 additions & 6 deletions contracts/proposal/dao-proposal-multiple/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ pub fn instantiate(
.pre_propose_info
.into_initial_policy_and_messages(dao.clone())?;

// if veto is configured we validate its fields
// if veto is configured, validate its fields
if let Some(veto_config) = &msg.veto {
veto_config.validate()?;
veto_config.validate(&deps.as_ref())?;
};

let config = Config {
Expand Down Expand Up @@ -629,10 +629,10 @@ pub fn execute_update_config(
let (min_voting_period, max_voting_period) =
validate_voting_period(min_voting_period, max_voting_period)?;

if let Some(ref veto_config) = veto {
// If veto is enabled, validate the vetoer address
deps.api.addr_validate(&veto_config.vetoer)?;
}
// if veto is configured, validate its fields
if let Some(veto_config) = &veto {
veto_config.validate(&deps.as_ref())?;
};

CONFIG.save(
deps.storage,
Expand Down
8 changes: 4 additions & 4 deletions contracts/proposal/dao-proposal-multiple/src/proposal.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::ops::Add;

use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Addr, BlockInfo, StdError, StdResult, Uint128};
use cw_utils::Expiration;
Expand Down Expand Up @@ -77,14 +79,12 @@ impl MultipleChoiceProposal {
// expiration. if it's expired, this proposal has passed.
// otherwise, set status to `VetoTimelock`.
Some(veto_config) => {
let expiration = veto_config.timelock_duration.after(block);
let expiration = self.expiration.add(veto_config.timelock_duration)?;

if expiration.is_expired(block) {
Ok(Status::Passed)
} else {
Ok(Status::VetoTimelock {
expiration: veto_config.timelock_duration.after(block),
})
Ok(Status::VetoTimelock { expiration })
}
}
// Otherwise the proposal is simply passed
Expand Down
101 changes: 0 additions & 101 deletions contracts/proposal/dao-proposal-multiple/src/testing/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ use cw_multi_test::{next_block, App, BankSudo, Contract, ContractWrapper, Execut
use cw_utils::Duration;
use dao_interface::state::ProposalModule;
use dao_interface::state::{Admin, ModuleInstantiateInfo};
use dao_testing::contracts::{
cw20_stake_contract, cw20_staked_balances_voting_contract, dao_dao_contract,
};
use dao_voting::veto::{VetoConfig, VetoError};
use dao_voting::{
deposit::{CheckedDepositInfo, DepositRefundPolicy, DepositToken, UncheckedDepositInfo},
Expand Down Expand Up @@ -5014,104 +5011,6 @@ fn test_veto_when_veto_timelock_expired() {
assert_eq!(err, ContractError::VetoError(VetoError::TimelockExpired {}),);
}

#[test]
fn test_prop_veto_config_validation() {
let mut app = App::default();
let timelock_duration = 0;
let veto_config = VetoConfig {
timelock_duration: Duration::Height(timelock_duration),
vetoer: "vetoer".to_string(),
early_execute: false,
veto_before_passed: false,
};
let initial_balances = vec![
Cw20Coin {
address: "a-1".to_string(),
amount: Uint128::new(110_000_000),
},
Cw20Coin {
address: "a-2".to_string(),
amount: Uint128::new(100_000_000),
},
];
let instantiate_msg = InstantiateMsg {
min_voting_period: None,
max_voting_period: Duration::Height(6),
only_members_execute: false,
allow_revoting: false,
voting_strategy: VotingStrategy::SingleChoice {
quorum: PercentageThreshold::Majority {},
},
close_proposal_on_execution_failure: false,
pre_propose_info: PreProposeInfo::AnyoneMayPropose {},
veto: Some(veto_config),
};

let proposal_module_code_id = app.store_code(proposal_multiple_contract());
let cw20_id = app.store_code(cw20_base_contract());
let cw20_stake_id = app.store_code(cw20_stake_contract());
let staked_balances_voting_id = app.store_code(cw20_staked_balances_voting_contract());
let core_contract_id = app.store_code(dao_dao_contract());

let instantiate_core = dao_interface::msg::InstantiateMsg {
admin: None,
name: "DAO DAO".to_string(),
description: "A DAO that builds DAOs".to_string(),
image_url: None,
automatically_add_cw20s: true,
automatically_add_cw721s: false,
voting_module_instantiate_info: ModuleInstantiateInfo {
code_id: staked_balances_voting_id,
msg: to_json_binary(&dao_voting_cw20_staked::msg::InstantiateMsg {
active_threshold: None,
token_info: dao_voting_cw20_staked::msg::TokenInfo::New {
code_id: cw20_id,
label: "DAO DAO governance token.".to_string(),
name: "DAO DAO".to_string(),
symbol: "DAO".to_string(),
decimals: 6,
initial_balances: initial_balances.clone(),
marketing: None,
staking_code_id: cw20_stake_id,
unstaking_duration: Some(Duration::Height(6)),
initial_dao_balance: None,
},
})
.unwrap(),
admin: None,
funds: vec![],
label: "DAO DAO voting module".to_string(),
},
proposal_modules_instantiate_info: vec![ModuleInstantiateInfo {
code_id: proposal_module_code_id,
msg: to_json_binary(&instantiate_msg).unwrap(),
admin: Some(Admin::CoreModule {}),
funds: vec![],
label: "DAO DAO governance module.".to_string(),
}],
initial_items: None,
dao_uri: None,
};

let err: ContractError = app
.instantiate_contract(
core_contract_id,
Addr::unchecked(CREATOR_ADDR),
&instantiate_core,
&[],
"DAO DAO",
None,
)
.unwrap_err()
.downcast()
.unwrap();

assert_eq!(
err,
ContractError::VetoError(VetoError::DurationMisconfiguration {})
);
}

#[test]
fn test_veto_sets_prop_status_to_vetoed() {
let mut app = App::default();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@
"type": "boolean"
},
"timelock_duration": {
"description": "The time duration to delay proposal execution for.",
"description": "The time duration to lock a proposal for after its expiration to allow the vetoer to veto.",
"allOf": [
{
"$ref": "#/definitions/Duration"
Expand Down Expand Up @@ -1616,7 +1616,7 @@
"type": "boolean"
},
"timelock_duration": {
"description": "The time duration to delay proposal execution for.",
"description": "The time duration to lock a proposal for after its expiration to allow the vetoer to veto.",
"allOf": [
{
"$ref": "#/definitions/Duration"
Expand Down Expand Up @@ -2386,7 +2386,7 @@
"type": "boolean"
},
"timelock_duration": {
"description": "The time duration to delay proposal execution for.",
"description": "The time duration to lock a proposal for after its expiration to allow the vetoer to veto.",
"allOf": [
{
"$ref": "#/definitions/Duration"
Expand Down Expand Up @@ -2650,7 +2650,7 @@
"type": "boolean"
},
"timelock_duration": {
"description": "The time duration to delay proposal execution for.",
"description": "The time duration to lock a proposal for after its expiration to allow the vetoer to veto.",
"allOf": [
{
"$ref": "#/definitions/Duration"
Expand Down Expand Up @@ -3777,7 +3777,7 @@
"type": "boolean"
},
"timelock_duration": {
"description": "The time duration to delay proposal execution for.",
"description": "The time duration to lock a proposal for after its expiration to allow the vetoer to veto.",
"allOf": [
{
"$ref": "#/definitions/Duration"
Expand Down Expand Up @@ -5057,7 +5057,7 @@
"type": "boolean"
},
"timelock_duration": {
"description": "The time duration to delay proposal execution for.",
"description": "The time duration to lock a proposal for after its expiration to allow the vetoer to veto.",
"allOf": [
{
"$ref": "#/definitions/Duration"
Expand Down Expand Up @@ -6322,7 +6322,7 @@
"type": "boolean"
},
"timelock_duration": {
"description": "The time duration to delay proposal execution for.",
"description": "The time duration to lock a proposal for after its expiration to allow the vetoer to veto.",
"allOf": [
{
"$ref": "#/definitions/Duration"
Expand Down
Loading

0 comments on commit 13498d6

Please sign in to comment.