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
use crate::{AccountId, Runtime};
use primitives::Price;
use super::*;
use frame_benchmarking::account;
use frame_benchmarking::BenchmarkError;
use frame_support::assert_ok;
use frame_system::RawOrigin;
use orml_benchmarking::runtime_benchmarks;
use hydradx_traits::pools::SpotPriceProvider;
type MultiPaymentPallet<T> = pallet_transaction_multi_payment::Pallet<T>;
const SEED: u32 = 1;
runtime_benchmarks! {
{ Runtime, pallet_transaction_multi_payment}
add_currency {
let price = Price::from(10);
}: { MultiPaymentPallet::<Runtime>::add_currency(RawOrigin::Root.into(), 10, price)? }
verify {
assert_eq!(MultiPaymentPallet::<Runtime>::currencies(10), Some(price));
}
remove_currency {
assert_ok!(MultiPaymentPallet::<Runtime>::add_currency(RawOrigin::Root.into(), 10, Price::from(2)));
}: { MultiPaymentPallet::<Runtime>::remove_currency(RawOrigin::Root.into(), 10)? }
verify {
assert_eq!(MultiPaymentPallet::<Runtime>::currencies(10), None)
}
set_currency {
let maker: AccountId = account("maker", 0, SEED);
let caller: AccountId = account("caller", 0, SEED);
let asset_id = register_asset(b"TST".to_vec(), 100u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?;
MultiPaymentPallet::<Runtime>::add_currency(RawOrigin::Root.into(), asset_id, Price::from(1)).map_err(|_| BenchmarkError::Stop("Failed to add supported currency"))?;
update_balance(asset_id, &caller,100_000_000_000_000);
}: { MultiPaymentPallet::<Runtime>::set_currency(RawOrigin::Signed(caller.clone()).into(), asset_id)? }
verify{
assert_eq!(MultiPaymentPallet::<Runtime>::get_currency(caller), Some(asset_id));
}
get_spot_price {
let maker: AccountId = account("maker", 0, SEED);
let asset_out = 0u32;
let asset_id = register_asset(b"TST".to_vec(), 1u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?;
update_balance(asset_out, &maker, 2_000_000_000_000_000);
update_balance(asset_id, &maker, 2_000_000_000_000_000);
create_pool(maker, asset_out, 1_000_000_000_000_000, asset_id, 500_000_000_000_000);
}: { <Runtime as pallet_transaction_multi_payment::Config>::SpotPriceProvider::spot_price(asset_id, asset_out) }
verify{
assert_eq!(<Runtime as pallet_transaction_multi_payment::Config>::SpotPriceProvider::spot_price(asset_id, asset_out),
Some(Price::from((2,1))));
}
}
#[cfg(test)]
mod tests {
use super::*;
use orml_benchmarking::impl_benchmark_test_suite;
fn new_test_ext() -> sp_io::TestExternalities {
frame_system::GenesisConfig::default()
.build_storage::<crate::Runtime>()
.unwrap()
.into()
}
impl_benchmark_test_suite!(new_test_ext(),);
}