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

Do not run slow running try state tests in CI #13286

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion frame/bags-list/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

#[cfg(feature = "try-runtime")]
use frame_support::traits::TryStateSelect;

#[pallet::pallet]
#[pallet::generate_store(pub(crate) trait Store)]
pub struct Pallet<T, I = ()>(_);
Expand Down Expand Up @@ -268,7 +271,7 @@ pub mod pallet {
}

#[cfg(feature = "try-runtime")]
fn try_state(_: BlockNumberFor<T>) -> Result<(), &'static str> {
fn try_state(_: BlockNumberFor<T>, _: TryStateSelect) -> Result<(), &'static str> {
<Self as SortedListProvider<T::AccountId>>::try_state()
}
}
Expand Down
4 changes: 2 additions & 2 deletions frame/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ where
let _guard = frame_support::StorageNoopGuard::default();
<AllPalletsWithSystem as frame_support::traits::TryState<System::BlockNumber>>::try_state(
frame_system::Pallet::<System>::block_number(),
frame_try_runtime::TryStateSelect::All,
frame_try_runtime::TryStateSelect::Fast,
)?;
}

Expand All @@ -353,7 +353,7 @@ where
let _guard = frame_support::StorageNoopGuard::default();
<AllPalletsWithSystem as frame_support::traits::TryState<System::BlockNumber>>::try_state(
frame_system::Pallet::<System>::block_number(),
frame_try_runtime::TryStateSelect::All,
frame_try_runtime::TryStateSelect::Fast,
)?;
}

