1234567891011121314151617use xcm::{18 VersionedXcm,19 latest::{prelude::*, Error}20};21use codec::Encode;22use crate::{Runtime, RuntimeCall, RuntimeOrigin, RuntimeEvent, PolkadotXcm};23use super::{new_test_ext, last_events, AccountId};24use frame_support::{25 pallet_prelude::Weight,26};2728const ALICE: AccountId = AccountId::new([0u8; 32]);29const BOB: AccountId = AccountId::new([1u8; 32]);3031const INITIAL_BALANCE: u128 = 1000000000000000000_0000; 3233#[test]34pub fn xcm_transact_is_forbidden() {35 new_test_ext(vec![(ALICE, INITIAL_BALANCE)]).execute_with(|| {36 PolkadotXcm::execute(37 RuntimeOrigin::signed(ALICE),38 Box::new(VersionedXcm::from(Xcm(vec![39 Transact {40 origin_kind: OriginKind::Native,41 require_weight_at_most: Weight::from_parts(1000, 1000),42 call: RuntimeCall::Balances(43 pallet_balances::Call::<Runtime>::transfer {44 dest: BOB.into(),45 value: INITIAL_BALANCE / 2,46 }47 ).encode().into(),48 }49 ]))),50 Weight::from_parts(1001000, 2000),51 ).expect("XCM execute must succeed, the error should be in the `PolkadotXcm::Attempted` event");5253 let xcm_event = &last_events(1)[0];54 match xcm_event {55 RuntimeEvent::PolkadotXcm(56 pallet_xcm::Event::<Runtime>::Attempted(57 Outcome::Incomplete(_weight, Error::NoPermission)58 )59 ) => { },60 _ => panic!(61 "Expected PolkadotXcm.Attempted(Incomplete(_weight, NoPermission)),\62 found: {xcm_event:#?}"63 )64 }65 });66}