From 71257add9d95453ce816886f350c8a03a60c406e Mon Sep 17 00:00:00 2001 From: claravanstaden Date: Mon, 15 Jan 2024 10:15:13 +0200 Subject: [PATCH] adds runtime tests --- Cargo.lock | 1 + .../bridge-hub-rococo/tests/snowbridge.rs | 62 ++++++++++++++++++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5eb5d13d3d6bc..46167c4cf0fed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17532,6 +17532,7 @@ dependencies = [ "sp-genesis-builder", "sp-inherents", "sp-io", + "sp-keyring", "sp-offchain", "sp-runtime", "sp-session", diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/snowbridge.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/snowbridge.rs index f32c6cae69c63..1ee3e8fc7647f 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/snowbridge.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/snowbridge.rs @@ -16,16 +16,24 @@ #![cfg(test)] +use bp_polkadot_core::Signature; use bridge_hub_rococo_runtime::{ - xcm_config::XcmConfig, MessageQueueServiceWeight, Runtime, RuntimeEvent, SessionKeys, + xcm_config::XcmConfig, Executive, MessageQueueServiceWeight, Runtime, RuntimeCall, RuntimeEvent, + SessionKeys, SignedExtra, UncheckedExtrinsic, BridgeRejectObsoleteHeadersAndMessages }; -use codec::Decode; +use bridge_hub_rococo_runtime::bridge_to_westend_config::OnBridgeHubRococoRefundBridgeHubWestendMessages; +use bridge_hub_rococo_runtime::bridge_to_bulletin_config::OnBridgeHubRococoRefundRococoBulletinMessages; +use codec::{Encode, Decode}; use cumulus_primitives_core::XcmError::{FailedToTransactAsset, NotHoldingFees}; use frame_support::parameter_types; use parachains_common::{AccountId, AuraId, Balance}; use snowbridge_pallet_ethereum_client::WeightInfo; use sp_core::H160; use sp_keyring::AccountKeyring::Alice; +use sp_runtime::{ + generic::{Era, SignedPayload}, + AccountId32, +}; parameter_types! { pub const DefaultBridgeHubEthereumBaseFee: Balance = 2_750_872_500_000; @@ -107,3 +115,53 @@ fn max_message_queue_service_weight_is_more_than_beacon_extrinsic_weights() { max_message_queue_weight.all_gt(force_checkpoint); max_message_queue_weight.all_gt(submit_checkpoint); } + +#[test] +fn ethereum_client_extrinsics() { + snowbridge_runtime_test_common::ethereum_extrinsic( + collator_session_keys(), + 1013, + construct_and_apply_extrinsic, + ); +} + +fn construct_extrinsic( + sender: sp_keyring::AccountKeyring, + call: RuntimeCall, +) -> UncheckedExtrinsic { + let account_id = AccountId32::from(sender.public()); + let extra: SignedExtra = ( + frame_system::CheckNonZeroSender::::new(), + frame_system::CheckSpecVersion::::new(), + frame_system::CheckTxVersion::::new(), + frame_system::CheckGenesis::::new(), + frame_system::CheckEra::::from(Era::immortal()), + frame_system::CheckNonce::::from( + frame_system::Pallet::::account(&account_id).nonce, + ), + frame_system::CheckWeight::::new(), + pallet_transaction_payment::ChargeTransactionPayment::::from(0), + BridgeRejectObsoleteHeadersAndMessages::default(), + ( + OnBridgeHubRococoRefundBridgeHubWestendMessages::default(), + OnBridgeHubRococoRefundRococoBulletinMessages::default(), + ), + ); + let payload = SignedPayload::new(call.clone(), extra.clone()).unwrap(); + let signature = payload.using_encoded(|e| sender.sign(e)); + UncheckedExtrinsic::new_signed( + call, + account_id.into(), + Signature::Sr25519(signature.clone()), + extra, + ) +} + +fn construct_and_apply_extrinsic( + origin: sp_keyring::AccountKeyring, + call: RuntimeCall, +) -> sp_runtime::DispatchOutcome { + let xt = construct_extrinsic(origin, call); + let r = Executive::apply_extrinsic(xt); + r.unwrap() +}