Skip to content

Commit

Permalink
Merge pull request #16 from Nexus-Protocol/add_migrate_msg_data_to_po…
Browse files Browse the repository at this point in the history
…ll_response

Add migrate msg data to poll response
  • Loading branch information
pronvis authored Oct 19, 2021
2 parents b3caded + fdca803 commit 5c20662
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 8 deletions.
2 changes: 1 addition & 1 deletion artifacts/checksums.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
0406c776d73eb75dfa160be3094f857559350c8b7c203f9bfbfd144a73a7a19a nexus_airdrop.wasm
b911bcadb0dfb9fcdef75f16ce20528eefcecc672da53509f6dbacc0238c5611 nexus_community.wasm
a94cb26b453b9e659b64d6d40a2901cdd2ce19578104c0d715976f77d23065ee nexus_governance.wasm
14d8e381717727fae0961ef5f1af14138b53c65a603e016c237aabde4215f7f8 nexus_governance.wasm
6cdf26b4ca4d10f060ad00593cb057e3c5b1e46805b949c8285ca50d27113e29 nexus_staking.wasm
1e910c3696b81b03d5ce33b7acf506527cb23ad5978cdf21d212ef481a41a7b1 nexus_vesting.wasm
Binary file modified artifacts/nexus_governance.wasm
Binary file not shown.
36 changes: 36 additions & 0 deletions contracts/governance/schema/poll_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@
"null"
]
},
"migrate_data": {
"type": [
"array",
"null"
],
"items": {
"$ref": "#/definitions/PollMigrateMsg"
}
},
"no_votes": {
"$ref": "#/definitions/Uint128"
},
Expand Down Expand Up @@ -107,6 +116,33 @@
}
}
},
"PollMigrateMsg": {
"type": "object",
"required": [
"contract",
"msg",
"new_code_id",
"order"
],
"properties": {
"contract": {
"type": "string"
},
"msg": {
"$ref": "#/definitions/Binary"
},
"new_code_id": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"order": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
}
},
"PollStatus": {
"type": "string",
"enum": [
Expand Down
36 changes: 36 additions & 0 deletions contracts/governance/schema/polls_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,33 @@
}
}
},
"PollMigrateMsg": {
"type": "object",
"required": [
"contract",
"msg",
"new_code_id",
"order"
],
"properties": {
"contract": {
"type": "string"
},
"msg": {
"$ref": "#/definitions/Binary"
},
"new_code_id": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"order": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
}
},
"PollResponse": {
"type": "object",
"required": [
Expand Down Expand Up @@ -87,6 +114,15 @@
"null"
]
},
"migrate_data": {
"type": [
"array",
"null"
],
"items": {
"$ref": "#/definitions/PollMigrateMsg"
}
},
"no_votes": {
"$ref": "#/definitions/Uint128"
},
Expand Down
39 changes: 33 additions & 6 deletions contracts/governance/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use cosmwasm_std::{Deps, Env, StdError, StdResult, Uint128};
use services::{
common::OrderBy,
governance::{
ConfigResponse, PollExecuteMsg, PollResponse, PollStatus, PollsResponse, StakerResponse,
StateResponse, VotersResponse, VotersResponseItem,
ConfigResponse, PollExecuteMsg, PollMigrateMsg, PollResponse, PollStatus, PollsResponse,
StakerResponse, StateResponse, VotersResponse, VotersResponseItem,
},
};

