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
#![cfg(test)]
18

            
19
use {
20
    crate::{tests::common::*, EthereumSystem},
21
    frame_support::assert_noop,
22
    pallet_xcm::Origin as XcmOrigin,
23
    snowbridge_core::outbound::OperatingMode,
24
    sp_core::H160,
25
    sp_runtime::DispatchError::BadOrigin,
26
    sp_std::vec,
27
    xcm::latest::{Junction::Parachain, Location},
28
};
29

            
30
#[test]
31
1
fn test_create_agent_not_allowed() {
32
1
    ExtBuilder::default()
33
1
        .with_balances(vec![(AccountId::from(ALICE), 210_000 * UNIT)])
34
1
        .build()
35
1
        .execute_with(|| {
36
1
            let sibling_para_location = Location::new(1, [Parachain(2000)]);
37
1

            
38
1
            // create_agent is disabled for sibling parachains
39
1
            assert_noop!(
40
1
                EthereumSystem::create_agent(XcmOrigin::Xcm(sibling_para_location).into()),
41
1
                BadOrigin
42
1
            );
43

            
44
1
            let relay_location = Location::new(1, []);
45
1

            
46
1
            // create_agent also disabled for relay origin
47
1
            assert_noop!(
48
1
                EthereumSystem::create_agent(XcmOrigin::Xcm(relay_location).into()),
49
1
                BadOrigin
50
1
            );
51

            
52
            // create_agent is disabled for signed origins
53
1
            assert_noop!(
54
1
                EthereumSystem::create_agent(
55
1
                    <Runtime as frame_system::Config>::RuntimeOrigin::signed(AccountId::from(
56
1
                        ALICE
57
1
                    ))
58
1
                ),
59
1
                BadOrigin
60
1
            );
61

            
62
            // create_agent is disabled for root
63
1
            assert_noop!(
64
1
                EthereumSystem::create_agent(
65
1
                    <Runtime as frame_system::Config>::RuntimeOrigin::root()
66
1
                ),
67
1
                BadOrigin
68
1
            );
69
1
        })
70
1
}
71

            
72
#[test]
73
1
fn test_create_channel_not_allowed() {
74
1
    ExtBuilder::default()
75
1
        .with_balances(vec![(AccountId::from(ALICE), 210_000 * UNIT)])
76
1
        .build()
77
1
        .execute_with(|| {
78
1
            let sibling_para_location = Location::new(1, [Parachain(2000)]);
79
1

            
80
1
            // create_channel is disabled for sibling parachains
81
1
            assert_noop!(
82
1
                EthereumSystem::create_channel(
83
1
                    XcmOrigin::Xcm(sibling_para_location).into(),
84
1
                    OperatingMode::Normal
85
1
                ),
86
1
                BadOrigin
87
1
            );
88

            
89
1
            let relay_location = Location::new(1, []);
90
1

            
91
1
            // create_channel also disabled for relay origin
92
1
            assert_noop!(
93
1
                EthereumSystem::create_channel(
94
1
                    XcmOrigin::Xcm(relay_location).into(),
95
1
                    OperatingMode::Normal
96
1
                ),
97
1
                BadOrigin
98
1
            );
99

            
100
            // create_channel is disabled for signed origins
101
1
            assert_noop!(
102
1
                EthereumSystem::create_channel(
103
1
                    <Runtime as frame_system::Config>::RuntimeOrigin::signed(AccountId::from(
104
1
                        ALICE
105
1
                    )),
106
1
                    OperatingMode::Normal
107
1
                ),
108
1
                BadOrigin
109
1
            );
110

            
111
            // create_channel is disabled for root
112
1
            assert_noop!(
113
1
                EthereumSystem::create_channel(
114
1
                    <Runtime as frame_system::Config>::RuntimeOrigin::root(),
115
1
                    OperatingMode::Normal
116
1
                ),
117
1
                BadOrigin
118
1
            );
119
1
        })
120
1
}
121

            
122
#[test]
123
1
fn test_update_channel_not_allowed() {
124
1
    ExtBuilder::default()
125
1
        .with_balances(vec![(AccountId::from(ALICE), 210_000 * UNIT)])
126
1
        .build()
127
1
        .execute_with(|| {
128
1
            let sibling_para_location = Location::new(1, [Parachain(2000)]);
129
1

            
130
1
            // update_channel is disabled for sibling parachains
131
1
            assert_noop!(
132
1
                EthereumSystem::update_channel(
133
1
                    XcmOrigin::Xcm(sibling_para_location).into(),
134
1
                    OperatingMode::Normal
135
1
                ),
136
1
                BadOrigin
137
1
            );
138

            
139
1
            let relay_location = Location::new(1, []);
140
1

            
141
1
            // update_channel also disabled for relay origin
142
1
            assert_noop!(
143
1
                EthereumSystem::update_channel(
144
1
                    XcmOrigin::Xcm(relay_location).into(),
145
1
                    OperatingMode::Normal
146
1
                ),
147
1
                BadOrigin
148
1
            );
149

            
150
            // update_channel is disabled for signed origins
151
1
            assert_noop!(
152
1
                EthereumSystem::update_channel(
153
1
                    <Runtime as frame_system::Config>::RuntimeOrigin::signed(AccountId::from(
154
1
                        ALICE
155
1
                    )),
156
1
                    OperatingMode::Normal
157
1
                ),
158
1
                BadOrigin
159
1
            );
160

            
161
            // update_channel is disabled for root
162
1
            assert_noop!(
163
1
                EthereumSystem::update_channel(
164
1
                    <Runtime as frame_system::Config>::RuntimeOrigin::root(),
165
1
                    OperatingMode::Normal
166
1
                ),
167
1
                BadOrigin
168
1
            );
169
1
        })
170
1
}
171

            
172
#[test]
173
1
fn test_transfer_native_from_agent_not_allowed() {
174
1
    ExtBuilder::default()
175
1
        .with_balances(vec![(AccountId::from(ALICE), 210_000 * UNIT)])
176
1
        .build()
177
1
        .execute_with(|| {
178
1
            let sibling_para_location = Location::new(1, [Parachain(2000)]);
179
1

            
180
1
            // transfer_native_from_agent is disabled for sibling parachains
181
1
            assert_noop!(
182
1
                EthereumSystem::transfer_native_from_agent(
183
1
                    XcmOrigin::Xcm(sibling_para_location).into(),
184
1
                    H160::default(),
185
1
                    1000u128
186
1
                ),
187
1
                BadOrigin
188
1
            );
189

            
190
1
            let relay_location = Location::new(1, []);
191
1

            
192
1
            // transfer_native_from_agent also disabled for relay origin
193
1
            assert_noop!(
194
1
                EthereumSystem::transfer_native_from_agent(
195
1
                    XcmOrigin::Xcm(relay_location).into(),
196
1
                    H160::default(),
197
1
                    1000u128
198
1
                ),
199
1
                BadOrigin
200
1
            );
201

            
202
            // transfer_native_from_agent is disabled for signed origins
203
1
            assert_noop!(
204
1
                EthereumSystem::transfer_native_from_agent(
205
1
                    <Runtime as frame_system::Config>::RuntimeOrigin::signed(AccountId::from(
206
1
                        ALICE
207
1
                    )),
208
1
                    H160::default(),
209
1
                    1000u128
210
1
                ),
211
1
                BadOrigin
212
1
            );
213

            
214
            // transfer_native_from_agent is disabled for root
215
1
            assert_noop!(
216
1
                EthereumSystem::transfer_native_from_agent(
217
1
                    <Runtime as frame_system::Config>::RuntimeOrigin::root(),
218
1
                    H160::default(),
219
1
                    1000u128
220
1
                ),
221
1
                BadOrigin
222
1
            );
223
1
        })
224
1
}