Skip to content

Commit

Permalink
Add benches for refund relayer extension
Browse files Browse the repository at this point in the history
Signed-off-by: georgepisaltu <george.pisaltu@parity.io>
  • Loading branch information
georgepisaltu committed Dec 15, 2023
1 parent a1140e3 commit 809b2e2
Show file tree
Hide file tree
Showing 9 changed files with 2,646 additions and 2,376 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions bridges/bin/runtime-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pallet-bridge-relayers = { path = "../../modules/relayers", default-features = f

# Substrate dependencies

frame-benchmarking = { path = "../../../substrate/frame/benchmarking", default-features = false, optional = true}
frame-support = { path = "../../../substrate/frame/support", default-features = false }
frame-system = { path = "../../../substrate/frame/system", default-features = false }
pallet-transaction-payment = { path = "../../../substrate/frame/transaction-payment", default-features = false }
Expand Down Expand Up @@ -65,6 +66,7 @@ std = [
"bp-xcm-bridge-hub-router/std",
"bp-xcm-bridge-hub/std",
"codec/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"hash-db/std",
Expand All @@ -86,6 +88,7 @@ std = [
"xcm/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
Expand Down
76 changes: 76 additions & 0 deletions bridges/bin/runtime-common/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,79 @@ impl BridgedChainWithMessages for BridgedChain {}
pub fn run_test(test: impl FnOnce()) {
sp_io::TestExternalities::new(Default::default()).execute_with(test)
}

/// Run test within test externalities.
pub fn new_test_ext() -> sp_io::TestExternalities {
sp_io::TestExternalities::new(Default::default())
}

#[cfg(feature = "runtime-benchmarks")]
impl crate::refund_relayer_extension::ExtBenchmarkingConfig for TestRuntime {
fn setup_environment() {
crate::refund_relayer_extension::tests::initialize_environment(100, 100, 100);
}

fn run_extension(choice: u32) {
use sp_runtime::traits::{DispatchTransaction, TransactionExtension};

let call = match choice {
0 => crate::refund_relayer_extension::tests::message_delivery_call(200),
1 => crate::refund_relayer_extension::tests::message_confirmation_call(200),
_ => unreachable!("only 2 types of messages"),
};
let mut dispatch_info = crate::refund_relayer_extension::tests::dispatch_info();
dispatch_info.weight = Weight::from_parts(
frame_support::weights::constants::WEIGHT_REF_TIME_PER_SECOND * 2,
0,
);
let pre_dispatch_data = crate::refund_relayer_extension::tests::pre_dispatch_data_get();

let extension = crate::refund_relayer_extension::tests::parachain_extension();
let _ = extension
.validate_and_prepare(Some(0).into(), &call, &dispatch_info, 0)
.map(|(pre, _)| pre);
let _ = crate::refund_relayer_extension::mock::TestExtension::post_dispatch(
Some(pre_dispatch_data),
&dispatch_info,
&frame_support::dispatch::PostDispatchInfo {
actual_weight: None,
pays_fee: frame_support::dispatch::Pays::Yes,
},
1024,
&Ok(()),
&(),
);
}

fn run_grandpa_extension(choice: u32) {
use sp_runtime::traits::{DispatchTransaction, TransactionExtension};

let call = match choice {
0 => crate::refund_relayer_extension::tests::message_delivery_call(200),
1 => crate::refund_relayer_extension::tests::message_confirmation_call(200),
_ => unreachable!("only 2 types of messages"),
};
let mut dispatch_info = crate::refund_relayer_extension::tests::dispatch_info();
dispatch_info.weight = Weight::from_parts(
frame_support::weights::constants::WEIGHT_REF_TIME_PER_SECOND * 2,
0,
);
let pre_dispatch_data = crate::refund_relayer_extension::tests::pre_dispatch_data_get();

let extension = crate::refund_relayer_extension::tests::grandpa_extension();
let _ = extension
.validate_and_prepare(Some(0).into(), &call, &dispatch_info, 0)
.map(|(pre, _)| pre);
let _ = crate::refund_relayer_extension::mock::TestExtension::post_dispatch(
Some(pre_dispatch_data),
&dispatch_info,
&frame_support::dispatch::PostDispatchInfo {
actual_weight: None,
pays_fee: frame_support::dispatch::Pays::Yes,
},
1024,
&Ok(()),
&(),
);
}
}
Loading

0 comments on commit 809b2e2

Please sign in to comment.