Skip to content

Commit

Permalink
fix(pallet-referenda): adjust ongoing checks when finalizing
Browse files Browse the repository at this point in the history
  • Loading branch information
pandres95 committed Mar 26, 2024
1 parent 37798c4 commit e9824c3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions substrate/frame/referenda/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,10 @@ pub mod pallet {
ensure_root(origin)?;
let now = frame_system::Pallet::<T>::block_number();

let mut status = Self::ensure_ongoing(index)?;
let mut status = match ReferendumInfoFor::<T, I>::get(index) {
Some(ReferendumInfo::Ongoing(status)) => Ok(status),
_ => Err(Error::<T, I>::NotOngoing),
}?;
// This is our wake-up, so we can disregard the alarm.
status.alarm = None;
let (info, dirty, branch) = Self::service_referendum(now, index, status);
Expand Down Expand Up @@ -762,7 +765,7 @@ impl<T: Config<I>, I: 'static> Polling<T::Tally> for Pallet<T, I> {
.clone()
.deciding
.map(|d| d.confirming.map(|x| now >= x).unwrap_or(false))
.unwrap();
.unwrap_or(false);
if is_finalizing {
return f(PollStatus::None);
}
Expand Down Expand Up @@ -791,7 +794,7 @@ impl<T: Config<I>, I: 'static> Polling<T::Tally> for Pallet<T, I> {
.clone()
.deciding
.map(|d| d.confirming.map(|x| now >= x).unwrap_or(false))
.unwrap();
.unwrap_or(false);
if is_finalizing {
return f(PollStatus::None);
}
Expand Down
6 changes: 3 additions & 3 deletions substrate/frame/referenda/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ fn basic_happy_path_works() {
run_to(7);
assert_eq!(confirming_until(0), 9);
run_to(10);
// #8: Should be confirmed & ended.
// #10: Should confirm via auction.
assert_eq!(approved_since(0), 10);
assert_ok!(Referenda::refund_decision_deposit(RuntimeOrigin::signed(2), 0));
run_to(13);
// #9: Should not yet be enacted.
// #13: Should not yet be enacted.
assert_eq!(Balances::free_balance(&42), 0);
run_to(14);
// #10: Proposal should be executed.
// #14: Proposal should be executed.
assert_eq!(Balances::free_balance(&42), 1);
});
}
Expand Down

0 comments on commit e9824c3

Please sign in to comment.