Skip to content

Commit

Permalink
Included integrity test to the test harness
Browse files Browse the repository at this point in the history
  • Loading branch information
syan095 committed Sep 12, 2023
1 parent 3ee6830 commit 9dee0c9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion state-chain/cf-integration-tests/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use frame_support::{
dispatch::UnfilteredDispatchable,
inherent::ProvideInherent,
pallet_prelude::InherentData,
traits::{OnFinalize, OnIdle},
traits::{IntegrityTest, OnFinalize, OnIdle},
};
use pallet_cf_funding::{MinimumFunding, RedemptionAmount};
use pallet_cf_validator::RotationPhase;
Expand Down Expand Up @@ -605,6 +605,7 @@ impl Network {

// We must finalise this to clear the previous author which is otherwise cached
AllPalletsWithSystem::on_finalize(block_number);
AllPalletsWithSystem::integrity_test();

// Process Engine responses. Store calls into a queue and dispatch these between
// `on_initialize` and `on_idle`
Expand Down
10 changes: 8 additions & 2 deletions state-chain/test-utilities/src/rich_test_externalities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use frame_support::{
assert_noop, assert_ok,
dispatch::UnfilteredDispatchable,
pallet_prelude::DispatchResult,
traits::{OnFinalize, OnIdle, OnInitialize},
traits::{IntegrityTest, OnFinalize, OnIdle, OnInitialize},
weights::Weight,
};
use frame_system::pallet_prelude::BlockNumberFor;
Expand All @@ -12,7 +12,8 @@ use sp_runtime::BuildStorage;
pub trait HasAllPallets: frame_system::Config {
type AllPalletsWithSystem: OnInitialize<BlockNumberFor<Self>>
+ OnIdle<BlockNumberFor<Self>>
+ OnFinalize<BlockNumberFor<Self>>;
+ OnFinalize<BlockNumberFor<Self>>
+ IntegrityTest;

fn on_initialize(block_number: BlockNumberFor<Self>) {
<Self::AllPalletsWithSystem as OnInitialize<BlockNumberFor<Self>>>::on_initialize(
Expand All @@ -25,6 +26,9 @@ pub trait HasAllPallets: frame_system::Config {
fn on_finalize(block_number: BlockNumberFor<Self>) {
<Self::AllPalletsWithSystem as OnFinalize<BlockNumberFor<Self>>>::on_finalize(block_number);
}
fn integrity_test() {
<Self::AllPalletsWithSystem as IntegrityTest>::integrity_test();
}
}

/// Basic [sp_io::TestExternalities] wrapper that provides a richer API for testing pallets.
Expand Down Expand Up @@ -70,6 +74,7 @@ impl<Runtime: HasAllPallets> RichExternalities<Runtime> {
let context = f();
Runtime::on_idle(block_number, Weight::MAX);
Runtime::on_finalize(block_number);
Runtime::integrity_test();
context
});
TestExternalities { ext: self, context }
Expand Down Expand Up @@ -105,6 +110,7 @@ where
let mut ext: sp_io::TestExternalities = config.build_storage().unwrap().into();
ext.execute_with(|| {
frame_system::Pallet::<Runtime>::set_block_number(1u32.into());
Runtime::integrity_test();
});
TestExternalities { ext: RichExternalities::new(ext), context: () }
}
Expand Down

0 comments on commit 9dee0c9

Please sign in to comment.