Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for BridgeHub(s) <> remote GRANDPA chain #2692

Merged
merged 5 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use bridge_hub_rococo_runtime::{
};
use codec::{Decode, Encode};
use frame_support::{dispatch::GetDispatchInfo, parameter_types};
use frame_system::pallet_prelude::HeaderFor;
use parachains_common::{rococo::fee::WeightToFee, AccountId, AuraId, Balance};
use sp_keyring::AccountKeyring::Alice;
use sp_runtime::{
Expand All @@ -46,13 +45,16 @@ fn construct_extrinsic(
sender: sp_keyring::AccountKeyring,
call: RuntimeCall,
) -> UncheckedExtrinsic {
let account_id = AccountId32::from(sender.public());
let extra: SignedExtra = (
frame_system::CheckNonZeroSender::<Runtime>::new(),
frame_system::CheckSpecVersion::<Runtime>::new(),
frame_system::CheckTxVersion::<Runtime>::new(),
frame_system::CheckGenesis::<Runtime>::new(),
frame_system::CheckEra::<Runtime>::from(Era::immortal()),
frame_system::CheckNonce::<Runtime>::from(0),
frame_system::CheckNonce::<Runtime>::from(
frame_system::Pallet::<Runtime>::account(&account_id).nonce,
),
frame_system::CheckWeight::<Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(0),
BridgeRejectObsoleteHeadersAndMessages::default(),
Expand All @@ -62,18 +64,17 @@ fn construct_extrinsic(
let signature = payload.using_encoded(|e| sender.sign(e));
UncheckedExtrinsic::new_signed(
call,
AccountId32::from(sender.public()).into(),
account_id.into(),
Signature::Sr25519(signature.clone()),
extra,
)
}

fn construct_and_apply_extrinsic(
relayer_at_target: sp_keyring::AccountKeyring,
batch: pallet_utility::Call<Runtime>,
call: RuntimeCall,
) -> sp_runtime::DispatchOutcome {
let batch_call = RuntimeCall::Utility(batch);
let xt = construct_extrinsic(relayer_at_target, batch_call);
let xt = construct_extrinsic(relayer_at_target, call);
let r = Executive::apply_extrinsic(xt);
r.unwrap()
}
Expand All @@ -85,10 +86,6 @@ fn construct_and_estimate_extrinsic_fee(batch: pallet_utility::Call<Runtime>) ->
TransactionPayment::compute_fee(xt.encoded_size() as _, &batch_info, 0)
}

fn executive_init_block(header: &HeaderFor<Runtime>) {
Executive::initialize_block(header)
}

fn collator_session_keys() -> bridge_hub_test_utils::CollatorSessionKeys<Runtime> {
bridge_hub_test_utils::CollatorSessionKeys::new(
AccountId::from(Alice),
Expand Down Expand Up @@ -235,10 +232,9 @@ mod bridge_hub_rococo_tests {
#[test]
fn relayed_incoming_message_works() {
// from Westend
bridge_hub_test_utils::test_cases::relayed_incoming_message_works::<
bridge_hub_test_utils::test_cases::from_parachain::relayed_incoming_message_works::<
Runtime,
AllPalletsWithoutSystem,
XcmConfig,
ParachainSystem,
BridgeGrandpaWestendInstance,
BridgeParachainWestendInstance,
Expand All @@ -248,17 +244,19 @@ mod bridge_hub_rococo_tests {
collator_session_keys(),
bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID,
bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_PARACHAIN_ID,
BridgeHubWestendChainId::get(),
SIBLING_PARACHAIN_ID,
Rococo,
XCM_LANE_FOR_ASSET_HUB_ROCOCO_TO_ASSET_HUB_WESTEND,
|| (),
construct_and_apply_extrinsic,
)
}

#[test]
pub fn complex_relay_extrinsic_works() {
// for Westend
bridge_hub_test_utils::test_cases::complex_relay_extrinsic_works::<
bridge_hub_test_utils::test_cases::from_parachain::complex_relay_extrinsic_works::<
Runtime,
AllPalletsWithoutSystem,
XcmConfig,
Expand All @@ -275,10 +273,8 @@ mod bridge_hub_rococo_tests {
BridgeHubWestendChainId::get(),
Rococo,
XCM_LANE_FOR_ASSET_HUB_ROCOCO_TO_ASSET_HUB_WESTEND,
ExistentialDeposit::get(),
executive_init_block,
construct_and_apply_extrinsic,
|| (),
construct_and_apply_extrinsic,
);
}

Expand All @@ -302,7 +298,7 @@ mod bridge_hub_rococo_tests {

#[test]
pub fn can_calculate_fee_for_complex_message_delivery_transaction() {
let estimated = bridge_hub_test_utils::test_cases::can_calculate_fee_for_complex_message_delivery_transaction::<
let estimated = bridge_hub_test_utils::test_cases::from_parachain::can_calculate_fee_for_complex_message_delivery_transaction::<
Runtime,
BridgeGrandpaWestendInstance,
BridgeParachainWestendInstance,
Expand All @@ -325,7 +321,7 @@ mod bridge_hub_rococo_tests {

#[test]
pub fn can_calculate_fee_for_complex_message_confirmation_transaction() {
let estimated = bridge_hub_test_utils::test_cases::can_calculate_fee_for_complex_message_confirmation_transaction::<
let estimated = bridge_hub_test_utils::test_cases::from_parachain::can_calculate_fee_for_complex_message_confirmation_transaction::<
Runtime,
BridgeGrandpaWestendInstance,
BridgeParachainWestendInstance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use bridge_to_rococo_config::{
};
use codec::{Decode, Encode};
use frame_support::{dispatch::GetDispatchInfo, parameter_types};
use frame_system::pallet_prelude::HeaderFor;
use parachains_common::{westend::fee::WeightToFee, AccountId, AuraId, Balance};
use sp_keyring::AccountKeyring::Alice;
use sp_runtime::{
Expand All @@ -52,13 +51,16 @@ fn construct_extrinsic(
sender: sp_keyring::AccountKeyring,
call: RuntimeCall,
) -> UncheckedExtrinsic {
let account_id = AccountId32::from(sender.public());
let extra: SignedExtra = (
frame_system::CheckNonZeroSender::<Runtime>::new(),
frame_system::CheckSpecVersion::<Runtime>::new(),
frame_system::CheckTxVersion::<Runtime>::new(),
frame_system::CheckGenesis::<Runtime>::new(),
frame_system::CheckEra::<Runtime>::from(Era::immortal()),
frame_system::CheckNonce::<Runtime>::from(0),
frame_system::CheckNonce::<Runtime>::from(
frame_system::Pallet::<Runtime>::account(&account_id).nonce,
),
frame_system::CheckWeight::<Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(0),
BridgeRejectObsoleteHeadersAndMessages::default(),
Expand All @@ -68,18 +70,17 @@ fn construct_extrinsic(
let signature = payload.using_encoded(|e| sender.sign(e));
UncheckedExtrinsic::new_signed(
call,
AccountId32::from(sender.public()).into(),
account_id.into(),
Signature::Sr25519(signature.clone()),
extra,
)
}

fn construct_and_apply_extrinsic(
relayer_at_target: sp_keyring::AccountKeyring,
batch: pallet_utility::Call<Runtime>,
call: RuntimeCall,
) -> sp_runtime::DispatchOutcome {
let batch_call = RuntimeCall::Utility(batch);
let xt = construct_extrinsic(relayer_at_target, batch_call);
let xt = construct_extrinsic(relayer_at_target, call);
let r = Executive::apply_extrinsic(xt);
r.unwrap()
}
Expand All @@ -91,10 +92,6 @@ fn construct_and_estimate_extrinsic_fee(batch: pallet_utility::Call<Runtime>) ->
TransactionPayment::compute_fee(xt.encoded_size() as _, &batch_info, 0)
}

fn executive_init_block(header: &HeaderFor<Runtime>) {
Executive::initialize_block(header)
}

fn collator_session_keys() -> bridge_hub_test_utils::CollatorSessionKeys<Runtime> {
bridge_hub_test_utils::CollatorSessionKeys::new(
AccountId::from(Alice),
Expand Down Expand Up @@ -221,10 +218,9 @@ fn message_dispatch_routing_works() {

#[test]
fn relayed_incoming_message_works() {
bridge_hub_test_utils::test_cases::relayed_incoming_message_works::<
bridge_hub_test_utils::test_cases::from_parachain::relayed_incoming_message_works::<
Runtime,
AllPalletsWithoutSystem,
XcmConfig,
ParachainSystem,
BridgeGrandpaRococoInstance,
BridgeParachainRococoInstance,
Expand All @@ -234,16 +230,18 @@ fn relayed_incoming_message_works() {
collator_session_keys(),
bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_PARACHAIN_ID,
bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID,
BridgeHubRococoChainId::get(),
SIBLING_PARACHAIN_ID,
Westend,
XCM_LANE_FOR_ASSET_HUB_WESTEND_TO_ASSET_HUB_ROCOCO,
|| (),
construct_and_apply_extrinsic,
)
}

#[test]
pub fn complex_relay_extrinsic_works() {
bridge_hub_test_utils::test_cases::complex_relay_extrinsic_works::<
bridge_hub_test_utils::test_cases::from_parachain::complex_relay_extrinsic_works::<
Runtime,
AllPalletsWithoutSystem,
XcmConfig,
Expand All @@ -260,10 +258,8 @@ pub fn complex_relay_extrinsic_works() {
BridgeHubRococoChainId::get(),
Westend,
XCM_LANE_FOR_ASSET_HUB_WESTEND_TO_ASSET_HUB_ROCOCO,
ExistentialDeposit::get(),
executive_init_block,
construct_and_apply_extrinsic,
|| (),
construct_and_apply_extrinsic,
);
}

Expand All @@ -287,7 +283,7 @@ pub fn can_calculate_weight_for_paid_export_message_with_reserve_transfer() {

#[test]
pub fn can_calculate_fee_for_complex_message_delivery_transaction() {
let estimated = bridge_hub_test_utils::test_cases::can_calculate_fee_for_complex_message_delivery_transaction::<
let estimated = bridge_hub_test_utils::test_cases::from_parachain::can_calculate_fee_for_complex_message_delivery_transaction::<
Runtime,
BridgeGrandpaRococoInstance,
BridgeParachainRococoInstance,
Expand All @@ -310,7 +306,7 @@ pub fn can_calculate_fee_for_complex_message_delivery_transaction() {

#[test]
pub fn can_calculate_fee_for_complex_message_confirmation_transaction() {
let estimated = bridge_hub_test_utils::test_cases::can_calculate_fee_for_complex_message_confirmation_transaction::<
let estimated = bridge_hub_test_utils::test_cases::from_parachain::can_calculate_fee_for_complex_message_confirmation_transaction::<
Runtime,
BridgeGrandpaRococoInstance,
BridgeParachainRococoInstance,
Expand Down
3 changes: 3 additions & 0 deletions cumulus/parachains/runtimes/bridge-hubs/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ license = "Apache-2.0"

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "max-encoded-len"] }
impl-trait-for-tuples = "0.2"
log = { version = "0.4.20", default-features = false }

# Substrate
Expand All @@ -19,6 +20,7 @@ sp-core = { path = "../../../../../substrate/primitives/core", default-features
sp-io = { path = "../../../../../substrate/primitives/io", default-features = false }
sp-keyring = { path = "../../../../../substrate/primitives/keyring" }
sp-runtime = { path = "../../../../../substrate/primitives/runtime", default-features = false }
sp-std = { path = "../../../../../substrate/primitives/std", default-features = false }
sp-tracing = { path = "../../../../../substrate/primitives/tracing" }
pallet-balances = { path = "../../../../../substrate/frame/balances", default-features = false }
pallet-utility = { path = "../../../../../substrate/frame/utility", default-features = false }
Expand Down Expand Up @@ -90,6 +92,7 @@ std = [
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
"xcm-builder/std",
"xcm-executor/std",
"xcm/std",
Expand Down
2 changes: 2 additions & 0 deletions cumulus/parachains/runtimes/bridge-hubs/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@
//! Module contains predefined test-case scenarios for "BridgeHub" `Runtime`s.

pub mod test_cases;
pub mod test_data;

pub use bp_test_utils::test_header;
pub use parachains_runtimes_test_utils::*;
Loading