Skip to content

Commit c3e21c0

Browse files
committed
Merge branch 'brent/fix-query-proposal-result' (#2573)
* brent/fix-query-proposal-result: change log and fix e2e tests changelog: add #2573 quick fix of query result for active proposal
2 parents c52a4fa + 94c9fc1 commit c3e21c0

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Fixes the query-proposal-result output in the case that a proposal is still
2+
voting. ([\#2573](https://github.com/anoma/namada/pull/2573))

crates/apps/src/lib/client/rpc.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,15 +1223,43 @@ pub async fn query_proposal_result(
12231223
let proposal_id =
12241224
args.proposal_id.expect("Proposal id should be defined.");
12251225

1226+
let current_epoch = query_epoch(context.client()).await.unwrap();
12261227
let proposal_result = namada_sdk::rpc::query_proposal_result(
12271228
context.client(),
12281229
proposal_id,
12291230
)
12301231
.await;
1232+
let proposal_query = namada_sdk::rpc::query_proposal_by_id(
1233+
context.client(),
1234+
proposal_id,
1235+
)
1236+
.await;
12311237

1232-
if let Ok(Some(proposal_result)) = proposal_result {
1238+
if let (Ok(Some(proposal_result)), Ok(Some(proposal_query))) =
1239+
(proposal_result, proposal_query)
1240+
{
12331241
display_line!(context.io(), "Proposal Id: {} ", proposal_id);
1234-
display_line!(context.io(), "{:4}{}", "", proposal_result);
1242+
if current_epoch >= proposal_query.voting_end_epoch {
1243+
display_line!(context.io(), "{:4}{}", "", proposal_result);
1244+
} else {
1245+
display_line!(
1246+
context.io(),
1247+
"{:4}Still voting until epoch {}",
1248+
"",
1249+
proposal_query.voting_end_epoch
1250+
);
1251+
let res = format!("{}", proposal_result);
1252+
if let Some(idx) = res.find(' ') {
1253+
let slice = &res[idx..];
1254+
display_line!(context.io(), "{:4}Currently{}", "", slice);
1255+
} else {
1256+
display_line!(
1257+
context.io(),
1258+
"{:4}Error parsing the result string",
1259+
"",
1260+
);
1261+
}
1262+
}
12351263
} else {
12361264
edisplay_line!(context.io(), "Proposal {} not found.", proposal_id);
12371265
};

crates/governance/src/utils.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,21 @@ impl Display for ProposalResult {
215215
_ => self.total_voting_power.mul_ceil(Dec::one() / 3),
216216
};
217217

218+
let thresh_frac =
219+
Dec::from(threshold) / Dec::from(self.total_voting_power);
220+
218221
write!(
219222
f,
220223
"{} with {} yay votes, {} nay votes and {} abstain votes, total \
221-
voting power: {} threshold was: {}",
224+
voting power: {}, threshold (fraction) of total voting power \
225+
needed to tally: {} ({})",
222226
self.result,
223227
self.total_yay_power.to_string_native(),
224228
self.total_nay_power.to_string_native(),
225229
self.total_abstain_power.to_string_native(),
226230
self.total_voting_power.to_string_native(),
227-
threshold.to_string_native()
231+
threshold.to_string_native(),
232+
thresh_frac
228233
)
229234
}
230235
}

crates/tests/src/e2e/ledger_tests.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,8 +2024,9 @@ fn proposal_submission() -> Result<()> {
20242024
client.exp_string("Proposal Id: 0")?;
20252025
client.exp_string(
20262026
"passed with 100000.000000 yay votes, 900.000000 nay votes and \
2027-
0.000000 abstain votes, total voting power: 100900.000000 threshold \
2028-
was: 67266.66666",
2027+
0.000000 abstain votes, total voting power: 100900.000000, threshold \
2028+
(fraction) of total voting power needed to tally: 67266.666667 \
2029+
(0.666666666669)",
20292030
)?;
20302031
client.assert_success();
20312032

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

0 commit comments

Comments
 (0)