mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 16:21:02 +00:00
Remove bridges subtree
This commit is contained in:
committed by
Bastian Köcher
parent
d38f6e6728
commit
9a3e2c8c5a
@@ -1,78 +0,0 @@
|
||||
[package]
|
||||
name = "pallet-xcm-bridge-hub"
|
||||
description = "Module that adds dynamic bridges/lanes support to XCM infrastructure at the bridge hub."
|
||||
version = "0.2.0"
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
|
||||
repository.workspace = true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false }
|
||||
log = { workspace = true }
|
||||
scale-info = { version = "2.11.1", default-features = false, features = ["derive"] }
|
||||
|
||||
# Bridge Dependencies
|
||||
bp-messages = { path = "../../primitives/messages", default-features = false }
|
||||
bp-runtime = { path = "../../primitives/runtime", default-features = false }
|
||||
bp-xcm-bridge-hub = { path = "../../primitives/xcm-bridge-hub", default-features = false }
|
||||
pallet-bridge-messages = { path = "../messages", default-features = false }
|
||||
bridge-runtime-common = { path = "../../bin/runtime-common", default-features = false }
|
||||
|
||||
# Substrate Dependencies
|
||||
frame-support = { path = "../../../substrate/frame/support", default-features = false }
|
||||
frame-system = { path = "../../../substrate/frame/system", default-features = false }
|
||||
sp-core = { path = "../../../substrate/primitives/core", default-features = false }
|
||||
sp-runtime = { path = "../../../substrate/primitives/runtime", default-features = false }
|
||||
sp-std = { path = "../../../substrate/primitives/std", default-features = false }
|
||||
|
||||
# Polkadot Dependencies
|
||||
xcm = { package = "staging-xcm", path = "../../../polkadot/xcm", default-features = false }
|
||||
xcm-builder = { package = "staging-xcm-builder", path = "../../../polkadot/xcm/xcm-builder", default-features = false }
|
||||
xcm-executor = { package = "staging-xcm-executor", path = "../../../polkadot/xcm/xcm-executor", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
bp-header-chain = { path = "../../primitives/header-chain" }
|
||||
pallet-balances = { path = "../../../substrate/frame/balances" }
|
||||
sp-io = { path = "../../../substrate/primitives/io" }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"bp-messages/std",
|
||||
"bp-runtime/std",
|
||||
"bp-xcm-bridge-hub/std",
|
||||
"bridge-runtime-common/std",
|
||||
"codec/std",
|
||||
"frame-support/std",
|
||||
"frame-system/std",
|
||||
"log/std",
|
||||
"pallet-bridge-messages/std",
|
||||
"scale-info/std",
|
||||
"sp-core/std",
|
||||
"sp-runtime/std",
|
||||
"sp-std/std",
|
||||
"xcm-builder/std",
|
||||
"xcm-executor/std",
|
||||
"xcm/std",
|
||||
]
|
||||
runtime-benchmarks = [
|
||||
"bridge-runtime-common/runtime-benchmarks",
|
||||
"frame-support/runtime-benchmarks",
|
||||
"frame-system/runtime-benchmarks",
|
||||
"pallet-balances/runtime-benchmarks",
|
||||
"pallet-bridge-messages/runtime-benchmarks",
|
||||
"sp-runtime/runtime-benchmarks",
|
||||
"xcm-builder/runtime-benchmarks",
|
||||
"xcm-executor/runtime-benchmarks",
|
||||
]
|
||||
try-runtime = [
|
||||
"frame-support/try-runtime",
|
||||
"frame-system/try-runtime",
|
||||
"pallet-balances/try-runtime",
|
||||
"pallet-bridge-messages/try-runtime",
|
||||
"sp-runtime/try-runtime",
|
||||
]
|
||||
@@ -1,206 +0,0 @@
|
||||
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Bridges Common.
|
||||
|
||||
// Parity Bridges Common is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity Bridges Common is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! The code that allows to use the pallet (`pallet-xcm-bridge-hub`) as XCM message
|
||||
//! exporter at the sending bridge hub. Internally, it just enqueues outbound blob
|
||||
//! in the messages pallet queue.
|
||||
//!
|
||||
//! This code is executed at the source bridge hub.
|
||||
|
||||
use crate::{Config, Pallet, LOG_TARGET};
|
||||
|
||||
use bp_messages::source_chain::MessagesBridge;
|
||||
use bp_xcm_bridge_hub::XcmAsPlainPayload;
|
||||
use bridge_runtime_common::messages_xcm_extension::{LocalXcmQueueManager, SenderAndLane};
|
||||
use pallet_bridge_messages::{Config as BridgeMessagesConfig, Pallet as BridgeMessagesPallet};
|
||||
use xcm::prelude::*;
|
||||
use xcm_builder::{HaulBlob, HaulBlobError, HaulBlobExporter};
|
||||
use xcm_executor::traits::ExportXcm;
|
||||
|
||||
/// An easy way to access `HaulBlobExporter`.
|
||||
pub type PalletAsHaulBlobExporter<T, I> = HaulBlobExporter<
|
||||
DummyHaulBlob,
|
||||
<T as Config<I>>::BridgedNetwork,
|
||||
<T as Config<I>>::DestinationVersion,
|
||||
<T as Config<I>>::MessageExportPrice,
|
||||
>;
|
||||
/// An easy way to access associated messages pallet.
|
||||
type MessagesPallet<T, I> = BridgeMessagesPallet<T, <T as Config<I>>::BridgeMessagesPalletInstance>;
|
||||
|
||||
impl<T: Config<I>, I: 'static> ExportXcm for Pallet<T, I>
|
||||
where
|
||||
T: BridgeMessagesConfig<T::BridgeMessagesPalletInstance, OutboundPayload = XcmAsPlainPayload>,
|
||||
{
|
||||
type Ticket = (
|
||||
SenderAndLane,
|
||||
<MessagesPallet<T, I> as MessagesBridge<T::OutboundPayload>>::SendMessageArgs,
|
||||
XcmHash,
|
||||
);
|
||||
|
||||
fn validate(
|
||||
network: NetworkId,
|
||||
channel: u32,
|
||||
universal_source: &mut Option<InteriorLocation>,
|
||||
destination: &mut Option<InteriorLocation>,
|
||||
message: &mut Option<Xcm<()>>,
|
||||
) -> Result<(Self::Ticket, Assets), SendError> {
|
||||
// Find supported lane_id.
|
||||
let sender_and_lane = Self::lane_for(
|
||||
universal_source.as_ref().ok_or(SendError::MissingArgument)?,
|
||||
(&network, destination.as_ref().ok_or(SendError::MissingArgument)?),
|
||||
)
|
||||
.ok_or(SendError::NotApplicable)?;
|
||||
|
||||
// check if we are able to route the message. We use existing `HaulBlobExporter` for that.
|
||||
// It will make all required changes and will encode message properly, so that the
|
||||
// `DispatchBlob` at the bridged bridge hub will be able to decode it
|
||||
let ((blob, id), price) = PalletAsHaulBlobExporter::<T, I>::validate(
|
||||
network,
|
||||
channel,
|
||||
universal_source,
|
||||
destination,
|
||||
message,
|
||||
)?;
|
||||
|
||||
let bridge_message = MessagesPallet::<T, I>::validate_message(sender_and_lane.lane, &blob)
|
||||
.map_err(|e| {
|
||||
log::debug!(
|
||||
target: LOG_TARGET,
|
||||
"XCM message {:?} cannot be exported because of bridge error {:?} on bridge {:?}",
|
||||
id,
|
||||
e,
|
||||
sender_and_lane.lane,
|
||||
);
|
||||
SendError::Transport("BridgeValidateError")
|
||||
})?;
|
||||
|
||||
Ok(((sender_and_lane, bridge_message, id), price))
|
||||
}
|
||||
|
||||
fn deliver((sender_and_lane, bridge_message, id): Self::Ticket) -> Result<XcmHash, SendError> {
|
||||
let lane_id = sender_and_lane.lane;
|
||||
let artifacts = MessagesPallet::<T, I>::send_message(bridge_message);
|
||||
|
||||
log::info!(
|
||||
target: LOG_TARGET,
|
||||
"XCM message {:?} has been enqueued at bridge {:?} with nonce {}",
|
||||
id,
|
||||
lane_id,
|
||||
artifacts.nonce,
|
||||
);
|
||||
|
||||
// notify XCM queue manager about updated lane state
|
||||
LocalXcmQueueManager::<T::LanesSupport>::on_bridge_message_enqueued(
|
||||
&sender_and_lane,
|
||||
artifacts.enqueued_messages,
|
||||
);
|
||||
|
||||
Ok(id)
|
||||
}
|
||||
}
|
||||
|
||||
/// Dummy implementation of the `HaulBlob` trait that is never called.
|
||||
///
|
||||
/// We are using `HaulBlobExporter`, which requires `HaulBlob` implementation. It assumes that
|
||||
/// there's a single channel between two bridge hubs - `HaulBlob` only accepts the blob and nothing
|
||||
/// else. But bridge messages pallet may have a dedicated channel (lane) for every pair of bridged
|
||||
/// chains. So we are using our own `ExportXcm` implementation, but to utilize `HaulBlobExporter` we
|
||||
/// still need this `DummyHaulBlob`.
|
||||
pub struct DummyHaulBlob;
|
||||
|
||||
impl HaulBlob for DummyHaulBlob {
|
||||
fn haul_blob(_blob: XcmAsPlainPayload) -> Result<(), HaulBlobError> {
|
||||
Err(HaulBlobError::Transport("DummyHaulBlob"))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::mock::*;
|
||||
use frame_support::assert_ok;
|
||||
use xcm_executor::traits::export_xcm;
|
||||
|
||||
fn universal_source() -> InteriorLocation {
|
||||
[GlobalConsensus(RelayNetwork::get()), Parachain(SIBLING_ASSET_HUB_ID)].into()
|
||||
}
|
||||
|
||||
fn universal_destination() -> InteriorLocation {
|
||||
BridgedDestination::get()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn export_works() {
|
||||
run_test(|| {
|
||||
assert_ok!(export_xcm::<XcmOverBridge>(
|
||||
BridgedRelayNetwork::get(),
|
||||
0,
|
||||
universal_source(),
|
||||
universal_destination(),
|
||||
vec![Instruction::ClearOrigin].into(),
|
||||
));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn export_fails_if_argument_is_missing() {
|
||||
run_test(|| {
|
||||
assert_eq!(
|
||||
XcmOverBridge::validate(
|
||||
BridgedRelayNetwork::get(),
|
||||
0,
|
||||
&mut None,
|
||||
&mut Some(universal_destination()),
|
||||
&mut Some(Vec::new().into()),
|
||||
),
|
||||
Err(SendError::MissingArgument),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
XcmOverBridge::validate(
|
||||
BridgedRelayNetwork::get(),
|
||||
0,
|
||||
&mut Some(universal_source()),
|
||||
&mut None,
|
||||
&mut Some(Vec::new().into()),
|
||||
),
|
||||
Err(SendError::MissingArgument),
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exporter_computes_correct_lane_id() {
|
||||
run_test(|| {
|
||||
let expected_lane_id = TEST_LANE_ID;
|
||||
|
||||
assert_eq!(
|
||||
XcmOverBridge::validate(
|
||||
BridgedRelayNetwork::get(),
|
||||
0,
|
||||
&mut Some(universal_source()),
|
||||
&mut Some(universal_destination()),
|
||||
&mut Some(Vec::new().into()),
|
||||
)
|
||||
.unwrap()
|
||||
.0
|
||||
.0
|
||||
.lane,
|
||||
expected_lane_id,
|
||||
);
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Bridges Common.
|
||||
|
||||
// Parity Bridges Common is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity Bridges Common is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Module that adds XCM support to bridge pallets.
|
||||
|
||||
#![warn(missing_docs)]
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use bridge_runtime_common::messages_xcm_extension::XcmBlobHauler;
|
||||
use pallet_bridge_messages::Config as BridgeMessagesConfig;
|
||||
use xcm::prelude::*;
|
||||
|
||||
pub use exporter::PalletAsHaulBlobExporter;
|
||||
pub use pallet::*;
|
||||
|
||||
mod exporter;
|
||||
mod mock;
|
||||
|
||||
/// The target that will be used when publishing logs related to this pallet.
|
||||
pub const LOG_TARGET: &str = "runtime::bridge-xcm";
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use bridge_runtime_common::messages_xcm_extension::SenderAndLane;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
|
||||
#[pallet::config]
|
||||
#[pallet::disable_frame_system_supertrait_check]
|
||||
pub trait Config<I: 'static = ()>:
|
||||
BridgeMessagesConfig<Self::BridgeMessagesPalletInstance>
|
||||
{
|
||||
/// Runtime's universal location.
|
||||
type UniversalLocation: Get<InteriorLocation>;
|
||||
// TODO: https://github.com/paritytech/parity-bridges-common/issues/1666 remove `ChainId` and
|
||||
// replace it with the `NetworkId` - then we'll be able to use
|
||||
// `T as pallet_bridge_messages::Config<T::BridgeMessagesPalletInstance>::BridgedChain::NetworkId`
|
||||
/// Bridged network as relative location of bridged `GlobalConsensus`.
|
||||
#[pallet::constant]
|
||||
type BridgedNetwork: Get<Location>;
|
||||
/// Associated messages pallet instance that bridges us with the
|
||||
/// `BridgedNetworkId` consensus.
|
||||
type BridgeMessagesPalletInstance: 'static;
|
||||
|
||||
/// Price of single message export to the bridged consensus (`Self::BridgedNetworkId`).
|
||||
type MessageExportPrice: Get<Assets>;
|
||||
/// Checks the XCM version for the destination.
|
||||
type DestinationVersion: GetVersion;
|
||||
|
||||
/// Get point-to-point links with bridged consensus (`Self::BridgedNetworkId`).
|
||||
/// (this will be replaced with dynamic on-chain bridges - `Bridges V2`)
|
||||
type Lanes: Get<sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorLocation))>>;
|
||||
/// Support for point-to-point links
|
||||
/// (this will be replaced with dynamic on-chain bridges - `Bridges V2`)
|
||||
type LanesSupport: XcmBlobHauler;
|
||||
}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T, I = ()>(PhantomData<(T, I)>);
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {
|
||||
fn integrity_test() {
|
||||
assert!(
|
||||
Self::bridged_network_id().is_some(),
|
||||
"Configured `T::BridgedNetwork`: {:?} does not contain `GlobalConsensus` junction with `NetworkId`",
|
||||
T::BridgedNetwork::get()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
/// Returns dedicated/configured lane identifier.
|
||||
pub(crate) fn lane_for(
|
||||
source: &InteriorLocation,
|
||||
dest: (&NetworkId, &InteriorLocation),
|
||||
) -> Option<SenderAndLane> {
|
||||
let source = source.clone().relative_to(&T::UniversalLocation::get());
|
||||
|
||||
// Check that we have configured a point-to-point lane for 'source' and `dest`.
|
||||
T::Lanes::get()
|
||||
.into_iter()
|
||||
.find_map(|(lane_source, (lane_dest_network, lane_dest))| {
|
||||
if lane_source.location == source &&
|
||||
&lane_dest_network == dest.0 &&
|
||||
Self::bridged_network_id().as_ref() == Some(dest.0) &&
|
||||
&lane_dest == dest.1
|
||||
{
|
||||
Some(lane_source)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns some `NetworkId` if contains `GlobalConsensus` junction.
|
||||
fn bridged_network_id() -> Option<NetworkId> {
|
||||
match T::BridgedNetwork::get().take_first_interior() {
|
||||
Some(GlobalConsensus(network)) => Some(network),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,317 +0,0 @@
|
||||
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Bridges Common.
|
||||
|
||||
// Parity Bridges Common is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity Bridges Common is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#![cfg(test)]
|
||||
|
||||
use crate as pallet_xcm_bridge_hub;
|
||||
|
||||
use bp_messages::{
|
||||
target_chain::{DispatchMessage, MessageDispatch},
|
||||
LaneId,
|
||||
};
|
||||
use bp_runtime::{messages::MessageDispatchResult, Chain, ChainId, UnderlyingChainProvider};
|
||||
use bridge_runtime_common::{
|
||||
messages::{
|
||||
source::TargetHeaderChainAdapter, target::SourceHeaderChainAdapter,
|
||||
BridgedChainWithMessages, HashOf, MessageBridge, ThisChainWithMessages,
|
||||
},
|
||||
messages_xcm_extension::{SenderAndLane, XcmBlobHauler},
|
||||
};
|
||||
use codec::Encode;
|
||||
use frame_support::{derive_impl, parameter_types, traits::ConstU32, weights::RuntimeDbWeight};
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
testing::Header as SubstrateHeader,
|
||||
traits::{BlakeTwo256, IdentityLookup},
|
||||
AccountId32, BuildStorage,
|
||||
};
|
||||
use xcm::prelude::*;
|
||||
|
||||
pub type AccountId = AccountId32;
|
||||
pub type Balance = u64;
|
||||
|
||||
type Block = frame_system::mocking::MockBlock<TestRuntime>;
|
||||
|
||||
pub const SIBLING_ASSET_HUB_ID: u32 = 2001;
|
||||
pub const THIS_BRIDGE_HUB_ID: u32 = 2002;
|
||||
pub const BRIDGED_ASSET_HUB_ID: u32 = 1001;
|
||||
pub const TEST_LANE_ID: LaneId = LaneId([0, 0, 0, 1]);
|
||||
|
||||
frame_support::construct_runtime! {
|
||||
pub enum TestRuntime {
|
||||
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
|
||||
Balances: pallet_balances::{Pallet, Event<T>},
|
||||
Messages: pallet_bridge_messages::{Pallet, Call, Event<T>},
|
||||
XcmOverBridge: pallet_xcm_bridge_hub::{Pallet},
|
||||
}
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const DbWeight: RuntimeDbWeight = RuntimeDbWeight { read: 1, write: 2 };
|
||||
pub const ExistentialDeposit: Balance = 1;
|
||||
}
|
||||
|
||||
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
|
||||
impl frame_system::Config for TestRuntime {
|
||||
type AccountId = AccountId;
|
||||
type AccountData = pallet_balances::AccountData<Balance>;
|
||||
type Block = Block;
|
||||
type Lookup = IdentityLookup<Self::AccountId>;
|
||||
}
|
||||
|
||||
#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)]
|
||||
impl pallet_balances::Config for TestRuntime {
|
||||
type AccountStore = System;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const ActiveOutboundLanes: &'static [LaneId] = &[TEST_LANE_ID];
|
||||
}
|
||||
|
||||
impl pallet_bridge_messages::Config for TestRuntime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type WeightInfo = TestMessagesWeights;
|
||||
|
||||
type BridgedChainId = ();
|
||||
type ActiveOutboundLanes = ActiveOutboundLanes;
|
||||
type MaxUnrewardedRelayerEntriesAtInboundLane = ();
|
||||
type MaxUnconfirmedMessagesAtInboundLane = ();
|
||||
type MaximalOutboundPayloadSize = ConstU32<2048>;
|
||||
type OutboundPayload = Vec<u8>;
|
||||
type InboundPayload = Vec<u8>;
|
||||
type InboundRelayer = ();
|
||||
type DeliveryPayments = ();
|
||||
type TargetHeaderChain = TargetHeaderChainAdapter<OnThisChainBridge>;
|
||||
type DeliveryConfirmationPayments = ();
|
||||
type OnMessagesDelivered = ();
|
||||
type SourceHeaderChain = SourceHeaderChainAdapter<OnThisChainBridge>;
|
||||
type MessageDispatch = TestMessageDispatch;
|
||||
}
|
||||
|
||||
pub struct TestMessagesWeights;
|
||||
|
||||
impl pallet_bridge_messages::WeightInfo for TestMessagesWeights {
|
||||
fn receive_single_message_proof() -> Weight {
|
||||
Weight::zero()
|
||||
}
|
||||
fn receive_single_message_proof_with_outbound_lane_state() -> Weight {
|
||||
Weight::zero()
|
||||
}
|
||||
fn receive_delivery_proof_for_single_message() -> Weight {
|
||||
Weight::zero()
|
||||
}
|
||||
fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight {
|
||||
Weight::zero()
|
||||
}
|
||||
fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight {
|
||||
Weight::zero()
|
||||
}
|
||||
|
||||
fn receive_two_messages_proof() -> Weight {
|
||||
Weight::zero()
|
||||
}
|
||||
|
||||
fn receive_single_message_proof_1_kb() -> Weight {
|
||||
Weight::zero()
|
||||
}
|
||||
|
||||
fn receive_single_message_proof_16_kb() -> Weight {
|
||||
Weight::zero()
|
||||
}
|
||||
|
||||
fn receive_single_message_proof_with_dispatch(_: u32) -> Weight {
|
||||
Weight::from_parts(1, 0)
|
||||
}
|
||||
}
|
||||
|
||||
impl pallet_bridge_messages::WeightInfoExt for TestMessagesWeights {
|
||||
fn expected_extra_storage_proof_size() -> u32 {
|
||||
0
|
||||
}
|
||||
|
||||
fn receive_messages_proof_overhead_from_runtime() -> Weight {
|
||||
Weight::zero()
|
||||
}
|
||||
|
||||
fn receive_messages_delivery_proof_overhead_from_runtime() -> Weight {
|
||||
Weight::zero()
|
||||
}
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const RelayNetwork: NetworkId = NetworkId::Kusama;
|
||||
pub const BridgedRelayNetwork: NetworkId = NetworkId::Polkadot;
|
||||
pub BridgedRelayNetworkLocation: Location = (Parent, GlobalConsensus(BridgedRelayNetwork::get())).into();
|
||||
pub const NonBridgedRelayNetwork: NetworkId = NetworkId::Rococo;
|
||||
pub const BridgeReserve: Balance = 100_000;
|
||||
pub UniversalLocation: InteriorLocation = [
|
||||
GlobalConsensus(RelayNetwork::get()),
|
||||
Parachain(THIS_BRIDGE_HUB_ID),
|
||||
].into();
|
||||
pub const Penalty: Balance = 1_000;
|
||||
}
|
||||
|
||||
impl pallet_xcm_bridge_hub::Config for TestRuntime {
|
||||
type UniversalLocation = UniversalLocation;
|
||||
type BridgedNetwork = BridgedRelayNetworkLocation;
|
||||
type BridgeMessagesPalletInstance = ();
|
||||
|
||||
type MessageExportPrice = ();
|
||||
type DestinationVersion = AlwaysLatest;
|
||||
|
||||
type Lanes = TestLanes;
|
||||
type LanesSupport = TestXcmBlobHauler;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub TestSenderAndLane: SenderAndLane = SenderAndLane {
|
||||
location: Location::new(1, [Parachain(SIBLING_ASSET_HUB_ID)]),
|
||||
lane: TEST_LANE_ID,
|
||||
};
|
||||
pub BridgedDestination: InteriorLocation = [
|
||||
Parachain(BRIDGED_ASSET_HUB_ID)
|
||||
].into();
|
||||
pub TestLanes: sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorLocation))> = sp_std::vec![
|
||||
(TestSenderAndLane::get(), (BridgedRelayNetwork::get(), BridgedDestination::get()))
|
||||
];
|
||||
}
|
||||
|
||||
pub struct TestXcmBlobHauler;
|
||||
impl XcmBlobHauler for TestXcmBlobHauler {
|
||||
type Runtime = TestRuntime;
|
||||
type MessagesInstance = ();
|
||||
type ToSourceChainSender = ();
|
||||
type CongestedMessage = ();
|
||||
type UncongestedMessage = ();
|
||||
}
|
||||
|
||||
pub struct ThisChain;
|
||||
|
||||
impl Chain for ThisChain {
|
||||
const ID: ChainId = *b"tuch";
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
type Hasher = BlakeTwo256;
|
||||
type Header = SubstrateHeader;
|
||||
type AccountId = AccountId;
|
||||
type Balance = Balance;
|
||||
type Nonce = u64;
|
||||
type Signature = sp_runtime::MultiSignature;
|
||||
|
||||
fn max_extrinsic_size() -> u32 {
|
||||
u32::MAX
|
||||
}
|
||||
|
||||
fn max_extrinsic_weight() -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BridgedChain;
|
||||
pub type BridgedHeaderHash = H256;
|
||||
pub type BridgedChainHeader = SubstrateHeader;
|
||||
|
||||
impl Chain for BridgedChain {
|
||||
const ID: ChainId = *b"tuch";
|
||||
type BlockNumber = u64;
|
||||
type Hash = BridgedHeaderHash;
|
||||
type Hasher = BlakeTwo256;
|
||||
type Header = BridgedChainHeader;
|
||||
type AccountId = AccountId;
|
||||
type Balance = Balance;
|
||||
type Nonce = u64;
|
||||
type Signature = sp_runtime::MultiSignature;
|
||||
|
||||
fn max_extrinsic_size() -> u32 {
|
||||
4096
|
||||
}
|
||||
|
||||
fn max_extrinsic_weight() -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
}
|
||||
|
||||
/// Test message dispatcher.
|
||||
pub struct TestMessageDispatch;
|
||||
|
||||
impl TestMessageDispatch {
|
||||
pub fn deactivate(lane: LaneId) {
|
||||
frame_support::storage::unhashed::put(&(b"inactive", lane).encode()[..], &false);
|
||||
}
|
||||
}
|
||||
|
||||
impl MessageDispatch for TestMessageDispatch {
|
||||
type DispatchPayload = Vec<u8>;
|
||||
type DispatchLevelResult = ();
|
||||
|
||||
fn is_active() -> bool {
|
||||
frame_support::storage::unhashed::take::<bool>(&(b"inactive").encode()[..]) != Some(false)
|
||||
}
|
||||
|
||||
fn dispatch_weight(_message: &mut DispatchMessage<Self::DispatchPayload>) -> Weight {
|
||||
Weight::zero()
|
||||
}
|
||||
|
||||
fn dispatch(
|
||||
_: DispatchMessage<Self::DispatchPayload>,
|
||||
) -> MessageDispatchResult<Self::DispatchLevelResult> {
|
||||
MessageDispatchResult { unspent_weight: Weight::zero(), dispatch_level_result: () }
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WrappedThisChain;
|
||||
impl UnderlyingChainProvider for WrappedThisChain {
|
||||
type Chain = ThisChain;
|
||||
}
|
||||
impl ThisChainWithMessages for WrappedThisChain {
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
}
|
||||
|
||||
pub struct WrappedBridgedChain;
|
||||
impl UnderlyingChainProvider for WrappedBridgedChain {
|
||||
type Chain = BridgedChain;
|
||||
}
|
||||
impl BridgedChainWithMessages for WrappedBridgedChain {}
|
||||
|
||||
pub struct BridgedHeaderChain;
|
||||
impl bp_header_chain::HeaderChain<BridgedChain> for BridgedHeaderChain {
|
||||
fn finalized_header_state_root(
|
||||
_hash: HashOf<WrappedBridgedChain>,
|
||||
) -> Option<HashOf<WrappedBridgedChain>> {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Bridge that is deployed on `ThisChain` and allows sending/receiving messages to/from
|
||||
/// `BridgedChain`.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct OnThisChainBridge;
|
||||
|
||||
impl MessageBridge for OnThisChainBridge {
|
||||
const BRIDGED_MESSAGES_PALLET_NAME: &'static str = "";
|
||||
|
||||
type ThisChain = WrappedThisChain;
|
||||
type BridgedChain = WrappedBridgedChain;
|
||||
type BridgedHeaderChain = BridgedHeaderChain;
|
||||
}
|
||||
|
||||
/// Run pallet test.
|
||||
pub fn run_test<T>(test: impl FnOnce() -> T) -> T {
|
||||
sp_io::TestExternalities::new(
|
||||
frame_system::GenesisConfig::<TestRuntime>::default().build_storage().unwrap(),
|
||||
)
|
||||
.execute_with(test)
|
||||
}
|
||||
Reference in New Issue
Block a user