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},
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: vec![(b":code".to_vec(), validation_code.clone()).into()],
53
1
                name: Default::default(),
54
1
                id: Default::default(),
55
1
                fork_id: Default::default(),
56
1
                extensions: vec![],
57
1
                properties: Default::default(),
58
1
            };
59
1
            let genesis_data_no_code = ContainerChainGenesisData {
60
1
                storage: vec![(b":code".to_vec(), vec![1u8]).into()],
61
1
                name: Default::default(),
62
1
                id: Default::default(),
63
1
                fork_id: Default::default(),
64
1
                extensions: vec![],
65
1
                properties: Default::default(),
66
1
            };
67
1

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

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

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

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

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

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

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

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

            
144
1
            let validation_code =
145
1
                vec![1u8; cumulus_primitives_core::relay_chain::MIN_CODE_SIZE as usize];
146
1
            let genesis_data_2000 = ContainerChainGenesisData {
147
1
                storage: vec![(b":code".to_vec(), validation_code.clone()).into()],
148
1
                name: Default::default(),
149
1
                id: Default::default(),
150
1
                fork_id: Default::default(),
151
1
                extensions: vec![],
152
1
                properties: Default::default(),
153
1
            };
154
1

            
155
1
            assert_ok!(Registrar::reserve(origin_of(ALICE.into())));
156
1
            assert_ok!(
157
1
                ContainerRegistrar::register(
158
1
                    origin_of(ALICE.into()),
159
1
                    2000.into(),
160
1
                    genesis_data_2000.clone(),
161
1
                    Some(HeadData(vec![1u8, 1u8, 1u8]))
162
1
                ),
163
1
                ()
164
1
            );
165

            
166
            // Now let's check if the para was preoperly registered in the relay.
167
            // Run to next session.
168
1
            run_to_session(1);
169
1
            assert!(Paras::lifecycle(2000.into())
170
1
                .expect("para should be onboarding")
171
1
                .is_onboarding());
172

            
173
            // We need to accept the validation code, so that the para is onboarded after 2 sessions.
174
1
            assert_ok!(Paras::add_trusted_validation_code(
175
1
                root_origin(),
176
1
                validation_code.into()
177
1
            ));
178
1
            run_to_session(3);
179
1

            
180
1
            // Now the para should be a parathread.
181
1
            assert!(Paras::lifecycle(2000.into())
182
1
                .expect("para should be parathread")
183
1
                .is_parathread());
184
1
        });
185
1
}
186

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

            
199
1
            assert_eq!(Runtime::registered_paras(), vec![1001.into(), 1002.into()]);
200
1
            assert_eq!(Runtime::genesis_data(2000.into()).as_ref(), None);
201
1
            assert_eq!(
202
1
                parachains_configuration::ActiveConfig::<Runtime>::get().max_head_data_size,
203
1
                20500
204
1
            );
205

            
206
1
            let validation_code =
207
1
                vec![1u8; cumulus_primitives_core::relay_chain::MIN_CODE_SIZE as usize];
208
1
            let genesis_data_2000 = ContainerChainGenesisData {
209
1
                storage: vec![(b":code".to_vec(), validation_code.clone()).into()],
210
1
                name: Default::default(),
211
1
                id: Default::default(),
212
1
                fork_id: Default::default(),
213
1
                extensions: vec![],
214
1
                properties: Default::default(),
215
1
            };
216
1

            
217
1
            assert_ok!(Registrar::reserve(origin_of(ALICE.into())));
218
1
            assert_ok!(
219
1
                ContainerRegistrar::register(
220
1
                    origin_of(ALICE.into()),
221
1
                    2000.into(),
222
1
                    genesis_data_2000.clone(),
223
1
                    Some(HeadData(vec![1u8, 1u8, 1u8]))
224
1
                ),
225
1
                ()
226
1
            );
227

            
228
            // Now let's check if the para was preoperly registered in the relay.
229
            // Run to next session.
230
1
            run_to_session(1);
231
1
            assert!(Paras::lifecycle(2000.into())
232
1
                .expect("para should be onboarding")
233
1
                .is_onboarding());