Expand Down Expand Up @@ -41,7 +41,7 @@ pub fn query_state(deps: Deps) -> StdResult<StateResponse> {
pub fn query_poll(deps: Deps, poll_id: u64) -> StdResult<PollResponse> {
let poll = may_load_poll(deps.storage, poll_id)?;
if let Some(poll) = poll {
let data_list: Option<Vec<PollExecuteMsg>> = poll.execute_data.map(|exe_msgs| {
let execute_messages: Option<Vec<PollExecuteMsg>> = poll.execute_data.map(|exe_msgs| {
exe_msgs
.iter()
.map(|msg| PollExecuteMsg {
Expand All @@ -52,6 +52,18 @@ pub fn query_poll(deps: Deps, poll_id: u64) -> StdResult<PollResponse> {
.collect()
});

let migrate_messages: Option<Vec<PollMigrateMsg>> = poll.migrate_data.map(|migrate_msgs| {
migrate_msgs
.iter()
.map(|msg| PollMigrateMsg {
order: msg.order,
contract: msg.contract.to_string(),
msg: msg.msg.clone(),
new_code_id: msg.new_code_id,
})
.collect()
});

Ok(PollResponse {
id: poll.id,
creator: poll.creator.to_string(),
Expand All @@ -61,7 +73,8 @@ pub fn query_poll(deps: Deps, poll_id: u64) -> StdResult<PollResponse> {
description: poll.description,
link: poll.link,
deposit_amount: poll.deposit_amount,
execute_data: data_list,
execute_data: execute_messages,
migrate_data: migrate_messages,
yes_votes: poll.yes_votes,
no_votes: poll.no_votes,
staked_amount: poll.staked_amount,
Expand All @@ -84,7 +97,7 @@ pub fn query_polls(
let poll_responses: StdResult<Vec<PollResponse>> = polls
.into_iter()
.map(|poll| {
let data_list: Option<Vec<PollExecuteMsg>> = poll.execute_data.map(|exe_msgs| {
let execute_messages: Option<Vec<PollExecuteMsg>> = poll.execute_data.map(|exe_msgs| {
exe_msgs
.iter()
.map(|msg| PollExecuteMsg {
Expand All @@ -95,6 +108,19 @@ pub fn query_polls(
.collect()
});

let migrate_messages: Option<Vec<PollMigrateMsg>> =
poll.migrate_data.map(|migrate_msgs| {
migrate_msgs
.iter()
.map(|msg| PollMigrateMsg {
order: msg.order,
contract: msg.contract.to_string(),
msg: msg.msg.clone(),
new_code_id: msg.new_code_id,
})
.collect()
});

Ok(PollResponse {
id: poll.id,
creator: poll.creator.to_string(),
Expand All @@ -104,7 +130,8 @@ pub fn query_polls(
description: poll.description.to_string(),
link: poll.link.clone(),
deposit_amount: poll.deposit_amount,
execute_data: data_list,
execute_data: execute_messages,
migrate_data: migrate_messages,
yes_votes: poll.yes_votes,
no_votes: poll.no_votes,
staked_amount: poll.staked_amount,
Expand Down
49 changes: 48 additions & 1 deletion contracts/governance/src/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ fn query_polls() {
link: Some("http://google.com".to_string()),
deposit_amount: Uint128::new(DEFAULT_PROPOSAL_DEPOSIT),
execute_data: Some(execute_msgs.clone()),
migrate_data: None,
yes_votes: Uint128::zero(),
no_votes: Uint128::zero(),
staked_amount: None,
Expand All @@ -440,6 +441,7 @@ fn query_polls() {
link: None,
deposit_amount: Uint128::new(DEFAULT_PROPOSAL_DEPOSIT),
execute_data: None,
migrate_data: None,
yes_votes: Uint128::zero(),
no_votes: Uint128::zero(),
staked_amount: None,
Expand Down Expand Up @@ -472,6 +474,7 @@ fn query_polls() {
link: None,
deposit_amount: Uint128::new(DEFAULT_PROPOSAL_DEPOSIT),
execute_data: None,
migrate_data: None,
yes_votes: Uint128::zero(),
no_votes: Uint128::zero(),
staked_amount: None,
Expand Down Expand Up @@ -503,6 +506,7 @@ fn query_polls() {
link: Some("http://google.com".to_string()),
deposit_amount: Uint128::new(DEFAULT_PROPOSAL_DEPOSIT),
execute_data: Some(execute_msgs),
migrate_data: None,
yes_votes: Uint128::zero(),
no_votes: Uint128::zero(),
staked_amount: None,
Expand Down Expand Up @@ -534,6 +538,7 @@ fn query_polls() {
link: None,
deposit_amount: Uint128::new(DEFAULT_PROPOSAL_DEPOSIT),
execute_data: None,
migrate_data: None,
yes_votes: Uint128::zero(),
no_votes: Uint128::zero(),
staked_amount: None,
Expand Down Expand Up @@ -2693,7 +2698,13 @@ fn execute_poll_with_order() {
new_code_id: 11,
});

let msg = create_poll_msg("test", "test", None, Some(execute_msgs), Some(migrate_msgs));
let msg = create_poll_msg(
"test",
"test",
None,
Some(execute_msgs.clone()),
Some(migrate_msgs.clone()),
);

let execute_res = execute(
deps.as_mut(),
Expand All @@ -2715,6 +2726,42 @@ fn execute_poll_with_order() {
&deps,
);

let query_res = query(
deps.as_ref(),
creator_env.clone(),
QueryMsg::Polls {
filter: None,
start_after: None,
limit: None,
order_by: Some(OrderBy::Desc),
},
)
.unwrap();
let query_response: PollsResponse = from_binary(&query_res).unwrap();
assert_eq!(
query_response.polls,
vec![PollResponse {
id: 1u64,
creator: TEST_CREATOR.to_string(),
status: PollStatus::InProgress,
end_time: creator_env
.block
.time
.plus_seconds(DEFAULT_VOTING_PERIOD)
.seconds(),
title: "test".to_string(),
description: "test".to_string(),
link: None,
deposit_amount: Uint128::new(DEFAULT_PROPOSAL_DEPOSIT),
execute_data: Some(execute_msgs),
migrate_data: Some(migrate_msgs),
yes_votes: Uint128::zero(),
no_votes: Uint128::zero(),
staked_amount: None,
total_balance_at_end_poll: None,
}]
);

deps.querier.with_token_balances(&[(
&VOTING_TOKEN.to_string(),
&[(
Expand Down
1 change: 1 addition & 0 deletions packages/services/src/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ pub struct PollResponse {
pub link: Option<String>,
pub deposit_amount: Uint128,
pub execute_data: Option<Vec<PollExecuteMsg>>,
pub migrate_data: Option<Vec<PollMigrateMsg>>,
pub yes_votes: Uint128, // balance
pub no_votes: Uint128, // balance
pub staked_amount: Option<Uint128>,
Expand Down

0 comments on commit 5c20662

Please sign in to comment.