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
use {
18
    cumulus_primitives_core::relay_chain::{
19
        AssignmentId, AuthorityDiscoveryId, BlockNumber, ValidatorId,
20
    },
21
    emulated_integration_tests_common::build_genesis_storage,
22
    polkadot_parachain_primitives::primitives::ValidationCode,
23
    rococo_runtime_constants::currency::UNITS as ROC,
24
    runtime_parachains::{
25
        configuration::HostConfiguration,
26
        paras::{ParaGenesisArgs, ParaKind},
27
    },
28
    sc_consensus_grandpa::AuthorityId as GrandpaId,
29
    sp_consensus_babe::AuthorityId as BabeId,
30
    sp_consensus_beefy::{ecdsa_crypto::AuthorityId as BeefyId, test_utils::Keyring},
31
    sp_core::storage::Storage,
32
    tanssi_emulated_integration_tests_common::{accounts, validators},
33
};
34
const ENDOWMENT: u128 = 1_000_000 * ROC;
35

            
36
48
pub fn get_host_config() -> HostConfiguration<BlockNumber> {
37
48
    HostConfiguration {
38
48
        max_upward_queue_count: 10,
39
48
        max_upward_queue_size: 51200,
40
48
        max_upward_message_size: 51200,
41
48
        max_upward_message_num_per_candidate: 10,
42
48
        max_downward_message_size: 51200,
43
48
        ..Default::default()
44
48
    }
45
48
}
46

            
47
48
fn session_keys(
48
48
    babe: BabeId,
49
48
    grandpa: GrandpaId,
50
48
    para_validator: ValidatorId,
51
48
    para_assignment: AssignmentId,
52
48
    authority_discovery: AuthorityDiscoveryId,
53
48
    beefy: BeefyId,
54
48
) -> rococo_runtime::SessionKeys {
55
48
    rococo_runtime::SessionKeys {
56
48
        babe,
57
48
        grandpa,
58
48
        para_validator,
59
48
        para_assignment,
60
48
        authority_discovery,
61
48
        beefy,
62
48
    }
63
48
}
64

            
65
48
pub fn genesis() -> Storage {
66
48
    let genesis_config = rococo_runtime::RuntimeGenesisConfig {
67
48
        balances: rococo_runtime::BalancesConfig {
68
48
            balances: accounts::init_balances()
69
48
                .iter()
70
48
                .cloned()
71
576
                .map(|k| (k, ENDOWMENT))
72
48
                .collect(),
73
48
        },
74
48
        session: rococo_runtime::SessionConfig {
75
48
            keys: validators::initial_authorities()
76
48
                .iter()
77
48
                .map(|x| {
78
48
                    (
79
48
                        x.0.clone(),
80
48
                        x.0.clone(),
81
48
                        session_keys(
82
48
                            x.2.clone(),
83
48
                            x.3.clone(),
84
48
                            x.4.clone(),
85
48
                            x.5.clone(),
86
48
                            x.6.clone(),
87
48
                            BeefyId::from(Keyring::<BeefyId>::Alice.public()),
88
48
                        ),
89
48
                    )
90
48
                })
91
48
                .collect::<Vec<_>>(),
92
48
            ..Default::default()
93
48
        },
94
48
        babe: rococo_runtime::BabeConfig {
95
48
            authorities: Default::default(),
96
48
            epoch_config: rococo_runtime::BABE_GENESIS_EPOCH_CONFIG,
97
48
            ..Default::default()
98
48
        },
99
48
        configuration: rococo_runtime::ConfigurationConfig {
100
48
            config: get_host_config(),
101
48
        },
102
48
        paras: rococo_runtime::ParasConfig {
103
48
            _config: Default::default(),
104
48
            paras: vec![(
105
48
                3333.into(),
106
48
                ParaGenesisArgs {
107
48
                    genesis_head: Default::default(),
108
48
                    validation_code: ValidationCode(vec![1, 1, 2, 3, 4]),
109
48
                    para_kind: ParaKind::Parathread,
110
48
                },
111
48
            )],
112
48
        },
113
48
        ..Default::default()
114
48
    };
115
48
    build_genesis_storage(&genesis_config, rococo_runtime::WASM_BINARY.unwrap())
116
48
}