-
Notifications
You must be signed in to change notification settings - Fork 382
Expand file tree
/
Copy pathmod.rs
More file actions
196 lines (162 loc) · 5.24 KB
/
mod.rs
File metadata and controls
196 lines (162 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// Copyright 2021 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot 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.
// Polkadot 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 Polkadot. If not, see <http://www.gnu.org/licenses/>.
pub mod parachain;
pub mod relay_chain;
pub mod statemine_like;
use cumulus_primitives_core::ParaId;
use polkadot_parachain::primitives::AccountIdConversion;
use sp_runtime::AccountId32;
use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain};
use sp_core::{H160, U256};
use std::{collections::BTreeMap, str::FromStr};
pub const PARAALICE: [u8; 20] = [1u8; 20];
pub const RELAYALICE: AccountId32 = AccountId32::new([0u8; 32]);
pub fn para_a_account() -> AccountId32 {
ParaId::from(1).into_account()
}
pub fn evm_account() -> H160 {
H160::from_str("1000000000000000000000000000000000000001").unwrap()
}
decl_test_parachain! {
pub struct ParaA {
Runtime = parachain::Runtime,
XcmpMessageHandler = parachain::MsgQueue,
DmpMessageHandler = parachain::MsgQueue,
new_ext = para_ext(1),
}
}
decl_test_parachain! {
pub struct ParaB {
Runtime = parachain::Runtime,
XcmpMessageHandler = parachain::MsgQueue,
DmpMessageHandler = parachain::MsgQueue,
new_ext = para_ext(2),
}
}
decl_test_parachain! {
pub struct ParaC {
Runtime = parachain::Runtime,
XcmpMessageHandler = parachain::MsgQueue,
DmpMessageHandler = parachain::MsgQueue,
new_ext = para_ext(3),
}
}
decl_test_parachain! {
pub struct Statemine {
Runtime = statemine_like::Runtime,
XcmpMessageHandler = statemine_like::MsgQueue,
DmpMessageHandler = statemine_like::MsgQueue,
new_ext = statemine_ext(4),
}
}
decl_test_relay_chain! {
pub struct Relay {
Runtime = relay_chain::Runtime,
XcmConfig = relay_chain::XcmConfig,
new_ext = relay_ext(),
}
}
decl_test_network! {
pub struct MockNet {
relay_chain = Relay,
parachains = vec![
(1, ParaA),
(2, ParaB),
(3, ParaC),
(4, Statemine),
],
}
}
pub const INITIAL_BALANCE: u128 = 10_000_000_000_000_000;
pub const INITIAL_EVM_BALANCE: u128 = 0;
pub const INITIAL_EVM_NONCE: u32 = 1;
pub fn para_ext(para_id: u32) -> sp_io::TestExternalities {
use parachain::{MsgQueue, Runtime, System};
let mut t = frame_system::GenesisConfig::default()
.build_storage::<Runtime>()
.unwrap();
pallet_balances::GenesisConfig::<Runtime> {
balances: vec![(PARAALICE.into(), INITIAL_BALANCE)],
}
.assimilate_storage(&mut t)
.unwrap();
// EVM accounts are self-sufficient.
let mut evm_accounts = BTreeMap::new();
evm_accounts.insert(
evm_account(),
pallet_evm::GenesisAccount {
nonce: U256::from(INITIAL_EVM_NONCE),
balance: U256::from(INITIAL_EVM_BALANCE),
storage: Default::default(),
code: vec![
0x00, // STOP
],
},
);
frame_support::traits::GenesisBuild::<Runtime>::assimilate_storage(
&pallet_evm::GenesisConfig {
accounts: evm_accounts,
},
&mut t,
)
.unwrap();
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| {
System::set_block_number(1);
MsgQueue::set_para_id(para_id.into());
});
ext
}
pub fn statemine_ext(para_id: u32) -> sp_io::TestExternalities {
use statemine_like::{MsgQueue, Runtime, System};
let mut t = frame_system::GenesisConfig::default()
.build_storage::<Runtime>()
.unwrap();
pallet_balances::GenesisConfig::<Runtime> {
balances: vec![(RELAYALICE.into(), INITIAL_BALANCE)],
}
.assimilate_storage(&mut t)
.unwrap();
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| {
System::set_block_number(1);
MsgQueue::set_para_id(para_id.into());
});
ext
}
pub fn relay_ext() -> sp_io::TestExternalities {
use relay_chain::{Runtime, System};
let mut t = frame_system::GenesisConfig::default()
.build_storage::<Runtime>()
.unwrap();
pallet_balances::GenesisConfig::<Runtime> {
balances: vec![(RELAYALICE, INITIAL_BALANCE)],
}
.assimilate_storage(&mut t)
.unwrap();
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| System::set_block_number(1));
ext
}
pub type RelayChainPalletXcm = pallet_xcm::Pallet<relay_chain::Runtime>;
pub type StatemineBalances = pallet_balances::Pallet<statemine_like::Runtime>;
pub type StatemineChainPalletXcm = pallet_xcm::Pallet<statemine_like::Runtime>;
pub type StatemineAssets = pallet_assets::Pallet<statemine_like::Runtime>;
pub type Assets = pallet_assets::Pallet<parachain::Runtime>;
pub type Treasury = pallet_treasury::Pallet<parachain::Runtime>;
pub type AssetManager = pallet_asset_manager::Pallet<parachain::Runtime>;
pub type XTokens = orml_xtokens::Pallet<parachain::Runtime>;
pub type RelayBalances = pallet_balances::Pallet<relay_chain::Runtime>;
pub type ParaBalances = pallet_balances::Pallet<parachain::Runtime>;
pub type XcmTransactor = xcm_transactor::Pallet<parachain::Runtime>;
pub type ParachainPalletXcm = pallet_xcm::Pallet<parachain::Runtime>;