-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathon_runtime_upgrade.rs
More file actions
409 lines (369 loc) · 11.4 KB
/
on_runtime_upgrade.rs
File metadata and controls
409 lines (369 loc) · 11.4 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
#![cfg(unix)]
mod on_runtime_upgrade {
use std::{path::PathBuf, time::Duration};
use assert_cmd::cargo_bin;
use substrate_cli_test_utils as common;
use tokio::process::Command;
struct TestConfig {
snap_path: String,
runtime_path: String,
command_extra_args: Vec<String>,
sub_command_extra_args: Vec<String>,
}
impl TestConfig {
fn new(snap_name: &str, runtime_name: &str) -> Self {
let project_root = env!("CARGO_MANIFEST_DIR");
Self {
snap_path: format!("{}/tests/snaps/{}.snap", project_root, snap_name),
runtime_path: format!(
"{}/tests/runtimes/{}.compact.compressed.wasm",
project_root, runtime_name
),
command_extra_args: Vec::new(),
sub_command_extra_args: Vec::new(),
}
}
fn with_command_args(mut self, args: &[&str]) -> Self {
self.command_extra_args = args.iter().map(|&s| s.to_string()).collect();
self
}
fn with_sub_command_args(mut self, args: &[&str]) -> Self {
self.sub_command_extra_args = args.iter().map(|&s| s.to_string()).collect();
self
}
}
async fn run_test(config: TestConfig, expected_success: bool) {
common::run_with_timeout(Duration::from_secs(300), async move {
let child = on_runtime_upgrade(&config);
let out = child.wait_with_output().await.unwrap();
if expected_success {
assert_ok(out);
} else {
assert_err(out);
}
})
.await;
}
fn on_runtime_upgrade(config: &TestConfig) -> tokio::process::Child {
let path = cargo_bin!("try-runtime");
assert!(
path.exists(),
"try-runtime binary not found at path: {}",
path.display()
);
Command::new(path)
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
.arg(format!("--runtime={}", config.runtime_path))
.args(&config.command_extra_args)
.arg("on-runtime-upgrade")
.arg("--blocktime=6000")
.args(&config.sub_command_extra_args)
.args(["snap", format!("--path={}", config.snap_path).as_str()])
.kill_on_drop(true)
.spawn()
.unwrap()
}
fn assert_ok(out: std::process::Output) {
if !out.status.success() {
panic!(
"Command failed with status: {}\nstdout: {}\nstderr: {}",
out.status,
String::from_utf8_lossy(&out.stdout),
String::from_utf8_lossy(&out.stderr)
);
}
}
fn assert_err(out: std::process::Output) {
if out.status.success() {
panic!(
"Command succeeded when it should have failed\nstdout: {}\nstderr: {}",
String::from_utf8_lossy(&out.stdout),
String::from_utf8_lossy(&out.stderr)
);
}
}
#[test]
fn precondition_snap_path_exists() {
let config = TestConfig::new("rococo-people", "people_rococo_runtime_ok");
let snap = PathBuf::from(&config.snap_path);
let project = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
assert!(
snap.exists(),
"Snap file not found at path: {}",
snap.display()
);
assert!(
project.exists(),
"Project directory not found at path: {}",
project.display()
);
}
#[tokio::test]
async fn ok_works() {
run_test(
TestConfig::new("rococo-people", "people_rococo_runtime_ok"),
true,
)
.await;
}
#[tokio::test]
async fn weight_max_fails() {
run_test(
TestConfig::new("rococo-people", "people_rococo_runtime_weight_max"),
false,
)
.await;
}
#[tokio::test]
async fn weight_max_can_be_ignored() {
run_test(
TestConfig::new("rococo-people", "people_rococo_runtime_weight_max")
.with_sub_command_args(&["--no-weight-warnings"]),
true,
)
.await;
}
#[tokio::test]
async fn pre_upgrade_fail_fails() {
run_test(
TestConfig::new("rococo-people", "people_rococo_runtime_pre_upgrade_fail"),
false,
)
.await;
}
#[tokio::test]
async fn pre_upgrade_fail_pre_and_postfails() {
run_test(
TestConfig::new("rococo-people", "people_rococo_runtime_pre_upgrade_fail")
.with_sub_command_args(&["--checks=pre-and-post"]),
false,
)
.await;
}
#[tokio::test]
async fn pre_upgrade_fail_can_be_ignored() {
run_test(
TestConfig::new("rococo-people", "people_rococo_runtime_pre_upgrade_fail")
.with_sub_command_args(&["--checks=none"]),
true,
)
.await;
}
#[tokio::test]
async fn post_upgrade_fail_fails() {
run_test(
TestConfig::new("rococo-people", "people_rococo_runtime_post_upgrade_fail"),
false,
)
.await;
}
#[tokio::test]
async fn post_upgrade_fail_pre_and_postfails() {
run_test(
TestConfig::new("rococo-people", "people_rococo_runtime_post_upgrade_fail")
.with_sub_command_args(&["--checks=pre-and-post"]),
false,
)
.await;
}
#[tokio::test]
async fn post_upgrade_fail_can_be_ignored() {
run_test(
TestConfig::new("rococo-people", "people_rococo_runtime_post_upgrade_fail")
.with_sub_command_args(&["--checks=none"]),
true,
)
.await;
}
#[tokio::test]
async fn post_upgrade_storage_change_fails() {
run_test(
TestConfig::new(
"rococo-people",
"people_rococo_runtime_post_upgrade_storage_change",
),
false,
)
.await;
}
#[tokio::test]
async fn not_idempotent_execution_fails() {
run_test(
TestConfig::new(
"rococo-people",
"people_rococo_runtime_not_idempotent_panic",
),
false,
)
.await;
}
/// If a Migration panics on second execution than it cannot be ignored. This is something that
/// also should not be ignored.
#[tokio::test]
async fn not_idempotent_execution_issue_canot_be_ignored() {
run_test(
TestConfig::new(
"rococo-people",
"people_rococo_runtime_not_idempotent_panic",
)
.with_sub_command_args(&["--disable-idempotency-checks"]),
false,
)
.await;
}
#[tokio::test]
async fn not_idempotent_state_root_fails() {
run_test(
TestConfig::new(
"rococo-people",
"people_rococo_runtime_not_idempotent_state_root",
),
false,
)
.await;
}
#[tokio::test]
async fn not_idempotent_state_root_issue_can_be_ignored() {
run_test(
TestConfig::new(
"rococo-people",
"people_rococo_runtime_not_idempotent_state_root",
)
.with_sub_command_args(&["--disable-idempotency-checks"]),
true,
)
.await;
}
#[tokio::test]
async fn non_matching_spec_name_fails() {
run_test(
TestConfig::new("rococo-people", "people_rococo_runtime_different_spec_name"),
false,
)
.await;
}
#[tokio::test]
async fn non_matching_spec_name_can_be_ignored() {
run_test(
TestConfig::new("rococo-people", "people_rococo_runtime_different_spec_name")
.with_command_args(&["--disable-spec-name-check"]),
true,
)
.await;
}
#[tokio::test]
async fn non_incrementing_spec_version_fails() {
run_test(
TestConfig::new("rococo-people", "people_rococo_runtime_same_spec_version"),
false,
)
.await;
}
#[tokio::test]
async fn non_incrementing_spec_version_can_be_ignored() {
run_test(
TestConfig::new("rococo-people", "people_rococo_runtime_same_spec_version")
.with_sub_command_args(&["--disable-spec-version-check"]),
true,
)
.await;
}
/// Two migrations, one taking 100 blocks and another one taking 200.
#[tokio::test]
async fn mbm_double_ok_300b_works() {
run_test(
TestConfig::new("rococo-people", "people_rococo_runtime_mbm_double_ok_300b"),
true,
)
.await;
}
/// 300 block migrations works since we give it 300 blocks.
#[tokio::test]
async fn mbm_double_ok_300b_with_300b_works() {
run_test(
TestConfig::new("rococo-people", "people_rococo_runtime_mbm_double_ok_300b")
.with_sub_command_args(&["--mbm-max-blocks=300"]),
true,
)
.await;
}
/// 300 block migrations fails since we only give it 299 blocks.
#[tokio::test]
async fn mbm_double_ok_300b_too_few_blocks_errors() {
run_test(
TestConfig::new("rococo-people", "people_rococo_runtime_mbm_double_ok_300b")
.with_sub_command_args(&["--mbm-max-blocks=299"]),
false,
)
.await;
}
/// The same MBM configured multiple times, with other ones in between.
#[tokio::test]
async fn mbm_double_ok_80b_duplicates_works() {
run_test(
TestConfig::new(
"rococo-people",
"people_rococo_runtime_mbm_duplicates_ok_80b",
),
true,
)
.await;
}
// TODO check that it does not modify storage on success
#[tokio::test]
async fn mbm_pre_upgrade_fail_fails() {
run_test(
TestConfig::new(
"rococo-people",
"people_rococo_runtime_mbm_pre_upgrade_fails",
),
false,
)
.await;
}
#[tokio::test]
async fn mbm_post_upgrade_fail_fails() {
run_test(
TestConfig::new(
"rococo-people",
"people_rococo_runtime_mbm_post_upgrade_fails",
),
false,
)
.await;
}
#[tokio::test]
async fn mbm_fail_fails() {
run_test(
TestConfig::new("rococo-people", "people_rococo_runtime_mbm_fails"),
false,
)
.await;
}
#[tokio::test]
async fn mbm_fail_ignore_mbms() {
run_test(
TestConfig::new("rococo-people", "people_rococo_runtime_mbm_fails")
.with_sub_command_args(&["--disable-mbms-checks"]),
false,
)
.await;
}
#[tokio::test]
async fn mbm_empty_works() {
run_test(
TestConfig::new("rococo-people", "people_rococo_runtime_mbm_empty"),
true,
)
.await;
}
/*#[tokio::test]
async fn no_migrations_works() {
run_test(
TestConfig::new("rococo-people", "people_rococo_runtime_no_migrations")
.with_sub_command_args(&["--disable-spec-version-check"]),
true
).await;
}*/
}