Skip to content

Commit

Permalink
Merge branch 'brent/fix-query-proposal-result' (#2573)
Browse files Browse the repository at this point in the history
* brent/fix-query-proposal-result:
  change log and fix e2e tests
  changelog: add #2573
  quick fix of query result for active proposal
  • Loading branch information
brentstone committed Feb 10, 2024
2 parents c52a4fa + 94c9fc1 commit c3e21c0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Fixes the query-proposal-result output in the case that a proposal is still
voting. ([\#2573](https://github.com/anoma/namada/pull/2573))
32 changes: 30 additions & 2 deletions crates/apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1223,15 +1223,43 @@ pub async fn query_proposal_result(
let proposal_id =
args.proposal_id.expect("Proposal id should be defined.");

let current_epoch = query_epoch(context.client()).await.unwrap();
let proposal_result = namada_sdk::rpc::query_proposal_result(
context.client(),
proposal_id,
)
.await;
let proposal_query = namada_sdk::rpc::query_proposal_by_id(
context.client(),
proposal_id,
)
.await;

if let Ok(Some(proposal_result)) = proposal_result {
if let (Ok(Some(proposal_result)), Ok(Some(proposal_query))) =
(proposal_result, proposal_query)
{
display_line!(context.io(), "Proposal Id: {} ", proposal_id);
display_line!(context.io(), "{:4}{}", "", proposal_result);
if current_epoch >= proposal_query.voting_end_epoch {
display_line!(context.io(), "{:4}{}", "", proposal_result);
} else {
display_line!(
context.io(),
"{:4}Still voting until epoch {}",
"",
proposal_query.voting_end_epoch
);
let res = format!("{}", proposal_result);
if let Some(idx) = res.find(' ') {
let slice = &res[idx..];
display_line!(context.io(), "{:4}Currently{}", "", slice);
} else {
display_line!(
context.io(),
"{:4}Error parsing the result string",
"",
);
}
}
} else {
edisplay_line!(context.io(), "Proposal {} not found.", proposal_id);
};
Expand Down
9 changes: 7 additions & 2 deletions crates/governance/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,21 @@ impl Display for ProposalResult {
_ => self.total_voting_power.mul_ceil(Dec::one() / 3),
};

let thresh_frac =
Dec::from(threshold) / Dec::from(self.total_voting_power);

write!(
f,
"{} with {} yay votes, {} nay votes and {} abstain votes, total \
voting power: {} threshold was: {}",
voting power: {}, threshold (fraction) of total voting power \
needed to tally: {} ({})",
self.result,
self.total_yay_power.to_string_native(),
self.total_nay_power.to_string_native(),
self.total_abstain_power.to_string_native(),
self.total_voting_power.to_string_native(),
threshold.to_string_native()
threshold.to_string_native(),
thresh_frac
)
}
}
Expand Down
10 changes: 6 additions & 4 deletions crates/tests/src/e2e/ledger_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2024,8 +2024,9 @@ fn proposal_submission() -> Result<()> {
client.exp_string("Proposal Id: 0")?;
client.exp_string(
"passed with 100000.000000 yay votes, 900.000000 nay votes and \
0.000000 abstain votes, total voting power: 100900.000000 threshold \
was: 67266.66666",
0.000000 abstain votes, total voting power: 100900.000000, threshold \
(fraction) of total voting power needed to tally: 67266.666667 \
(0.666666666669)",
)?;
client.assert_success();

Expand Down Expand Up @@ -3896,8 +3897,9 @@ fn proposal_change_shielded_reward() -> Result<()> {
client.exp_string("Proposal Id: 0")?;
client.exp_string(
"passed with 100000.000000 yay votes, 900.000000 nay votes and \
0.000000 abstain votes, total voting power: 100900.000000 threshold \
was: 67266.66666",
0.000000 abstain votes, total voting power: 100900.000000, threshold \
(fraction) of total voting power needed to tally: 67266.666667 \
(0.666666666669)",
)?;
client.assert_success();

Expand Down

0 comments on commit c3e21c0

Please sign in to comment.