1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use xcm_executor::traits::ShouldExecute;18use xcm::latest::prelude::*;19use logtest::Logger;20use crate::{21 Call,22 xcm_config::Barrier,23};2425fn catch_xcm_barrier_log(logger: &mut Logger, expected_msg: &str) {26 for record in logger {27 if record.target() == "xcm::barrier"28 && record.args() == expected_msg {29 return;30 }31 }3233 panic!("the expected XCM barrier log `{}` is not found", expected_msg);34}3536#[test]37fn xcm_barrier_does_not_allow_transact() {38 // We have a `AllowTopLevelPaidExecutionFrom` barrier,39 // so an XCM program should start from one of the following commands: 40 // * `WithdrawAsset`41 // * `ReceiveTeleportedAsset`42 // * `ReserveAssetDeposited`43 // * `ClaimAsset` 44 // We use the `WithdrawAsset` in this test4546 let location = MultiLocation {47 parents: 0,48 interior: Junctions::Here,49 };5051 // let id = AssetId::Concrete(location.clone());52 // let fun = Fungibility::Fungible(42);53 // let multiasset = MultiAsset {54 // id,55 // fun,56 // };57 // let withdraw_inst = WithdrawAsset(multiasset.into());5859 // We will never decode this "call",60 // so it is irrelevant what we are passing to the `transact` cmd.61 let fake_encoded_call = vec![0u8];6263 let transact_inst = Transact {64 origin_type: OriginKind::Superuser,65 require_weight_at_most: 0,66 call: fake_encoded_call.into(),67 };6869 let mut xcm_program = Xcm::<Call>(vec![transact_inst]);7071 let mut logger = Logger::start();7273 let max_weight = 100_000;74 let mut weight_credit = 0;7576 let result = Barrier::should_execute(77 &location,78 &mut xcm_program,79 max_weight,80 &mut weight_credit81 );8283 assert!(result.is_err(), "the barrier should disallow the XCM transact cmd");8485 catch_xcm_barrier_log(&mut logger, "transact XCM rejected");86}difftreelog
source
runtime/common/tests/xcm.rs2.6 KiBsourcehistory