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
    babe_primitives::AuthorityId as BabeId,
19
    cumulus_primitives_core::relay_chain::{
20
        AccountId, AssignmentId, AuthorityDiscoveryId, ValidatorId,
21
    },
22
    frame_support::traits::OnIdle,
23
    frame_system::Pallet as SystemPallet,
24
    sc_consensus_grandpa::AuthorityId as GrandpaId,
25
    sp_core::{crypto::get_public_from_string_or_panic, sr25519},
26
    sp_weights::Weight,
27
    xcm_emulator::{Parachain, RelayChain},
28
};
29

            
30
pub mod accounts;
31
pub mod impls;
32
pub mod snowbridge;
33
pub mod validators;
34

            
35
2
pub fn force_process_bridge<R, P>(weight: Weight)
36
2
where
37
2
    R: RelayChain,
38
2
    P: Parachain<Network = R::Network>,
39
2
    R::Runtime: pallet_message_queue::Config,
40
2
{
41
2
    // Process MessageQueue on relay chain to consume the message we want to send to eth
42
2
    R::execute_with(|| {
43
2
        <pallet_message_queue::Pallet<R::Runtime>>::on_idle(
44
2
            SystemPallet::<R::Runtime>::block_number(),
45
2
            weight,
46
2
        );
47
2
    });
48
2

            
49
2
    // Execute empty block in parachain to trigger bridge message
50
2
    P::execute_with(|| {});
51
2
}
52

            
53
/// Helper function to generate stash, controller and session key from seed
54
4200
pub fn get_authority_keys_from_seed_no_beefy(
55
4200
    seed: &str,
56
4200
) -> (
57
4200
    AccountId,
58
4200
    AccountId,
59
4200
    BabeId,
60
4200
    GrandpaId,
61
4200
    ValidatorId,
62
4200
    AssignmentId,
63
4200
    AuthorityDiscoveryId,
64
4200
) {
65
4200
    (
66
4200
        get_public_from_string_or_panic::<sr25519::Public>(&format!("{}//stash", seed)).into(),
67
4200
        get_public_from_string_or_panic::<sr25519::Public>(seed).into(),
68
4200
        get_public_from_string_or_panic::<BabeId>(seed),
69
4200
        get_public_from_string_or_panic::<GrandpaId>(seed),
70
4200
        get_public_from_string_or_panic::<ValidatorId>(seed),
71
4200
        get_public_from_string_or_panic::<AssignmentId>(seed),
72
4200
        get_public_from_string_or_panic::<AuthorityDiscoveryId>(seed),
73
4200
    )
74
4200
}