@@ -5,37 +5,44 @@ use frame_support::assert_ok;
55use 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
2022pub 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) ;
0 commit comments