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
};
34

            
35
#[test]
36
1
fn registrar_needs_a_reserved_para_id() {
37
1
    ExtBuilder::default()
38
1
        .with_balances(vec![
39
1
            // Alice gets 10k extra tokens for her mapping deposit
40
1
            (AccountId::from(ALICE), 210_000 * UNIT),
41
1
            (AccountId::from(BOB), 100_000 * UNIT),
42
1
            (AccountId::from(CHARLIE), 100_000 * UNIT),
43
1
            (AccountId::from(DAVE), 100_000 * UNIT),
44
1
        ])
45
1
        .with_next_free_para_id(2000u32.into())
46
1
        .build()
47
1
        .execute_with(|| {
48
1
            run_to_block(2);
49
1
            assert_noop!(
50
1
                Registrar::register(
51
1
                    origin_of(ALICE.into()),
52
1
                    100u32.into(),
53
1
                    vec![].into(),
54
1
                    vec![].into()
55
1
                ),
56
1
                paras_registrar::Error::<Runtime>::NotReserved
57
1
            );
58

            
59
            // After a reservation, we can register
60
1
            let next_para_id = paras_registrar::NextFreeParaId::<Runtime>::get();
61
1

            
62
1
            assert_ok!(Registrar::reserve(origin_of(ALICE.into())));
63

            
64
1
            assert_noop!(
65
1
                Registrar::register(
66
1
                    origin_of(ALICE.into()),
67
1
                    next_para_id,
68
1
                    vec![].into(),
69
1
                    vec![].into()
70
1
                ),
71
1
                paras_registrar::Error::<Runtime>::InvalidCode
72
1
            );
73

            
74
1
            let validation_code: cumulus_primitives_core::relay_chain::ValidationCode =
75
1
                vec![1u8; cumulus_primitives_core::relay_chain::MIN_CODE_SIZE as usize].into();
76
1
            assert_ok!(Registrar::register(
77
1
                origin_of(ALICE.into()),
78
1
                next_para_id,
79
1
                vec![].into(),
80
1
                validation_code.clone()
81
1
            ));
82

            
83
1
            assert!(Paras::lifecycle(next_para_id)
84
1
                .expect("para should be onboarding")
85
1
                .is_onboarding());
86
            // Two sessions later the para should be a parathread
87
            // But only if the pvf is accepted! which we havent done
88
1
            run_to_session(2);
89
1
            assert!(Paras::lifecycle(next_para_id)
90
1
                .expect("para should be onboarding")
91
1
                .is_onboarding());
92

            
93
            // Now let's accept the pvf, so that after 2 sesssions we have the chain onboarded
94
1
            assert_ok!(Paras::add_trusted_validation_code(
95
1
                root_origin(),
96
1
                validation_code
97
1
            ));
98
1
            run_to_session(4);
99
1

            
100
1
            // PVF accepted and the para should be a parathread
101
1
            assert!(Paras::lifecycle(next_para_id)
102
1
                .expect("para should be parathread")
103
1
                .is_parathread());
104
1
        });
105
1
}
106

            
107
#[test]
108
1
fn register_para_via_container_registrar() {
109
1
    ExtBuilder::default()
110
1
        .with_para_ids(vec![
111
1
            (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(),
112
1
            (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(),
113
1
        ])
114
1
        .build()
115
1
        .execute_with(|| {
116
1
            // In this test we're gonna register a para via ContainerRegistrar,
117
1
            // which will internally use the InnerRegistrar type to also register the para
118
1
            // in the relay Registrar pallet.
119
1

            
120
1
            assert_eq!(Runtime::registered_paras(), vec![1001.into(), 1002.into()]);
121
1
            assert_eq!(Runtime::genesis_data(1003.into()).as_ref(), None);
122
1
            assert_eq!(
123
1
                parachains_configuration::ActiveConfig::<Runtime>::get().max_head_data_size,
124
1
                20500
125
1
            );
126

            
127
1
            let validation_code =
128
1
                vec![1u8; cumulus_primitives_core::relay_chain::MIN_CODE_SIZE as usize];
129
1
            let genesis_data_1003 = ContainerChainGenesisData {
130
1
                storage: vec![(b":code".to_vec(), validation_code.clone()).into()],
131
1
                name: Default::default(),
132
1
                id: Default::default(),
133
1
                fork_id: Default::default(),
134
1
                extensions: vec![],
135
1
                properties: Default::default(),
136
1
            };
137
1

            
138
1
            assert_ok!(
139
1
                ContainerRegistrar::register(
140
1
                    origin_of(ALICE.into()),
141
1
                    1003.into(),
142
1
                    genesis_data_1003.clone(),
143
1
                    Some(HeadData(vec![1u8, 1u8, 1u8]))
144
1
                ),
145
1
                ()
146
1
            );
147

            
148
            // Now let's check if the para was preoperly registered in the relay.
149
            // Run to next session.
150
1
            run_to_session(1);
151
1
            assert!(Paras::lifecycle(1003.into())
152
1
                .expect("para should be onboarding")
153
1
                .is_onboarding());
154

            
155
            // We need to accept the validation code, so that the para is onboarded after 2 sessions.
156
1
            assert_ok!(Paras::add_trusted_validation_code(
157
1
                root_origin(),
158
1
                validation_code.into()
159
1
            ));
160
1
            run_to_session(3);
161
1

            
162
1
            // Now the para should be a parathread.
163
1
            assert!(Paras::lifecycle(1003.into())
164
1
                .expect("para should be parathread")
165
1
                .is_parathread());
166
1
        });
167
1
}
168

            
169
#[test]
170
1
fn cannot_register_para_twice_in_relay() {
171
1
    ExtBuilder::default()
172
1
        .with_para_ids(vec![
173
1
            (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(),
174
1
            (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(),
175
1
        ])
176
1
        .build()
177
1
        .execute_with(|| {
178
1
            // In this test we're gonna confirm that a para cannot be registered in the relay
179
1
            // after being already registered through ContainerRegistrar.
180
1

            
181
1
            assert_eq!(Runtime::registered_paras(), vec![1001.into(), 1002.into()]);
182
1
            assert_eq!(Runtime::genesis_data(1003.into()).as_ref(), None);
183
1
            assert_eq!(
184
1
                parachains_configuration::ActiveConfig::<Runtime>::get().max_head_data_size,
185
1
                20500
186
1
            );
187

            
188
1
            let validation_code =
189
1
                vec![1u8; cumulus_primitives_core::relay_chain::MIN_CODE_SIZE as usize];
190
1
            let genesis_data_1003 = ContainerChainGenesisData {
191
1
                storage: vec![(b":code".to_vec(), validation_code.clone()).into()],
192
1
                name: Default::default(),
193
1
                id: Default::default(),
194
1
                fork_id: Default::default(),
195
1
                extensions: vec![],
196
1
                properties: Default::default(),
197
1
            };
198
1

            
199
1
            assert_ok!(
200
1
                ContainerRegistrar::register(
201
1
                    origin_of(ALICE.into()),
202
1
                    1003.into(),
203
1
                    genesis_data_1003.clone(),
204
1
                    Some(HeadData(vec![1u8, 1u8, 1u8]))
205
1
                ),
206
1
                ()
207
1
            );
208

            
209
            // Now let's check if the para was preoperly registered in the relay.
210
            // Run to next session.
211
1
            run_to_session(1);
212
1
            assert!(Paras::lifecycle(1003.into())
213
1
                .expect("para should be onboarding")
214
1
                .is_onboarding());
215

            
216
            // We need to accept the validation code, so that the para is onboarded after 2 sessions.
217
1
            assert_ok!(Paras::add_trusted_validation_code(
218
1
                root_origin(),
219
1
                validation_code.clone().into()
220
1
            ));
221
1
            run_to_session(3);
222
1

            
223
1
            // Now the para should be a parathread.
224
1
            assert!(Paras::lifecycle(1003.into())
225
1
                .expect("para should be parathread")
226
1
                .is_parathread());
227

            
228
            // We shouldn't be able to register the para again
229
1
            assert_noop!(
230
1
                Registrar::register(
231
1
                    origin_of(ALICE.into()),
232
1
                    1003.into(),
233
1
                    vec![].into(),
234
1
                    validation_code.into()
235
1
                ),
236
1
                paras_registrar::Error::<Runtime>::AlreadyRegistered
237
1
            );
238
1
        });
239
1
}
240

            
241
#[test]
242
1
fn mark_valid_for_collating_converts_to_parachain() {
243
1
    ExtBuilder::default()
244
1
        .with_para_ids(vec![
245
1
            (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(),
246
1
            (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(),
247
1
        ])
248
1
        .build()
249
1
        .execute_with(|| {
250
1
            // In this test we're gonna check that inside mark_valid_for_collating(),
251
1
            // if we are passing a parathread, this one will be upgraded to a parachain
252
1
            // at the end of the execution.
253
1

            
254
1
            assert_eq!(Runtime::registered_paras(), vec![1001.into(), 1002.into()]);
255
1
            assert_eq!(Runtime::genesis_data(1003.into()).as_ref(), None);
256
1
            assert_eq!(
257
1
                parachains_configuration::ActiveConfig::<Runtime>::get().max_head_data_size,
258
1
                20500
259
1
            );
260

            
261
1
            let validation_code =
262
1
                vec![1u8; cumulus_primitives_core::relay_chain::MIN_CODE_SIZE as usize];
263
1
            let genesis_data_1003 = ContainerChainGenesisData {
264
1
                storage: vec![(b":code".to_vec(), validation_code.clone()).into()],
265
1
                name: Default::default(),
266
1
                id: Default::default(),
267
1
                fork_id: Default::default(),
268
1
                extensions: vec![],
269
1
                properties: Default::default(),
270
1
            };
271
1

            
272
1
            assert_ok!(
273
1
                ContainerRegistrar::register(
274
1
                    origin_of(ALICE.into()),
275
1
                    1003.into(),
276
1
                    genesis_data_1003.clone(),
277
1
                    Some(HeadData(vec![1u8, 1u8, 1u8]))
278
1
                ),
279
1
                ()
280
1
            );
281

            
282
            // Now let's check if the para was preoperly registered in the relay.
283
            // Run to next session.
284
1
            run_to_session(1);
285
1
            assert!(Paras::lifecycle(1003.into())
286
1
                .expect("para should be onboarding")
287
1
                .is_onboarding());
288

            
289
            // We need to accept the validation code, so that the para is onboarded after 2 sessions.
290
1
            assert_ok!(Paras::add_trusted_validation_code(
291
1
                root_origin(),
292
1
                validation_code.into()
293
1
            ));
294
1
            run_to_session(3);
295
1

            
296
1
            // Now the para should be a parathread.
297
1
            assert!(Paras::lifecycle(1003.into())
298
1
                .expect("para should be parathread")
299
1
                .is_parathread());
300

            
301
1
            set_dummy_boot_node(origin_of(ALICE.into()), 1003.into());
302
1

            
303
1
            // Call mark_valid_for_collating.
304
1
            assert_ok!(
305
1
                ContainerRegistrar::mark_valid_for_collating(root_origin(), 1003.into()),
306
1
                ()
307
1
            );
308

            
309
            // The change should be applied after 2 sessions.
310
1
            run_to_session(5);
311
1
            assert!(Paras::lifecycle(1003.into())
312
1
                .expect("para should be parachain")
313
1
                .is_parachain());
314
1
        });
315
1
}
316

            
317
#[test]
318
1
fn deregister_calls_schedule_para_cleanup() {
319
1
    ExtBuilder::default()
320
1
        .with_para_ids(vec![
321
1
            (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(),
322
1
            (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(),
323
1
        ])
324
1
        .build()
325
1
        .execute_with(|| {
326
1
            // In this test we're gonna check that when calling ContainerRegistrar::deregister(),
327
1
            // the para is also offboarded from the relay.
328
1

            
329
1
            assert_eq!(Runtime::registered_paras(), vec![1001.into(), 1002.into()]);
330
1
            assert_eq!(Runtime::genesis_data(1003.into()).as_ref(), None);
331
1
            assert_eq!(
332
1
                parachains_configuration::ActiveConfig::<Runtime>::get().max_head_data_size,
333
1
                20500
334
1
            );
335

            
336
1
            let validation_code =
337
1
                vec![1u8; cumulus_primitives_core::relay_chain::MIN_CODE_SIZE as usize];
338
1
            let genesis_data_1003 = ContainerChainGenesisData {
339
1
                storage: vec![(b":code".to_vec(), validation_code.clone()).into()],
340
1
                name: Default::default(),
341
1
                id: Default::default(),
342
1
                fork_id: Default::default(),
343
1
                extensions: vec![],
344
1
                properties: Default::default(),
345
1
            };
346
1

            
347
1
            assert_ok!(
348
1
                ContainerRegistrar::register(
349
1
                    origin_of(ALICE.into()),
350
1
                    1003.into(),
351
1
                    genesis_data_1003.clone(),
352
1
                    Some(HeadData(vec![1u8, 1u8, 1u8]))
353
1
                ),
354
1
                ()
355
1
            );
356

            
357
            // Now let's check if the para was preoperly registered in the relay.
358
            // Run to next session.
359
1
            run_to_session(1);
360
1
            assert!(Paras::lifecycle(1003.into())
361
1
                .expect("para should be onboarding")
362
1
                .is_onboarding());
363

            
364
            // We need to accept the validation code, so that the para is onboarded after 2 sessions.
365
1
            assert_ok!(Paras::add_trusted_validation_code(
366
1
                root_origin(),
367
1
                validation_code.into()
368
1
            ));
369

            
370
1
            run_to_session(3);
371
1

            
372
1
            // Now the para should be a parathread.
373
1
            assert!(Paras::lifecycle(1003.into())
374
1
                .expect("para should be parathread")
375
1
                .is_parathread());
376

            
377
1
            set_dummy_boot_node(origin_of(ALICE.into()), 1003.into());
378
1

            
379
1
            // Call mark_valid_for_collating.
380
1
            assert_ok!(
381
1
                ContainerRegistrar::mark_valid_for_collating(root_origin(), 1003.into()),
382
1
                ()
383
1
            );
384

            
385
            // The change should be applied after 2 sessions.
386
1
            run_to_session(5);
387
1
            assert!(Paras::lifecycle(1003.into())
388
1
                .expect("para should be parachain")
389
1
                .is_parachain());
390

            
391
1
            assert_eq!(
392
1
                Runtime::genesis_data(1003.into()).as_ref(),
393
1
                Some(&genesis_data_1003)
394
1
            );
395

            
396
1
            assert_ok!(ContainerRegistrar::deregister(root_origin(), 1003.into()));
397

            
398
            // Assert that the ParaIdDeregistered event was properly deposited
399
1
            System::assert_last_event(
400
1
                ContainerRegistrarEvent::ParaIdDeregistered {
401
1
                    para_id: 1003.into(),
402
1
                }
403
1
                .into(),
404
1
            );
405
1

            
406
1
            run_to_session(7);
407
1
            end_block();
408
1

            
409
1
            assert_eq!(Runtime::genesis_data(1003.into()).as_ref(), None);
410

            
411
            // Para should be offboarding after 2 sessions.
412
            // we need one more block to trigger the on_initialize of containerRegistrar
413
            // which should fully clean everything
414
1
            start_block();
415
1
            assert!(Paras::lifecycle(1003.into())
416
1
                .expect("para should be offboarding")
417
1
                .is_offboarding());
418
1
        });
419
1
}
420

            
421
#[test]
422
1
fn deregister_two_paras_in_the_same_block() {
423
1
    ExtBuilder::default()
424
1
        .with_para_ids(vec![
425
1
            (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(),
426
1
            (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(),
427
1
        ])
428
1
        .build()
429
1
        .execute_with(|| {
430
1
            // In this test we're gonna check that when calling ContainerRegistrar::deregister(),
431
1
            // two paraIds are properly offboarded from the relay.
432
1

            
433
1
            assert_eq!(Runtime::registered_paras(), vec![1001.into(), 1002.into()]);
434
1
            assert_eq!(Runtime::genesis_data(1003.into()).as_ref(), None);
435
1
            assert_eq!(Runtime::genesis_data(1004.into()).as_ref(), None);
436
1
            assert_eq!(
437
1
                parachains_configuration::ActiveConfig::<Runtime>::get().max_head_data_size,
438
1
                20500
439
1
            );
440

            
441
1
            let validation_code =
442
1
                vec![1u8; cumulus_primitives_core::relay_chain::MIN_CODE_SIZE as usize];
443
1
            let genesis_data_1003_and_1004 = ContainerChainGenesisData {
444
1
                storage: vec![(b":code".to_vec(), validation_code.clone()).into()],
445
1
                name: Default::default(),
446
1
                id: Default::default(),
447
1
                fork_id: Default::default(),
448
1
                extensions: vec![],
449
1
                properties: Default::default(),
450
1
            };
451
1

            
452
1
            // Register paraId 1003
453
1
            assert_ok!(
454
1
                ContainerRegistrar::register(
455
1
                    origin_of(ALICE.into()),
456
1
                    1003.into(),
457
1
                    genesis_data_1003_and_1004.clone(),
458
1
                    Some(HeadData(vec![1u8, 1u8, 1u8]))
459
1
                ),
460
1
                ()
461
1
            );
462

            
463
            // Register paraId 1004
464
1
            assert_ok!(
465
1
                ContainerRegistrar::register(
466
1
                    origin_of(ALICE.into()),
467
1
                    1004.into(),
468
1
                    genesis_data_1003_and_1004.clone(),
469
1
                    Some(HeadData(vec![1u8, 1u8, 1u8]))
470
1
                ),
471
1
                ()
472
1
            );
473

            
474
            // Now let's check if the paras were preoperly registered in the relay.
475
            // Run to next session.
476
1
            run_to_session(1);
477
1
            assert!(Paras::lifecycle(1003.into())
478
1
                .expect("para should be onboarding")
479
1
                .is_onboarding());
480

            
481
1
            assert!(Paras::lifecycle(1004.into())
482
1
                .expect("para should be onboarding")
483
1
                .is_onboarding());
484

            
485
            // We need to accept the validation code, so that paras are onboarded after 2 sessions.
486
1
            assert_ok!(Paras::add_trusted_validation_code(
487
1
                root_origin(),
488
1
                validation_code.into()
489
1
            ));
490

            
491
1
            run_to_session(3);
492
1

            
493
1
            // Now paras should be parathreads.
494
1
            assert!(Paras::lifecycle(1003.into())
495
1
                .expect("para should be parathread")
496
1
                .is_parathread());
497
1
            assert!(Paras::lifecycle(1004.into())
498
1
                .expect("para should be parathread")
499
1
                .is_parathread());
500

            
501
1
            set_dummy_boot_node(origin_of(ALICE.into()), 1003.into());
502
1
            set_dummy_boot_node(origin_of(ALICE.into()), 1004.into());
503
1

            
504
1
            // Call mark_valid_for_collating.
505
1
            assert_ok!(
506
1
                ContainerRegistrar::mark_valid_for_collating(root_origin(), 1003.into()),
507
1
                ()
508
1
            );
509

            
510
1
            assert_ok!(
511
1
                ContainerRegistrar::mark_valid_for_collating(root_origin(), 1004.into()),
512
1
                ()
513
1
            );
514

            
515
            // The change should be applied after 2 sessions.
516
1
            run_to_session(5);
517
1
            assert!(Paras::lifecycle(1003.into())
518
1
                .expect("para should be parachain")
519
1
                .is_parachain());
520

            
521
1
            assert!(Paras::lifecycle(1004.into())
522
1
                .expect("para should be parachain")
523
1
                .is_parachain());
524

            
525
1
            assert_eq!(
526
1
                Runtime::genesis_data(1003.into()).as_ref(),
527
1
                Some(&genesis_data_1003_and_1004)
528
1
            );
529

            
530
1
            assert_eq!(
531
1
                Runtime::genesis_data(1004.into()).as_ref(),
532
1
                Some(&genesis_data_1003_and_1004)
533
1
            );
534

            
535
1
            assert_ok!(ContainerRegistrar::deregister(root_origin(), 1003.into()));
536

            
537
            // Assert that the ParaIdDeregistered event was properly deposited
538
1
            System::assert_last_event(
539
1
                ContainerRegistrarEvent::ParaIdDeregistered {
540
1
                    para_id: 1003.into(),
541
1
                }
542
1
                .into(),
543
1
            );
544
1

            
545
1
            assert_ok!(ContainerRegistrar::deregister(root_origin(), 1004.into()));
546
1
            System::assert_last_event(
547
1
                ContainerRegistrarEvent::ParaIdDeregistered {
548
1
                    para_id: 1004.into(),
549
1
                }
550
1
                .into(),
551
1
            );
552
1

            
553
1
            run_to_session(7);
554
1
            end_block();
555
1

            
556
1
            assert_eq!(Runtime::genesis_data(1003.into()).as_ref(), None);
557
1
            assert_eq!(Runtime::genesis_data(1004.into()).as_ref(), None);
558

            
559
1
            start_block();
560
1
            // Paras should be offboarding after 2 sessions.
561
1
            assert!(Paras::lifecycle(1003.into())
562
1
                .expect("para should be offboarding")
563
1
                .is_offboarding());
564

            
565
1
            assert!(Paras::lifecycle(1004.into())
566
1
                .expect("para should be offboarding")
567
1
                .is_offboarding());
568
1
        });
569
1
}
570

            
571
#[test]
572
1
fn test_register_parathread_not_allowed() {
573
1
    ExtBuilder::default()
574
1
        .with_balances(vec![
575
1
            // Alice gets 10k extra tokens for her mapping deposit
576
1
            (AccountId::from(ALICE), 210_000 * UNIT),
577
1
            (AccountId::from(BOB), 100_000 * UNIT),
578
1
            (AccountId::from(CHARLIE), 100_000 * UNIT),
579
1
            (AccountId::from(DAVE), 100_000 * UNIT),
580
1
        ])
581
1
        .with_collators(vec![
582
1
            (AccountId::from(ALICE), 210 * UNIT),
583
1
            (AccountId::from(BOB), 100 * UNIT),
584
1
            (AccountId::from(CHARLIE), 100 * UNIT),
585
1
            (AccountId::from(DAVE), 100 * UNIT),
586
1
        ])
587
1
        .build()
588
1
        .execute_with(|| {
589
1
            run_to_block(2);
590
1

            
591
1
            assert_noop!(
592
1
                RuntimeCall::ContainerRegistrar(
593
1
                    pallet_registrar::Call::<Runtime>::register_parathread {
594
1
                        para_id: 3001.into(),
595
1
                        slot_frequency: SlotFrequency { min: 1, max: 1 },
596
1
                        genesis_data: empty_genesis_data(),
597
1
                        head_data: None
598
1
                    }
599
1
                )
600
1
                .dispatch(
601
1
                    <Runtime as frame_system::Config>::RuntimeOrigin::signed(AccountId::from(
602
1
                        ALICE
603
1
                    ))
604
1
                ),
605
1
                frame_system::Error::<Runtime>::CallFiltered
606
1
            );
607
1
        });
608
1
}
609

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

            
630
1
            let validation_code =
631
1
                vec![1u8; cumulus_primitives_core::relay_chain::MIN_CODE_SIZE as usize];
632
1

            
633
1
            assert_noop!(
634
1
                RuntimeCall::Registrar(paras_registrar::Call::<Runtime>::register {
635
1
                    id: 3001.into(),
636
1
                    validation_code: cumulus_primitives_core::relay_chain::ValidationCode(
637
1
                        validation_code
638
1
                    ),
639
1
                    genesis_head: HeadData(vec![1u8, 1u8, 1u8]),
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_deregister_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
            assert_noop!(
672
1
                RuntimeCall::Registrar(paras_registrar::Call::<Runtime>::deregister {
673
1
                    id: 3001.into()
674
1
                })
675
1
                .dispatch(
676
1
                    <Runtime as frame_system::Config>::RuntimeOrigin::signed(AccountId::from(
677
1
                        ALICE
678
1
                    ))
679
1
                ),
680
1
                frame_system::Error::<Runtime>::CallFiltered
681
1
            );
682
1
        });
683
1
}