-
Notifications
You must be signed in to change notification settings - Fork 299
Expand file tree
/
Copy pathtests.rs
More file actions
90 lines (79 loc) · 1.97 KB
/
tests.rs
File metadata and controls
90 lines (79 loc) · 1.97 KB
1
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//! Unit tests for xcm-support implementations.
#![cfg(test)]
use super::*;
use orml_traits::{location::RelativeLocations, ConcreteFungibleAsset};
#[derive(Debug, PartialEq, Eq)]
pub enum TestCurrencyId {
TokenA,
TokenB,
RelayChainToken,
}
pub struct CurrencyIdConvert;
impl Convert<Location, Option<TestCurrencyId>> for CurrencyIdConvert {
fn convert(l: Location) -> Option<TestCurrencyId> {
use TestCurrencyId::*;
if l == Location::parent() {
return Some(RelayChainToken);
}
if l == Location::sibling_parachain_general_key(1, b"TokenA".to_vec().try_into().unwrap()) {
return Some(TokenA);
}
if l == Location::sibling_parachain_general_key(2, b"TokenB".to_vec().try_into().unwrap()) {
return Some(TokenB);
}
None
}
}
type MatchesCurrencyId = IsNativeConcrete<TestCurrencyId, CurrencyIdConvert>;
#[test]
fn is_native_concrete_matches_native_currencies() {
assert_eq!(
MatchesCurrencyId::matches_fungible(&Asset::parent_asset(100)),
Some(100),
);
assert_eq!(
MatchesCurrencyId::matches_fungible(&Asset::sibling_parachain_asset(
1,
b"TokenA".to_vec().try_into().unwrap(),
100
)),
Some(100),
);
assert_eq!(
MatchesCurrencyId::matches_fungible(&Asset::sibling_parachain_asset(
2,
b"TokenB".to_vec().try_into().unwrap(),
100
)),
Some(100),
);
}
#[test]
fn is_native_concrete_does_not_matches_non_native_currencies() {
assert!(
<MatchesCurrencyId as MatchesFungible<u128>>::matches_fungible(&Asset::sibling_parachain_asset(
2,
b"TokenC".to_vec().try_into().unwrap(),
100
))
.is_none()
);
assert!(
<MatchesCurrencyId as MatchesFungible<u128>>::matches_fungible(&Asset::sibling_parachain_asset(
1,
b"TokenB".to_vec().try_into().unwrap(),
100
))
.is_none()
);
assert!(<MatchesCurrencyId as MatchesFungible<u128>>::matches_fungible(&Asset {
fun: Fungible(100),
id: AssetId(Location::new(
1,
[Junction::from(
sp_runtime::BoundedVec::try_from(b"TokenB".to_vec()).unwrap()
)]
)),
})
.is_none());
}