referrerpolicy=no-referrer-when-downgrade

xcm_docs/cookbook/relay_token_transactor/
network.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
3// This file is part of Polkadot.
4
5// Polkadot is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9
10// Polkadot is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13// GNU General Public License for more details.
14
15// You should have received a copy of the GNU General Public License
16// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
17
18//! Mock network
19
20use frame::deps::{
21	frame_system,
22	sp_io::TestExternalities,
23	sp_runtime::{AccountId32, BuildStorage},
24};
25use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt};
26
27use super::{parachain, relay_chain};
28
29pub const ALICE: AccountId32 = AccountId32::new([0u8; 32]);
30pub const BOB: AccountId32 = AccountId32::new([1u8; 32]);
31pub const UNITS: u64 = 10_000_000_000;
32pub const CENTS: u64 = 100_000_000;
33pub const INITIAL_BALANCE: u64 = UNITS;
34
35decl_test_parachain! {
36	pub struct ParaA {
37		Runtime = parachain::Runtime,
38		XcmpMessageHandler = parachain::MessageQueue,
39		DmpMessageHandler = parachain::MessageQueue,
40		new_ext = para_ext(),
41	}
42}
43
44decl_test_relay_chain! {
45	pub struct Relay {
46		Runtime = relay_chain::Runtime,
47		RuntimeCall = relay_chain::RuntimeCall,
48		RuntimeEvent = relay_chain::RuntimeEvent,
49		XcmConfig = relay_chain::XcmConfig,
50		MessageQueue = relay_chain::MessageQueue,
51		System = relay_chain::System,
52		new_ext = relay_ext(),
53	}
54}
55
56decl_test_network! {
57	pub struct MockNet {
58		relay_chain = Relay,
59		parachains = vec![
60			(2222, ParaA),
61		],
62	}
63}
64
65pub fn para_ext() -> TestExternalities {
66	use parachain::{MessageQueue, Runtime, System};
67
68	let t = frame_system::GenesisConfig::<Runtime>::default().build_storage().unwrap();
69	let mut ext = frame::deps::sp_io::TestExternalities::new(t);
70	ext.execute_with(|| {
71		System::set_block_number(1);
72		MessageQueue::set_para_id(2222.into());
73	});
74	ext
75}
76
77pub fn relay_ext() -> TestExternalities {
78	use relay_chain::{Runtime, System};
79
80	let mut t = frame_system::GenesisConfig::<Runtime>::default().build_storage().unwrap();
81
82	pallet_balances::GenesisConfig::<Runtime> {
83		balances: vec![(ALICE, INITIAL_BALANCE)],
84		..Default::default()
85	}
86	.assimilate_storage(&mut t)
87	.unwrap();
88
89	let mut ext = TestExternalities::new(t);
90	ext.execute_with(|| {
91		System::set_block_number(1);
92	});
93	ext
94}