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::{pallet_prelude::Weight};2526const ALICE: AccountId = AccountId::new([0u8; 32]);27const BOB: AccountId = AccountId::new([1u8; 32]);2829const INITIAL_BALANCE: u128 = 10_000_000_000_000_000_000_000; 3031#[test]32pub fn xcm_transact_is_forbidden() {33 new_test_ext(vec![(ALICE, INITIAL_BALANCE)]).execute_with(|| {34 PolkadotXcm::execute(35 RuntimeOrigin::signed(ALICE),36 Box::new(VersionedXcm::from(Xcm(vec![Transact {37 origin_kind: OriginKind::Native,38 require_weight_at_most: Weight::from_parts(1000, 1000),39 call: RuntimeCall::Balances(pallet_balances::Call::<Runtime>::transfer {40 dest: BOB.into(),41 value: INITIAL_BALANCE / 2,42 })43 .encode()44 .into(),45 }]))),46 Weight::from_parts(1001000, 2000),47 )48 .expect(49 "XCM execute must succeed, the error should be in the `PolkadotXcm::Attempted` event",50 );5152 let xcm_event = &last_events(1)[0];53 match xcm_event {54 RuntimeEvent::PolkadotXcm(pallet_xcm::Event::<Runtime>::Attempted(55 Outcome::Incomplete(_weight, Error::NoPermission),56 )) => { }57 _ => panic!(58 "Expected PolkadotXcm.Attempted(Incomplete(_weight, NoPermission)),\59 found: {xcm_event:#?}"60 ),61 }62 });63}