Newer
Older
// Copyright (C) Parity Technologies (UK) Ltd.
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// This file is part of Polkadot.
// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use super::*;
#[test]
fn take_weight_credit_barrier_should_work() {
let mut message =
Xcm::<()>(vec![TransferAsset { assets: (Parent, 100).into(), beneficiary: Here.into() }]);
let mut weight_credit = Weight::from_parts(10, 10);
let r = TakeWeightCredit::should_execute(
&Parent.into(),
message.inner_mut(),
Weight::from_parts(10, 10),
&mut weight_credit,
);
assert_eq!(r, Ok(()));
assert_eq!(weight_credit, Weight::zero());
let r = TakeWeightCredit::should_execute(
&Parent.into(),
message.inner_mut(),
Weight::from_parts(10, 10),
&mut weight_credit,
);
assert_eq!(r, Err(ProcessMessageError::Overweight(Weight::from_parts(10, 10))));
assert_eq!(weight_credit, Weight::zero());
}
#[test]
fn computed_origin_should_work() {
let mut message = Xcm::<()>(vec![
UniversalOrigin(GlobalConsensus(Kusama)),
DescendOrigin(Parachain(100).into()),
DescendOrigin(PalletInstance(69).into()),
WithdrawAsset((Parent, 100).into()),
BuyExecution {
fees: (Parent, 100).into(),
weight_limit: Limited(Weight::from_parts(100, 100)),
},
TransferAsset { assets: (Parent, 100).into(), beneficiary: Here.into() },
]);
AllowPaidFrom::set(vec![(
Parent,
Parent,
GlobalConsensus(Kusama),
Parachain(100),
PalletInstance(69),
)
.into()]);
let r = AllowTopLevelPaidExecutionFrom::<IsInVec<AllowPaidFrom>>::should_execute(
&Parent.into(),
message.inner_mut(),
Weight::from_parts(100, 100),
&mut Weight::zero(),
);
assert_eq!(r, Err(ProcessMessageError::Unsupported));
let r = WithComputedOrigin::<
AllowTopLevelPaidExecutionFrom<IsInVec<AllowPaidFrom>>,
ExecutorUniversalLocation,
ConstU32<2>,
>::should_execute(
&Parent.into(),
message.inner_mut(),
Weight::from_parts(100, 100),
&mut Weight::zero(),
);
assert_eq!(r, Err(ProcessMessageError::Unsupported));
let r = WithComputedOrigin::<
AllowTopLevelPaidExecutionFrom<IsInVec<AllowPaidFrom>>,
ExecutorUniversalLocation,
ConstU32<5>,
>::should_execute(
&Parent.into(),
message.inner_mut(),
Weight::from_parts(100, 100),
&mut Weight::zero(),
);
assert_eq!(r, Ok(()));
}
#[test]
fn allow_unpaid_should_work() {
let mut message =
Xcm::<()>(vec![TransferAsset { assets: (Parent, 100).into(), beneficiary: Here.into() }]);
AllowUnpaidFrom::set(vec![Parent.into()]);
let r = AllowUnpaidExecutionFrom::<IsInVec<AllowUnpaidFrom>>::should_execute(
&Parachain(1).into(),
message.inner_mut(),
Weight::from_parts(10, 10),
&mut Weight::zero(),
);
assert_eq!(r, Err(ProcessMessageError::Unsupported));
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
let r = AllowUnpaidExecutionFrom::<IsInVec<AllowUnpaidFrom>>::should_execute(
&Parent.into(),
message.inner_mut(),
Weight::from_parts(10, 10),
&mut Weight::zero(),
);
assert_eq!(r, Ok(()));
}
#[test]
fn allow_explicit_unpaid_should_work() {
let mut bad_message1 =
Xcm::<()>(vec![TransferAsset { assets: (Parent, 100).into(), beneficiary: Here.into() }]);
let mut bad_message2 = Xcm::<()>(vec![
UnpaidExecution {
weight_limit: Limited(Weight::from_parts(10, 10)),
check_origin: Some(Parent.into()),
},
TransferAsset { assets: (Parent, 100).into(), beneficiary: Here.into() },
]);
let mut good_message = Xcm::<()>(vec![
UnpaidExecution {
weight_limit: Limited(Weight::from_parts(20, 20)),
check_origin: Some(Parent.into()),
},
TransferAsset { assets: (Parent, 100).into(), beneficiary: Here.into() },
]);
AllowExplicitUnpaidFrom::set(vec![Parent.into()]);
let r = AllowExplicitUnpaidExecutionFrom::<IsInVec<AllowExplicitUnpaidFrom>>::should_execute(
&Parachain(1).into(),
good_message.inner_mut(),
Weight::from_parts(20, 20),
&mut Weight::zero(),
);
assert_eq!(r, Err(ProcessMessageError::Unsupported));
let r = AllowExplicitUnpaidExecutionFrom::<IsInVec<AllowExplicitUnpaidFrom>>::should_execute(
&Parent.into(),
bad_message1.inner_mut(),
Weight::from_parts(20, 20),
&mut Weight::zero(),
);
assert_eq!(r, Err(ProcessMessageError::Overweight(Weight::from_parts(20, 20))));
let r = AllowExplicitUnpaidExecutionFrom::<IsInVec<AllowExplicitUnpaidFrom>>::should_execute(
&Parent.into(),
bad_message2.inner_mut(),
Weight::from_parts(20, 20),
&mut Weight::zero(),
);
assert_eq!(r, Err(ProcessMessageError::Overweight(Weight::from_parts(20, 20))));
let r = AllowExplicitUnpaidExecutionFrom::<IsInVec<AllowExplicitUnpaidFrom>>::should_execute(
&Parent.into(),
good_message.inner_mut(),
Weight::from_parts(20, 20),
&mut Weight::zero(),
);
assert_eq!(r, Ok(()));
let mut message_with_different_weight_parts = Xcm::<()>(vec![
UnpaidExecution {
weight_limit: Limited(Weight::from_parts(20, 10)),
check_origin: Some(Parent.into()),
},
TransferAsset { assets: (Parent, 100).into(), beneficiary: Here.into() },
]);
let r = AllowExplicitUnpaidExecutionFrom::<IsInVec<AllowExplicitUnpaidFrom>>::should_execute(
&Parent.into(),
message_with_different_weight_parts.inner_mut(),
Weight::from_parts(20, 20),
&mut Weight::zero(),
);
assert_eq!(r, Err(ProcessMessageError::Overweight(Weight::from_parts(20, 20))));
let r = AllowExplicitUnpaidExecutionFrom::<IsInVec<AllowExplicitUnpaidFrom>>::should_execute(
&Parent.into(),
message_with_different_weight_parts.inner_mut(),
Weight::from_parts(10, 10),
&mut Weight::zero(),
);
assert_eq!(r, Ok(()));
}
#[test]
fn allow_paid_should_work() {
AllowPaidFrom::set(vec![Parent.into()]);
let mut message =
Xcm::<()>(vec![TransferAsset { assets: (Parent, 100).into(), beneficiary: Here.into() }]);
let r = AllowTopLevelPaidExecutionFrom::<IsInVec<AllowPaidFrom>>::should_execute(
&Parachain(1).into(),
message.inner_mut(),
Weight::from_parts(10, 10),
&mut Weight::zero(),
);
assert_eq!(r, Err(ProcessMessageError::Unsupported));
let fees = (Parent, 1).into();
let mut underpaying_message = Xcm::<()>(vec![
ReserveAssetDeposited((Parent, 100).into()),
BuyExecution { fees, weight_limit: Limited(Weight::from_parts(20, 20)) },
DepositAsset { assets: AllCounted(1).into(), beneficiary: Here.into() },
]);
let r = AllowTopLevelPaidExecutionFrom::<IsInVec<AllowPaidFrom>>::should_execute(
&Parent.into(),
underpaying_message.inner_mut(),
Weight::from_parts(30, 30),
&mut Weight::zero(),
);
assert_eq!(r, Err(ProcessMessageError::Overweight(Weight::from_parts(30, 30))));
let fees = (Parent, 1).into();
let mut paying_message = Xcm::<()>(vec![
ReserveAssetDeposited((Parent, 100).into()),
BuyExecution { fees, weight_limit: Limited(Weight::from_parts(30, 30)) },
DepositAsset { assets: AllCounted(1).into(), beneficiary: Here.into() },
]);
let r = AllowTopLevelPaidExecutionFrom::<IsInVec<AllowPaidFrom>>::should_execute(
&Parachain(1).into(),
paying_message.inner_mut(),
Weight::from_parts(30, 30),
&mut Weight::zero(),
);
assert_eq!(r, Err(ProcessMessageError::Unsupported));
let r = AllowTopLevelPaidExecutionFrom::<IsInVec<AllowPaidFrom>>::should_execute(
&Parent.into(),
paying_message.inner_mut(),
Weight::from_parts(30, 30),
&mut Weight::zero(),
);
assert_eq!(r, Ok(()));
let fees = (Parent, 1).into();
let mut paying_message_with_different_weight_parts = Xcm::<()>(vec![
WithdrawAsset((Parent, 100).into()),
BuyExecution { fees, weight_limit: Limited(Weight::from_parts(20, 10)) },
DepositAsset { assets: AllCounted(1).into(), beneficiary: Here.into() },
]);
let r = AllowTopLevelPaidExecutionFrom::<IsInVec<AllowPaidFrom>>::should_execute(
&Parent.into(),
paying_message_with_different_weight_parts.inner_mut(),
Weight::from_parts(20, 20),
&mut Weight::zero(),
);
assert_eq!(r, Err(ProcessMessageError::Overweight(Weight::from_parts(20, 20))));
let r = AllowTopLevelPaidExecutionFrom::<IsInVec<AllowPaidFrom>>::should_execute(
&Parent.into(),
paying_message_with_different_weight_parts.inner_mut(),
Weight::from_parts(10, 10),
&mut Weight::zero(),
);
assert_eq!(r, Ok(()))
}
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
#[test]
fn suspension_should_work() {
TestSuspender::set_suspended(true);
AllowUnpaidFrom::set(vec![Parent.into()]);
let mut message =
Xcm::<()>(vec![TransferAsset { assets: (Parent, 100).into(), beneficiary: Here.into() }]);
let r = RespectSuspension::<AllowUnpaidExecutionFrom::<IsInVec<AllowUnpaidFrom>>, TestSuspender>::should_execute(
&Parent.into(),
message.inner_mut(),
Weight::from_parts(10, 10),
&mut Weight::zero(),
);
assert_eq!(r, Err(ProcessMessageError::Yield));
TestSuspender::set_suspended(false);
let mut message =
Xcm::<()>(vec![TransferAsset { assets: (Parent, 100).into(), beneficiary: Here.into() }]);
let r = RespectSuspension::<AllowUnpaidExecutionFrom::<IsInVec<AllowUnpaidFrom>>, TestSuspender>::should_execute(
&Parent.into(),
message.inner_mut(),
Weight::from_parts(10, 10),
&mut Weight::zero(),
);
assert_eq!(r, Ok(()));
}