Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test xcm message export is disabled #817

Merged
merged 4 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
mod constants;
mod mocknets;
mod reserver_transfers_polkadot_xcm;
mod xcm_message_exporter;
pub use xcm_emulator::{bx, TestExt};
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (C) Moondance Labs Ltd.
// This file is part of Tanssi.

// Tanssi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Tanssi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>

use {
super::{
super::{AccountId, ExtBuilder, ALICE},
mocknets::{DancelightRelay as Dancelight, DancelightRelayPallet},
},
crate::xcm_config,
frame_support::{assert_err, weights::Weight},
pallet_xcm::Error,
sp_runtime::DispatchError,
xcm::{latest::prelude::*, v4::Location, VersionedXcm},
xcm_emulator::Chain,
};

#[test]
fn test_message_exporter_disabled_for_origin_account() {
ExtBuilder::default().build().execute_with(|| {
// The only test we can do is with signed runtime origins since we are ensuring local origin in xcm config
let origin = <Dancelight as Chain>::RuntimeOrigin::signed(AccountId::from(ALICE));

let message = Xcm(vec![Instruction::ExportMessage {
network: NetworkId::Ethereum { chain_id: 1 },
destination: Junctions::Here,
xcm: Xcm(vec![]),
}]);

assert_eq!(
<Dancelight as DancelightRelayPallet>::XcmPallet::execute(
origin,
Box::new(VersionedXcm::V4(message)),
Weight::from_parts(0, 0)
)
.unwrap_err()
.error,
DispatchError::from(Error::<<Dancelight as Chain>::Runtime>::LocalExecutionIncomplete)
);
});
}

#[test]
fn test_message_exporter_validate_should_fail() {
let mut location = Some(Location {
parents: 1,
interior: Junctions::Here,
});

let mut message = Some(Xcm(vec![Instruction::ExportMessage {
network: NetworkId::Ethereum { chain_id: 1 },
destination: Junctions::Here,
xcm: Xcm(vec![]),
}]));

assert_err!(
<xcm_config::XcmConfig as xcm_executor::Config>::MessageExporter::validate(
&mut location,
&mut message
),
SendError::NotApplicable
);
}
Loading