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
    dancelight_emulated_chain::Dancelight,
21
    frame_support::parameter_types,
22
    frontier_template_emulated_chain::FrontierTemplate,
23
    simple_template_emulated_chain::SimpleTemplate,
24
    sp_keyring::Sr25519Keyring,
25
    tanssi_emulated_integration_tests_common::accounts::{BOB, RANDOM},
26
    xcm_emulator::{
27
        decl_test_networks, Bridge, BridgeLaneId, BridgeMessage, BridgeMessageDispatchError,
28
        BridgeMessageHandler, Chain, Network,
29
    },
30
};
31

            
32
pub struct DancelightEthMockBridge;
33
impl Bridge for DancelightEthMockBridge {
34
    type Source = DancelightRelay;
35
    type Target = ();
36
    type Handler = DancelightEthMockBridgeHandler;
37

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

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

            
54
parameter_types! {
55
    // Dancelight
56
    pub DancelightSender: AccountId = Sr25519Keyring::Alice.to_account_id();
57
    pub DancelightReceiver: AccountId = Sr25519Keyring::Bob.to_account_id();
58
    pub DancelightEmptyReceiver: AccountId = DancelightRelay::account_id_of(RANDOM);
59

            
60
     // FrontierTemplate
61
     pub FrontierTemplateSender: AccountId = Sr25519Keyring::Alice.to_account_id();
62
     pub FrontierTemplateReceiver: AccountId = AccountId::from(BOB);
63
     pub FrontierTemplateEmptyReceiver: AccountId = FrontierTemplatePara::account_id_of(RANDOM);
64

            
65
    // SimpleTemplate
66
    pub SimpleTemplateSender: AccountId = Sr25519Keyring::Alice.to_account_id();
67
    pub SimpleTemplateReceiver: AccountId = AccountId::from(BOB);
68
    pub SimpleTemplateEmptyReceiver: AccountId = SimpleTemplatePara::account_id_of(RANDOM);
69
}
70

            
71
pub struct DancelightEthMockBridgeHandler;
72
impl BridgeMessageHandler for DancelightEthMockBridgeHandler {
73
46
    fn get_source_outbound_messages() -> Vec<BridgeMessage> {
74
        // Get messages from the outbound queue
75
46
        let msgs = DancelightRelay::ext_wrapper(|| {
76
46
            snowbridge_pallet_outbound_queue::Messages::<<DancelightRelay as Chain>::Runtime>::get()
77
46
        });
78

            
79
        // Store messages in our static mock buffer
80
46
        tanssi_emulated_integration_tests_common::impls::ETH_BRIDGE_SENT_MSGS.with(|sent_msgs| {
81
46
            sent_msgs.borrow_mut().extend(msgs.clone());
82
46
        });
83

            
84
        // TODO: We don't check the dispatches messages from the bridge so it's fine to return default value here
85
46
        Default::default()
86
46
    }
87

            
88
    fn dispatch_target_inbound_message(
89
        _message: BridgeMessage,
90
    ) -> Result<(), BridgeMessageDispatchError> {
91
        unimplemented!("dispatch_target_inbound_message")
92
    }
93

            
94
    fn notify_source_message_delivery(_lane_id: BridgeLaneId) {
95
        unimplemented!("notify_source_message_delivery")
96
    }
97
}