Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
16 changes: 6 additions & 10 deletions frame/fast-unstake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,12 @@ pub mod pallet {
}

fn integrity_test() {
sp_std::if_std! {
sp_io::TestExternalities::new_empty().execute_with(|| {
// ensure that the value of `ErasToCheckPerBlock` is less than
// `T::MaxErasToCheckPerBlock`.
assert!(
ErasToCheckPerBlock::<T>::get() <= T::MaxErasToCheckPerBlock::get(),
"the value of `ErasToCheckPerBlock` is greater than `T::MaxErasToCheckPerBlock`",
);
});
}
// Ensure that the value of `ErasToCheckPerBlock` is less or equal to
// `T::MaxErasToCheckPerBlock`.
assert!(
ErasToCheckPerBlock::<T>::get() <= T::MaxErasToCheckPerBlock::get(),
"the value of `ErasToCheckPerBlock` is greater than `T::MaxErasToCheckPerBlock`",
);
}

#[cfg(feature = "try-runtime")]
Expand Down
16 changes: 6 additions & 10 deletions frame/staking/src/pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,16 +794,12 @@ pub mod pallet {
<T::GenesisElectionProvider as ElectionProviderBase>::MaxWinners::get()
);

sp_std::if_std! {
sp_io::TestExternalities::new_empty().execute_with(||
assert!(
T::SlashDeferDuration::get() < T::BondingDuration::get() || T::BondingDuration::get() == 0,
"As per documentation, slash defer duration ({}) should be less than bonding duration ({}).",
T::SlashDeferDuration::get(),
T::BondingDuration::get(),
)
);
}
assert!(
T::SlashDeferDuration::get() < T::BondingDuration::get() || T::BondingDuration::get() == 0,
"As per documentation, slash defer duration ({}) should be less than bonding duration ({}).",
T::SlashDeferDuration::get(),
T::BondingDuration::get(),
)
}

#[cfg(feature = "try-runtime")]
Expand Down
10 changes: 6 additions & 4 deletions frame/support/procedural/src/pallet/expand/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,13 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream {
for #pallet_ident<#type_use_gen> #where_clause
{
fn integrity_test() {
<
Self as #frame_support::traits::Hooks<
#frame_system::pallet_prelude::BlockNumberFor::<T>
>
#frame_support::sp_io::TestExternalities::default().execute_with(|| {
<
Self as #frame_support::traits::Hooks<
#frame_system::pallet_prelude::BlockNumberFor::<T>
>
>::integrity_test()
});
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions frame/support/src/traits/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ pub trait Hooks<BlockNumber> {
/// `type Bar: Get<u32>` where `Foo::get()` must always be greater than `Bar::get()`, such
/// checks can be asserted upon here.
///
/// Note that this hook is not executed in an externality environment, so if access to state is
/// needed, the code should be wrapped in `sp_io::TestExternalities`.
/// Note that this hook is executed in an externality environment, provided by
/// `sp_io::TestExternalities`. This makes it possible to access the storage.
fn integrity_test() {}
}

Expand Down
1 change: 1 addition & 0 deletions frame/system/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// Benchmarks for Utility Pallet

#![cfg_attr(not(feature = "std"), no_std)]
#![cfg(feature = "runtime-benchmarks")]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird that the pallet even has this feature as this pallet should only be used when runtime-benchmarks are enabled somewhere else.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just running the tests for all pallets and one of the benchmarking tests failed. So it was "enabled" manually by cargo test.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without this, my build isn't working. can we have this ported to the 1.0.0 release branch @bkchr

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the correct solution #14617

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.0.0 release branch is for the node - not the runtime. There is no 1.0.0 runtime release yet.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this for Acala to compile with polkadot-v1.0.0 branch


use codec::Encode;
use frame_benchmarking::{
Expand Down
4 changes: 1 addition & 3 deletions frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,7 @@ pub mod pallet {
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
#[cfg(feature = "std")]
fn integrity_test() {
sp_io::TestExternalities::default().execute_with(|| {
T::BlockWeights::get().validate().expect("The weights are invalid.");
});
T::BlockWeights::get().validate().expect("The weights are invalid.");
}
}

Expand Down
35 changes: 16 additions & 19 deletions frame/transaction-payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ pub mod pallet {
});
}

#[cfg(feature = "std")]
fn integrity_test() {
// given weight == u64, we build multipliers from `diff` of two weight values, which can
// at most be maximum block weight. Make sure that this can fit in a multiplier without
Expand All @@ -441,25 +442,21 @@ pub mod pallet {
return
}

#[cfg(any(feature = "std", test))]
sp_io::TestExternalities::new_empty().execute_with(|| {
// This is the minimum value of the multiplier. Make sure that if we collapse to
// this value, we can recover with a reasonable amount of traffic. For this test we
// assert that if we collapse to minimum, the trend will be positive with a weight
// value which is 1% more than the target.
let min_value = T::FeeMultiplierUpdate::min();

let target = target + addition;

<frame_system::Pallet<T>>::set_block_consumed_resources(target, 0);
let next = T::FeeMultiplierUpdate::convert(min_value);
assert!(
next > min_value,
"The minimum bound of the multiplier is too low. When \
block saturation is more than target by 1% and multiplier is minimal then \
the multiplier doesn't increase."
);
});
// This is the minimum value of the multiplier. Make sure that if we collapse to this
// value, we can recover with a reasonable amount of traffic. For this test we assert
// that if we collapse to minimum, the trend will be positive with a weight value which
// is 1% more than the target.
let min_value = T::FeeMultiplierUpdate::min();
let target = target + addition;

<frame_system::Pallet<T>>::set_block_consumed_resources(target, 0);
let next = T::FeeMultiplierUpdate::convert(min_value);
assert!(
next > min_value,
"The minimum bound of the multiplier is too low. When \
block saturation is more than target by 1% and multiplier is minimal then \
the multiplier doesn't increase."
);
}
}
}
Expand Down