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
//! Generate mocked values of relay chain storage, for dev tests
18

            
19
use {
20
    dp_core::{well_known_keys::REGISTRAR_PARAS_INDEX, ParaInfo},
21
    frame_support::Hashable,
22
    sp_core::{ed25519, Pair},
23
    tc_consensus::{Encode, ParaId},
24
};
25

            
26
7810
pub fn get_mocked_registrar_paras(para_id: ParaId) -> (Vec<u8>, Vec<u8>) {
27
7810
    let bytes = para_id.twox_64_concat();
28
7810

            
29
7810
    let pairs = get_ed25519_pairs(1);
30
7810
    //panic!("relay manager private key: {:?}", pairs[0].seed());
31
7810
    let registrar_paras_key = [REGISTRAR_PARAS_INDEX, bytes.as_slice()].concat();
32
7810
    let para_info: ParaInfo<
33
7810
        cumulus_primitives_core::relay_chain::AccountId,
34
7810
        cumulus_primitives_core::relay_chain::Balance,
35
7810
    > = ParaInfo {
36
7810
        manager: pairs[0].public().into(),
37
7810
        deposit: Default::default(),
38
7810
        locked: None,
39
7810
    };
40
7810

            
41
7810
    (registrar_paras_key, para_info.encode())
42
7810
}
43

            
44
7810
pub fn get_ed25519_pairs(num: u32) -> Vec<ed25519::Pair> {
45
7810
    let seed: u128 = 12345678901234567890123456789012;
46
7810
    let mut pairs = Vec::new();
47
7810
    for i in 0..num {
48
7810
        pairs.push(ed25519::Pair::from_seed(
49
7810
            (seed + u128::from(i))
50
7810
                .to_string()
51
7810
                .as_bytes()
52
7810
                .try_into()
53
7810
                .unwrap(),
54
7810
        ))
55
    }
56
7810
    pairs
57
7810
}