mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 21:01:02 +00:00
Xcm in Rialto<>Millau bridge (#1379)
* add XCM pallet to Millau runtime * some progress * messages are delivered (no fee) * temp * flush * flush * some progress * progress * Trap(42) is dispatched successfully * fix spelling * no more manual sending * parametrize weight credit for tests * actually charge fees * enable send-using-messages-pallet to keep our test deployments alive + send valid XCM sometimes * fix benchmarks build * fix tests
This commit is contained in:
committed by
Bastian Köcher
parent
f54bd6c779
commit
748c265c47
@@ -290,6 +290,7 @@ fn testnet_genesis(
|
||||
owner: Some(get_account_id_from_seed::<sr25519::Public>("MillauMessagesOwner")),
|
||||
..Default::default()
|
||||
},
|
||||
xcm_pallet: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,12 +66,17 @@ sp-version = { git = "https://github.com/paritytech/substrate", branch = "master
|
||||
|
||||
# Polkadot (parachain) Dependencies
|
||||
|
||||
pallet-xcm = { git = "https://github.com/paritytech/polkadot", branch = "gav-xcm-v3", default-features = false }
|
||||
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "gav-xcm-v3", default-features = false }
|
||||
polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", branch = "gav-xcm-v3", default-features = false }
|
||||
polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "gav-xcm-v3", default-features = false }
|
||||
xcm = { git = "https://github.com/paritytech/polkadot", branch = "gav-xcm-v3", default-features = false }
|
||||
xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "gav-xcm-v3", default-features = false }
|
||||
xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "gav-xcm-v3", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
bridge-runtime-common = { path = "../../runtime-common", features = ["integrity-test"] }
|
||||
env_logger = "0.8"
|
||||
libsecp256k1 = { version = "0.7", features = ["hmac"] }
|
||||
static_assertions = "1.1"
|
||||
|
||||
@@ -104,6 +109,7 @@ std = [
|
||||
"pallet-bridge-messages/std",
|
||||
"pallet-grandpa/std",
|
||||
"pallet-mmr/std",
|
||||
"pallet-xcm/std",
|
||||
"sp-mmr-primitives/std",
|
||||
"pallet-shift-session-manager/std",
|
||||
"pallet-sudo/std",
|
||||
@@ -130,6 +136,9 @@ std = [
|
||||
"sp-transaction-pool/std",
|
||||
"sp-trie/std",
|
||||
"sp-version/std",
|
||||
"xcm/std",
|
||||
"xcm-builder/std",
|
||||
"xcm-executor/std",
|
||||
]
|
||||
runtime-benchmarks = [
|
||||
"bridge-runtime-common/runtime-benchmarks",
|
||||
@@ -138,5 +147,7 @@ runtime-benchmarks = [
|
||||
"frame-system/runtime-benchmarks",
|
||||
"libsecp256k1",
|
||||
"pallet-bridge-messages/runtime-benchmarks",
|
||||
"pallet-xcm/runtime-benchmarks",
|
||||
"sp-runtime/runtime-benchmarks",
|
||||
"xcm-builder/runtime-benchmarks",
|
||||
]
|
||||
|
||||
@@ -30,6 +30,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
||||
|
||||
pub mod millau_messages;
|
||||
pub mod parachains;
|
||||
pub mod xcm_config;
|
||||
|
||||
use crate::millau_messages::{ToMillauMessagePayload, WithMillauMessageBridge};
|
||||
|
||||
@@ -449,13 +450,7 @@ impl pallet_bridge_messages::Config<WithMillauMessagesInstance> for Runtime {
|
||||
|
||||
type TargetHeaderChain = crate::millau_messages::Millau;
|
||||
type LaneMessageVerifier = crate::millau_messages::ToMillauMessageVerifier;
|
||||
type MessageDeliveryAndDispatchPayment =
|
||||
pallet_bridge_messages::instant_payments::InstantCurrencyPayments<
|
||||
Runtime,
|
||||
WithMillauMessagesInstance,
|
||||
pallet_balances::Pallet<Runtime>,
|
||||
GetDeliveryConfirmationTransactionFee,
|
||||
>;
|
||||
type MessageDeliveryAndDispatchPayment = ();
|
||||
type OnMessageAccepted = ();
|
||||
type OnDeliveryConfirmed = ();
|
||||
|
||||
@@ -513,6 +508,9 @@ construct_runtime!(
|
||||
Registrar: polkadot_runtime_common::paras_registrar::{Pallet, Call, Storage, Event<T>},
|
||||
Slots: polkadot_runtime_common::slots::{Pallet, Call, Storage, Event<T>},
|
||||
ParasSudoWrapper: polkadot_runtime_common::paras_sudo_wrapper::{Pallet, Call},
|
||||
|
||||
// Pallet for sending XCM.
|
||||
XcmPallet: pallet_xcm::{Pallet, Call, Storage, Event<T>, Origin, Config} = 99,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -902,6 +900,7 @@ impl_runtime_apis! {
|
||||
Runtime,
|
||||
WithMillauMessagesInstance,
|
||||
WithMillauMessageBridge,
|
||||
xcm_config::OutboundXcmWeigher,
|
||||
>(lane, begin, end)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Everything required to serve Millau <-> Rialto messages.
|
||||
|
||||
use crate::Runtime;
|
||||
use crate::{Call, OriginCaller, Runtime};
|
||||
|
||||
use bp_messages::{
|
||||
source_chain::{SenderOrigin, TargetHeaderChain},
|
||||
@@ -40,6 +40,10 @@ pub const INITIAL_MILLAU_TO_RIALTO_CONVERSION_RATE: FixedU128 =
|
||||
FixedU128::from_inner(FixedU128::DIV);
|
||||
/// Initial value of `MillauFeeMultiplier` parameter.
|
||||
pub const INITIAL_MILLAU_FEE_MULTIPLIER: FixedU128 = FixedU128::from_inner(FixedU128::DIV);
|
||||
/// Weight of 2 XCM instructions is for simple `Trap(42)` program, coming through bridge
|
||||
/// (it is prepended with `UniversalOrigin` instruction). It is used just for simplest manual
|
||||
/// tests, confirming that we don't break encoding somewhere between.
|
||||
pub const BASE_XCM_WEIGHT_TWICE: Weight = 2 * crate::xcm_config::BASE_XCM_WEIGHT;
|
||||
|
||||
parameter_types! {
|
||||
/// Millau to Rialto conversion rate. Initially we treat both tokens as equal.
|
||||
@@ -56,14 +60,15 @@ pub type ToMillauMessageVerifier =
|
||||
messages::source::FromThisChainMessageVerifier<WithMillauMessageBridge>;
|
||||
|
||||
/// Message payload for Millau -> Rialto messages.
|
||||
pub type FromMillauMessagePayload = messages::target::FromBridgedChainMessagePayload;
|
||||
pub type FromMillauMessagePayload = messages::target::FromBridgedChainMessagePayload<Call>;
|
||||
|
||||
/// Call-dispatch based message dispatch for Millau -> Rialto messages.
|
||||
pub type FromMillauMessageDispatch = messages::target::FromBridgedChainMessageDispatch<
|
||||
WithMillauMessageBridge,
|
||||
crate::Runtime,
|
||||
pallet_balances::Pallet<Runtime>,
|
||||
(),
|
||||
xcm_executor::XcmExecutor<crate::xcm_config::XcmConfig>,
|
||||
crate::xcm_config::XcmWeigher,
|
||||
//
|
||||
frame_support::traits::ConstU64<BASE_XCM_WEIGHT_TWICE>,
|
||||
>;
|
||||
|
||||
/// Messages proof for Millau -> Rialto messages.
|
||||
@@ -115,7 +120,23 @@ impl messages::ThisChainWithMessages for Rialto {
|
||||
type Call = crate::Call;
|
||||
|
||||
fn is_message_accepted(send_origin: &Self::Origin, lane: &LaneId) -> bool {
|
||||
send_origin.linked_account().is_some() && (*lane == [0, 0, 0, 0] || *lane == [0, 0, 0, 1])
|
||||
let here_location =
|
||||
xcm::v3::MultiLocation::from(crate::xcm_config::UniversalLocation::get());
|
||||
match send_origin.caller {
|
||||
OriginCaller::XcmPallet(pallet_xcm::Origin::Xcm(ref location))
|
||||
if *location == here_location =>
|
||||
{
|
||||
log::trace!(target: "runtime::bridge", "Verifying message sent using XCM pallet to Millau");
|
||||
},
|
||||
_ => {
|
||||
// keep in mind that in this case all messages are free (in term of fees)
|
||||
// => it's just to keep testing bridge on our test deployments until we'll have a
|
||||
// better option
|
||||
log::trace!(target: "runtime::bridge", "Verifying message sent using messages pallet to Millau");
|
||||
},
|
||||
}
|
||||
|
||||
*lane == [0, 0, 0, 0] || *lane == [0, 0, 0, 1]
|
||||
}
|
||||
|
||||
fn maximal_pending_messages_at_outbound_lane() -> MessageNonce {
|
||||
@@ -262,14 +283,8 @@ impl SourceHeaderChain<bp_millau::Balance> for Millau {
|
||||
|
||||
impl SenderOrigin<crate::AccountId> for crate::Origin {
|
||||
fn linked_account(&self) -> Option<crate::AccountId> {
|
||||
match self.caller {
|
||||
crate::OriginCaller::system(frame_system::RawOrigin::Signed(ref submitter)) =>
|
||||
Some(submitter.clone()),
|
||||
crate::OriginCaller::system(frame_system::RawOrigin::Root) |
|
||||
crate::OriginCaller::system(frame_system::RawOrigin::None) =>
|
||||
crate::RootAccountForPayments::get(),
|
||||
_ => None,
|
||||
}
|
||||
// XCM deals wit fees in our deployments
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,318 @@
|
||||
// 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/>.
|
||||
|
||||
//! XCM configurations for the Rialto runtime.
|
||||
|
||||
use super::{
|
||||
millau_messages::WithMillauMessageBridge, AccountId, AllPalletsWithSystem, Balances,
|
||||
BridgeMillauMessages, Call, Event, Origin, Runtime, XcmPallet,
|
||||
};
|
||||
use bp_messages::source_chain::MessagesBridge;
|
||||
use bp_rialto::{Balance, WeightToFee};
|
||||
use bridge_runtime_common::messages::{
|
||||
source::{estimate_message_dispatch_and_delivery_fee, FromThisChainMessagePayload},
|
||||
MessageBridge,
|
||||
};
|
||||
use codec::Encode;
|
||||
use frame_support::{
|
||||
parameter_types,
|
||||
traits::{Everything, Nothing},
|
||||
weights::Weight,
|
||||
};
|
||||
use sp_std::marker::PhantomData;
|
||||
use xcm::latest::prelude::*;
|
||||
use xcm_builder::{
|
||||
AccountId32Aliases, AllowKnownQueryResponses, AllowTopLevelPaidExecutionFrom,
|
||||
CurrencyAdapter as XcmCurrencyAdapter, IsConcrete, SignedAccountId32AsNative,
|
||||
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents,
|
||||
};
|
||||
|
||||
parameter_types! {
|
||||
/// The location of the `MLAU` token, from the context of this chain. Since this token is native to this
|
||||
/// chain, we make it synonymous with it and thus it is the `Here` location, which means "equivalent to
|
||||
/// the context".
|
||||
pub const TokenLocation: MultiLocation = Here.into_location();
|
||||
/// The Rialto network ID, associated with Polkadot.
|
||||
pub const ThisNetwork: NetworkId = Polkadot;
|
||||
/// The Millau network ID, associated with Kusama.
|
||||
pub const MillauNetwork: NetworkId = Kusama;
|
||||
|
||||
/// Our XCM location ancestry - i.e. our location within the Consensus Universe.
|
||||
///
|
||||
/// Since Polkadot is a top-level relay-chain with its own consensus, it's just our network ID.
|
||||
pub UniversalLocation: InteriorMultiLocation = ThisNetwork::get().into();
|
||||
/// The check account, which holds any native assets that have been teleported out and not back in (yet).
|
||||
pub CheckAccount: AccountId = XcmPallet::check_account();
|
||||
}
|
||||
|
||||
/// The canonical means of converting a `MultiLocation` into an `AccountId`, used when we want to
|
||||
/// determine the sovereign account controlled by a location.
|
||||
pub type SovereignAccountOf = (
|
||||
// We can directly alias an `AccountId32` into a local account.
|
||||
AccountId32Aliases<ThisNetwork, AccountId>,
|
||||
);
|
||||
|
||||
/// Our asset transactor. This is what allows us to interest with the runtime facilities from the
|
||||
/// point of view of XCM-only concepts like `MultiLocation` and `MultiAsset`.
|
||||
///
|
||||
/// Ours is only aware of the Balances pallet, which is mapped to `TokenLocation`.
|
||||
pub type LocalAssetTransactor = XcmCurrencyAdapter<
|
||||
// Use this currency:
|
||||
Balances,
|
||||
// Use this currency when it is a fungible asset matching the given location or name:
|
||||
IsConcrete<TokenLocation>,
|
||||
// We can convert the MultiLocations with our converter above:
|
||||
SovereignAccountOf,
|
||||
// Our chain's account ID type (we can't get away without mentioning it explicitly):
|
||||
AccountId,
|
||||
// We track our teleports in/out to keep total issuance correct.
|
||||
CheckAccount,
|
||||
>;
|
||||
|
||||
/// The means that we convert the XCM message origin location into a local dispatch origin.
|
||||
type LocalOriginConverter = (
|
||||
// A `Signed` origin of the sovereign account that the original location controls.
|
||||
SovereignSignedViaLocation<SovereignAccountOf, Origin>,
|
||||
// The AccountId32 location type can be expressed natively as a `Signed` origin.
|
||||
SignedAccountId32AsNative<ThisNetwork, Origin>,
|
||||
);
|
||||
|
||||
/// The amount of weight an XCM operation takes. This is a safe overestimate.
|
||||
pub const BASE_XCM_WEIGHT: Weight = 1_000_000_000;
|
||||
|
||||
parameter_types! {
|
||||
/// The amount of weight an XCM operation takes. This is a safe overestimate.
|
||||
pub const BaseXcmWeight: Weight = BASE_XCM_WEIGHT;
|
||||
/// Maximum number of instructions in a single XCM fragment. A sanity check against weight
|
||||
/// calculations getting too crazy.
|
||||
pub const MaxInstructions: u32 = 100;
|
||||
}
|
||||
|
||||
/// The XCM router. When we want to send an XCM message, we use this type. It amalgamates all of our
|
||||
/// individual routers.
|
||||
pub type XcmRouter = (
|
||||
// Router to send messages to Millau.
|
||||
ToMillauBridge<BridgeMillauMessages>,
|
||||
);
|
||||
|
||||
parameter_types! {
|
||||
pub const MaxAssetsIntoHolding: u32 = 64;
|
||||
}
|
||||
|
||||
/// The barriers one of which must be passed for an XCM message to be executed.
|
||||
pub type Barrier = (
|
||||
// Weight that is paid for may be consumed.
|
||||
TakeWeightCredit,
|
||||
// If the message is one that immediately attemps to pay for execution, then allow it.
|
||||
AllowTopLevelPaidExecutionFrom<Everything>,
|
||||
// Expected responses are OK.
|
||||
AllowKnownQueryResponses<XcmPallet>,
|
||||
);
|
||||
|
||||
/// Outbound XCM weigher type.
|
||||
pub type OutboundXcmWeigher = xcm_builder::FixedWeightBounds<BaseXcmWeight, (), MaxInstructions>;
|
||||
/// Incoming XCM weigher type.
|
||||
pub type XcmWeigher = xcm_builder::FixedWeightBounds<BaseXcmWeight, Call, MaxInstructions>;
|
||||
|
||||
pub struct XcmConfig;
|
||||
impl xcm_executor::Config for XcmConfig {
|
||||
type Call = Call;
|
||||
type XcmSender = XcmRouter;
|
||||
type AssetTransactor = LocalAssetTransactor;
|
||||
type OriginConverter = LocalOriginConverter;
|
||||
type IsReserve = ();
|
||||
type IsTeleporter = ();
|
||||
type UniversalLocation = UniversalLocation;
|
||||
type Barrier = Barrier;
|
||||
type Weigher = XcmWeigher;
|
||||
// The weight trader piggybacks on the existing transaction-fee conversion logic.
|
||||
type Trader = UsingComponents<WeightToFee, TokenLocation, AccountId, Balances, ()>;
|
||||
type ResponseHandler = XcmPallet;
|
||||
type AssetTrap = XcmPallet;
|
||||
type AssetLocker = ();
|
||||
type AssetExchanger = ();
|
||||
type AssetClaims = XcmPallet;
|
||||
type SubscriptionService = XcmPallet;
|
||||
type PalletInstancesInfo = AllPalletsWithSystem;
|
||||
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
|
||||
type FeeManager = ();
|
||||
type MessageExporter = ();
|
||||
type UniversalAliases = Nothing;
|
||||
}
|
||||
|
||||
/// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior
|
||||
/// location of this chain.
|
||||
pub type LocalOriginToLocation = (
|
||||
// Usual Signed origin to be used in XCM as a corresponding AccountId32
|
||||
SignedToAccountId32<Origin, AccountId, ThisNetwork>,
|
||||
);
|
||||
|
||||
impl pallet_xcm::Config for Runtime {
|
||||
type Event = Event;
|
||||
// We don't allow any messages to be sent via the transaction yet. This is basically safe to
|
||||
// enable, (safe the possibility of someone spamming the parachain if they're willing to pay
|
||||
// the DOT to send from the Relay-chain). But it's useless until we bring in XCM v3 which will
|
||||
// make `DescendOrigin` a bit more useful.
|
||||
type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<Origin, LocalOriginToLocation>;
|
||||
type XcmRouter = XcmRouter;
|
||||
// Anyone can execute XCM messages locally.
|
||||
type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<Origin, LocalOriginToLocation>;
|
||||
type XcmExecuteFilter = Everything;
|
||||
type XcmExecutor = xcm_executor::XcmExecutor<XcmConfig>;
|
||||
// Anyone is able to use teleportation regardless of who they are and what they want to
|
||||
// teleport.
|
||||
type XcmTeleportFilter = Everything;
|
||||
// Anyone is able to use reserve transfers regardless of who they are and what they want to
|
||||
// transfer.
|
||||
type XcmReserveTransferFilter = Everything;
|
||||
type Weigher = XcmWeigher;
|
||||
type UniversalLocation = UniversalLocation;
|
||||
type Origin = Origin;
|
||||
type Call = Call;
|
||||
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
|
||||
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
|
||||
type Currency = Balances;
|
||||
type CurrencyMatcher = ();
|
||||
type TrustedLockers = ();
|
||||
type SovereignAccountOf = SovereignAccountOf;
|
||||
type MaxLockers = frame_support::traits::ConstU32<8>;
|
||||
}
|
||||
|
||||
/// With-rialto bridge.
|
||||
pub struct ToMillauBridge<MB>(PhantomData<MB>);
|
||||
|
||||
impl<MB: MessagesBridge<Origin, AccountId, Balance, FromThisChainMessagePayload>> SendXcm
|
||||
for ToMillauBridge<MB>
|
||||
{
|
||||
type Ticket = (Balance, FromThisChainMessagePayload);
|
||||
|
||||
fn validate(
|
||||
dest: &mut Option<MultiLocation>,
|
||||
msg: &mut Option<Xcm<()>>,
|
||||
) -> SendResult<Self::Ticket> {
|
||||
let d = dest.take().ok_or(SendError::MissingArgument)?;
|
||||
if !matches!(d, MultiLocation { parents: 1, interior: X1(GlobalConsensus(r)) } if r == MillauNetwork::get())
|
||||
{
|
||||
*dest = Some(d);
|
||||
return Err(SendError::NotApplicable)
|
||||
};
|
||||
|
||||
let dest: InteriorMultiLocation = MillauNetwork::get().into();
|
||||
let here = UniversalLocation::get();
|
||||
let route = dest.relative_to(&here);
|
||||
let msg = (route, msg.take().unwrap()).encode();
|
||||
|
||||
let fee = estimate_message_dispatch_and_delivery_fee::<WithMillauMessageBridge>(
|
||||
&msg,
|
||||
WithMillauMessageBridge::RELAYER_FEE_PERCENT,
|
||||
None,
|
||||
)
|
||||
.map_err(SendError::Transport)?;
|
||||
let fee_assets = MultiAssets::from((Here, fee));
|
||||
|
||||
Ok(((fee, msg), fee_assets))
|
||||
}
|
||||
|
||||
fn deliver(ticket: Self::Ticket) -> Result<XcmHash, SendError> {
|
||||
let lane = [0, 0, 0, 0];
|
||||
let (fee, msg) = ticket;
|
||||
let result = MB::send_message(
|
||||
pallet_xcm::Origin::from(MultiLocation::from(UniversalLocation::get())).into(),
|
||||
lane,
|
||||
msg,
|
||||
fee,
|
||||
);
|
||||
result
|
||||
.map(|artifacts| {
|
||||
let hash = (lane, artifacts.nonce).using_encoded(sp_io::hashing::blake2_256);
|
||||
log::debug!(target: "runtime::bridge", "Sent XCM message {:?}/{} to Rialto: {:?}", lane, artifacts.nonce, hash);
|
||||
hash
|
||||
})
|
||||
.map_err(|e| {
|
||||
log::debug!(target: "runtime::bridge", "Failed to send XCM message over lane {:?} to Rialto: {:?}", lane, e);
|
||||
SendError::Transport("Bridge has rejected the message")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use bp_messages::{
|
||||
target_chain::{DispatchMessage, DispatchMessageData, MessageDispatch},
|
||||
MessageKey,
|
||||
};
|
||||
use bp_runtime::messages::MessageDispatchResult;
|
||||
use bridge_runtime_common::messages::target::FromBridgedChainMessageDispatch;
|
||||
|
||||
fn new_test_ext() -> sp_io::TestExternalities {
|
||||
sp_io::TestExternalities::new(
|
||||
frame_system::GenesisConfig::default().build_storage::<Runtime>().unwrap(),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn xcm_messages_to_millau_are_sent() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// the encoded message (origin ++ xcm) is 0x010109030419A8
|
||||
let dest = (Parent, X1(GlobalConsensus(MillauNetwork::get())));
|
||||
let xcm: Xcm<()> = vec![Instruction::Trap(42)].into();
|
||||
|
||||
let send_result = send_xcm::<XcmRouter>(dest.into(), xcm);
|
||||
let expected_fee = MultiAssets::from((Here, 4_345_002_552_u128));
|
||||
let expected_hash =
|
||||
([0u8, 0u8, 0u8, 0u8], 1u64).using_encoded(sp_io::hashing::blake2_256);
|
||||
assert_eq!(send_result, Ok((expected_hash, expected_fee)),);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn xcm_messages_from_millau_are_dispatched() {
|
||||
type XcmExecutor = xcm_executor::XcmExecutor<XcmConfig>;
|
||||
type MessageDispatcher = FromBridgedChainMessageDispatch<
|
||||
WithMillauMessageBridge,
|
||||
XcmExecutor,
|
||||
XcmWeigher,
|
||||
frame_support::traits::ConstU64<BASE_XCM_WEIGHT>,
|
||||
>;
|
||||
|
||||
new_test_ext().execute_with(|| {
|
||||
let location: MultiLocation =
|
||||
(Parent, X1(GlobalConsensus(MillauNetwork::get()))).into();
|
||||
let xcm: Xcm<Call> = vec![Instruction::Trap(42)].into();
|
||||
|
||||
let mut incoming_message = DispatchMessage {
|
||||
key: MessageKey { lane_id: [0, 0, 0, 0], nonce: 1 },
|
||||
data: DispatchMessageData { payload: Ok((location, xcm).into()), fee: 0 },
|
||||
}
|
||||
.into();
|
||||
|
||||
let dispatch_weight = MessageDispatcher::dispatch_weight(&mut incoming_message);
|
||||
assert_eq!(dispatch_weight, 1_000_000_000);
|
||||
|
||||
let dispatch_result =
|
||||
MessageDispatcher::dispatch(&AccountId::from([0u8; 32]), incoming_message);
|
||||
assert_eq!(
|
||||
dispatch_result,
|
||||
MessageDispatchResult {
|
||||
dispatch_result: true,
|
||||
unspent_weight: 0,
|
||||
dispatch_fee_paid_during_dispatch: false,
|
||||
}
|
||||
);
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user