Skip to content

Commit 86f9a1d

Browse files
committed
update
1 parent e8e95bc commit 86f9a1d

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

tokens/src/benchmarking.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,26 @@ use frame_system::RawOrigin;
66
use sp_runtime::traits::SaturatedConversion;
77

88
/// Helper trait for benchmarking.
9-
pub trait BenchmarkHelper<CurrencyId> {
10-
/// Returns a currency id to be used for benchmarking.
11-
fn get_currency_id() -> Option<CurrencyId>;
9+
pub trait BenchmarkHelper<CurrencyId, Balance> {
10+
/// Returns a currency id and amount to be used in benchmarking.
11+
fn get_currency_id_and_amount() -> Option<(CurrencyId, Balance)>;
1212
}
1313

14-
impl<CurrencyId> BenchmarkHelper<CurrencyId> for () {
15-
fn get_currency_id() -> Option<CurrencyId> {
14+
impl<CurrencyId, Balance> BenchmarkHelper<CurrencyId, Balance> for () {
15+
fn get_currency_id_and_amount() -> Option<(CurrencyId, Balance)> {
1616
None
1717
}
1818
}
1919

20-
const AMOUNT: u32 = 1_000_000_000;
21-
2220
#[benchmarks]
2321
mod benchmarks {
2422
use super::*;
2523

2624
#[benchmark]
2725
fn transfer() {
2826
let from: T::AccountId = account("from", 0, 0);
29-
let amount: T::Balance = AMOUNT.into();
3027

31-
let currency_id: T::CurrencyId = T::BenchmarkHelper::get_currency_id().unwrap();
28+
let (currency_id, amount) = T::BenchmarkHelper::get_currency_id_and_amount().unwrap();
3229

3330
assert_ok!(<Pallet::<T> as MultiCurrencyExtended<_>>::update_balance(
3431
currency_id,
@@ -48,9 +45,8 @@ mod benchmarks {
4845
#[benchmark]
4946
fn transfer_all() {
5047
let from: T::AccountId = account("from", 0, 0);
51-
let amount: T::Balance = AMOUNT.into();
5248

53-
let currency_id: T::CurrencyId = T::BenchmarkHelper::get_currency_id().unwrap();
49+
let (currency_id, amount) = T::BenchmarkHelper::get_currency_id_and_amount().unwrap();
5450

5551
assert_ok!(<Pallet::<T> as MultiCurrencyExtended<_>>::update_balance(
5652
currency_id,
@@ -73,9 +69,8 @@ mod benchmarks {
7369
#[benchmark]
7470
fn transfer_keep_alive() {
7571
let from: T::AccountId = account("from", 0, 0);
76-
let amount: T::Balance = AMOUNT.into();
7772

78-
let currency_id: T::CurrencyId = T::BenchmarkHelper::get_currency_id().unwrap();
73+
let (currency_id, amount) = T::BenchmarkHelper::get_currency_id_and_amount().unwrap();
7974

8075
assert_ok!(<Pallet::<T> as MultiCurrencyExtended<_>>::update_balance(
8176
currency_id,
@@ -99,9 +94,8 @@ mod benchmarks {
9994
fn force_transfer() {
10095
let from: T::AccountId = account("from", 0, 0);
10196
let from_lookup = <T as frame_system::Config>::Lookup::unlookup(from.clone());
102-
let amount: T::Balance = AMOUNT.into();
10397

104-
let currency_id: T::CurrencyId = T::BenchmarkHelper::get_currency_id().unwrap();
98+
let (currency_id, amount) = T::BenchmarkHelper::get_currency_id_and_amount().unwrap();
10599

106100
assert_ok!(<Pallet::<T> as MultiCurrencyExtended<_>>::update_balance(
107101
currency_id,
@@ -125,9 +119,8 @@ mod benchmarks {
125119
fn set_balance() {
126120
let who: T::AccountId = account("who", 0, 0);
127121
let who_lookup = <T as frame_system::Config>::Lookup::unlookup(who.clone());
128-
let amount: T::Balance = AMOUNT.into();
129122

130-
let currency_id: T::CurrencyId = T::BenchmarkHelper::get_currency_id().unwrap();
123+
let (currency_id, amount) = T::BenchmarkHelper::get_currency_id_and_amount().unwrap();
131124

132125
#[extrinsic_call]
133126
_(RawOrigin::Root, who_lookup, currency_id, amount, amount);

tokens/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ pub mod module {
233233

234234
/// The benchmarks need a way to provide currency id.
235235
#[cfg(feature = "runtime-benchmarks")]
236-
type BenchmarkHelper: BenchmarkHelper<Self::CurrencyId>;
236+
type BenchmarkHelper: BenchmarkHelper<Self::CurrencyId, Self::Balance>;
237237
}
238238

239239
#[pallet::error]

tokens/src/mock.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,9 @@ where
378378
#[cfg(feature = "runtime-benchmarks")]
379379
pub struct MockBenchmarkHelper;
380380
#[cfg(feature = "runtime-benchmarks")]
381-
impl BenchmarkHelper<CurrencyId> for MockBenchmarkHelper {
382-
fn get_currency_id() -> Option<CurrencyId> {
383-
Some(DOT)
381+
impl BenchmarkHelper<CurrencyId, Balance> for MockBenchmarkHelper {
382+
fn get_currency_id_and_amount() -> Option<(CurrencyId, Balance)> {
383+
Some((DOT, 1000))
384384
}
385385
}
386386

0 commit comments

Comments
 (0)