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
//! Generic transfer helpers for XCM tests
18

            
19
use crate::xcm_mock::{parachain, relay_chain, ParaA, Relay, RelayChainPalletXcm, RELAYALICE};
20
use frame_support::assert_ok;
21
use sp_std::boxed::Box;
22
use xcm::latest::prelude::{Location, Parachain, WeightLimit};
23
use xcm_simulator::TestExt;
24

            
25
use super::weights::standard_transfer_weight;
26

            
27
// Generic transfer execution helpers
28

            
29
2
pub fn execute_transfer_to_para(
30
2
	from_account: [u8; 20],
31
2
	asset: xcm::VersionedAssets,
32
2
	dest_para: u32,
33
2
	dest_account: [u8; 20],
34
2
	weight: Option<WeightLimit>,
35
2
) {
36
2
	let dest = Location {
37
2
		parents: 1,
38
2
		interior: [
39
2
			xcm::latest::prelude::Parachain(dest_para),
40
2
			xcm::latest::prelude::AccountKey20 {
41
2
				network: None,
42
2
				key: dest_account,
43
2
			},
44
2
		]
45
2
		.into(),
46
2
	};
47
2
	let (chain_part, beneficiary) =
48
2
		xcm_primitives::split_location_into_chain_part_and_beneficiary(dest).unwrap();
49
2
	let weight_limit = weight.unwrap_or(standard_transfer_weight());
50
2

            
51
2
	ParaA::execute_with(|| {
52
2
		assert_ok!(crate::xcm_mock::parachain::PolkadotXcm::transfer_assets(
53
2
			parachain::RuntimeOrigin::signed(parachain::AccountId::from(from_account)),
54
2
			Box::new(xcm::VersionedLocation::from(chain_part)),
55
2
			Box::new(xcm::VersionedLocation::from(beneficiary)),
56
2
			Box::new(asset),
57
2
			0,
58
2
			weight_limit
59
2
		));
60
2
	});
61
2
}
62

            
63
// Relay to Statemint transfer helper
64
4
pub fn execute_relay_to_statemint_transfer(beneficiary: Location, amount: u128) {
65
4
	Relay::execute_with(|| {
66
4
		assert_ok!(RelayChainPalletXcm::limited_teleport_assets(
67
4
			relay_chain::RuntimeOrigin::signed(RELAYALICE),
68
4
			Box::new(Parachain(1000).into()),
69
4
			Box::new(xcm::VersionedLocation::from(beneficiary).into()),
70
4
			Box::new(([], amount).into()),
71
4
			0,
72
4
			WeightLimit::Unlimited
73
4
		));
74
4
	});
75
4
}