Skip to content

Commit 6117dfc

Browse files
committed
fix
1 parent a48047d commit 6117dfc

2 files changed

Lines changed: 19 additions & 15 deletions

File tree

auction/src/benchmarking.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,44 @@ use frame_support::assert_ok;
55
use frame_system::{EventRecord, RawOrigin};
66

77
/// Helper trait for benchmarking.
8-
pub trait BenchmarkHelper<BlockNumber> {
9-
fn setup_bid();
8+
pub trait BenchmarkHelper<BlockNumber, AccountId, Balance> {
9+
fn setup_bid() -> Option<(AccountId, Balance)>;
1010
fn setup_on_finalize(rand: u32) -> Option<BlockNumber>;
1111
}
1212

13-
impl<BlockNumber> BenchmarkHelper<BlockNumber> for () {
14-
fn setup_bid() {}
13+
impl<BlockNumber, AccountId, Balance> BenchmarkHelper<BlockNumber, AccountId, Balance> for () {
14+
fn setup_bid() -> Option<(AccountId, Balance)> {
15+
None
16+
}
1517
fn setup_on_finalize(_rand: u32) -> Option<BlockNumber> {
1618
None
1719
}
1820
}
1921

2022
pub struct BaseBenchmarkHelper<T>(sp_std::marker::PhantomData<T>);
2123

22-
impl<T: Config> BenchmarkHelper<BlockNumberFor<T>> for BaseBenchmarkHelper<T> {
23-
fn setup_bid() {
24+
impl<T: Config> BenchmarkHelper<BlockNumberFor<T>, T::AccountId, T::Balance> for BaseBenchmarkHelper<T> {
25+
fn setup_bid() -> Option<(T::AccountId, T::Balance)> {
2426
let end_block: BlockNumberFor<T> = frame_system::Pallet::<T>::block_number() + 10u32.into();
2527
assert_ok!(Pallet::<T>::new_auction(
2628
frame_system::Pallet::<T>::block_number(),
2729
Some(end_block),
2830
));
2931

3032
let auction_id: T::AuctionId = 0u32.into();
31-
let bidder: T::AccountId = account("pre_bidder", 0, 0);
32-
let bid_price: T::Balance = 10_000u32.into();
33+
let pre_bidder: T::AccountId = account("pre_bidder", 0, 0);
34+
let pre_bid_price: T::Balance = 10_000u32.into();
3335

3436
assert_ok!(Pallet::<T>::bid(
35-
RawOrigin::Signed(bidder.clone()).into(),
37+
RawOrigin::Signed(pre_bidder).into(),
3638
auction_id,
37-
bid_price
39+
pre_bid_price
3840
));
41+
42+
let bidder: T::AccountId = account("bidder", 0, 0);
43+
let bid_price: T::Balance = 20_000u32.into();
44+
45+
Some((bidder, bid_price))
3946
}
4047

4148
fn setup_on_finalize(rand: u32) -> Option<BlockNumberFor<T>> {
@@ -67,11 +74,8 @@ mod benchmarks {
6774
// there's bidder before and bid price will exceed target amount
6875
#[benchmark]
6976
fn bid() {
70-
T::BenchmarkHelper::setup_bid();
71-
7277
let auction_id: T::AuctionId = 0u32.into();
73-
let bidder: T::AccountId = account("bidder", 0, 0);
74-
let bid_price: T::Balance = 20_000u32.into();
78+
let (bidder, bid_price) = T::BenchmarkHelper::setup_bid().unwrap();
7579

7680
#[extrinsic_call]
7781
_(RawOrigin::Signed(bidder.clone()), auction_id, bid_price);

auction/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub mod module {
6767
type WeightInfo: WeightInfo;
6868

6969
#[cfg(feature = "runtime-benchmarks")]
70-
type BenchmarkHelper: BenchmarkHelper<BlockNumberFor<Self>>;
70+
type BenchmarkHelper: BenchmarkHelper<BlockNumberFor<Self>, Self::AccountId, Self::Balance>;
7171
}
7272

7373
#[pallet::error]

0 commit comments

Comments
 (0)