Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
FRAME: Fix the Referenda confirming alarm (#13704)
Browse files Browse the repository at this point in the history
* Fix the Referenda confirming alarm

* Add minimal regression test

This fails on bf395c8 since the
downwards rounding voids the curve delay.

Signed-off-by: Oliver Tale-Yazdi <[email protected]>

---------

Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Co-authored-by: Oliver Tale-Yazdi <[email protected]>
  • Loading branch information
2 people authored and pgherveou committed Apr 4, 2023
1 parent 895f9f6 commit c9ad7aa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion frame/referenda/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
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))
})
}

Expand Down
18 changes: 18 additions & 0 deletions frame/referenda/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Test>::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(|| {
Expand Down

0 comments on commit c9ad7aa

Please sign in to comment.