2020use ethereum:: { TransactionAction , TransactionSignature } ;
2121use rlp:: RlpStream ;
2222// Substrate
23- use frame_support:: {
24- derive_impl, parameter_types,
25- traits:: { ConstU32 , FindAuthor } ,
26- weights:: Weight ,
27- ConsensusEngineId , PalletId ,
28- } ;
23+ use frame_support:: { derive_impl, parameter_types, traits:: FindAuthor , ConsensusEngineId } ;
2924use sp_core:: { hashing:: keccak_256, H160 , H256 , U256 } ;
3025use sp_runtime:: {
31- traits:: { BlakeTwo256 , Dispatchable , IdentityLookup } ,
26+ traits:: { Dispatchable , IdentityLookup } ,
3227 AccountId32 , BuildStorage ,
3328} ;
3429// Frontier
35- use pallet_evm:: { AddressMapping , EnsureAddressTruncated , FeeCalculator } ;
30+ use pallet_evm:: { config_preludes :: ChainId , AddressMapping } ;
3631
3732use super :: * ;
38- use crate :: IntermediateStateRoot ;
3933
4034pub type SignedExtra = ( frame_system:: CheckSpecVersion < Test > , ) ;
4135
@@ -55,30 +49,11 @@ parameter_types! {
5549
5650#[ derive_impl( frame_system:: config_preludes:: TestDefaultConfig as frame_system:: DefaultConfig ) ]
5751impl frame_system:: Config for Test {
58- type RuntimeEvent = RuntimeEvent ;
59- type BaseCallFilter = frame_support:: traits:: Everything ;
60- type BlockWeights = ( ) ;
61- type BlockLength = ( ) ;
62- type RuntimeOrigin = RuntimeOrigin ;
63- type RuntimeCall = RuntimeCall ;
64- type RuntimeTask = RuntimeTask ;
65- type Nonce = u64 ;
66- type Hash = H256 ;
67- type Hashing = BlakeTwo256 ;
6852 type AccountId = AccountId32 ;
6953 type Lookup = IdentityLookup < Self :: AccountId > ;
7054 type Block = frame_system:: mocking:: MockBlock < Self > ;
7155 type BlockHashCount = BlockHashCount ;
72- type DbWeight = ( ) ;
73- type Version = ( ) ;
74- type PalletInfo = PalletInfo ;
7556 type AccountData = pallet_balances:: AccountData < u64 > ;
76- type OnNewAccount = ( ) ;
77- type OnKilledAccount = ( ) ;
78- type SystemWeightInfo = ( ) ;
79- type SS58Prefix = ( ) ;
80- type OnSetCode = ( ) ;
81- type MaxConsumers = ConstU32 < 16 > ;
8257}
8358
8459parameter_types ! {
@@ -89,39 +64,14 @@ parameter_types! {
8964 pub const MaxReserves : u32 = 50 ;
9065}
9166
67+ #[ derive_impl( pallet_balances:: config_preludes:: TestDefaultConfig ) ]
9268impl pallet_balances:: Config for Test {
93- type RuntimeEvent = RuntimeEvent ;
94- type RuntimeHoldReason = RuntimeHoldReason ;
95- type RuntimeFreezeReason = RuntimeFreezeReason ;
96- type WeightInfo = ( ) ;
97- type Balance = u64 ;
98- type DustRemoval = ( ) ;
9969 type ExistentialDeposit = ExistentialDeposit ;
10070 type AccountStore = System ;
101- type ReserveIdentifier = [ u8 ; 8 ] ;
102- type FreezeIdentifier = RuntimeFreezeReason ;
103- type MaxLocks = MaxLocks ;
104- type MaxReserves = MaxReserves ;
105- type MaxFreezes = ConstU32 < 1 > ;
106- }
107-
108- parameter_types ! {
109- pub const MinimumPeriod : u64 = 6000 / 2 ;
11071}
11172
112- impl pallet_timestamp:: Config for Test {
113- type Moment = u64 ;
114- type OnTimestampSet = ( ) ;
115- type MinimumPeriod = MinimumPeriod ;
116- type WeightInfo = ( ) ;
117- }
118-
119- pub struct FixedGasPrice ;
120- impl FeeCalculator for FixedGasPrice {
121- fn min_gas_price ( ) -> ( U256 , Weight ) {
122- ( 1 . into ( ) , Weight :: zero ( ) )
123- }
124- }
73+ #[ derive_impl( pallet_timestamp:: config_preludes:: TestDefaultConfig ) ]
74+ impl pallet_timestamp:: Config for Test { }
12575
12676pub struct FindAuthorTruncated ;
12777impl FindAuthor < H160 > for FindAuthorTruncated {
@@ -133,66 +83,24 @@ impl FindAuthor<H160> for FindAuthorTruncated {
13383 }
13484}
13585
136- const BLOCK_GAS_LIMIT : u64 = 150_000_000 ;
137- const MAX_POV_SIZE : u64 = 5 * 1024 * 1024 ;
138-
13986parameter_types ! {
14087 pub const TransactionByteFee : u64 = 1 ;
141- pub const ChainId : u64 = 42 ;
142- pub const EVMModuleId : PalletId = PalletId ( * b"py/evmpa" ) ;
143- pub BlockGasLimit : U256 = U256 :: from( BLOCK_GAS_LIMIT ) ;
144- pub const GasLimitPovSizeRatio : u64 = BLOCK_GAS_LIMIT . saturating_div( MAX_POV_SIZE ) ;
145- pub const WeightPerGas : Weight = Weight :: from_parts( 20_000 , 0 ) ;
146- }
147-
148- pub struct HashedAddressMapping ;
149- impl AddressMapping < AccountId32 > for HashedAddressMapping {
150- fn into_account_id ( address : H160 ) -> AccountId32 {
151- let mut data = [ 0u8 ; 32 ] ;
152- data[ 0 ..20 ] . copy_from_slice ( & address[ ..] ) ;
153- AccountId32 :: from ( Into :: < [ u8 ; 32 ] > :: into ( data) )
154- }
155- }
156-
157- parameter_types ! {
158- pub SuicideQuickClearLimit : u32 = 0 ;
15988}
16089
90+ #[ derive_impl( pallet_evm:: config_preludes:: TestDefaultConfig ) ]
16191impl pallet_evm:: Config for Test {
16292 type AccountProvider = pallet_evm:: FrameSystemAccountProvider < Self > ;
163- type FeeCalculator = FixedGasPrice ;
164- type GasWeightMapping = pallet_evm:: FixedGasWeightMapping < Self > ;
165- type WeightPerGas = WeightPerGas ;
16693 type BlockHashMapping = crate :: EthereumBlockHashMapping < Self > ;
167- type CallOrigin = EnsureAddressTruncated ;
168- type WithdrawOrigin = EnsureAddressTruncated ;
169- type AddressMapping = HashedAddressMapping ;
17094 type Currency = Balances ;
171- type RuntimeEvent = RuntimeEvent ;
17295 type PrecompilesType = ( ) ;
17396 type PrecompilesValue = ( ) ;
174- type ChainId = ChainId ;
175- type BlockGasLimit = BlockGasLimit ;
17697 type Runner = pallet_evm:: runner:: stack:: Runner < Self > ;
177- type OnChargeTransaction = ( ) ;
178- type OnCreate = ( ) ;
17998 type FindAuthor = FindAuthorTruncated ;
180- type GasLimitPovSizeRatio = GasLimitPovSizeRatio ;
181- type SuicideQuickClearLimit = SuicideQuickClearLimit ;
18299 type Timestamp = Timestamp ;
183- type WeightInfo = ( ) ;
184- }
185-
186- parameter_types ! {
187- pub const PostBlockAndTxnHashes : PostLogContent = PostLogContent :: BlockAndTxnHashes ;
188100}
189101
190- impl Config for Test {
191- type RuntimeEvent = RuntimeEvent ;
192- type StateRoot = IntermediateStateRoot < Self > ;
193- type PostLogContent = PostBlockAndTxnHashes ;
194- type ExtraDataLength = ConstU32 < 30 > ;
195- }
102+ #[ derive_impl( crate :: config_preludes:: TestDefaultConfig ) ]
103+ impl Config for Test { }
196104
197105impl fp_self_contained:: SelfContainedCall for RuntimeCall {
198106 type SignedInfo = H160 ;
@@ -262,12 +170,9 @@ fn address_build(seed: u8) -> AccountInfo {
262170 let public_key = & libsecp256k1:: PublicKey :: from_secret_key ( & secret_key) . serialize ( ) [ 1 ..65 ] ;
263171 let address = H160 :: from ( H256 :: from ( keccak_256 ( public_key) ) ) ;
264172
265- let mut data = [ 0u8 ; 32 ] ;
266- data[ 0 ..20 ] . copy_from_slice ( & address[ ..] ) ;
267-
268173 AccountInfo {
269174 private_key,
270- account_id : AccountId32 :: from ( Into :: < [ u8 ; 32 ] > :: into ( data ) ) ,
175+ account_id : < Test as pallet_evm :: Config > :: AddressMapping :: into_account_id ( address ) ,
271176 address,
272177 }
273178}
@@ -301,7 +206,6 @@ pub fn new_test_ext_with_initial_balance(
301206 accounts_len : usize ,
302207 initial_balance : u64 ,
303208) -> ( Vec < AccountInfo > , sp_io:: TestExternalities ) {
304- // sc_cli::init_logger("");
305209 let mut ext = frame_system:: GenesisConfig :: < Test > :: default ( )
306210 . build_storage ( )
307211 . unwrap ( ) ;
0 commit comments