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

Commit

Permalink
use ensure
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed May 22, 2023
1 parent b748825 commit 4b5db23
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 6 additions & 4 deletions runtime/common/src/crowdloan/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ impl<T: Config> OnRuntimeUpgrade for MigrateToTrackInactiveV2<T> {

#[cfg(feature = "try-runtime")]
fn post_upgrade(total: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
let (total, active) = <(BalanceOf<T>, BalanceOf<T>)>::decode(&mut total.as_slice())
.expect("the state parameter should be something that was generated by pre_upgrade");
assert_eq!(active - total, CurrencyOf::<T>::active_issuance(), "the total be correct");
Ok(())
if let Ok((total, active)) = <(BalanceOf<T>, BalanceOf<T>)>::decode(&mut total.as_slice()) {
ensure!(active - total == CurrencyOf::<T>::active_issuance(), "the total be correct");
Ok(())
} else {
Err("the state parameter should be something that was generated by pre_upgrade".into())
}
}
}

Expand Down
7 changes: 3 additions & 4 deletions runtime/parachains/src/configuration/migration_ump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use parity_scale_codec::{Decode, Encode};

pub mod latest {
use super::*;
use frame_support::{pallet_prelude::Weight, traits::OnRuntimeUpgrade};
use frame_support::{ensure, pallet_prelude::Weight, traits::OnRuntimeUpgrade};

/// Force update the UMP limits in the parachain host config.
// NOTE: `OnRuntimeUpgrade` does not have a `self`, so everything must be compile time.
Expand Down Expand Up @@ -99,9 +99,8 @@ pub mod latest {
"Last pending HostConfig upgrade:\n\n{:#?}\n",
pending.last()
);
assert_eq!(
pending.len(),
old_pending as usize + 1,
ensure!(
pending.len() == old_pending as usize + 1,
"There must be a new pending upgrade enqueued"
);

Expand Down

0 comments on commit 4b5db23

Please sign in to comment.