Run benchmarks for mock runtimes (#1996)

* run benchmarks for pallet-bridge-grandpa mock runtime

* run benchmarks for pallet-bridge-relayers mock runtime

* run benchmarks for pallet-bridge-parachains mock runtime

* run benchmarks for pallet-bridge-messages mock runtime

* test benchmarks on mockj runtimes from CI

* clippy and spelling
This commit is contained in:
Svyatoslav Nikolsky
2023-03-27 14:33:12 +03:00
committed by Bastian Köcher
parent 88fb2befa0
commit 068f6f648b
10 changed files with 130 additions and 18 deletions
+38 -1
View File
@@ -228,6 +228,36 @@ impl pallet_bridge_parachains::Config for TestRuntime {
type MaxParaHeadDataSize = ConstU32<MAXIMAL_PARACHAIN_HEAD_DATA_SIZE>;
}
#[cfg(feature = "runtime-benchmarks")]
impl pallet_bridge_parachains::benchmarking::Config<()> for TestRuntime {
fn parachains() -> Vec<ParaId> {
vec![
ParaId(Parachain1::PARACHAIN_ID),
ParaId(Parachain2::PARACHAIN_ID),
ParaId(Parachain3::PARACHAIN_ID),
]
}
fn prepare_parachain_heads_proof(
parachains: &[ParaId],
_parachain_head_size: u32,
_proof_size: bp_runtime::StorageProofSize,
) -> (
crate::RelayBlockNumber,
crate::RelayBlockHash,
bp_polkadot_core::parachains::ParaHeadsProof,
Vec<(ParaId, bp_polkadot_core::parachains::ParaHash)>,
) {
// in mock run we only care about benchmarks correctness, not the benchmark results
// => ignore size related arguments
let (state_root, proof, parachains) = crate::tests::prepare_parachain_heads_proof(
parachains.iter().map(|p| (p.0, crate::tests::head_data(p.0, 1))).collect(),
);
let relay_genesis_hash = crate::tests::initialize(state_root);
(0, relay_genesis_hash, proof, parachains)
}
}
#[derive(Debug)]
pub struct TestBridgedChain;
@@ -290,14 +320,21 @@ impl ChainWithGrandpa for OtherBridgedChain {
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
}
/// Return test externalities to use in tests.
pub fn new_test_ext() -> sp_io::TestExternalities {
sp_io::TestExternalities::new(Default::default())
}
/// Run pallet test.
pub fn run_test<T>(test: impl FnOnce() -> T) -> T {
sp_io::TestExternalities::new(Default::default()).execute_with(|| {
new_test_ext().execute_with(|| {
System::set_block_number(1);
System::reset_events();
test()
})
}
/// Return test relay chain header with given number.
pub fn test_relay_header(
num: crate::RelayBlockNumber,
state_root: crate::RelayBlockHash,