44
55use super :: * ;
66use frame_benchmarking:: account;
7- use frame_support:: {
8- assert_err, assert_ok, decl_module, decl_storage, dispatch:: DispatchResult , ensure, impl_outer_origin,
9- } ;
10- use frame_system:: { ensure_none, ensure_signed, RawOrigin } ;
7+ use frame_support:: { assert_err, assert_ok, construct_runtime, ensure} ;
8+ use frame_system:: RawOrigin ;
119use sp_runtime:: {
1210 testing:: { Header , H256 } ,
1311 traits:: { BlakeTwo256 , IdentityLookup } ,
1412} ;
1513use sp_std:: prelude:: * ;
1614
17- decl_storage ! {
18- trait Store for Module <T : Config > as Test {
19- Value get( fn value) : Option <u32 >;
15+ mod test {
16+ use frame_support:: { decl_module, decl_storage, dispatch:: DispatchResult } ;
17+ use frame_system:: { ensure_none, ensure_signed} ;
18+ use sp_std:: prelude:: * ;
19+
20+ pub trait Config : frame_system:: Config {
21+ type Event ;
22+ type BlockNumber ;
2023 }
21- }
2224
23- decl_module ! {
24- pub struct Module <T : Config > for enum Call where origin: T :: Origin {
25- #[ weight = 0 ]
26- fn set_value( origin, n: u32 ) -> DispatchResult {
27- let _sender = ensure_signed( origin) ?;
28- Value :: put( n) ;
29- Ok ( ( ) )
25+ decl_storage ! {
26+ trait Store for Module <T : Config > as Test {
27+ pub Value get( fn value) config( ) : Option <u32 >;
3028 }
29+ }
3130
32- #[ weight = 0 ]
33- fn dummy( origin, _n: u32 ) -> DispatchResult {
34- let _sender = ensure_none( origin) ?;
35- Ok ( ( ) )
31+ decl_module ! {
32+ pub struct Module <T : Config > for enum Call where origin: T :: Origin {
33+ #[ weight = 0 ]
34+ fn set_value( origin, n: u32 ) -> DispatchResult {
35+ let _sender = ensure_signed( origin) ?;
36+ Value :: put( n) ;
37+ Ok ( ( ) )
38+ }
39+
40+ #[ weight = 0 ]
41+ fn dummy( origin, _n: u32 ) -> DispatchResult {
42+ let _sender = ensure_none( origin) ?;
43+ Ok ( ( ) )
44+ }
3645 }
3746 }
3847}
3948
40- impl_outer_origin ! {
41- pub enum Origin for Test { }
42- }
43-
4449pub trait Config : frame_system:: Config {
4550 type Event ;
4651 type BlockNumber ;
4752}
4853
4954type AccountId = u128 ;
5055
51- #[ derive( Clone , Eq , PartialEq ) ]
52- pub struct Test ;
53-
5456impl frame_system:: Config for Test {
5557 type Origin = Origin ;
5658 type Index = u64 ;
5759 type BlockNumber = u64 ;
5860 type Hash = H256 ;
59- type Call = ( ) ;
61+ type Call = Call ;
6062 type Hashing = BlakeTwo256 ;
6163 type AccountId = AccountId ;
6264 type Lookup = IdentityLookup < Self :: AccountId > ;
6365 type Header = Header ;
64- type Event = ( ) ;
66+ type Event = Event ;
6567 type BlockHashCount = ( ) ;
6668 type DbWeight = ( ) ;
6769 type BlockWeights = ( ) ;
6870 type BlockLength = ( ) ;
6971 type Version = ( ) ;
70- type PalletInfo = ( ) ;
72+ type PalletInfo = PalletInfo ;
7173 type AccountData = ( ) ;
7274 type OnNewAccount = ( ) ;
7375 type OnKilledAccount = ( ) ;
@@ -76,11 +78,31 @@ impl frame_system::Config for Test {
7678 type SS58Prefix = ( ) ;
7779}
7880
81+ impl tests:: test:: Config for Test {
82+ type Event = Event ;
83+ type BlockNumber = u32 ;
84+ }
85+
7986impl Config for Test {
80- type Event = ( ) ;
87+ type Event = Event ;
8188 type BlockNumber = u32 ;
8289}
8390
91+ pub type Block = sp_runtime:: generic:: Block < Header , UncheckedExtrinsic > ;
92+ pub type UncheckedExtrinsic = sp_runtime:: generic:: UncheckedExtrinsic < u32 , Call , u32 , ( ) > ;
93+
94+ construct_runtime ! (
95+ pub enum Test where
96+ Block = Block ,
97+ NodeBlock = Block ,
98+ UncheckedExtrinsic = UncheckedExtrinsic ,
99+ {
100+ System : frame_system:: { Module , Call , Storage , Config , Event <T >} ,
101+ Pallet : test:: { Module , Call , Storage , Config } ,
102+
103+ }
104+ ) ;
105+
84106// This function basically just builds a genesis storage key/value store
85107// according to our desired mockup.
86108fn new_test_ext ( ) -> sp_io:: TestExternalities {
@@ -91,7 +113,7 @@ fn new_test_ext() -> sp_io::TestExternalities {
91113}
92114
93115runtime_benchmarks ! {
94- { Test , self }
116+ { Test , test }
95117
96118 _ {
97119 // Define a common range for `b`.
@@ -103,7 +125,7 @@ runtime_benchmarks! {
103125 let caller = account:: <AccountId >( "caller" , 0 , 0 ) ;
104126 } : _ ( RawOrigin :: Signed ( caller) , b. into( ) )
105127 verify {
106- assert_eq!( Value :: get ( ) , Some ( b) ) ;
128+ assert_eq!( Pallet :: value ( ) , Some ( b) ) ;
107129 }
108130
109131 other_name {
0 commit comments