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