From c9ad7aa090d95442ad14c6ad0cd3754ff98098d1 Mon Sep 17 00:00:00 2001 From: Gavin Wood Date: Mon, 27 Mar 2023 14:04:24 +0200 Subject: [PATCH] FRAME: Fix the Referenda confirming alarm (#13704) * Fix the Referenda confirming alarm * Add minimal regression test This fails on bf395c8308c481a9774373e0b0b14bd7a2e4b8d2 since the downwards rounding voids the curve delay. Signed-off-by: Oliver Tale-Yazdi --------- Signed-off-by: Oliver Tale-Yazdi Co-authored-by: Oliver Tale-Yazdi --- frame/referenda/src/lib.rs | 2 +- frame/referenda/src/tests.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/frame/referenda/src/lib.rs b/frame/referenda/src/lib.rs index f699850062267..b96cf5a76733d 100644 --- a/frame/referenda/src/lib.rs +++ b/frame/referenda/src/lib.rs @@ -1206,7 +1206,7 @@ impl, I: 'static> Pallet { let until_approval = track.min_approval.delay(approval); let until_support = track.min_support.delay(support); let offset = until_support.max(until_approval); - deciding.since.saturating_add(offset * track.decision_period) + deciding.since.saturating_add(offset.mul_ceil(track.decision_period)) }) } diff --git a/frame/referenda/src/tests.rs b/frame/referenda/src/tests.rs index f728350c37e6f..0a1561d001a7d 100644 --- a/frame/referenda/src/tests.rs +++ b/frame/referenda/src/tests.rs @@ -286,6 +286,24 @@ fn alarm_interval_works() { }); } +#[test] +fn decision_time_is_correct() { + new_test_ext().execute_with(|| { + let decision_time = |since: u64| { + Pallet::::decision_time( + &DecidingStatus { since: since.into(), confirming: None }, + &Tally { ayes: 100, nays: 5 }, + TestTracksInfo::tracks()[0].0, + &TestTracksInfo::tracks()[0].1, + ) + }; + + for i in 0u64..=100 { + assert!(decision_time(i) > i, "The decision time should be delayed by the curve"); + } + }); +} + #[test] fn auto_timeout_should_happen_with_nothing_but_submit() { new_test_ext().execute_with(|| {