mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-23 14:21:11 +00:00
BREAKING - Try-runtime: Use proper error types (#13993)
* Try-state: DispatchResult as return type * try_state for the rest of the pallets * pre_upgrade * post_upgrade * try_runtime_upgrade * fixes * bags-list fix * fix * update test * warning fix * ... * final fixes 🤞 * warning.. * frame-support * warnings * Update frame/staking/src/migrations.rs Co-authored-by: Liam Aharon <liam.aharon@hotmail.com> * fix * fix warning * nit fix * merge fixes * small fix * should be good now * missed these ones * introduce TryRuntimeError and TryRuntimeResult * fixes * fix * removed TryRuntimeResult & made some fixes * fix testsg * tests passing * unnecessary imports * Update frame/assets/src/migration.rs Co-authored-by: Keith Yeung <kungfukeith11@gmail.com> --------- Co-authored-by: Liam Aharon <liam.aharon@hotmail.com> Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
@@ -42,6 +42,9 @@ use sp_std::{
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
#[cfg(any(test, feature = "try-runtime", feature = "fuzz"))]
|
||||
use sp_runtime::TryRuntimeError;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Encode, Decode, MaxEncodedLen, TypeInfo, PalletError)]
|
||||
pub enum ListError {
|
||||
/// A duplicate id has been detected.
|
||||
@@ -512,11 +515,11 @@ impl<T: Config<I>, I: 'static> List<T, I> {
|
||||
/// * and sanity-checks all bags and nodes. This will cascade down all the checks and makes sure
|
||||
/// all bags and nodes are checked per *any* update to `List`.
|
||||
#[cfg(any(test, feature = "try-runtime", feature = "fuzz"))]
|
||||
pub(crate) fn do_try_state() -> Result<(), &'static str> {
|
||||
pub(crate) fn do_try_state() -> Result<(), TryRuntimeError> {
|
||||
let mut seen_in_list = BTreeSet::new();
|
||||
ensure!(
|
||||
Self::iter().map(|node| node.id).all(|id| seen_in_list.insert(id)),
|
||||
"duplicate identified",
|
||||
"duplicate identified"
|
||||
);
|
||||
|
||||
let iter_count = Self::iter().count() as u32;
|
||||
@@ -750,7 +753,7 @@ impl<T: Config<I>, I: 'static> Bag<T, I> {
|
||||
/// * Ensures tail has no next.
|
||||
/// * Ensures there are no loops, traversal from head to tail is correct.
|
||||
#[cfg(any(test, feature = "try-runtime", feature = "fuzz"))]
|
||||
fn do_try_state(&self) -> Result<(), &'static str> {
|
||||
fn do_try_state(&self) -> Result<(), TryRuntimeError> {
|
||||
frame_support::ensure!(
|
||||
self.head()
|
||||
.map(|head| head.prev().is_none())
|
||||
@@ -895,15 +898,12 @@ impl<T: Config<I>, I: 'static> Node<T, I> {
|
||||
}
|
||||
|
||||
#[cfg(any(test, feature = "try-runtime", feature = "fuzz"))]
|
||||
fn do_try_state(&self) -> Result<(), &'static str> {
|
||||
fn do_try_state(&self) -> Result<(), TryRuntimeError> {
|
||||
let expected_bag = Bag::<T, I>::get(self.bag_upper).ok_or("bag not found for node")?;
|
||||
|
||||
let id = self.id();
|
||||
|
||||
frame_support::ensure!(
|
||||
expected_bag.contains(id),
|
||||
"node does not exist in the expected bag"
|
||||
);
|
||||
frame_support::ensure!(expected_bag.contains(id), "node does not exist in the bag");
|
||||
|
||||
let non_terminal_check = !self.is_terminal() &&
|
||||
expected_bag.head.as_ref() != Some(id) &&
|
||||
|
||||
@@ -22,6 +22,7 @@ use crate::{
|
||||
};
|
||||
use frame_election_provider_support::{SortedListProvider, VoteWeight};
|
||||
use frame_support::{assert_ok, assert_storage_noop};
|
||||
use sp_runtime::TryRuntimeError;
|
||||
|
||||
fn node(
|
||||
id: AccountId,
|
||||
@@ -359,7 +360,10 @@ mod list {
|
||||
// make sure there are no duplicates.
|
||||
ExtBuilder::default().build_and_execute_no_post_check(|| {
|
||||
Bag::<Runtime>::get(10).unwrap().insert_unchecked(2, 10);
|
||||
assert_eq!(List::<Runtime>::do_try_state(), Err("duplicate identified"));
|
||||
assert_eq!(
|
||||
List::<Runtime>::do_try_state(),
|
||||
TryRuntimeError::Other("duplicate identified").into()
|
||||
);
|
||||
});
|
||||
|
||||
// ensure count is in sync with `ListNodes::count()`.
|
||||
@@ -373,7 +377,10 @@ mod list {
|
||||
CounterForListNodes::<Runtime>::mutate(|counter| *counter += 1);
|
||||
assert_eq!(crate::ListNodes::<Runtime>::count(), 5);
|
||||
|
||||
assert_eq!(List::<Runtime>::do_try_state(), Err("iter_count != stored_count"));
|
||||
assert_eq!(
|
||||
List::<Runtime>::do_try_state(),
|
||||
TryRuntimeError::Other("iter_count != stored_count").into()
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user