1
// Copyright (C) Moondance Labs Ltd.
2
// This file is part of Tanssi.
3

            
4
// Tanssi 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
// Tanssi 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 Tanssi.  If not, see <http://www.gnu.org/licenses/>
16

            
17
#![cfg(test)]
18

            
19
use {
20
    crate::{
21
        tests::common::*, ContainerRegistrar, Paras, Registrar, RuntimeCall, SlotFrequency, System,
22
    },
23
    cumulus_primitives_core::relay_chain::HeadData,
24
    frame_support::{assert_noop, assert_ok, BoundedVec},
25
    pallet_registrar::Event as ContainerRegistrarEvent,
26
    pallet_registrar_runtime_api::{
27
        runtime_decl_for_registrar_api::RegistrarApi, ContainerChainGenesisData,
28
    },
29
    runtime_common::paras_registrar,
30
    runtime_parachains::configuration as parachains_configuration,
31
    sp_runtime::traits::Dispatchable,
32
    sp_std::vec,
33
    tp_traits::ParaId,
34
};
35

            
36
#[test]
37
1
fn registrar_needs_a_reserved_para_id() {
38
1
    ExtBuilder::default()
39
1
        .with_balances(vec![
40
1
            // Alice gets 10k extra tokens for her mapping deposit
41
1
            (AccountId::from(ALICE), 210_000 * UNIT),
42
1
            (AccountId::from(BOB), 100_000 * UNIT),
43
1
            (AccountId::from(CHARLIE), 100_000 * UNIT),
44
1
            (AccountId::from(DAVE), 100_000 * UNIT),
45
1
        ])
46
1
        .build()
47
1
        .execute_with(|| {
48
1
            run_to_block(2);
49
1
            let validation_code =
50
1
                vec![1u8; cumulus_primitives_core::relay_chain::MIN_CODE_SIZE as usize];
51
1
            let genesis_data_2000 = ContainerChainGenesisData {
52
1
                storage: BoundedVec::try_from(vec![
53
1
                    (b":code".to_vec(), validation_code.clone()).into()
54
1
                ])
55
1
                .unwrap(),
56
1
                name: Default::default(),
57
1
                id: Default::default(),
58
1
                fork_id: Default::default(),
59
1
                extensions: BoundedVec::try_from(vec![]).unwrap(),
60
1
                properties: Default::default(),
61
1
            };
62
1
            let genesis_data_no_code = ContainerChainGenesisData {
63
1
                storage: BoundedVec::try_from(vec![(b":code".to_vec(), vec![1u8]).into()]).unwrap(),
64
1
                name: Default::default(),
65
1
                id: Default::default(),
66
1
                fork_id: Default::default(),
67
1
                extensions: BoundedVec::try_from(vec![]).unwrap(),
68
1
                properties: Default::default(),
69
1
            };
70
1

            
71
1
            let next_para_id = ParaId::from(2000);
72
1
            assert_noop!(
73
1
                ContainerRegistrar::register(
74
1
                    origin_of(ALICE.into()),
75
1
                    next_para_id,
76
1
                    genesis_data_2000.clone(),
77
1
                    Some(HeadData(vec![1u8, 1u8, 1u8])),
78
1
                ),
79
1
                paras_registrar::Error::<Runtime>::NotReserved
80
1
            );
81

            
82
            // After a reservation, we can register
83
1
            assert_ok!(Registrar::reserve(origin_of(ALICE.into())));
84
1
            assert_noop!(
85
1
                ContainerRegistrar::register(
86
1
                    origin_of(ALICE.into()),
87
1
                    next_para_id,
88
1
                    genesis_data_no_code,
89
1
                    Some(HeadData(vec![1u8, 1u8, 1u8])),
90
1
                ),
91
1
                paras_registrar::Error::<Runtime>::InvalidCode
92
1
            );
93

            
94
1
            let validation_code: cumulus_primitives_core::relay_chain::ValidationCode =
95
1
                vec![1u8; cumulus_primitives_core::relay_chain::MIN_CODE_SIZE as usize].into();
96
1
            assert_ok!(ContainerRegistrar::register(
97
1
                origin_of(ALICE.into()),
98
1
                next_para_id,
99
1
                genesis_data_2000.clone(),
100
1
                Some(HeadData(vec![1u8, 1u8, 1u8])),
101
1
            ));
102

            
103
1
            assert!(Paras::lifecycle(next_para_id)
104
1
                .expect("para should be onboarding")
105
1
                .is_onboarding());
106
            // Two sessions later the para should be a parathread
107
            // But only if the pvf is accepted! which we havent done
108
1
            run_to_session(2);
109
1
            assert!(Paras::lifecycle(next_para_id)
110
1
                .expect("para should be onboarding")
111
1
                .is_onboarding());
112

            
113
            // Now let's accept the pvf, so that after 2 sesssions we have the chain onboarded
114
1
            assert_ok!(Paras::add_trusted_validation_code(
115
1
                root_origin(),
116
1
                validation_code
117
1
            ));
118
1
            run_to_session(4);
119
1

            
120
1
            // PVF accepted and the para should be a parathread
121
1
            assert!(Paras::lifecycle(next_para_id)
122
1
                .expect("para should be parathread")
123
1
                .is_parathread());
124
1
        });
125
1
}
126

            
127
#[test]
128
1
fn register_para_via_container_registrar() {
129
1
    ExtBuilder::default()
130
1
        .with_para_ids(vec![
131
1
            (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(),
132
1
            (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(),
133
1
        ])
134
1
        .build()
135
1
        .execute_with(|| {
136
1
            // In this test we're gonna register a para via ContainerRegistrar,
137
1
            // which will internally use the InnerRegistrar type to also register the para
138
1
            // in the relay Registrar pallet.
139
1

            
140
1
            assert_eq!(Runtime::registered_paras(), vec![1001.into(), 1002.into()]);
141
1
            assert_eq!(Runtime::genesis_data(2000.into()).as_ref(), None);
142
1
            assert_eq!(
143
1
                parachains_configuration::ActiveConfig::<Runtime>::get().max_head_data_size,
144
1
                20500
145
1
            );
146

            
147
1
            let validation_code =
148
1
                vec![1u8; cumulus_primitives_core::relay_chain::MIN_CODE_SIZE as usize];
149
1
            let genesis_data_2000 = ContainerChainGenesisData {
150
1
                storage: BoundedVec::try_from(vec![
151
1
                    (b":code".to_vec(), validation_code.clone()).into()
152
1
                ])
153
1
                .unwrap(),
154
1
                name: Default::default(),
155
1
                id: Default::default(),
156
1
                fork_id: Default::default(),
157
1
                extensions: BoundedVec::try_from(vec![]).unwrap(),
158
1
                properties: Default::default(),
159
1
            };
160
1

            
161
1
            assert_ok!(Registrar::reserve(origin_of(ALICE.into())));
162
1
            assert_ok!(
163
1
                ContainerRegistrar::register(
164
1
                    origin_of(ALICE.into()),
165
1
                    2000.into(),
166
1
                    genesis_data_2000.clone(),
167
1
                    Some(HeadData(vec![1u8, 1u8, 1u8]))
168
1
                ),
169
1
                ()
170
1
            );
171

            
172
            // Now let's check if the para was preoperly registered in the relay.
173
            // Run to next session.
174
1
            run_to_session(1);
175
1
            assert!(Paras::lifecycle(2000.into())
176
1
                .expect("para should be onboarding")
177
1
                .is_onboarding());
178

            
179
            // We need to accept the validation code, so that the para is onboarded after 2 sessions.
180
1
            assert_ok!(Paras::add_trusted_validation_code(
181
1
                root_origin(),
182
1
                validation_code.into()
183
1
            ));
184
1
            run_to_session(3);
185
1

            
186
1
            // Now the para should be a parathread.
187
1
            assert!(Paras::lifecycle(2000.into())
188
1
                .expect("para should be parathread")
189
1
                .is_parathread());
190
1
        });
191
1
}
192

            
193
#[test]
194
1
fn cannot_register_para_twice_in_relay() {
195
1
    ExtBuilder::default()
196
1
        .with_para_ids(vec![
197
1
            (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(),
198
1
            (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(),
199
1
        ])
200
1
        .build()
201
1
        .execute_with(|| {
202
1
            // In this test we're gonna confirm that a para cannot be registered in the relay
203
1
            // after being already registered through ContainerRegistrar.
204
1

            
205
1
            assert_eq!(Runtime::registered_paras(), vec![1001.into(), 1002.into()]);
206
1
            assert_eq!(Runtime::genesis_data(2000.into()).as_ref(), None);
207
1
            assert_eq!(
208
1
                parachains_configuration::ActiveConfig::<Runtime>::get().max_head_data_size,
209
1
                20500
210
1
            );
211

            
212
1
            let validation_code =
213
1
                vec![1u8; cumulus_primitives_core::relay_chain::MIN_CODE_SIZE as usize];
214
1
            let genesis_data_2000 = ContainerChainGenesisData {
215
1
                storage: BoundedVec::try_from(vec![
216
1
                    (b":code".to_vec(), validation_code.clone()).into()
217
1
                ])
218
1
                .unwrap(),
219
1
                name: Default::default(),
220
1
                id: Default::default(),
221
1
                fork_id: Default::default(),
222
1
                extensions: BoundedVec::try_from(vec![]).unwrap(),
223
1
                properties: Default::default(),
224
1
            };
225
1

            
226
1
            assert_ok!(Registrar::reserve(origin_of(ALICE.into())));
227
1
            assert_ok!(
228
1
                ContainerRegistrar::register(
229
1
                    origin_of(ALICE.into()),
230
1
                    2000.into(),
231
1
                    genesis_data_2000.clone(),
232
1
                    Some(HeadData(vec![1u8, 1u8, 1u8]))
233
1
                ),
234
1
                ()
235
1
            );
236

            
237
            // Now let's check if the para was preoperly registered in the relay.
238
            // Run to next session.
239
1
            run_to_session(1);
240
1
            assert!(Paras::lifecycle(2000.into())
241
1
                .expect("para should be onboarding")
242
1
                .is_onboarding());
243

            
244
            // We need to accept the validation code, so that the para is onboarded after 2 sessions.
245
1
            assert_ok!(Paras::add_trusted_validation_code(
246
1
                root_origin(),
247
1
                validation_code.clone().into()
248
1
            ));
249
1
            run_to_session(3);
250
1

            
251
1
            // Now the para should be a parathread.
252
1
            assert!(Paras::lifecycle(2000.into())
253
1
                .expect("para should be parathread")
254
1
                .is_parathread());
255

            
256
            // We shouldn't be able to register the para again
257
1
            assert_noop!(
258
1
                ContainerRegistrar::register(
259
1
                    origin_of(ALICE.into()),
260
1
                    2000.into(),
261
1
                    genesis_data_2000.clone(),
262
1
                    Some(HeadData(vec![1u8, 1u8, 1u8]))
263
1
                ),
264
1
                pallet_registrar::Error::<Runtime>::ParaIdAlreadyRegistered,
265
1
            );
266
1
        });
267
1
}
268

            
269
#[test]
270
1
fn mark_valid_for_collating_converts_to_parachain() {
271
1
    ExtBuilder::default()
272
1
        .with_para_ids(vec![
273
1
            (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(),
274
1
            (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(),
275
1
        ])
276
1
        .build()
277
1
        .execute_with(|| {
278
1
            // In this test we're gonna check that inside mark_valid_for_collating(),
279
1
            // if we are passing a parathread, this one will be upgraded to a parachain
280
1
            // at the end of the execution.
281
1

            
282
1
            assert_eq!(Runtime::registered_paras(), vec![1001.into(), 1002.into()]);
283
1
            assert_eq!(Runtime::genesis_data(2000.into()).as_ref(), None);
284
1
            assert_eq!(
285
1
                parachains_configuration::ActiveConfig::<Runtime>::get().max_head_data_size,
286
1
                20500
287
1
            );
288

            
289
1
            let validation_code =
290
1
                vec![1u8; cumulus_primitives_core::relay_chain::MIN_CODE_SIZE as usize];
291
1
            let genesis_data_2000 = ContainerChainGenesisData {
292
1
                storage: BoundedVec::try_from(vec![
293
1
                    (b":code".to_vec(), validation_code.clone()).into()
294
1
                ])
295
1
                .unwrap(),
296
1
                name: Default::default(),
297
1
                id: Default::default(),
298
1
                fork_id: Default::default(),
299
1
                extensions: BoundedVec::try_from(vec![]).unwrap(),
300
1
                properties: Default::default(),
301
1
            };
302
1

            
303
1
            assert_ok!(Registrar::reserve(origin_of(ALICE.into())));
304
1
            assert_ok!(
305
1
                ContainerRegistrar::register(
306
1
                    origin_of(ALICE.into()),
307
1
                    2000.into(),
308
1
                    genesis_data_2000.clone(),
309
1
                    Some(HeadData(vec![1u8, 1u8, 1u8]))
310
1
                ),
311
1
                ()
312
1
            );
313

            
314
            // Now let's check if the para was preoperly registered in the relay.
315
            // Run to next session.
316
1
            run_to_session(1);
317
1
            assert!(Paras::lifecycle(2000.into())
318
1
                .expect("para should be onboarding")
319
1
                .is_onboarding());
320

            
321
            // We need to accept the validation code, so that the para is onboarded after 2 sessions.
322
1
            assert_ok!(Paras::add_trusted_validation_code(
323
1
                root_origin(),
324
1
                validation_code.into()
325
1
            ));
326
1
            run_to_session(3);
327
1

            
328
1
            // Now the para should be a parathread.
329
1
            assert!(Paras::lifecycle(2000.into())
330
1
                .expect("para should be parathread")
331
1
                .is_parathread());
332

            
333
1
            set_dummy_boot_node(origin_of(ALICE.into()), 2000.into());
334
1

            
335
1
            // Call mark_valid_for_collating.
336
1
            assert_ok!(
337
1
                ContainerRegistrar::mark_valid_for_collating(root_origin(), 2000.into()),
338
1
                ()
339
1
            );
340

            
341
            // The change should be applied after 2 sessions.
342
1
            run_to_session(5);
343
1
            assert!(Paras::lifecycle(2000.into())
344
1
                .expect("para should be parachain")
345
1
                .is_parachain());
346
1
        });
347
1
}
348

            
349
#[test]
350
1
fn deregister_calls_schedule_para_cleanup() {
351
1
    ExtBuilder::default()
352
1
        .with_para_ids(vec![
353
1
            (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(),
354
1
            (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(),
355
1
        ])
356
1
        .build()
357
1
        .execute_with(|| {
358
1
            // In this test we're gonna check that when calling ContainerRegistrar::deregister(),
359
1
            // the para is also offboarded from the relay.
360
1

            
361
1
            assert_eq!(Runtime::registered_paras(), vec![1001.into(), 1002.into()]);
362
1
            assert_eq!(Runtime::genesis_data(2000.into()).as_ref(), None);
363
1
            assert_eq!(
364
1
                parachains_configuration::ActiveConfig::<Runtime>::get().max_head_data_size,
365
1
                20500
366
1
            );
367

            
368
1
            let validation_code =
369
1
                vec![1u8; cumulus_primitives_core::relay_chain::MIN_CODE_SIZE as usize];
370
1
            let genesis_data_2000 = ContainerChainGenesisData {
371
1
                storage: BoundedVec::try_from(vec![
372
1
                    (b":code".to_vec(), validation_code.clone()).into()
373
1
                ])
374
1
                .unwrap(),
375
1
                name: Default::default(),
376
1
                id: Default::default(),
377
1
                fork_id: Default::default(),
378
1
                extensions: BoundedVec::try_from(vec![]).unwrap(),
379
1
                properties: Default::default(),
380
1
            };
381
1

            
382
1
            assert_ok!(Registrar::reserve(origin_of(ALICE.into())));
383
1
            assert_ok!(
384
1
                ContainerRegistrar::register(
385
1
                    origin_of(ALICE.into()),
386
1
                    2000.into(),
387
1
                    genesis_data_2000.clone(),
388
1
                    Some(HeadData(vec![1u8, 1u8, 1u8]))
389
1
                ),
390
1
                ()
391
1
            );
392

            
393
            // Now let's check if the para was preoperly registered in the relay.
394
            // Run to next session.
395
1
            run_to_session(1);
396
1
            assert!(Paras::lifecycle(2000.into())
397
1
                .expect("para should be onboarding")
398
1
                .is_onboarding());
399

            
400
            // We need to accept the validation code, so that the para is onboarded after 2 sessions.
401
1
            assert_ok!(Paras::add_trusted_validation_code(
402
1
                root_origin(),
403
1
                validation_code.into()
404
1
            ));
405

            
406
1
            run_to_session(3);
407
1

            
408
1
            // Now the para should be a parathread.
409
1
            assert!(Paras::lifecycle(2000.into())
410
1
                .expect("para should be parathread")
411
1
                .is_parathread());
412

            
413
1
            set_dummy_boot_node(origin_of(ALICE.into()), 2000.into());
414
1

            
415
1
            // Call mark_valid_for_collating.
416
1
            assert_ok!(
417
1
                ContainerRegistrar::mark_valid_for_collating(root_origin(), 2000.into()),
418
1
                ()
419
1
            );
420

            
421
            // The change should be applied after 2 sessions.
422
1
            run_to_session(5);
423
1
            assert!(Paras::lifecycle(2000.into())
424
1
                .expect("para should be parachain")
425
1
                .is_parachain());
426

            
427
1
            assert_eq!(
428
1
                Runtime::genesis_data(2000.into()).as_ref(),
429
1
                Some(&genesis_data_2000)
430
1
            );
431

            
432
1
            assert_ok!(ContainerRegistrar::deregister(root_origin(), 2000.into()));
433

            
434
            // Assert that the ParaIdDeregistered event was properly deposited
435
1
            System::assert_last_event(
436
1
                ContainerRegistrarEvent::ParaIdDeregistered {
437
1
                    para_id: 2000.into(),
438
1
                }
439
1
                .into(),
440
1
            );
441
1

            
442
1
            run_to_session(7);
443
1
            end_block();
444
1

            
445
1
            assert_eq!(Runtime::genesis_data(2000.into()).as_ref(), None);
446

            
447
            // Para should be offboarding after 2 sessions.
448
            // we need one more block to trigger the on_initialize of containerRegistrar
449
            // which should fully clean everything
450
1
            start_block();
451
1
            assert!(Paras::lifecycle(2000.into())
452
1
                .expect("para should be offboarding")
453
1
                .is_offboarding());
454
1
        });
455
1
}
456

            
457
#[test]
458
1
fn deregister_two_paras_in_the_same_block() {
459
1
    ExtBuilder::default()
460
1
        .with_para_ids(vec![
461
1
            (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(),
462
1
            (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(),
463
1
        ])
464
1
        .build()
465
1
        .execute_with(|| {
466
1
            // In this test we're gonna check that when calling ContainerRegistrar::deregister(),
467
1
            // two paraIds are properly offboarded from the relay.
468
1

            
469
1
            assert_eq!(Runtime::registered_paras(), vec![1001.into(), 1002.into()]);
470
1
            assert_eq!(Runtime::genesis_data(2000.into()).as_ref(), None);
471
1
            assert_eq!(Runtime::genesis_data(2001.into()).as_ref(), None);
472
1
            assert_eq!(
473
1
                parachains_configuration::ActiveConfig::<Runtime>::get().max_head_data_size,
474
1
                20500
475
1
            );
476

            
477
1
            let validation_code =
478
1
                vec![1u8; cumulus_primitives_core::relay_chain::MIN_CODE_SIZE as usize];
479
1
            let genesis_data_2000_and_2001 = ContainerChainGenesisData {
480
1
                storage: BoundedVec::try_from(vec![
481
1
                    (b":code".to_vec(), validation_code.clone()).into()
482
1
                ])
483
1
                .unwrap(),
484
1
                name: Default::default(),
485
1
                id: Default::default(),
486
1
                fork_id: Default::default(),
487
1
                extensions: BoundedVec::try_from(vec![]).unwrap(),
488
1
                properties: Default::default(),
489
1
            };
490
1

            
491
1
            // Register paraId 2000
492
1
            assert_ok!(Registrar::reserve(origin_of(ALICE.into())));
493
1
            assert_ok!(
494
1
                ContainerRegistrar::register(
495
1
                    origin_of(ALICE.into()),
496
1
                    2000.into(),
497
1
                    genesis_data_2000_and_2001.clone(),
498
1
                    Some(HeadData(vec![1u8, 1u8, 1u8]))
499
1
                ),
500
1
                ()
501
1
            );
502

            
503
            // Register paraId 2001
504
1
            assert_ok!(Registrar::reserve(origin_of(ALICE.into())));
505
1
            assert_ok!(
506
1
                ContainerRegistrar::register(
507
1
                    origin_of(ALICE.into()),
508
1
                    2001.into(),
509
1
                    genesis_data_2000_and_2001.clone(),
510
1
                    Some(HeadData(vec![1u8, 1u8, 1u8]))
511
1
                ),
512
1
                ()
513
1
            );
514

            
515
            // Now let's check if the paras were preoperly registered in the relay.
516
            // Run to next session.
517
1
            run_to_session(1);
518
1
            assert!(Paras::lifecycle(2000.into())
519
1
                .expect("para should be onboarding")
520
1
                .is_onboarding());
521

            
522
1
            assert!(Paras::lifecycle(2001.into())
523
1
                .expect("para should be onboarding")
524
1
                .is_onboarding());
525

            
526
            // We need to accept the validation code, so that paras are onboarded after 2 sessions.
527
1
            assert_ok!(Paras::add_trusted_validation_code(
528
1
                root_origin(),
529
1
                validation_code.into()
530
1
            ));
531

            
532
1
            run_to_session(3);
533
1

            
534
1
            // Now paras should be parathreads.
535
1
            assert!(Paras::lifecycle(2000.into())
536
1
                .expect("para should be parathread")
537
1
                .is_parathread());
538
1
            assert!(Paras::lifecycle(2001.into())
539
1
                .expect("para should be parathread")
540
1
                .is_parathread());
541

            
542
1
            set_dummy_boot_node(origin_of(ALICE.into()), 2000.into());
543
1
            set_dummy_boot_node(origin_of(ALICE.into()), 2001.into());
544
1

            
545
1
            // Call mark_valid_for_collating.
546
1
            assert_ok!(
547
1
                ContainerRegistrar::mark_valid_for_collating(root_origin(), 2000.into()),
548
1
                ()
549
1
            );
550

            
551
1
            assert_ok!(
552
1
                ContainerRegistrar::mark_valid_for_collating(root_origin(), 2001.into()),
553
1
                ()
554
1
            );
555

            
556
            // The change should be applied after 2 sessions.
557
1
            run_to_session(5);
558
1
            assert!(Paras::lifecycle(2000.into())
559
1
                .expect("para should be parachain")
560
1
                .is_parachain());
561

            
562
1
            assert!(Paras::lifecycle(2001.into())
563
1
                .expect("para should be parachain")
564
1
                .is_parachain());
565

            
566
1
            assert_eq!(
567
1
                Runtime::genesis_data(2000.into()).as_ref(),
568
1
                Some(&genesis_data_2000_and_2001)
569
1
            );
570

            
571
1
            assert_eq!(
572
1
                Runtime::genesis_data(2001.into()).as_ref(),
573
1
                Some(&genesis_data_2000_and_2001)
574
1
            );
575

            
576
1
            assert_ok!(ContainerRegistrar::deregister(root_origin(), 2000.into()));
577

            
578
            // Assert that the ParaIdDeregistered event was properly deposited
579
1
            System::assert_last_event(
580
1
                ContainerRegistrarEvent::ParaIdDeregistered {
581
1
                    para_id: 2000.into(),
582
1
                }
583
1
                .into(),
584
1
            );
585
1

            
586
1
            assert_ok!(ContainerRegistrar::deregister(root_origin(), 2001.into()));
587
1
            System::assert_last_event(
588
1
                ContainerRegistrarEvent::ParaIdDeregistered {
589
1
                    para_id: 2001.into(),
590
1
                }
591
1
                .into(),
592
1
            );
593
1

            
594
1
            run_to_session(7);
595
1
            end_block();
596
1

            
597
1
            assert_eq!(Runtime::genesis_data(2000.into()).as_ref(), None);
598
1
            assert_eq!(Runtime::genesis_data(2001.into()).as_ref(), None);
599

            
600
1
            start_block();
601
1
            // Paras should be offboarding after 2 sessions.
602
1
            assert!(Paras::lifecycle(2000.into())
603
1
                .expect("para should be offboarding")
604
1
                .is_offboarding());
605

            
606
1
            assert!(Paras::lifecycle(2001.into())
607
1
                .expect("para should be offboarding")
608
1
                .is_offboarding());
609
1
        });
610
1
}
611

            
612
#[test]
613
1
fn test_register_parathread_not_allowed() {
614
1
    ExtBuilder::default()
615
1
        .with_balances(vec![
616
1
            // Alice gets 10k extra tokens for her mapping deposit
617
1
            (AccountId::from(ALICE), 210_000 * UNIT),
618
1
            (AccountId::from(BOB), 100_000 * UNIT),
619
1
            (AccountId::from(CHARLIE), 100_000 * UNIT),
620
1
            (AccountId::from(DAVE), 100_000 * UNIT),
621
1
        ])
622
1
        .with_collators(vec![
623
1
            (AccountId::from(ALICE), 210 * UNIT),
624
1
            (AccountId::from(BOB), 100 * UNIT),
625
1
            (AccountId::from(CHARLIE), 100 * UNIT),
626
1
            (AccountId::from(DAVE), 100 * UNIT),
627
1
        ])
628
1
        .build()
629
1
        .execute_with(|| {
630
1
            run_to_block(2);
631
1

            
632
1
            assert_noop!(
633
1
                RuntimeCall::ContainerRegistrar(
634
1
                    pallet_registrar::Call::<Runtime>::register_parathread {
635
1
                        para_id: 3001.into(),
636
1
                        slot_frequency: SlotFrequency { min: 1, max: 1 },
637
1
                        genesis_data: empty_genesis_data(),
638
1
                        head_data: None
639
1
                    }
640
1
                )
641
1
                .dispatch(
642
1
                    <Runtime as frame_system::Config>::RuntimeOrigin::signed(AccountId::from(
643
1
                        ALICE
644
1
                    ))
645
1
                ),
646
1
                frame_system::Error::<Runtime>::CallFiltered
647
1
            );
648
1
        });
649
1
}
650

            
651
#[test]
652
1
fn test_relay_registrar_through_extrinsic_not_allowed() {
653
1
    ExtBuilder::default()
654
1
        .with_balances(vec![
655
1
            // Alice gets 10k extra tokens for her mapping deposit
656
1
            (AccountId::from(ALICE), 210_000 * UNIT),
657
1
            (AccountId::from(BOB), 100_000 * UNIT),
658
1
            (AccountId::from(CHARLIE), 100_000 * UNIT),
659
1
            (AccountId::from(DAVE), 100_000 * UNIT),
660
1
        ])
661
1
        .with_collators(vec![
662
1
            (AccountId::from(ALICE), 210 * UNIT),
663
1
            (AccountId::from(BOB), 100 * UNIT),
664
1
            (AccountId::from(CHARLIE), 100 * UNIT),
665
1
            (AccountId::from(DAVE), 100 * UNIT),
666
1
        ])
667
1
        .build()
668
1
        .execute_with(|| {
669
1
            run_to_block(2);
670
1

            
671
1
            let validation_code =
672
1
                vec![1u8; cumulus_primitives_core::relay_chain::MIN_CODE_SIZE as usize];
673
1

            
674
1
            assert_noop!(
675
1
                RuntimeCall::Registrar(paras_registrar::Call::<Runtime>::register {
676
1
                    id: 3001.into(),
677
1
                    validation_code: cumulus_primitives_core::relay_chain::ValidationCode(
678
1
                        validation_code
679
1
                    ),
680
1
                    genesis_head: HeadData(vec![1u8, 1u8, 1u8]),
681
1
                })
682
1
                .dispatch(
683
1
                    <Runtime as frame_system::Config>::RuntimeOrigin::signed(AccountId::from(
684
1
                        ALICE
685
1
                    ))
686
1
                ),
687
1
                frame_system::Error::<Runtime>::CallFiltered
688
1
            );
689
1
        });
690
1
}
691

            
692
#[test]
693
1
fn test_relay_registrar_deregister_through_extrinsic_not_allowed() {
694
1
    ExtBuilder::default()
695
1
        .with_balances(vec![
696
1
            // Alice gets 10k extra tokens for her mapping deposit
697
1
            (AccountId::from(ALICE), 210_000 * UNIT),
698
1
            (AccountId::from(BOB), 100_000 * UNIT),
699
1
            (AccountId::from(CHARLIE), 100_000 * UNIT),
700
1
            (AccountId::from(DAVE), 100_000 * UNIT),
701
1
        ])
702
1
        .with_collators(vec![
703
1
            (AccountId::from(ALICE), 210 * UNIT),
704
1
            (AccountId::from(BOB), 100 * UNIT),
705
1
            (AccountId::from(CHARLIE), 100 * UNIT),
706
1
            (AccountId::from(DAVE), 100 * UNIT),
707
1
        ])
708
1
        .build()
709
1
        .execute_with(|| {
710
1
            run_to_block(2);
711
1

            
712
1
            assert_noop!(
713
1
                RuntimeCall::Registrar(paras_registrar::Call::<Runtime>::deregister {
714
1
                    id: 3001.into()
715
1
                })
716
1
                .dispatch(
717
1
                    <Runtime as frame_system::Config>::RuntimeOrigin::signed(AccountId::from(
718
1
                        ALICE
719
1
                    ))
720
1
                ),
721
1
                frame_system::Error::<Runtime>::CallFiltered
722
1
            );
723
1
        });
724
1
}