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::accounts::{ALICE, BOB, RANDOM},
26
    xcm_emulator::{
27
        decl_test_networks, Bridge, BridgeLaneId, BridgeMessage, BridgeMessageDispatchError,
28
        BridgeMessageHandler, Chain, Network,
29
    },
30
};
31

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

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

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

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

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

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

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

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

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

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