-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathhrmp_channels.rs
More file actions
206 lines (173 loc) · 6.67 KB
/
hrmp_channels.rs
File metadata and controls
206 lines (173 loc) · 6.67 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
197
198
199
200
201
202
203
204
205
206
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::*;
const MAX_CAPACITY: u32 = 8;
const MAX_MESSAGE_SIZE: u32 = 8192;
/// Opening HRMP channels between Parachains should work
#[test]
fn open_hrmp_channel_between_paras_works() {
// Parchain A init values
let para_a_id = PenpalKusamaA::para_id();
let para_a_root_origin = <PenpalKusamaA as Chain>::RuntimeOrigin::root();
// Parachain B init values
let para_b_id = PenpalKusamaB::para_id();
let para_b_root_origin = <PenpalKusamaB as Chain>::RuntimeOrigin::root();
let fee_amount = KUSAMA_ED * 1000;
let fund_amount = KUSAMA_ED * 1000_000_000;
// Fund Parachain's Sovereign accounts to be able to reserve the deposit
let para_a_sovereign_account = Kusama::fund_para_sovereign(fund_amount, para_a_id);
let para_b_sovereign_account = Kusama::fund_para_sovereign(fund_amount, para_b_id);
let relay_destination: VersionedMultiLocation = PenpalKusamaA::parent_location().into();
// ---- Init Open channel from Parachain to System Parachain
let mut call = Kusama::init_open_channel_call(para_b_id, MAX_CAPACITY, MAX_MESSAGE_SIZE);
let origin_kind = OriginKind::Native;
let native_asset: MultiAsset = (Here, fee_amount).into();
let beneficiary = Kusama::sovereign_account_id_of_child_para(para_a_id);
let mut xcm = xcm_transact_paid_execution(call, origin_kind, native_asset.clone(), beneficiary);
PenpalKusamaA::execute_with(|| {
assert_ok!(<PenpalKusamaA as PenpalKusamaAPallet>::PolkadotXcm::send(
para_a_root_origin,
bx!(relay_destination.clone()),
bx!(xcm),
));
PenpalKusamaA::assert_xcm_pallet_sent();
});
Kusama::execute_with(|| {
type RuntimeEvent = <Kusama as Chain>::RuntimeEvent;
Kusama::assert_ump_queue_processed(
true,
Some(para_a_id),
Some(Weight::from_parts(1_312_558_000, 200000)),
);
assert_expected_events!(
Kusama,
vec![
// Parachain's Sovereign account balance is withdrawn to pay XCM fees
RuntimeEvent::Balances(pallet_balances::Event::Withdraw { who, amount }) => {
who: *who == para_a_sovereign_account.clone(),
amount: *amount == fee_amount,
},
// Sender deposit is reserved for Parachain's Sovereign account
RuntimeEvent::Balances(pallet_balances::Event::Reserved { who, .. }) =>{
who: *who == para_a_sovereign_account,
},
// Open channel requested from Para A to Para B
RuntimeEvent::Hrmp(
polkadot_runtime_parachains::hrmp::Event::OpenChannelRequested(
sender, recipient, max_capacity, max_message_size
)
) => {
sender: *sender == para_a_id.into(),
recipient: *recipient == para_b_id.into(),
max_capacity: *max_capacity == MAX_CAPACITY,
max_message_size: *max_message_size == MAX_MESSAGE_SIZE,
},
]
);
});
// ---- Accept Open channel from Parachain to System Parachain
call = Kusama::accept_open_channel_call(para_a_id);
let beneficiary = Kusama::sovereign_account_id_of_child_para(para_b_id);
xcm = xcm_transact_paid_execution(call, origin_kind, native_asset, beneficiary);
PenpalKusamaB::execute_with(|| {
assert_ok!(<PenpalKusamaB as PenpalKusamaBPallet>::PolkadotXcm::send(
para_b_root_origin,
bx!(relay_destination),
bx!(xcm),
));
PenpalKusamaB::assert_xcm_pallet_sent();
});
PenpalKusamaB::execute_with(|| {});
Kusama::execute_with(|| {
type RuntimeEvent = <Kusama as Chain>::RuntimeEvent;
Kusama::assert_ump_queue_processed(
true,
Some(para_b_id),
Some(Weight::from_parts(1_312_558_000, 200_000)),
);
assert_expected_events!(
Kusama,
vec![
// Parachain's Sovereign account balance is withdrawn to pay XCM fees
RuntimeEvent::Balances(pallet_balances::Event::Withdraw { who, amount }) => {
who: *who == para_b_sovereign_account.clone(),
amount: *amount == fee_amount,
},
// Sender deposit is reserved for Parachain's Sovereign account
RuntimeEvent::Balances(pallet_balances::Event::Reserved { who, .. }) =>{
who: *who == para_b_sovereign_account,
},
// Open channel accepted for Para A to Para B
RuntimeEvent::Hrmp(
polkadot_runtime_parachains::hrmp::Event::OpenChannelAccepted(
sender, recipient
)
) => {
sender: *sender == para_a_id.into(),
recipient: *recipient == para_b_id.into(),
},
]
);
});
Kusama::force_process_hrmp_open(para_a_id, para_b_id);
}
/// Opening HRMP channels between System Parachains and Parachains should work
#[test]
fn force_open_hrmp_channel_for_system_para_works() {
// Relay Chain init values
let relay_root_origin = <Kusama as Chain>::RuntimeOrigin::root();
// System Para init values
let system_para_id = AssetHubKusama::para_id();
// Parachain A init values
let para_a_id = PenpalKusamaA::para_id();
let fund_amount = KUSAMA_ED * 1000_000_000;
// Fund Parachain's Sovereign accounts to be able to reserve the deposit
let para_a_sovereign_account = Kusama::fund_para_sovereign(fund_amount, para_a_id);
let system_para_sovereign_account = Kusama::fund_para_sovereign(fund_amount, system_para_id);
Kusama::execute_with(|| {
assert_ok!(<Kusama as KusamaPallet>::Hrmp::force_open_hrmp_channel(
relay_root_origin,
system_para_id,
para_a_id,
MAX_CAPACITY,
MAX_MESSAGE_SIZE
));
type RuntimeEvent = <Kusama as Chain>::RuntimeEvent;
assert_expected_events!(
Kusama,
vec![
// Sender deposit is reserved for System Parachain's Sovereign account
RuntimeEvent::Balances(pallet_balances::Event::Reserved { who, .. }) =>{
who: *who == system_para_sovereign_account,
},
// Recipient deposit is reserved for Parachain's Sovereign account
RuntimeEvent::Balances(pallet_balances::Event::Reserved { who, .. }) =>{
who: *who == para_a_sovereign_account,
},
// HRMP channel forced opened
RuntimeEvent::Hrmp(
polkadot_runtime_parachains::hrmp::Event::HrmpChannelForceOpened(
sender, recipient, max_capacity, max_message_size
)
) => {
sender: *sender == system_para_id.into(),
recipient: *recipient == para_a_id.into(),
max_capacity: *max_capacity == MAX_CAPACITY,
max_message_size: *max_message_size == MAX_MESSAGE_SIZE,
},
]
);
});
Kusama::force_process_hrmp_open(system_para_id, para_a_id);
}