Skip to content

Commit

Permalink
Remove test dependecies on specific relay clients (paritytech#2898)
Browse files Browse the repository at this point in the history
  • Loading branch information
serban300 committed Apr 8, 2024
1 parent c7ab61d commit 98ece52
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
17 changes: 15 additions & 2 deletions bridges/relays/client-substrate/src/test_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions bridges/relays/lib-substrate-relay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
34 changes: 12 additions & 22 deletions bridges/relays/lib-substrate-relay/src/messages_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,7 @@ fn split_msgs_to_refine<Source: Chain + ChainWithMessages, Target: Chain>(
#[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<MessageNonce>,
Expand All @@ -573,52 +571,46 @@ mod tests {

#[test]
fn validate_out_msgs_details_succeeds_if_no_messages_are_missing() {
assert!(validate_out_msgs_details::<BridgeHubRococo>(
&message_details_from_rpc(1..=3),
1..=3,
)
.is_ok());
assert!(validate_out_msgs_details::<TestChain>(&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::<BridgeHubRococo>(
&message_details_from_rpc(2..=3),
1..=3,
)
.is_ok())
assert!(validate_out_msgs_details::<TestChain>(&message_details_from_rpc(2..=3), 1..=3,)
.is_ok())
}

#[test]
fn validate_out_msgs_details_fails_if_mid_messages_are_missing() {
let mut message_details_from_rpc = message_details_from_rpc(1..=3);
message_details_from_rpc.remove(1);
assert!(matches!(
validate_out_msgs_details::<BridgeHubRococo>(&message_details_from_rpc, 1..=3,),
validate_out_msgs_details::<TestChain>(&message_details_from_rpc, 1..=3,),
Err(SubstrateError::Custom(_))
));
}

#[test]
fn validate_out_msgs_details_map_fails_if_tail_messages_are_missing() {
assert!(matches!(
validate_out_msgs_details::<BridgeHubRococo>(&message_details_from_rpc(1..=2), 1..=3,),
validate_out_msgs_details::<TestChain>(&message_details_from_rpc(1..=2), 1..=3,),
Err(SubstrateError::Custom(_))
));
}

#[test]
fn validate_out_msgs_details_fails_if_all_messages_are_missing() {
assert!(matches!(
validate_out_msgs_details::<BridgeHubRococo>(&[], 1..=3),
validate_out_msgs_details::<TestChain>(&[], 1..=3),
Err(SubstrateError::Custom(_))
));
}

#[test]
fn validate_out_msgs_details_fails_if_more_messages_than_nonces() {
assert!(matches!(
validate_out_msgs_details::<BridgeHubRococo>(&message_details_from_rpc(1..=5), 2..=5,),
validate_out_msgs_details::<TestChain>(&message_details_from_rpc(1..=5), 2..=5,),
Err(SubstrateError::Custom(_))
));
}
Expand All @@ -644,10 +636,8 @@ mod tests {
msgs_to_refine.push((payload, out_msg_details));
}

let maybe_batches = split_msgs_to_refine::<BridgeHubRococo, BridgeHubWestend>(
Default::default(),
msgs_to_refine,
);
let maybe_batches =
split_msgs_to_refine::<TestChain, TestChain>(Default::default(), msgs_to_refine);
match expected_batches {
Ok(expected_batches) => {
let batches = maybe_batches.unwrap();
Expand All @@ -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(()));
Expand Down
3 changes: 1 addition & 2 deletions bridges/relays/lib-substrate-relay/src/on_demand/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,7 @@ fn on_demand_headers_relay_name<SourceChain: Chain, TargetChain: Chain>() -> Str
#[cfg(test)]
mod tests {
use super::*;

type TestChain = relay_rococo_client::Rococo;
use relay_substrate_client::test_chain::TestChain;

const AT_SOURCE: Option<bp_rococo::BlockNumber> = Some(10);
const AT_TARGET: Option<bp_rococo::BlockNumber> = Some(1);
Expand Down

0 comments on commit 98ece52

Please sign in to comment.