Skip to content

Commit

Permalink
Cast vote on proposal creation (#799)
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso authored Feb 9, 2024
1 parent 7cc41b5 commit 43eccde
Show file tree
Hide file tree
Showing 30 changed files with 1,041 additions and 227 deletions.
1 change: 1 addition & 0 deletions ci/integration-tests/src/helpers/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ pub fn create_proposal(
title: "title".to_string(),
description: "desc".to_string(),
msgs,
vote: None,
},
},
key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,16 @@
},
"title": {
"type": "string"
},
"vote": {
"anyOf": [
{
"$ref": "#/definitions/SingleChoiceAutoVote"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false
Expand All @@ -1047,6 +1057,30 @@
}
]
},
"SingleChoiceAutoVote": {
"type": "object",
"required": [
"vote"
],
"properties": {
"rationale": {
"description": "An optional rationale for why this vote was cast. This can be updated, set, or removed later by the address casting the vote.",
"type": [
"string",
"null"
]
},
"vote": {
"description": "The proposer's position on the proposal.",
"allOf": [
{
"$ref": "#/definitions/Vote"
}
]
}
},
"additionalProperties": false
},
"StakingMsg": {
"description": "The message types of the staking module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto",
"oneOf": [
Expand Down Expand Up @@ -1289,6 +1323,31 @@
},
"additionalProperties": false
},
"Vote": {
"oneOf": [
{
"description": "Marks support for the proposal.",
"type": "string",
"enum": [
"yes"
]
},
{
"description": "Marks opposition to the proposal.",
"type": "string",
"enum": [
"no"
]
},
{
"description": "Marks participation but does not count towards the ratio of support / opposed.",
"type": "string",
"enum": [
"abstain"
]
}
]
},
"VoteOption": {
"type": "string",
"enum": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ pub fn execute_propose(
title,
description,
msgs,
vote,
} => ProposeMsg {
title,
description,
msgs,
proposer: Some(info.sender.to_string()),
vote,
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use cosmwasm_std::{CosmosMsg, Empty};
use dao_pre_propose_base::msg::{
ExecuteMsg as ExecuteBase, InstantiateMsg as InstantiateBase, QueryMsg as QueryBase,
};
use dao_voting::proposal::SingleChoiceProposeMsg as ProposeMsg;
use dao_voting::{proposal::SingleChoiceProposeMsg as ProposeMsg, voting::SingleChoiceAutoVote};

#[cw_serde]
pub enum ApproverProposeMessage {
Expand All @@ -20,6 +20,7 @@ pub enum ProposeMessage {
title: String,
description: String,
msgs: Vec<CosmosMsg<Empty>>,
vote: Option<SingleChoiceAutoVote>,
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ fn make_pre_proposal(app: &mut App, pre_propose: Addr, proposer: &str, funds: &[
title: "title".to_string(),
description: "description".to_string(),
msgs: vec![],
vote: None,
},
},
funds,
Expand Down Expand Up @@ -1156,6 +1157,7 @@ fn test_permissions() {
title: "I would like to join the DAO".to_string(),
description: "though, I am currently not a member.".to_string(),
msgs: vec![],
vote: None,
},
},
&[],
Expand Down Expand Up @@ -1304,6 +1306,7 @@ fn test_no_deposit_required_members_submission() {
title: "I would like to join the DAO".to_string(),
description: "though, I am currently not a member.".to_string(),
msgs: vec![],
vote: None,
},
},
&[],
Expand Down
2 changes: 2 additions & 0 deletions contracts/pre-propose/dao-pre-propose-approver/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ fn make_pre_proposal(app: &mut App, pre_propose: Addr, proposer: &str, funds: &[
title: "title".to_string(),
description: "description".to_string(),
msgs: vec![],
vote: None,
},
},
funds,
Expand Down Expand Up @@ -1151,6 +1152,7 @@ fn test_permissions() {
title: "I would like to join the DAO".to_string(),
description: "though, I am currently not a member.".to_string(),
msgs: vec![],
vote: None,
},
},
&[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,30 @@
}
}
},
"MultipleChoiceAutoVote": {
"type": "object",
"required": [
"vote"
],
"properties": {
"rationale": {
"description": "An optional rationale for why this vote was cast. This can be updated, set, or removed later by the address casting the vote.",
"type": [
"string",
"null"
]
},
"vote": {
"description": "The proposer's position on the proposal.",
"allOf": [
{
"$ref": "#/definitions/MultipleChoiceVote"
}
]
}
},
"additionalProperties": false
},
"MultipleChoiceOption": {
"description": "Unchecked multiple choice option",
"type": "object",
Expand Down Expand Up @@ -969,6 +993,21 @@
},
"additionalProperties": false
},
"MultipleChoiceVote": {
"description": "A multiple choice vote, picking the desired option",
"type": "object",
"required": [
"option_id"
],
"properties": {
"option_id": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
},
"ProposeMessage": {
"oneOf": [
{
Expand All @@ -993,6 +1032,16 @@
},
"title": {
"type": "string"
},
"vote": {
"anyOf": [
{
"$ref": "#/definitions/MultipleChoiceAutoVote"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false
Expand Down
19 changes: 10 additions & 9 deletions contracts/pre-propose/dao-pre-propose-multiple/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use dao_pre_propose_base::{
msg::{ExecuteMsg as ExecuteBase, InstantiateMsg as InstantiateBase, QueryMsg as QueryBase},
state::PreProposeContract,
};
use dao_voting::multiple_choice::MultipleChoiceOptions;
use dao_voting::{
multiple_choice::{MultipleChoiceAutoVote, MultipleChoiceOptions},
proposal::MultipleChoiceProposeMsg as ProposeMsg,
};

pub(crate) const CONTRACT_NAME: &str = "crates.io:dao-pre-propose-multiple";
pub(crate) const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
Expand All @@ -20,6 +23,7 @@ pub enum ProposeMessage {
title: String,
description: String,
choices: MultipleChoiceOptions,
vote: Option<MultipleChoiceAutoVote>,
},
}

Expand All @@ -32,12 +36,7 @@ pub type QueryMsg = QueryBase<Empty>;
/// of the external message.
#[cw_serde]
enum ProposeMessageInternal {
Propose {
title: String,
description: String,
choices: MultipleChoiceOptions,
proposer: Option<String>,
},
Propose(ProposeMsg),
}

type PrePropose = PreProposeContract<Empty, Empty, Empty, ProposeMessageInternal>;
Expand Down Expand Up @@ -73,14 +72,16 @@ pub fn execute(
title,
description,
choices,
vote,
},
} => ExecuteInternal::Propose {
msg: ProposeMessageInternal::Propose {
msg: ProposeMessageInternal::Propose(ProposeMsg {
proposer: Some(info.sender.to_string()),
title,
description,
choices,
},
vote,
}),
},
ExecuteMsg::Extension { msg } => ExecuteInternal::Extension { msg },
ExecuteMsg::Withdraw { denom } => ExecuteInternal::Withdraw { denom },
Expand Down
3 changes: 3 additions & 0 deletions contracts/pre-propose/dao-pre-propose-multiple/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ fn make_proposal(
},
],
},
vote: None,
},
},
funds,
Expand Down Expand Up @@ -869,6 +870,7 @@ fn test_permissions() {
title: "title".to_string(),
}],
},
vote: None,
},
},
&[],
Expand Down Expand Up @@ -975,6 +977,7 @@ fn test_no_deposit_required_members_submission() {
title: "title".to_string(),
}],
},
vote: None,
},
},
&[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,16 @@
},
"title": {
"type": "string"
},
"vote": {
"anyOf": [
{
"$ref": "#/definitions/SingleChoiceAutoVote"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false
Expand All @@ -966,6 +976,30 @@
}
]
},
"SingleChoiceAutoVote": {
"type": "object",
"required": [
"vote"
],
"properties": {
"rationale": {
"description": "An optional rationale for why this vote was cast. This can be updated, set, or removed later by the address casting the vote.",
"type": [
"string",
"null"
]
},
"vote": {
"description": "The proposer's position on the proposal.",
"allOf": [
{
"$ref": "#/definitions/Vote"
}
]
}
},
"additionalProperties": false
},
"StakingMsg": {
"description": "The message types of the staking module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto",
"oneOf": [
Expand Down Expand Up @@ -1208,6 +1242,31 @@
},
"additionalProperties": false
},
"Vote": {
"oneOf": [
{
"description": "Marks support for the proposal.",
"type": "string",
"enum": [
"yes"
]
},
{
"description": "Marks opposition to the proposal.",
"type": "string",
"enum": [
"no"
]
},
{
"description": "Marks participation but does not count towards the ratio of support / opposed.",
"type": "string",
"enum": [
"abstain"
]
}
]
},
"VoteOption": {
"type": "string",
"enum": [
Expand Down
Loading

0 comments on commit 43eccde

Please sign in to comment.