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
    crate as container_chain_template_frontier_runtime,
19
    crate::{
20
        AccountId, EVMChainIdConfig, EVMConfig, MaintenanceModeConfig, MigrationsConfig,
21
        PolkadotXcmConfig, Precompiles,
22
    },
23
    alloc::{vec, vec::Vec},
24
    cumulus_primitives_core::ParaId,
25
    fp_evm::GenesisAccount,
26
    hex_literal::hex,
27
};
28

            
29
/// Orcherstrator's parachain id
30
pub const ORCHESTRATOR: ParaId = ParaId::new(1000);
31

            
32
pub fn local(
33
    endowed_accounts: Vec<AccountId>,
34
    id: ParaId,
35
    root_key: AccountId,
36
) -> serde_json::Value {
37
    testnet_genesis(endowed_accounts, id, root_key)
38
}
39

            
40
2
pub fn development(
41
2
    endowed_accounts: Vec<AccountId>,
42
2
    id: ParaId,
43
2
    root_key: AccountId,
44
2
) -> serde_json::Value {
45
2
    testnet_genesis(endowed_accounts, id, root_key)
46
2
}
47

            
48
2
fn testnet_genesis(
49
2
    endowed_accounts: Vec<AccountId>,
50
2
    id: ParaId,
51
2
    root_key: AccountId,
52
2
) -> serde_json::Value {
53
    // This is the simplest bytecode to revert without returning any data.
54
    // We will pre-deploy it under all of our precompiles to ensure they can be called from
55
    // within contracts.
56
    // (PUSH1 0x00 PUSH1 0x00 REVERT)
57
2
    let revert_bytecode = vec![0x60, 0x00, 0x60, 0x00, 0xFD];
58

            
59
2
    let g = container_chain_template_frontier_runtime::RuntimeGenesisConfig {
60
2
        system: Default::default(),
61
        balances: container_chain_template_frontier_runtime::BalancesConfig {
62
2
            balances: endowed_accounts
63
2
                .iter()
64
2
                .cloned()
65
8
                .map(|k| (k, 1 << 80))
66
2
                .collect(),
67
2
            ..Default::default()
68
        },
69
2
        parachain_info: container_chain_template_frontier_runtime::ParachainInfoConfig {
70
2
            parachain_id: id,
71
2
            ..Default::default()
72
2
        },
73
2
        parachain_system: Default::default(),
74
        // EVM compatibility
75
        // We should change this to something different than Moonbeam
76
        // For now moonwall is very tailored for moonbeam so we need it for tests
77
2
        evm_chain_id: EVMChainIdConfig {
78
2
            chain_id: 1281,
79
2
            ..Default::default()
80
2
        },
81
        evm: EVMConfig {
82
            // We need _some_ code inserted at the precompile address so that
83
            // the evm will actually call the address.
84
2
            accounts: Precompiles::used_addresses()
85
26
                .map(|addr| {
86
26
                    (
87
26
                        addr.into(),
88
26
                        GenesisAccount {
89
26
                            nonce: Default::default(),
90
26
                            balance: Default::default(),
91
26
                            storage: Default::default(),
92
26
                            code: revert_bytecode.clone(),
93
26
                        },
94
26
                    )
95
26
                })
96
2
                .collect(),
97
2
            ..Default::default()
98
        },
99
2
        ethereum: Default::default(),
100
2
        base_fee: Default::default(),
101
2
        transaction_payment: Default::default(),
102
2
        sudo: container_chain_template_frontier_runtime::SudoConfig {
103
2
            key: Some(root_key),
104
2
        },
105
2
        authorities_noting: container_chain_template_frontier_runtime::AuthoritiesNotingConfig {
106
2
            orchestrator_para_id: ORCHESTRATOR,
107
2
            ..Default::default()
108
2
        },
109
2
        migrations: MigrationsConfig {
110
2
            ..Default::default()
111
2
        },
112
2
        maintenance_mode: MaintenanceModeConfig {
113
2
            start_in_maintenance_mode: false,
114
2
            ..Default::default()
115
2
        },
116
        // This should initialize it to whatever we have set in the pallet
117
2
        polkadot_xcm: PolkadotXcmConfig::default(),
118
2
        tx_pause: Default::default(),
119
    };
120

            
121
2
    serde_json::to_value(g).unwrap()
122
2
}
123

            
124
/// Get pre-funded accounts
125
2
pub fn pre_funded_accounts() -> Vec<AccountId> {
126
    // These addresses are derived from Substrate's canonical mnemonic:
127
    // bottom drive obey lake curtain smoke basket hold race lonely fit walk
128
2
    vec![
129
2
        AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), // Alith
130
2
        AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), // Baltathar
131
2
        AccountId::from(hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")), // Charleth
132
2
        AccountId::from(hex!("773539d4Ac0e786233D90A233654ccEE26a613D9")), // Dorothy
133
    ]
134
2
}