1
// Copyright 2019-2025 PureStake Inc.
2
// This file is part of Moonbeam.
3

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

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

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

            
17
use frame_support::{parameter_types, traits::ContainsPair, weights::Weight};
18
use xcm::latest::prelude::*;
19
use xcm_executor::traits::ConvertLocation;
20

            
21
// An xcm sender/receiver akin to > /dev/null
22
pub struct DevNull;
23
impl SendXcm for DevNull {
24
	type Ticket = ();
25

            
26
	fn validate(
27
		_destination: &mut Option<Location>,
28
		_message: &mut Option<opaque::Xcm>,
29
	) -> SendResult<Self::Ticket> {
30
		Ok(((), Assets::new()))
31
	}
32

            
33
	fn deliver(_: Self::Ticket) -> Result<XcmHash, SendError> {
34
		Ok(XcmHash::default())
35
	}
36
}
37

            
38
impl xcm_executor::traits::OnResponse for DevNull {
39
	fn expecting_response(_: &Location, _: u64, _: Option<&Location>) -> bool {
40
		false
41
	}
42
	fn on_response(
43
		_: &Location,
44
		_: u64,
45
		_: Option<&Location>,
46
		_: Response,
47
		_: Weight,
48
		_: &XcmContext,
49
	) -> Weight {
50
		Weight::zero()
51
	}
52
}
53

            
54
#[allow(dead_code)]
55
pub struct AccountIdConverter;
56

            
57
impl ConvertLocation<u64> for AccountIdConverter {
58
	fn convert_location(ml: &Location) -> Option<u64> {
59
		match ml.unpack() {
60
			(0, [Junction::AccountId32 { id, .. }]) => {
61
				Some(<u64 as parity_scale_codec::Decode>::decode(&mut &*id.to_vec()).unwrap())
62
			}
63
			_ => None,
64
		}
65
	}
66
}
67

            
68
parameter_types! {
69
	pub Ancestry: Location = Junction::Parachain(101).into();
70
	pub UnitWeightCost: u64 = 10;
71
	pub WeightPrice: (AssetId, u128, u128) = (AssetId(Location::parent()), 1_000_000, 1024);
72
}
73

            
74
#[allow(dead_code)]
75
pub struct AllAssetLocationsPass;
76

            
77
impl ContainsPair<Asset, Location> for AllAssetLocationsPass {
78
	fn contains(_: &Asset, _: &Location) -> bool {
79
		true
80
	}
81
}
82

            
83
#[cfg(feature = "runtime-benchmarks")]
84
pub fn mock_worst_case_holding() -> Assets {
85
	let assets: Vec<Asset> = vec![Asset {
86
		id: AssetId(Location::parent()),
87
		fun: Fungible(u128::MAX),
88
	}];
89
	assets.into()
90
}