From ae3ddb77365e62740261c8d12e3c793a933acf98 Mon Sep 17 00:00:00 2001 From: Diego Date: Fri, 24 Jan 2025 17:44:43 -0300 Subject: [PATCH] Test xcm message export is disabled (#817) * Test xcm message export is disabled * Add missing copyright * Fix clippy * Add test to check validate fail --- .../dancelight/src/tests/common/xcm/mod.rs | 1 + .../tests/common/xcm/xcm_message_exporter.rs | 75 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 chains/orchestrator-relays/runtime/dancelight/src/tests/common/xcm/xcm_message_exporter.rs diff --git a/chains/orchestrator-relays/runtime/dancelight/src/tests/common/xcm/mod.rs b/chains/orchestrator-relays/runtime/dancelight/src/tests/common/xcm/mod.rs index f19b25444..f8329d03c 100644 --- a/chains/orchestrator-relays/runtime/dancelight/src/tests/common/xcm/mod.rs +++ b/chains/orchestrator-relays/runtime/dancelight/src/tests/common/xcm/mod.rs @@ -17,4 +17,5 @@ mod constants; mod mocknets; mod reserver_transfers_polkadot_xcm; +mod xcm_message_exporter; pub use xcm_emulator::{bx, TestExt}; diff --git a/chains/orchestrator-relays/runtime/dancelight/src/tests/common/xcm/xcm_message_exporter.rs b/chains/orchestrator-relays/runtime/dancelight/src/tests/common/xcm/xcm_message_exporter.rs new file mode 100644 index 000000000..47a46b937 --- /dev/null +++ b/chains/orchestrator-relays/runtime/dancelight/src/tests/common/xcm/xcm_message_exporter.rs @@ -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 + +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 = ::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!( + ::XcmPallet::execute( + origin, + Box::new(VersionedXcm::V4(message)), + Weight::from_parts(0, 0) + ) + .unwrap_err() + .error, + DispatchError::from(Error::<::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!( + ::MessageExporter::validate( + &mut location, + &mut message + ), + SendError::NotApplicable + ); +}