Skip to content

Commit 89fbcb9

Browse files
committed
Test and fix GovMsg serialization
1 parent 2eb9707 commit 89fbcb9

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

packages/std/src/results/cosmos_msg.rs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ pub enum GovMsg {
213213
#[cfg(feature = "cosmwasm_1_2")]
214214
VoteWeighted {
215215
proposal_id: u64,
216-
vote: WeightedVoteOption,
216+
options: Vec<WeightedVoteOption>,
217217
},
218218
}
219219

@@ -359,4 +359,47 @@ mod tests {
359359
"Execute { contract_addr: \"joe\", msg: Binary(009f9296), funds: [] }"
360360
);
361361
}
362+
363+
#[test]
364+
#[cfg(feature = "stargate")]
365+
fn gov_msg_serializes_to_correct_json() {
366+
// Vote
367+
let msg = GovMsg::Vote {
368+
proposal_id: 4,
369+
vote: VoteOption::NoWithVeto,
370+
};
371+
let json = to_binary(&msg).unwrap();
372+
assert_eq!(
373+
String::from_utf8_lossy(&json),
374+
r#"{"vote":{"proposal_id":4,"vote":"no_with_veto"}}"#,
375+
);
376+
377+
// VoteWeighted
378+
#[cfg(feature = "cosmwasm_1_2")]
379+
{
380+
let msg = GovMsg::VoteWeighted {
381+
proposal_id: 25,
382+
options: vec![
383+
WeightedVoteOption {
384+
weight: Decimal::percent(25),
385+
option: VoteOption::Yes,
386+
},
387+
WeightedVoteOption {
388+
weight: Decimal::percent(25),
389+
option: VoteOption::No,
390+
},
391+
WeightedVoteOption {
392+
weight: Decimal::percent(50),
393+
option: VoteOption::Abstain,
394+
},
395+
],
396+
};
397+
398+
let json = to_binary(&msg).unwrap();
399+
assert_eq!(
400+
String::from_utf8_lossy(&json),
401+
r#"{"vote_weighted":{"proposal_id":25,"options":[{"option":"yes","weight":"0.25"},{"option":"no","weight":"0.25"},{"option":"abstain","weight":"0.5"}]}}"#,
402+
);
403+
}
404+
}
362405
}

0 commit comments

Comments
 (0)