234

            
235
            // We need to accept the validation code, so that the para is onboarded after 2 sessions.
236
1
            assert_ok!(Paras::add_trusted_validation_code(
237
1
                root_origin(),
238
1
                validation_code.clone().into()
239
1
            ));
240
1
            run_to_session(3);
241
1

            
242
1
            // Now the para should be a parathread.
243
1
            assert!(Paras::lifecycle(2000.into())
244
1
                .expect("para should be parathread")
245
1
                .is_parathread());
246

            
247
            // We shouldn't be able to register the para again
248
1
            assert_noop!(
249
1
                ContainerRegistrar::register(
250
1
                    origin_of(ALICE.into()),
251
1
                    2000.into(),
252
1
                    genesis_data_2000.clone(),
253
1
                    Some(HeadData(vec![1u8, 1u8, 1u8]))
254
1
                ),
255
1
                pallet_registrar::Error::<Runtime>::ParaIdAlreadyRegistered,
256
1
            );
257
1
        });
258
1
}
259

            
260
#[test]
261
1
fn mark_valid_for_collating_converts_to_parachain() {
262
1
    ExtBuilder::default()
263
1
        .with_para_ids(vec![
264
1
            (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(),
265
1
            (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(),
266
1
        ])
267
1
        .build()
268
1
        .execute_with(|| {
269
1
            // In this test we're gonna check that inside mark_valid_for_collating(),
270
1
            // if we are passing a parathread, this one will be upgraded to a parachain
271
1
            // at the end of the execution.
272
1

            
273
1
            assert_eq!(Runtime::registered_paras(), vec![1001.into(), 1002.into()]);
274
1
            assert_eq!(Runtime::genesis_data(2000.into()).as_ref(), None);
275
1
            assert_eq!(
276
1
                parachains_configuration::ActiveConfig::<Runtime>::get().max_head_data_size,
277
1
                20500
278
1
            );
279

            
280
1
            let validation_code =
281
1
                vec![1u8; cumulus_primitives_core::relay_chain::MIN_CODE_SIZE as usize];
282
1
            let genesis_data_2000 = ContainerChainGenesisData {
283
1
                storage: vec![(b":code".to_vec(), validation_code.clone()).into()],
284
1
                name: Default::default(),
285
1
                id: Default::default(),
286
1
                fork_id: Default::default(),
287
1
                extensions: vec![],
288
1
                properties: Default::default(),
289
1
            };
290
1

            
291
1
            assert_ok!(Registrar::reserve(origin_of(ALICE.into())));
292
1
            assert_ok!(
293
1
                ContainerRegistrar::register(
294
1
                    origin_of(ALICE.into()),
295
1
                    2000.into(),
296
1
                    genesis_data_2000.clone(),
297
1
                    Some(HeadData(vec![1u8, 1u8, 1u8]))
298
1
                ),
299
1
                ()
300
1
            );
301

            
302
            // Now let's check if the para was preoperly registered in the relay.
303
            // Run to next session.
304
1
            run_to_session(1);
305
1
            assert!(Paras::lifecycle(2000.into())
306
1
                .expect("para should be onboarding")
307
1
                .is_onboarding());
308

            
309
            // We need to accept the validation code, so that the para is onboarded after 2 sessions.
310
1
            assert_ok!(Paras::add_trusted_validation_code(
311
1
                root_origin(),
312
1
                validation_code.into()
313
1
            ));
314
1
            run_to_session(3);
315
1

            
316
1
            // Now the para should be a parathread.
317
1
            assert!(Paras::lifecycle(2000.into())
318
1
                .expect("para should be parathread")
319
1
                .is_parathread());
320

            
321
1
            set_dummy_boot_node(origin_of(ALICE.into()), 2000.into());
322
1

            
323
1
            // Call mark_valid_for_collating.
324
1
            assert_ok!(
325
1
                ContainerRegistrar::mark_valid_for_collating(root_origin(), 2000.into()),
326
1
                ()
327
1
            );
328

            
329
            // The change should be applied after 2 sessions.
330
1
            run_to_session(5);
331
1
            assert!(Paras::lifecycle(2000.into())
332
1
                .expect("para should be parachain")
333
1
                .is_parachain());
334
1
        });
335
1
}
336

            
337
#[test]
338
1
fn deregister_calls_schedule_para_cleanup() {
339
1
    ExtBuilder::default()
340
1
        .with_para_ids(vec![
341
1
            (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(),
342
1
            (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(),
343
1
        ])
344
1
        .build()
345
1
        .execute_with(|| {
346
1
            // In this test we're gonna check that when calling ContainerRegistrar::deregister(),
347
1
            // the para is also offboarded from the relay.
348
1

            
349
1
            assert_eq!(Runtime::registered_paras(), vec![1001.into(), 1002.into()]);
350
1
            assert_eq!(Runtime::genesis_data(2000.into()).as_ref(), None);
351
1
            assert_eq!(
352
1
                parachains_configuration::ActiveConfig::<Runtime>::get().max_head_data_size,
353
1
                20500
354
1
            );
355

            
356
1
            let validation_code =
357
1
                vec![1u8; cumulus_primitives_core::relay_chain::MIN_CODE_SIZE as usize];
358
1
            let genesis_data_2000 = ContainerChainGenesisData {
359
1
                storage: vec![(b":code".to_vec(), validation_code.clone()).into()],
360
1
                name: Default::default(),
361
1
                id: Default::default(),
362
1
                fork_id: Default::default(),
363
1
                extensions: vec![],
364
1
                properties: Default::default(),
365
1
            };
366
1

            
367
1
            assert_ok!(Registrar::reserve(origin_of(ALICE.into())));
368
1
            assert_ok!(
369
1
                ContainerRegistrar::register(
370
1
                    origin_of(ALICE.into()),
371
1
                    2000.into(),
372
1
                    genesis_data_2000.clone(),
373
1
                    Some(HeadData(vec![1u8, 1u8, 1u8]))
374
1
                ),
375
1
                ()
376
1
            );
377

            
378
            // Now let's check if the para was preoperly registered in the relay.
379
            // Run to next session.
380
1
            run_to_session(1);
381
1
            assert!(Paras::lifecycle(2000.into())
382
1
                .expect("para should be onboarding")
383
1
                .is_onboarding());
384

            
385
            // We need to accept the validation code, so that the para is onboarded after 2 sessions.
386
1
            assert_ok!(Paras::add_trusted_validation_code(
387
1
                root_origin(),
388
1
                validation_code.into()
389
1
            ));
390

            
391
1
            run_to_session(3);
392
1

            
393
1
            // Now the para should be a parathread.
394
1
            assert!(Paras::lifecycle(2000.into())
395
1
                .expect("para should be parathread")
396
1
                .is_parathread());
397

            
398
1
            set_dummy_boot_node(origin_of(ALICE.into()), 2000.into());
399
1

            
400
1
            // Call mark_valid_for_collating.
401
1
            assert_ok!(
402
1
                ContainerRegistrar::mark_valid_for_collating(root_origin(), 2000.into()),
403
1
                ()
404
1
            );
405

            
406
            // The change should be applied after 2 sessions.
407
1
            run_to_session(5);
408
1
            assert!(Paras::lifecycle(2000.into())
409
1
                .expect("para should be parachain")
410
1
                .is_parachain());
411

            
412
1
            assert_eq!(
413
1
                Runtime::genesis_data(2000.into()).as_ref(),
414
1
                Some(&genesis_data_2000)
415
1
            );
416

            
417
1
            assert_ok!(ContainerRegistrar::deregister(root_origin(), 2000.into()));
418

            
419
            // Assert that the ParaIdDeregistered event was properly deposited
420
1
            System::assert_last_event(
421
1
                ContainerRegistrarEvent::ParaIdDeregistered {
422
1
                    para_id: 2000.into(),
423
1
                }
424
1
                .into(),
425
1
            );
426
1

            
427
1
            run_to_session(7);
428
1
            end_block();
429
1

            
430
1
            assert_eq!(Runtime::genesis_data(2000.into()).as_ref(), None);
431

            
432
            // Para should be offboarding after 2 sessions.
433
            // we need one more block to trigger the on_initialize of containerRegistrar
434
            // which should fully clean everything
435
1
            start_block();
436
1
            assert!(Paras::lifecycle(2000.into())
437
1
                .expect("para should be offboarding")
438
1
                .is_offboarding());
439
1
        });
440
1
}
441

            
442
#[test]
443
1
fn deregister_two_paras_in_the_same_block() {
444
1
    ExtBuilder::default()
445
1
        .with_para_ids(vec![
446
1
            (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(),
447
1
            (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(),
448
1
        ])
449
1
        .build()
450
1
        .execute_with(|| {
451
1
            // In this test we're gonna check that when calling ContainerRegistrar::deregister(),
452
1
            // two paraIds are properly offboarded from the relay.
453
1

            
454
1
            assert_eq!(Runtime::registered_paras(), vec![1001.into(), 1002.into()]);
455
1
            assert_eq!(Runtime::genesis_data(2000.into()).as_ref(), None);
456
1
            assert_eq!(Runtime::genesis_data(2001.into()).as_ref(), None);
457
1
            assert_eq!(
458
1
                parachains_configuration::ActiveConfig::<Runtime>::get().max_head_data_size,
459
1
                20500
460
1
            );
461

            
462
1
            let validation_code =
463
1
                vec![1u8; cumulus_primitives_core::relay_chain::MIN_CODE_SIZE as usize];
464
1
            let genesis_data_2000_and_2001 = ContainerChainGenesisData {
465
1
                storage: vec![(b":code".to_vec(), validation_code.clone()).into()],
466
1
                name: Default::default(),
467
1
                id: Default::default(),
468
1
                fork_id: Default::default(),
469
1
                extensions: vec![],
470
1
                properties: Default::default(),
471
1
            };
472
1

            
473
1
            // Register paraId 2000
474
1
            assert_ok!(Registrar::reserve(origin_of(ALICE.into())));
475
1
            assert_ok!(
476
1
                ContainerRegistrar::register(
477
1
                    origin_of(ALICE.into()),
478
1
                    2000.into(),
479
1
                    genesis_data_2000_and_2001.clone(),
480
1
                    Some(HeadData(vec![1u8, 1u8, 1u8]))
481
1
                ),
482
1
                ()
483
1
            );
484

            
485
            // Register paraId 2001
486
1
            assert_ok!(Registrar::reserve(origin_of(ALICE.into())));
487
1
            assert_ok!(
488
1
                ContainerRegistrar::register(
489
1
                    origin_of(ALICE.into()),
490
1
                    2001.into(),
491
1
                    genesis_data_2000_and_2001.clone(),
492
1
                    Some(HeadData(vec![1u8, 1u8, 1u8]))
493
1
                ),
494
1
                ()
495
1
            );
496

            
497
            // Now let's check if the paras were preoperly registered in the relay.
498
            // Run to next session.
499
1
            run_to_session(1);
500
1
            assert!(Paras::lifecycle(2000.into())
501
1
                .expect("para should be onboarding")
502
1
                .is_onboarding());
503

            
504
1
            assert!(Paras::lifecycle(2001.into())
505
1
                .expect("para should be onboarding")
506
1
                .is_onboarding());
507

            
508
            // We need to accept the validation code, so that paras are onboarded after 2 sessions.
509
1
            assert_ok!(Paras::add_trusted_validation_code(
510
1
                root_origin(),
511
1
                validation_code.into()
512
1
            ));
513

            
514
1
            run_to_session(3);
515
1

            
516
1
            // Now paras should be parathreads.
517
1
            assert!(Paras::lifecycle(2000.into())
518
1
                .expect("para should be parathread")
519
1
                .is_parathread());
520
1
            assert!(Paras::lifecycle(2001.into())
521
1
                .expect("para should be parathread")
522
1
                .is_parathread());
523

            
524
1
            set_dummy_boot_node(origin_of(ALICE.into()), 2000.into());
525
1
            set_dummy_boot_node(origin_of(ALICE.into()), 2001.into());
526
1

            
527
1
            // Call mark_valid_for_collating.
528
1
            assert_ok!(
529
1
                ContainerRegistrar::mark_valid_for_collating(root_origin(), 2000.into()),
530
1
                ()
531
1
            );
532

            
533
1
            assert_ok!(
534
1
                ContainerRegistrar::mark_valid_for_collating(root_origin(), 2001.into()),
535
1
                ()
536
1
            );
537

            
538
            // The change should be applied after 2 sessions.
539
1
            run_to_session(5);
540
1
            assert!(Paras::lifecycle(2000.into())
541
1
                .expect("para should be parachain")
542
1
                .is_parachain());
543

            
544
1
            assert!(Paras::lifecycle(2001.into())
545
1
                .expect("para should be parachain")
546
1
                .is_parachain());
547

            
548
1
            assert_eq!(
549
1
                Runtime::genesis_data(2000.into()).as_ref(),
550
1
                Some(&genesis_data_2000_and_2001)
551
1
            );
552

            
553
1
            assert_eq!(
554
1
                Runtime::genesis_data(2001.into()).as_ref(),
555
1
                Some(&genesis_data_2000_and_2001)
556
1
            );
557

            
558
1
            assert_ok!(ContainerRegistrar::deregister(root_origin(), 2000.into()));
559

            
560
            // Assert that the ParaIdDeregistered event was properly deposited
561
1
            System::assert_last_event(
562
1
                ContainerRegistrarEvent::ParaIdDeregistered {
563
1
                    para_id: 2000.into(),
564
1
                }
565
1
                .into(),
566
1
            );
567
1

            
568
1
            assert_ok!(ContainerRegistrar::deregister(root_origin(), 2001.into()));
569
1
            System::assert_last_event(
570
1
                ContainerRegistrarEvent::ParaIdDeregistered {
571
1
                    para_id: 2001.into(),
572
1
                }
573
1
                .into(),
574
1
            );
575
1

            
576
1
            run_to_session(7);
577
1
            end_block();
578
1

            
579
1
            assert_eq!(Runtime::genesis_data(2000.into()).as_ref(), None);
580
1
            assert_eq!(Runtime::genesis_data(2001.into()).as_ref(), None);
581

            
582
1
            start_block();
583
1
            // Paras should be offboarding after 2 sessions.
584
1
            assert!(Paras::lifecycle(2000.into())
585
1
                .expect("para should be offboarding")
586
1
                .is_offboarding());
587

            
588
1
            assert!(Paras::lifecycle(2001.into())
589
1
                .expect("para should be offboarding")
590
1
                .is_offboarding());
591
1
        });
592
1
}
593

            
594
#[test]
595
1
fn test_register_parathread_not_allowed() {
596
1
    ExtBuilder::default()
597
1
        .with_balances(vec![
598
1
            // Alice gets 10k extra tokens for her mapping deposit
599
1
            (AccountId::from(ALICE), 210_000 * UNIT),
600
1
            (AccountId::from(BOB), 100_000 * UNIT),
601
1
            (AccountId::from(CHARLIE), 100_000 * UNIT),
602
1
            (AccountId::from(DAVE), 100_000 * UNIT),
603
1
        ])
604
1
        .with_collators(vec![
605
1
            (AccountId::from(ALICE), 210 * UNIT),
606
1
            (AccountId::from(BOB), 100 * UNIT),
607
1
            (AccountId::from(CHARLIE), 100 * UNIT),
608
1
            (AccountId::from(DAVE), 100 * UNIT),
609
1
        ])
610
1
        .build()
611
1
        .execute_with(|| {
612
1
            run_to_block(2);
613
1

            
614
1
            assert_noop!(
615
1
                RuntimeCall::ContainerRegistrar(
616
1
                    pallet_registrar::Call::<Runtime>::register_parathread {
617
1
                        para_id: 3001.into(),
618
1
                        slot_frequency: SlotFrequency { min: 1, max: 1 },
619
1
                        genesis_data: empty_genesis_data(),
620
1
                        head_data: None
621
1
                    }
622
1
                )
623
1
                .dispatch(
624
1
                    <Runtime as frame_system::Config>::RuntimeOrigin::signed(AccountId::from(
625
1
                        ALICE
626
1
                    ))
627
1
                ),
628
1
                frame_system::Error::<Runtime>::CallFiltered
629
1
            );
630
1
        });
631
1
}
632

            
633
#[test]
634
1
fn test_relay_registrar_through_extrinsic_not_allowed() {
635
1
    ExtBuilder::default()
636
1
        .with_balances(vec![
637
1
            // Alice gets 10k extra tokens for her mapping deposit
638
1
            (AccountId::from(ALICE), 210_000 * UNIT),
639
1
            (AccountId::from(BOB), 100_000 * UNIT),
640
1
            (AccountId::from(CHARLIE), 100_000 * UNIT),
641
1
            (AccountId::from(DAVE), 100_000 * UNIT),
642
1
        ])
643
1
        .with_collators(vec![
644
1
            (AccountId::from(ALICE), 210 * UNIT),
645
1
            (AccountId::from(BOB), 100 * UNIT),
646
1
            (AccountId::from(CHARLIE), 100 * UNIT),
647
1
            (AccountId::from(DAVE), 100 * UNIT),
648
1
        ])
649
1
        .build()
650
1
        .execute_with(|| {
651
1
            run_to_block(2);
652
1

            
653
1
            let validation_code =
654
1
                vec![1u8; cumulus_primitives_core::relay_chain::MIN_CODE_SIZE as usize];
655
1

            
656
1
            assert_noop!(
657
1
                RuntimeCall::Registrar(paras_registrar::Call::<Runtime>::register {
658
1
                    id: 3001.into(),
659
1
                    validation_code: cumulus_primitives_core::relay_chain::ValidationCode(
660
1
                        validation_code
661
1
                    ),
662
1
                    genesis_head: HeadData(vec![1u8, 1u8, 1u8]),
663
1
                })
664
1
                .dispatch(
665
1
                    <Runtime as frame_system::Config>::RuntimeOrigin::signed(AccountId::from(
666
1
                        ALICE
667
1
                    ))
668
1
                ),
669
1
                frame_system::Error::<Runtime>::CallFiltered
670
1
            );
671
1
        });
672
1
}
673

            
674
#[test]
675
1
fn test_relay_registrar_deregister_through_extrinsic_not_allowed() {
676
1
    ExtBuilder::default()
677
1
        .with_balances(vec![
678
1
            // Alice gets 10k extra tokens for her mapping deposit
679
1
            (AccountId::from(ALICE), 210_000 * UNIT),
680
1
            (AccountId::from(BOB), 100_000 * UNIT),
681
1
            (AccountId::from(CHARLIE), 100_000 * UNIT),
682
1
            (AccountId::from(DAVE), 100_000 * UNIT),
683
1
        ])
684
1
        .with_collators(vec![
685
1
            (AccountId::from(ALICE), 210 * UNIT),
686
1
            (AccountId::from(BOB), 100 * UNIT),
687
1
            (AccountId::from(CHARLIE), 100 * UNIT),
688
1
            (AccountId::from(DAVE), 100 * UNIT),
689
1
        ])
690
1
        .build()
691
1
        .execute_with(|| {
692
1
            run_to_block(2);
693
1

            
694
1
            assert_noop!(
695
1
                RuntimeCall::Registrar(paras_registrar::Call::<Runtime>::deregister {
696
1
                    id: 3001.into()
697
1
                })
698
1
                .dispatch(
699
1
                    <Runtime as frame_system::Config>::RuntimeOrigin::signed(AccountId::from(
700
1
                        ALICE
701
1
                    ))
702
1
                ),
703
1
                frame_system::Error::<Runtime>::CallFiltered
704
1
            );
705
1
        });
706
1
}