Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Add Rococo <> Wococo integrity tests (#1975)
Browse files Browse the repository at this point in the history
* Remove 1 integrity test

In sync with paritytech/parity-bridges-common#1816

* use TargetHeaderChainAdapter and SourceHeaderChainAdapter

* Rococo <-> Wococo integrity tests

* Add message lane weights tests

* Add signed extension integrity test
  • Loading branch information
serban300 authored Jan 25, 2023
1 parent 1a1a4f5 commit 5ad38a1
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 92 deletions.
45 changes: 42 additions & 3 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion bridges/bin/runtime-common/src/integrity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ macro_rules! assert_bridge_messages_pallet_types(

assert_type_eq_all!(<$r as MessagesConfig<$i>>::OutboundPayload, FromThisChainMessagePayload);

assert_type_eq_all!(<$r as MessagesConfig<$i>>::InboundPayload, FromBridgedChainMessagePayload<CallOf<ThisChain<$bridge>>>);
assert_type_eq_all!(<$r as MessagesConfig<$i>>::InboundRelayer, AccountIdOf<BridgedChain<$bridge>>);

assert_type_eq_all!(<$r as MessagesConfig<$i>>::TargetHeaderChain, TargetHeaderChainAdapter<$bridge>);
Expand Down
3 changes: 3 additions & 0 deletions parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ pallet-bridge-relayers = { path = "../../../../bridges/modules/relayers", defaul
bridge-runtime-common = { path = "../../../../bridges/bin/runtime-common", default-features = false }

[dev-dependencies]
serial_test = "0.9.0"
static_assertions = "1.1"
bridge-hub-test-utils = { path = "../test-utils"}
bridge-runtime-common = { path = "../../../../bridges/bin/runtime-common", features = ["integrity-test"] }

[features]
default = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,13 @@

use crate::{
BridgeParachainWococoInstance, ParachainInfo, Runtime, WithBridgeHubWococoMessagesInstance,
XcmAsPlainPayload, XcmBlobHauler, XcmBlobHaulerAdapter, XcmRouter,
};
use bp_messages::{
source_chain::TargetHeaderChain,
target_chain::{ProvedMessages, SourceHeaderChain},
InboundLaneData, LaneId, Message, MessageNonce,
XcmBlobHauler, XcmBlobHaulerAdapter, XcmRouter,
};
use bp_messages::{LaneId, MessageNonce};
use bp_runtime::ChainId;
use bridge_runtime_common::{
messages,
messages::{
target::FromBridgedChainMessagesProof, MessageBridge, ThisChainWithMessages,
UnderlyingChainProvider,
},
messages::{MessageBridge, ThisChainWithMessages, UnderlyingChainProvider},
};
use frame_support::{parameter_types, RuntimeDebug};
use xcm::{
Expand Down Expand Up @@ -110,37 +103,6 @@ impl UnderlyingChainProvider for BridgeHubWococo {
type Chain = bp_bridge_hub_wococo::BridgeHubWococo;
}

impl SourceHeaderChain for BridgeHubWococo {
type Error = &'static str;
type MessagesProof = FromBridgedChainMessagesProof<crate::Hash>;

fn verify_messages_proof(
proof: Self::MessagesProof,
messages_count: u32,
) -> Result<ProvedMessages<Message>, Self::Error> {
bridge_runtime_common::messages::target::verify_messages_proof::<
WithBridgeHubWococoMessageBridge,
>(proof, messages_count)
.map_err(Into::into)
}
}

impl TargetHeaderChain<XcmAsPlainPayload, crate::AccountId> for BridgeHubWococo {
type Error = &'static str;
type MessagesDeliveryProof =
messages::source::FromBridgedChainMessagesDeliveryProof<bp_bridge_hub_wococo::Hash>;

fn verify_message(payload: &XcmAsPlainPayload) -> Result<(), Self::Error> {
messages::source::verify_chain_message::<WithBridgeHubWococoMessageBridge>(payload)
}

fn verify_messages_delivery_proof(
proof: Self::MessagesDeliveryProof,
) -> Result<(LaneId, InboundLaneData<bp_bridge_hub_rococo::AccountId>), Self::Error> {
messages::source::verify_messages_delivery_proof::<WithBridgeHubWococoMessageBridge>(proof)
}
}

impl messages::BridgedChainWithMessages for BridgeHubWococo {
fn verify_dispatch_weight(_message_payload: &[u8]) -> bool {
true
Expand Down Expand Up @@ -172,3 +134,65 @@ impl ThisChainWithMessages for BridgeHubRococo {
MessageNonce::MAX / 2
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::BridgeGrandpaWococoInstance;
use bridge_runtime_common::{
assert_complete_bridge_types,
integrity::{
assert_complete_bridge_constants, check_message_lane_weights,
AssertBridgeMessagesPalletConstants, AssertBridgePalletNames, AssertChainConstants,
AssertCompleteBridgeConstants,
},
};

#[test]
fn ensure_bridge_hub_rococo_message_lane_weights_are_correct() {
check_message_lane_weights::<bp_bridge_hub_rococo::BridgeHubRococo, Runtime>(
bp_bridge_hub_wococo::EXTRA_STORAGE_PROOF_SIZE,
bp_bridge_hub_rococo::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX,
bp_bridge_hub_rococo::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX,
);
}

#[test]
fn ensure_bridge_integrity() {
assert_complete_bridge_types!(
runtime: Runtime,
with_bridged_chain_grandpa_instance: BridgeGrandpaWococoInstance,
with_bridged_chain_messages_instance: WithBridgeHubWococoMessagesInstance,
bridge: WithBridgeHubWococoMessageBridge,
this_chain: bp_rococo::Rococo,
bridged_chain: bp_wococo::Wococo,
);

assert_complete_bridge_constants::<
Runtime,
BridgeGrandpaWococoInstance,
WithBridgeHubWococoMessagesInstance,
WithBridgeHubWococoMessageBridge,
bp_rococo::Rococo,
>(AssertCompleteBridgeConstants {
this_chain_constants: AssertChainConstants {
block_length: bp_bridge_hub_rococo::BlockLength::get(),
block_weights: bp_bridge_hub_rococo::BlockWeights::get(),
},
messages_pallet_constants: AssertBridgeMessagesPalletConstants {
max_unrewarded_relayers_in_bridged_confirmation_tx:
bp_bridge_hub_wococo::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX,
max_unconfirmed_messages_in_bridged_confirmation_tx:
bp_bridge_hub_wococo::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX,
bridged_chain_id: bp_runtime::BRIDGE_HUB_WOCOCO_CHAIN_ID,
},
pallet_names: AssertBridgePalletNames {
with_this_chain_messages_pallet_name:
bp_bridge_hub_rococo::WITH_BRIDGE_HUB_ROCOCO_MESSAGES_PALLET_NAME,
with_bridged_chain_grandpa_pallet_name: bp_wococo::WITH_WOCOCO_GRANDPA_PALLET_NAME,
with_bridged_chain_messages_pallet_name:
bp_bridge_hub_wococo::WITH_BRIDGE_HUB_WOCOCO_MESSAGES_PALLET_NAME,
},
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,13 @@

use crate::{
BridgeParachainRococoInstance, ParachainInfo, Runtime, WithBridgeHubRococoMessagesInstance,
XcmAsPlainPayload, XcmBlobHauler, XcmBlobHaulerAdapter, XcmRouter,
};
use bp_messages::{
source_chain::TargetHeaderChain,
target_chain::{ProvedMessages, SourceHeaderChain},
InboundLaneData, LaneId, Message, MessageNonce,
XcmBlobHauler, XcmBlobHaulerAdapter, XcmRouter,
};
use bp_messages::{LaneId, MessageNonce};
use bp_runtime::ChainId;
use bridge_runtime_common::{
messages,
messages::{
target::FromBridgedChainMessagesProof, MessageBridge, ThisChainWithMessages,
UnderlyingChainProvider,
},
messages::{MessageBridge, ThisChainWithMessages, UnderlyingChainProvider},
};
use frame_support::{parameter_types, RuntimeDebug};
use xcm::{
Expand Down Expand Up @@ -110,37 +103,6 @@ impl UnderlyingChainProvider for BridgeHubRococo {
type Chain = bp_bridge_hub_rococo::BridgeHubRococo;
}

impl SourceHeaderChain for BridgeHubRococo {
type Error = &'static str;
type MessagesProof = FromBridgedChainMessagesProof<crate::Hash>;

fn verify_messages_proof(
proof: Self::MessagesProof,
messages_count: u32,
) -> Result<ProvedMessages<Message>, Self::Error> {
bridge_runtime_common::messages::target::verify_messages_proof::<
WithBridgeHubRococoMessageBridge,
>(proof, messages_count)
.map_err(Into::into)
}
}

impl TargetHeaderChain<XcmAsPlainPayload, crate::AccountId> for BridgeHubRococo {
type Error = &'static str;
type MessagesDeliveryProof =
messages::source::FromBridgedChainMessagesDeliveryProof<bp_bridge_hub_rococo::Hash>;

fn verify_message(payload: &XcmAsPlainPayload) -> Result<(), Self::Error> {
messages::source::verify_chain_message::<WithBridgeHubRococoMessageBridge>(payload)
}

fn verify_messages_delivery_proof(
proof: Self::MessagesDeliveryProof,
) -> Result<(LaneId, InboundLaneData<bp_bridge_hub_wococo::AccountId>), Self::Error> {
messages::source::verify_messages_delivery_proof::<WithBridgeHubRococoMessageBridge>(proof)
}
}

impl messages::BridgedChainWithMessages for BridgeHubRococo {
fn verify_dispatch_weight(_message_payload: &[u8]) -> bool {
true
Expand Down Expand Up @@ -172,3 +134,65 @@ impl ThisChainWithMessages for BridgeHubWococo {
MessageNonce::MAX / 2
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::BridgeGrandpaRococoInstance;
use bridge_runtime_common::{
assert_complete_bridge_types,
integrity::{
assert_complete_bridge_constants, check_message_lane_weights,
AssertBridgeMessagesPalletConstants, AssertBridgePalletNames, AssertChainConstants,
AssertCompleteBridgeConstants,
},
};

#[test]
fn ensure_bridge_hub_wococo_message_lane_weights_are_correct() {
check_message_lane_weights::<bp_bridge_hub_wococo::BridgeHubWococo, Runtime>(
bp_bridge_hub_rococo::EXTRA_STORAGE_PROOF_SIZE,
bp_bridge_hub_wococo::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX,
bp_bridge_hub_wococo::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX,
);
}

#[test]
fn ensure_bridge_integrity() {
assert_complete_bridge_types!(
runtime: Runtime,
with_bridged_chain_grandpa_instance: BridgeGrandpaRococoInstance,
with_bridged_chain_messages_instance: WithBridgeHubRococoMessagesInstance,
bridge: WithBridgeHubRococoMessageBridge,
this_chain: bp_wococo::Wococo,
bridged_chain: bp_rococo::Rococo,
);

assert_complete_bridge_constants::<
Runtime,
BridgeGrandpaRococoInstance,
WithBridgeHubRococoMessagesInstance,
WithBridgeHubRococoMessageBridge,
bp_wococo::Wococo,
>(AssertCompleteBridgeConstants {
this_chain_constants: AssertChainConstants {
block_length: bp_bridge_hub_wococo::BlockLength::get(),
block_weights: bp_bridge_hub_wococo::BlockWeights::get(),
},
messages_pallet_constants: AssertBridgeMessagesPalletConstants {
max_unrewarded_relayers_in_bridged_confirmation_tx:
bp_bridge_hub_rococo::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX,
max_unconfirmed_messages_in_bridged_confirmation_tx:
bp_bridge_hub_rococo::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX,
bridged_chain_id: bp_runtime::BRIDGE_HUB_ROCOCO_CHAIN_ID,
},
pallet_names: AssertBridgePalletNames {
with_this_chain_messages_pallet_name:
bp_bridge_hub_wococo::WITH_BRIDGE_HUB_WOCOCO_MESSAGES_PALLET_NAME,
with_bridged_chain_grandpa_pallet_name: bp_rococo::WITH_ROCOCO_GRANDPA_PALLET_NAME,
with_bridged_chain_messages_pallet_name:
bp_bridge_hub_rococo::WITH_BRIDGE_HUB_ROCOCO_MESSAGES_PALLET_NAME,
},
});
}
}
Loading

0 comments on commit 5ad38a1

Please sign in to comment.