Expand Down
4 changes: 2 additions & 2 deletions frame/fast-unstake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub mod pallet {
use crate::types::*;
use frame_support::{
pallet_prelude::*,
traits::{Defensive, ReservableCurrency, StorageVersion},
traits::{Defensive, ReservableCurrency, StorageVersion, TryStateSelect},
};
use frame_system::pallet_prelude::*;
use sp_runtime::{traits::Zero, DispatchResult};
Expand Down Expand Up @@ -228,7 +228,7 @@ pub mod pallet {
}

#[cfg(feature = "try-runtime")]
fn try_state(_n: T::BlockNumber) -> Result<(), &'static str> {
fn try_state(_n: T::BlockNumber, _: TryStateSelect) -> Result<(), &'static str> {
// ensure that the value of `ErasToCheckPerBlock` is less than
// `T::MaxErasToCheckPerBlock`.
assert!(
Expand Down
4 changes: 2 additions & 2 deletions frame/nomination-pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ impl<T: Config> Get<u32> for TotalUnbondingPools<T> {
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::traits::StorageVersion;
use frame_support::traits::{StorageVersion, TryStateSelect};
use frame_system::{ensure_signed, pallet_prelude::*};

/// The current storage version.
Expand Down Expand Up @@ -2122,7 +2122,7 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
#[cfg(feature = "try-runtime")]
fn try_state(_n: BlockNumberFor<T>) -> Result<(), &'static str> {
fn try_state(_n: BlockNumberFor<T>, _: TryStateSelect) -> Result<(), &'static str> {
Self::do_try_state(u8::MAX)
}

Expand Down
3 changes: 2 additions & 1 deletion frame/nomination-pools/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use sp_std::{collections::btree_map::BTreeMap, vec::Vec};

pub mod v1 {
use super::*;
use frame_support::traits::TryStateSelect;

#[derive(Decode)]
pub struct OldPoolRoles<AccountId> {
Expand Down Expand Up @@ -100,7 +101,7 @@ pub mod v1 {
fn post_upgrade(_: Vec<u8>) -> Result<(), &'static str> {
// new version must be set.
assert_eq!(Pallet::<T>::on_chain_storage_version(), 1);
Pallet::<T>::try_state(frame_system::Pallet::<T>::block_number())?;
Pallet::<T>::try_state(frame_system::Pallet::<T>::block_number(), TryStateSelect::All)?;
Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion frame/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ impl ExtBuilder {
let mut ext = self.build();
ext.execute_with(test);
ext.execute_with(|| {
Staking::do_try_state(System::block_number()).unwrap();
Staking::do_try_state(System::block_number(), false).unwrap();
});
}
}
Expand Down
22 changes: 19 additions & 3 deletions frame/staking/src/pallet/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1668,19 +1668,35 @@ impl<T: Config> StakingInterface for Pallet<T> {
}
}

#[cfg(any(test, feature = "try-runtime"))]
#[derive(PartialEq)]
pub(crate) enum TestMode {
// run only fast running tests
Fast,
// run all the tests
All,
}

#[cfg(any(test, feature = "try-runtime"))]
impl<T: Config> Pallet<T> {
pub(crate) fn do_try_state(_: BlockNumberFor<T>) -> Result<(), &'static str> {
pub(crate) fn do_try_state(_: BlockNumberFor<T>, fast_mode: bool) -> Result<(), &'static str> {
// fast tests
ensure!(
T::VoterList::iter()
.all(|x| <Nominators<T>>::contains_key(&x) || <Validators<T>>::contains_key(&x)),
"VoterList contains non-staker"
);

Self::check_nominators()?;
Self::check_exposures()?;
Self::check_ledgers()?;
Self::check_count()
Self::check_count()?;

if !fast_mode {
// slow running tests (should be avoided on CI)
Self::check_nominators()?;
}

Ok(())
}

fn check_count() -> Result<(), &'static str> {
Expand Down
5 changes: 3 additions & 2 deletions frame/staking/src/pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub(crate) const SPECULATIVE_NUM_SPANS: u32 = 32;
#[frame_support::pallet]
pub mod pallet {
use frame_election_provider_support::ElectionDataProvider;
use frame_support::traits::TryStateSelect;

use crate::BenchmarkingConfig;

Expand Down Expand Up @@ -825,8 +826,8 @@ pub mod pallet {
}

#[cfg(feature = "try-runtime")]
fn try_state(n: BlockNumberFor<T>) -> Result<(), &'static str> {
Self::do_try_state(n)
fn try_state(n: BlockNumberFor<T>, select: TryStateSelect) -> Result<(), &'static str> {
Self::do_try_state(n, select == TryStateSelect::Fast)
}
}

Expand Down
4 changes: 2 additions & 2 deletions frame/support/procedural/src/pallet/expand/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,14 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream {
{
fn try_state(
n: <T as #frame_system::Config>::BlockNumber,
_s: #frame_support::traits::TryStateSelect
s: #frame_support::traits::TryStateSelect
) -> Result<(), &'static str> {
#log_try_state
<
Self as #frame_support::traits::Hooks<
<T as #frame_system::Config>::BlockNumber
>
>::try_state(n)
>::try_state(n, s)
}
}
)
Expand Down
4 changes: 3 additions & 1 deletion frame/support/src/traits/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

//! Traits for hooking tasks to events in a blockchain's lifecycle.

#[cfg(feature = "try-runtime")]
use super::try_runtime::Select as TryStateSelect;
use crate::weights::Weight;
use impl_trait_for_tuples::impl_for_tuples;
use sp_runtime::traits::AtLeast32BitUnsigned;
Expand Down Expand Up @@ -272,7 +274,7 @@ pub trait Hooks<BlockNumber> {
///
/// This hook should not alter any storage.
#[cfg(feature = "try-runtime")]
fn try_state(_n: BlockNumber) -> Result<(), &'static str> {
fn try_state(_n: BlockNumber, _s: TryStateSelect) -> Result<(), &'static str> {
Ok(())
}

Expand Down
16 changes: 11 additions & 5 deletions frame/support/src/traits/try_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use sp_arithmetic::traits::AtLeast32BitUnsigned;
use sp_std::prelude::*;

/// Which state tests to execute.
#[derive(codec::Encode, codec::Decode, Clone)]
#[derive(codec::Encode, codec::Decode, Clone, Eq, PartialEq)]
pub enum Select {
/// None of them.
None,
Expand All @@ -34,6 +34,10 @@ pub enum Select {
///
/// Pallet names are obtained from [`super::PalletInfoAccess`].
Only(Vec<Vec<u8>>),
/// Run only fast running tests.
///
/// Optimal mode for CI. Avoids long running tests.
Fast,
}

impl Default for Select {
Expand All @@ -55,6 +59,7 @@ impl sp_std::fmt::Debug for Select {
),
Select::All => write!(f, "All"),
Select::None => write!(f, "None"),
Select::Fast => write!(f, "Fast"),
}
}
}
Expand All @@ -63,9 +68,10 @@ impl sp_std::fmt::Debug for Select {
impl sp_std::str::FromStr for Select {
type Err = &'static str;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"all" | "All" => Ok(Select::All),
"none" | "None" => Ok(Select::None),
match s.to_lowercase().as_ref() {
"fast" => Ok(Select::Fast),
"all" => Ok(Select::All),
"none" => Ok(Select::None),
_ =>
if s.starts_with("rr-") {
let count = s
Expand Down Expand Up @@ -142,7 +148,7 @@ impl<BlockNumber: Clone + sp_std::fmt::Debug + AtLeast32BitUnsigned> TryState<Bl
fn try_state(n: BlockNumber, targets: Select) -> Result<(), &'static str> {
match targets {
Select::None => Ok(()),
Select::All => {
Select::All | Select::Fast => {
let mut result = Ok(());
for_tuples!( #( result = result.and(Tuple::try_state(n.clone(), targets.clone())); )* );
result
Expand Down
1 change: 1 addition & 0 deletions utils/frame/try-runtime/cli/src/commands/execute_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub struct ExecuteBlockCmd {
///
/// Expected values:
/// - `all`
/// - `fast`
/// - `none`
/// - A comma separated list of pallets, as per pallet names in `construct_runtime!()` (e.g.
/// `Staking, System`).
Expand Down
1 change: 1 addition & 0 deletions utils/frame/try-runtime/cli/src/commands/follow_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub struct FollowChainCmd {
///
/// Expected values:
/// - `all`
/// - `fast`
/// - `none`
/// - A comma separated list of pallets, as per pallet names in `construct_runtime!()` (e.g.
/// `Staking, System`).
Expand Down