Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
alarm interval, test (#12818)
  • Loading branch information
muharem authored Dec 1, 2022
commit 797caafcc25ff1663f1a56ceb37379e0678bcbdf
17 changes: 1 addition & 16 deletions frame/referenda/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,9 +866,6 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
// Set an alarm call for the next block to nudge the track along.
let now = frame_system::Pallet::<T>::block_number();
let next_block = now + One::one();
let alarm_interval = T::AlarmInterval::get().max(One::one());
let when = (next_block + alarm_interval - One::one()) / alarm_interval * alarm_interval;

let call = match T::Preimages::bound(CallOf::<T, I>::from(Call::one_fewer_deciding {
track,
})) {
Expand All @@ -878,19 +875,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
return
},
};
let maybe_result = T::Scheduler::schedule(
DispatchTime::At(when),
None,
128u8,
frame_system::RawOrigin::Root.into(),
call,
);
debug_assert!(
maybe_result.is_ok(),
"Unable to schedule a new alarm at #{:?} (now: #{:?})?!",
when,
now
);
Self::set_alarm(call, next_block);
}

/// Ensure that a `service_referendum` alarm happens for the referendum `index` at `alarm`.
Expand Down
21 changes: 21 additions & 0 deletions frame/referenda/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,27 @@ fn queueing_works() {
});
}

#[test]
fn alarm_interval_works() {
new_test_ext().execute_with(|| {
let call =
<Test as Config>::Preimages::bound(CallOf::<Test, ()>::from(Call::nudge_referendum {
index: 0,
}))
.unwrap();
for n in 0..10 {
let interval = n * n;
let now = 100 * (interval + 1);
System::set_block_number(now);
AlarmInterval::set(interval);
let when = now + 1;
let (actual, _) = Referenda::set_alarm(call.clone(), when).unwrap();
assert!(actual >= when);
assert!(actual - interval <= when);
}
});
}

#[test]
fn auto_timeout_should_happen_with_nothing_but_submit() {
new_test_ext().execute_with(|| {
Expand Down