diff --git a/Cargo.lock b/Cargo.lock index d7c7a63df74..25acccb2b9a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9115,9 +9115,6 @@ dependencies = [ "parachains-relay", "parity-scale-codec", "rbtag", - "relay-bridge-hub-rococo-client", - "relay-bridge-hub-westend-client", - "relay-rococo-client", "relay-substrate-client", "relay-utils", "sp-consensus-grandpa", diff --git a/relays/client-substrate/src/test_chain.rs b/relays/client-substrate/src/test_chain.rs index 214f8d87a1f..77240d15884 100644 --- a/relays/client-substrate/src/test_chain.rs +++ b/relays/client-substrate/src/test_chain.rs @@ -21,7 +21,8 @@ #![cfg(any(feature = "test-helpers", test))] -use crate::{Chain, ChainWithBalances}; +use crate::{Chain, ChainWithBalances, ChainWithMessages}; +use bp_messages::{ChainWithMessages as ChainWithMessagesBase, MessageNonce}; use bp_runtime::ChainId; use frame_support::weights::Weight; use std::time::Duration; @@ -44,7 +45,7 @@ impl bp_runtime::Chain for TestChain { type Signature = sp_runtime::testing::TestSignature; fn max_extrinsic_size() -> u32 { - unreachable!() + 100000 } fn max_extrinsic_weight() -> Weight { @@ -69,6 +70,18 @@ impl ChainWithBalances for TestChain { } } +impl ChainWithMessagesBase for TestChain { + const WITH_CHAIN_MESSAGES_PALLET_NAME: &'static str = "Test"; + const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce = 0; + const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce = 0; +} + +impl ChainWithMessages for TestChain { + const WITH_CHAIN_RELAYERS_PALLET_NAME: Option<&'static str> = None; + const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = "TestMessagesDetailsMethod"; + const FROM_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = "TestFromMessagesDetailsMethod"; +} + /// Primitives-level parachain that may be used in tests. #[derive(Clone, Debug, PartialEq, Eq)] pub struct TestParachainBase; diff --git a/relays/lib-substrate-relay/Cargo.toml b/relays/lib-substrate-relay/Cargo.toml index 5bd14bb8320..99ff91a7506 100644 --- a/relays/lib-substrate-relay/Cargo.toml +++ b/relays/lib-substrate-relay/Cargo.toml @@ -58,6 +58,4 @@ sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "mas [dev-dependencies] bp-rococo = { path = "../../chains/chain-rococo" } pallet-transaction-payment = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master" } -relay-bridge-hub-rococo-client = { path = "../../relay-clients/client-bridge-hub-rococo" } -relay-bridge-hub-westend-client = { path = "../../relay-clients/client-bridge-hub-westend" } -relay-rococo-client = { path = "../../relay-clients/client-rococo" } +relay-substrate-client = { path = "../client-substrate", features = ["test-helpers"] } diff --git a/relays/lib-substrate-relay/src/messages_source.rs b/relays/lib-substrate-relay/src/messages_source.rs index 26e10f8868c..49deff046f9 100644 --- a/relays/lib-substrate-relay/src/messages_source.rs +++ b/relays/lib-substrate-relay/src/messages_source.rs @@ -554,9 +554,7 @@ fn split_msgs_to_refine( #[cfg(test)] mod tests { use super::*; - use bp_runtime::Chain as ChainBase; - use relay_bridge_hub_rococo_client::BridgeHubRococo; - use relay_bridge_hub_westend_client::BridgeHubWestend; + use relay_substrate_client::test_chain::TestChain; fn message_details_from_rpc( nonces: RangeInclusive, @@ -573,20 +571,14 @@ mod tests { #[test] fn validate_out_msgs_details_succeeds_if_no_messages_are_missing() { - assert!(validate_out_msgs_details::( - &message_details_from_rpc(1..=3), - 1..=3, - ) - .is_ok()); + assert!(validate_out_msgs_details::(&message_details_from_rpc(1..=3), 1..=3,) + .is_ok()); } #[test] fn validate_out_msgs_details_succeeds_if_head_messages_are_missing() { - assert!(validate_out_msgs_details::( - &message_details_from_rpc(2..=3), - 1..=3, - ) - .is_ok()) + assert!(validate_out_msgs_details::(&message_details_from_rpc(2..=3), 1..=3,) + .is_ok()) } #[test] @@ -594,7 +586,7 @@ mod tests { let mut message_details_from_rpc = message_details_from_rpc(1..=3); message_details_from_rpc.remove(1); assert!(matches!( - validate_out_msgs_details::(&message_details_from_rpc, 1..=3,), + validate_out_msgs_details::(&message_details_from_rpc, 1..=3,), Err(SubstrateError::Custom(_)) )); } @@ -602,7 +594,7 @@ mod tests { #[test] fn validate_out_msgs_details_map_fails_if_tail_messages_are_missing() { assert!(matches!( - validate_out_msgs_details::(&message_details_from_rpc(1..=2), 1..=3,), + validate_out_msgs_details::(&message_details_from_rpc(1..=2), 1..=3,), Err(SubstrateError::Custom(_)) )); } @@ -610,7 +602,7 @@ mod tests { #[test] fn validate_out_msgs_details_fails_if_all_messages_are_missing() { assert!(matches!( - validate_out_msgs_details::(&[], 1..=3), + validate_out_msgs_details::(&[], 1..=3), Err(SubstrateError::Custom(_)) )); } @@ -618,7 +610,7 @@ mod tests { #[test] fn validate_out_msgs_details_fails_if_more_messages_than_nonces() { assert!(matches!( - validate_out_msgs_details::(&message_details_from_rpc(1..=5), 2..=5,), + validate_out_msgs_details::(&message_details_from_rpc(1..=5), 2..=5,), Err(SubstrateError::Custom(_)) )); } @@ -644,10 +636,8 @@ mod tests { msgs_to_refine.push((payload, out_msg_details)); } - let maybe_batches = split_msgs_to_refine::( - Default::default(), - msgs_to_refine, - ); + let maybe_batches = + split_msgs_to_refine::(Default::default(), msgs_to_refine); match expected_batches { Ok(expected_batches) => { let batches = maybe_batches.unwrap(); @@ -669,7 +659,7 @@ mod tests { #[test] fn test_split_msgs_to_refine() { - let max_extrinsic_size = BridgeHubRococo::max_extrinsic_size() as usize; + let max_extrinsic_size = 100000; // Check that an error is returned when one of the messages is too big. check_split_msgs_to_refine(vec![max_extrinsic_size], Err(())); diff --git a/relays/lib-substrate-relay/src/on_demand/headers.rs b/relays/lib-substrate-relay/src/on_demand/headers.rs index 8b58552d292..99ca1d4d5a7 100644 --- a/relays/lib-substrate-relay/src/on_demand/headers.rs +++ b/relays/lib-substrate-relay/src/on_demand/headers.rs @@ -526,8 +526,7 @@ fn on_demand_headers_relay_name() -> Str #[cfg(test)] mod tests { use super::*; - - type TestChain = relay_rococo_client::Rococo; + use relay_substrate_client::test_chain::TestChain; const AT_SOURCE: Option = Some(10); const AT_TARGET: Option = Some(1);