bridge_hub_test_utils/test_data/
mod.rs1pub mod from_grandpa_chain;
20pub mod from_parachain;
21
22use bp_messages::{
23 target_chain::{DispatchMessage, DispatchMessageData},
24 MessageKey,
25};
26use codec::Encode;
27use frame_support::traits::Get;
28use pallet_bridge_grandpa::BridgedHeader;
29use xcm::latest::prelude::*;
30
31use bp_messages::MessageNonce;
32use bp_runtime::BasicOperatingMode;
33use bp_test_utils::authority_list;
34use xcm::GetVersion;
35use xcm_builder::{BridgeMessage, HaulBlob, HaulBlobError, HaulBlobExporter};
36use xcm_executor::traits::{validate_export, ExportXcm};
37
38pub(crate) type XcmAsPlainPayload = sp_std::vec::Vec<u8>;
39
40pub fn prepare_inbound_xcm(xcm_message: Xcm<()>, destination: InteriorLocation) -> Vec<u8> {
41 let location = xcm::VersionedInteriorLocation::from(destination);
42 let xcm = xcm::VersionedXcm::<()>::from(xcm_message);
43
44 BridgeMessage { universal_dest: location, message: xcm }.encode().encode()
47}
48
49pub fn initialization_data<
52 Runtime: pallet_bridge_grandpa::Config<GrandpaPalletInstance>,
53 GrandpaPalletInstance: 'static,
54>(
55 block_number: u32,
56) -> bp_header_chain::InitializationData<BridgedHeader<Runtime, GrandpaPalletInstance>> {
57 bp_header_chain::InitializationData {
58 header: Box::new(bp_test_utils::test_header(block_number.into())),
59 authority_list: authority_list(),
60 set_id: 1,
61 operating_mode: BasicOperatingMode::Normal,
62 }
63}
64
65pub(crate) fn dummy_xcm() -> Xcm<()> {
67 vec![Trap(42)].into()
68}
69
70pub(crate) fn dispatch_message<LaneId: Encode>(
71 lane_id: LaneId,
72 nonce: MessageNonce,
73 payload: Vec<u8>,
74) -> DispatchMessage<Vec<u8>, LaneId> {
75 DispatchMessage {
76 key: MessageKey { lane_id, nonce },
77 data: DispatchMessageData { payload: Ok(payload) },
78 }
79}
80
81macro_rules! grab_haul_blob (
83 ($name:ident, $grabbed_payload:ident) => {
84 std::thread_local! {
85 static $grabbed_payload: std::cell::RefCell<Option<Vec<u8>>> = std::cell::RefCell::new(None);
86 }
87
88 struct $name;
89 impl HaulBlob for $name {
90 fn haul_blob(blob: Vec<u8>) -> Result<(), HaulBlobError>{
91 $grabbed_payload.with(|rm| *rm.borrow_mut() = Some(blob));
92 Ok(())
93 }
94 }
95 }
96);
97
98pub(crate) fn simulate_message_exporter_on_bridged_chain<
101 SourceNetwork: Get<NetworkId>,
102 DestinationNetwork: Get<Location>,
103 DestinationVersion: GetVersion,
104>(
105 (destination_network, destination_junctions): (NetworkId, Junctions),
106) -> Vec<u8> {
107 grab_haul_blob!(GrabbingHaulBlob, GRABBED_HAUL_BLOB_PAYLOAD);
108
109 let universal_source_on_bridged_chain: Junctions =
111 [GlobalConsensus(SourceNetwork::get()), Parachain(5678)].into();
112 let channel = 1_u32;
113
114 let (ticket, fee) = validate_export::<
116 HaulBlobExporter<GrabbingHaulBlob, DestinationNetwork, DestinationVersion, ()>,
117 >(
118 destination_network,
119 channel,
120 universal_source_on_bridged_chain,
121 destination_junctions,
122 dummy_xcm(),
123 )
124 .expect("validate_export to pass");
125 tracing::info!(
126 target: "simulate_message_exporter_on_bridged_chain",
127 ?fee,
128 "HaulBlobExporter::validate"
129 );
130 let xcm_hash =
131 HaulBlobExporter::<GrabbingHaulBlob, DestinationNetwork, DestinationVersion, ()>::deliver(
132 ticket,
133 )
134 .expect("deliver to pass");
135 tracing::info!(
136 target: "simulate_message_exporter_on_bridged_chain",
137 ?xcm_hash,
138 "HaulBlobExporter::deliver"
139 );
140
141 GRABBED_HAUL_BLOB_PAYLOAD.with(|r| r.take().expect("Encoded message should be here"))
142}