1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Cumulus.
3// SPDX-License-Identifier: Apache-2.0
45// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
1617//! Module contains predefined test-case scenarios for `Runtime` with various assets.
1819pub mod test_cases;
20pub mod test_cases_over_bridge;
21pub mod xcm_helpers;
2223use frame_support::traits::ProcessMessageError;
24pub use parachains_runtimes_test_utils::*;
25use std::fmt::Debug;
2627use xcm::latest::prelude::*;
28use xcm_builder::{CreateMatcher, MatchXcm};
2930/// Given a message, a sender, and a destination, it returns the delivery fees
31fn get_fungible_delivery_fees<S: SendXcm>(destination: Location, message: Xcm<()>) -> u128 {
32let Ok((_, delivery_fees)) = validate_send::<S>(destination, message) else {
33unreachable!("message can be sent; qed")
34 };
35if let Some(delivery_fee) = delivery_fees.inner().first() {
36let Fungible(delivery_fee_amount) = delivery_fee.fun else {
37unreachable!("asset is fungible; qed");
38 };
39 delivery_fee_amount
40 } else {
410
42}
43}
4445/// Helper function to verify `xcm` contains all relevant instructions expected on destination
46/// chain as part of a reserve-asset-transfer.
47pub(crate) fn assert_matches_reserve_asset_deposited_instructions<RuntimeCall: Debug>(
48 xcm: &mut Xcm<RuntimeCall>,
49 expected_reserve_assets_deposited: &Assets,
50 expected_beneficiary: &Location,
51) {
52let _ = xcm
53 .0
54.matcher()
55 .skip_inst_while(|inst| !matches!(inst, ReserveAssetDeposited(..)))
56 .expect("no instruction ReserveAssetDeposited?")
57 .match_next_inst(|instr| match instr {
58 ReserveAssetDeposited(reserve_assets) => {
59assert_eq!(reserve_assets, expected_reserve_assets_deposited);
60Ok(())
61 },
62_ => Err(ProcessMessageError::BadFormat),
63 })
64 .expect("expected instruction ReserveAssetDeposited")
65 .match_next_inst(|instr| match instr {
66 ClearOrigin => Ok(()),
67_ => Err(ProcessMessageError::BadFormat),
68 })
69 .expect("expected instruction ClearOrigin")
70 .match_next_inst(|instr| match instr {
71 BuyExecution { .. } => Ok(()),
72_ => Err(ProcessMessageError::BadFormat),
73 })
74 .expect("expected instruction BuyExecution")
75 .match_next_inst(|instr| match instr {
76 DepositAsset { assets: _, beneficiary } if beneficiary == expected_beneficiary =>
77Ok(()),
78_ => Err(ProcessMessageError::BadFormat),
79 })
80 .expect("expected instruction DepositAsset");
81}