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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#![cfg(feature = "runtime-benchmarks")]
use super::*;
use frame_benchmarking::benchmarks;
use frame_system::RawOrigin;
use crate::types::Metadata;
use sp_std::vec;
benchmarks! {
register{
let name = vec![1; T::StringLimit::get() as usize];
let ed = T::Balance::from(1_000_000u32);
let symbol = vec![1; T::StringLimit::get() as usize];
let metadata = Metadata {
symbol,
decimals: 100,
};
}: _(RawOrigin::Root, name.clone(), AssetType::Token, ed, None, Some(metadata), Some(Default::default()))
verify {
let bname = crate::Pallet::<T>::to_bounded_name(name).unwrap();
assert!(crate::Pallet::<T>::asset_ids(bname).is_some());
}
update{
let name = b"NAME".to_vec();
let ed = T::Balance::from(1_000_000u32);
let asset_id = T::AssetId::from(10u8);
let _ = crate::Pallet::<T>::register(RawOrigin::Root.into(), name, AssetType::Token, ed, Some(asset_id),None,None);
let new_name= vec![1; T::StringLimit::get() as usize];
let new_ed = T::Balance::from(2_000_000u32);
}: _(RawOrigin::Root, asset_id, new_name.clone(), AssetType::PoolShare(T::AssetId::from(10u8),T::AssetId::from(20u8)), Some(new_ed))
verify {
let bname = crate::Pallet::<T>::to_bounded_name(new_name).unwrap();
assert_eq!(crate::Pallet::<T>::asset_ids(&bname), Some(asset_id));
let stored = crate::Pallet::<T>::assets(asset_id);
assert!(stored.is_some());
let stored = stored.unwrap();
let expected = AssetDetails{
asset_type: AssetType::PoolShare(T::AssetId::from(10u8), T::AssetId::from(20u8)),
locked: false,
existential_deposit: new_ed,
name: bname,};
assert_eq!(stored.asset_type, expected.asset_type);
assert_eq!(stored.locked, expected.locked);
assert_eq!(stored.existential_deposit, expected.existential_deposit);
assert_eq!(stored.name.to_vec(), expected.name.to_vec());
}
set_metadata{
let name = b"NAME".to_vec();
let bname = crate::Pallet::<T>::to_bounded_name(name.clone()).unwrap();
let ed = T::Balance::from(1_000_000u32);
let _ = crate::Pallet::<T>::register(RawOrigin::Root.into(), name, AssetType::Token, ed, None, None, None);
let asset_id = crate::Pallet::<T>::asset_ids(bname).unwrap();
let max_symbol = vec![1; T::StringLimit::get() as usize];
}: _(RawOrigin::Root, asset_id, max_symbol.clone(), 10u8)
verify {
let bsymbol= crate::Pallet::<T>::to_bounded_name(max_symbol).unwrap();
let stored = crate::Pallet::<T>::asset_metadata(asset_id);
assert!(stored.is_some());
let stored = stored.unwrap();
let expected =AssetMetadata{
symbol: bsymbol,
decimals: 10u8
};
assert_eq!(stored.symbol.to_vec(), expected.symbol.to_vec());
assert_eq!(stored.decimals, expected.decimals);
}
set_location{
let name = b"NAME".to_vec();
let ed = T::Balance::from(1_000_000u32);
let asset_id = T::AssetId::from(10u8);
let _ = crate::Pallet::<T>::register(RawOrigin::Root.into(), name.clone(), AssetType::Token, ed, Some(asset_id), None, None);
}: _(RawOrigin::Root, asset_id, Default::default())
verify {
let bname = crate::Pallet::<T>::to_bounded_name(name).unwrap();
let bsymbol= crate::Pallet::<T>::to_bounded_name(b"SYMBOL".to_vec()).unwrap();
assert_eq!(crate::Pallet::<T>::locations(asset_id), Some(Default::default()));
assert_eq!(crate::Pallet::<T>::location_assets(T::AssetNativeLocation::default()), Some(asset_id));
}
}
#[cfg(test)]
mod tests {
use super::Pallet;
use crate::mock::*;
use frame_benchmarking::impl_benchmark_test_suite;
impl_benchmark_test_suite!(Pallet, super::ExtBuilder::default().build(), super::Test);
}