difftreelog
fix xcm unit test
in: master
1 file changed
runtime/common/tests/xcm.rsdiffbeforeafterboth232324use super::{last_events, new_test_ext, AccountId};24use super::{last_events, new_test_ext, AccountId};25use crate::{PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin};25use crate::{26 runtime_common::config::xcm::XcmExecutorConfig, PolkadotXcm, Runtime, RuntimeCall,27 RuntimeEvent, RuntimeOrigin,28};2930type XcmExecutor = staging_xcm_executor::XcmExecutor<XcmExecutorConfig<Runtime>>;263127const ALICE: AccountId = AccountId::new([0u8; 32]);32const ALICE: AccountId = AccountId::new([0u8; 32]);28const BOB: AccountId = AccountId::new([1u8; 32]);33const BOB: AccountId = AccountId::new([1u8; 32]);32#[test]37#[test]33pub fn xcm_transact_is_forbidden() {38pub fn xcm_transact_is_forbidden() {34 new_test_ext(vec![(ALICE, INITIAL_BALANCE)]).execute_with(|| {39 new_test_ext(vec![(ALICE, INITIAL_BALANCE)]).execute_with(|| {35 PolkadotXcm::execute(40 let max_weight = Weight::from_parts(1001000, 2000);36 RuntimeOrigin::signed(ALICE),4142 let origin: Location = AccountId32 {43 network: None,44 id: *ALICE.as_ref(),45 }46 .into();37 Box::new(VersionedXcm::from(Xcm(vec![Transact {47 let message = Xcm(vec![Transact {38 origin_kind: OriginKind::Native,48 origin_kind: OriginKind::Native,39 require_weight_at_most: Weight::from_parts(1000, 1000),49 require_weight_at_most: Weight::from_parts(1000, 1000),40 call: RuntimeCall::Balances(50 call: RuntimeCall::Balances(pallet_balances::Call::<Runtime>::transfer_keep_alive {45 )46 .encode()54 .encode()47 .into(),55 .into(),48 }]))),56 }]);49 Weight::from_parts(1001000, 2000),50 )51 .expect(52 "XCM execute must succeed, the error should be in the `PolkadotXcm::Attempted` event",53 );5455 let xcm_event = &last_events(1)[0];57 let mut hash = message.using_encoded(sp_io::hashing::blake2_256);56 match xcm_event {58 let weight_limit = max_weight;57 RuntimeEvent::PolkadotXcm(pallet_xcm::Event::<Runtime>::Attempted {59 let weight_credit = max_weight;6058 outcome: Outcome::Incomplete {61 let error = XcmExecutor::prepare_and_execute(59 used: _weight,62 origin,63 message,60 error: Error::NoPermission,64 &mut hash,61 },65 weight_limit,62 }) => { /* Pass */ }66 weight_credit,63 _ => panic!(67 )64 "Expected PolkadotXcm.Attempted(Incomplete(_weight, NoPermission)),\68 .ensure_complete()65 found: {xcm_event:#?}"69 .expect_err("XCM Transact shouldn't succeed");66 ),7067 }71 assert_eq!(error, Error::NoPermission);68 });72 });69}73}7074