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
pub use xcm_emulator::{bx, TestExt};
18
use {
19
    container_chain_template_simple_runtime::AccountId,
20
    frame_support::parameter_types,
21
    frontier_template_emulated_chain::FrontierTemplate,
22
    simple_template_emulated_chain::SimpleTemplate,
23
    sp_keyring::Sr25519Keyring,
24
    starlight_emulated_chain::Starlight,
25
    tanssi_emulated_integration_tests_common,
26
    tanssi_emulated_integration_tests_common::accounts::{ALICE, BOB, RANDOM},
27
    xcm_emulator::{
28
        decl_test_networks, Bridge, BridgeLaneId, BridgeMessage, BridgeMessageDispatchError,
29
        BridgeMessageHandler, Chain, Network,
30
    },
31
};
32

            
33
pub struct StarlightEthMockBridge;
34
impl Bridge for StarlightEthMockBridge {
35
    type Source = StarlightRelay;
36
    type Target = ();
37
    type Handler = StarlightEthMockBridgeHandler;
38

            
39
2
    fn init() {
40
2
        <StarlightRelay as Chain>::Network::init();
41
2
    }
42
}
43

            
44
decl_test_networks! {
45
    pub struct StarlightMockNet {
46
        relay_chain = Starlight,
47
        parachains = vec![
48
            FrontierTemplate,
49
            SimpleTemplate,
50
        ],
51
        bridge = StarlightEthMockBridge
52
    }
53
}
54

            
55
parameter_types! {
56
    // Starlight
57
    pub StarlightSender: AccountId = Sr25519Keyring::Alice.to_account_id();
58
    pub StarlightReceiver: AccountId = Sr25519Keyring::Bob.to_account_id();
59
    pub StarlightEmptyReceiver: AccountId = StarlightRelay::account_id_of(RANDOM);
60

            
61
    // SimpleTemplate
62
    pub SimpleTemplateSender: AccountId = AccountId::from(ALICE);
63
    pub SimpleTemplateReceiver: AccountId = AccountId::from(BOB);
64
    pub SimpleTemplateEmptyReceiver: AccountId = SimpleTemplatePara::account_id_of(RANDOM);
65
}
66

            
67
pub struct StarlightEthMockBridgeHandler;
68
impl BridgeMessageHandler for StarlightEthMockBridgeHandler {
69
6
    fn get_source_outbound_messages() -> Vec<BridgeMessage> {
70
6
        // Get messages from the outbound queue
71
6
        let msgs = StarlightRelay::ext_wrapper(|| {
72
6
            snowbridge_pallet_outbound_queue::Messages::<<StarlightRelay as Chain>::Runtime>::get()
73
6
        });
74
6

            
75
6
        // Store messages in our static mock buffer
76
6
        tanssi_emulated_integration_tests_common::impls::ETH_BRIDGE_SENT_MSGS.with(|sent_msgs| {
77
6
            sent_msgs.borrow_mut().extend(msgs.clone());
78
6
        });
79
6

            
80
6
        // TODO: We don't check the dispatches messages from the bridge so it's fine to return default value here
81
6
        Default::default()
82
6
    }
83

            
84
    fn dispatch_target_inbound_message(
85
        _message: BridgeMessage,
86
    ) -> Result<(), BridgeMessageDispatchError> {
87
        unimplemented!("dispatch_target_inbound_message")
88
    }
89

            
90
    fn notify_source_message_delivery(_lane_id: BridgeLaneId) {
91
        unimplemented!("notify_source_message_delivery")
92
    }
93
}