@@ -335,123 +335,12 @@ pub fn validate_against_parent_4844<H: BlockHeader>(
335335#[ cfg( test) ]
336336mod tests {
337337 use super :: * ;
338- use alloy_consensus:: { Header , TxEip4844 , EMPTY_OMMER_ROOT_HASH , EMPTY_ROOT_HASH } ;
339- use alloy_eips:: {
340- eip4895:: { Withdrawal , Withdrawals } ,
341- BlockHashOrNumber ,
342- } ;
343- use alloy_primitives:: {
344- hex_literal:: hex, Address , BlockHash , BlockNumber , Bytes , PrimitiveSignature as Signature ,
345- U256 ,
346- } ;
347- use mockall:: mock;
338+ use alloy_consensus:: { Header , TxEip4844 } ;
339+ use alloy_eips:: eip4895:: Withdrawals ;
340+ use alloy_primitives:: { Address , Bytes , PrimitiveSignature as Signature , U256 } ;
348341 use rand:: Rng ;
349342 use reth_chainspec:: ChainSpecBuilder ;
350- use reth_ethereum_primitives:: { Transaction , TransactionSigned } ;
351- use reth_primitives:: { proofs, Account , BlockBody } ;
352- use reth_storage_api:: {
353- errors:: provider:: ProviderResult , AccountReader , HeaderProvider , WithdrawalsProvider ,
354- } ;
355- use std:: ops:: RangeBounds ;
356-
357- mock ! {
358- WithdrawalsProvider { }
359-
360- impl WithdrawalsProvider for WithdrawalsProvider {
361- fn latest_withdrawal( & self ) -> ProviderResult <Option <Withdrawal >> ;
362-
363- fn withdrawals_by_block(
364- & self ,
365- _id: BlockHashOrNumber ,
366- _timestamp: u64 ,
367- ) -> ProviderResult <Option <Withdrawals >> ;
368- }
369- }
370-
371- struct Provider {
372- is_known : bool ,
373- parent : Option < Header > ,
374- account : Option < Account > ,
375- withdrawals_provider : MockWithdrawalsProvider ,
376- }
377-
378- impl Provider {
379- /// New provider with parent
380- fn new ( parent : Option < Header > ) -> Self {
381- Self {
382- is_known : false ,
383- parent,
384- account : None ,
385- withdrawals_provider : MockWithdrawalsProvider :: new ( ) ,
386- }
387- }
388- }
389-
390- impl AccountReader for Provider {
391- fn basic_account ( & self , _address : & Address ) -> ProviderResult < Option < Account > > {
392- Ok ( self . account )
393- }
394- }
395-
396- impl HeaderProvider for Provider {
397- type Header = Header ;
398-
399- fn is_known ( & self , _block_hash : & BlockHash ) -> ProviderResult < bool > {
400- Ok ( self . is_known )
401- }
402-
403- fn header ( & self , _block_number : & BlockHash ) -> ProviderResult < Option < Header > > {
404- Ok ( self . parent . clone ( ) )
405- }
406-
407- fn header_by_number ( & self , _num : u64 ) -> ProviderResult < Option < Header > > {
408- Ok ( self . parent . clone ( ) )
409- }
410-
411- fn header_td ( & self , _hash : & BlockHash ) -> ProviderResult < Option < U256 > > {
412- Ok ( None )
413- }
414-
415- fn header_td_by_number ( & self , _number : BlockNumber ) -> ProviderResult < Option < U256 > > {
416- Ok ( None )
417- }
418-
419- fn headers_range (
420- & self ,
421- _range : impl RangeBounds < BlockNumber > ,
422- ) -> ProviderResult < Vec < Header > > {
423- Ok ( vec ! [ ] )
424- }
425-
426- fn sealed_header (
427- & self ,
428- _block_number : BlockNumber ,
429- ) -> ProviderResult < Option < SealedHeader > > {
430- Ok ( None )
431- }
432-
433- fn sealed_headers_while (
434- & self ,
435- _range : impl RangeBounds < BlockNumber > ,
436- _predicate : impl FnMut ( & SealedHeader ) -> bool ,
437- ) -> ProviderResult < Vec < SealedHeader > > {
438- Ok ( vec ! [ ] )
439- }
440- }
441-
442- impl WithdrawalsProvider for Provider {
443- fn withdrawals_by_block (
444- & self ,
445- _id : BlockHashOrNumber ,
446- _timestamp : u64 ,
447- ) -> ProviderResult < Option < Withdrawals > > {
448- self . withdrawals_provider . withdrawals_by_block ( _id, _timestamp)
449- }
450-
451- fn latest_withdrawal ( & self ) -> ProviderResult < Option < Withdrawal > > {
452- self . withdrawals_provider . latest_withdrawal ( )
453- }
454- }
343+ use reth_primitives:: { proofs, BlockBody , Transaction , TransactionSigned } ;
455344
456345 fn mock_blob_tx ( nonce : u64 , num_blobs : usize ) -> TransactionSigned {
457346 let mut rng = rand:: thread_rng ( ) ;
@@ -474,97 +363,6 @@ mod tests {
474363 TransactionSigned :: new_unhashed ( request, signature)
475364 }
476365
477- /// got test block
478- fn mock_block ( ) -> ( SealedBlock , Header ) {
479- // https://etherscan.io/block/15867168 where transaction root and receipts root are cleared
480- // empty merkle tree: 0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
481-
482- let header = Header {
483- parent_hash : hex ! ( "859fad46e75d9be177c2584843501f2270c7e5231711e90848290d12d7c6dcdd" ) . into ( ) ,
484- ommers_hash : EMPTY_OMMER_ROOT_HASH ,
485- beneficiary : hex ! ( "4675c7e5baafbffbca748158becba61ef3b0a263" ) . into ( ) ,
486- state_root : hex ! ( "8337403406e368b3e40411138f4868f79f6d835825d55fd0c2f6e17b1a3948e9" ) . into ( ) ,
487- transactions_root : EMPTY_ROOT_HASH ,
488- receipts_root : EMPTY_ROOT_HASH ,
489- logs_bloom : hex ! ( "002400000000004000220000800002000000000000000000000000000000100000000000000000100000000000000021020000000800000006000000002100040000000c0004000000000008000008200000000000000000000000008000000001040000020000020000002000000800000002000020000000022010000000000000010002001000000000020200000000000001000200880000004000000900020000000000020000000040000000000000000000000000000080000000000001000002000000000000012000200020000000000000001000000000000020000010321400000000100000000000000000000000000000400000000000000000" ) . into ( ) ,
490- difficulty : U256 :: ZERO , // total difficulty: 0xc70d815d562d3cfa955).into(),
491- number : 0xf21d20 ,
492- gas_limit : 0x1c9c380 ,
493- gas_used : 0x6e813 ,
494- timestamp : 0x635f9657 ,
495- extra_data : hex ! ( "" ) [ ..] . into ( ) ,
496- mix_hash : hex ! ( "0000000000000000000000000000000000000000000000000000000000000000" ) . into ( ) ,
497- nonce : 0x0000000000000000u64 . into ( ) ,
498- base_fee_per_gas : 0x28f0001df . into ( ) ,
499- withdrawals_root : None ,
500- blob_gas_used : None ,
501- excess_blob_gas : None ,
502- parent_beacon_block_root : None ,
503- requests_hash : None ,
504- } ;
505- // size: 0x9b5
506-
507- let mut parent = header. clone ( ) ;
508- parent. gas_used = 17763076 ;
509- parent. gas_limit = 30000000 ;
510- parent. base_fee_per_gas = Some ( 0x28041f7f5 ) ;
511- parent. number -= 1 ;
512- parent. timestamp -= 1 ;
513-
514- let ommers = Vec :: new ( ) ;
515- let transactions = Vec :: new ( ) ;
516-
517- (
518- SealedBlock :: new (
519- SealedHeader :: seal ( header) ,
520- BlockBody { transactions, ommers, withdrawals : None } ,
521- ) ,
522- parent,
523- )
524- }
525-
526- #[ test]
527- fn valid_withdrawal_index ( ) {
528- let chain_spec = ChainSpecBuilder :: mainnet ( ) . shanghai_activated ( ) . build ( ) ;
529-
530- let create_block_with_withdrawals = |indexes : & [ u64 ] | {
531- let withdrawals = Withdrawals :: new (
532- indexes
533- . iter ( )
534- . map ( |idx| Withdrawal { index : * idx, ..Default :: default ( ) } )
535- . collect ( ) ,
536- ) ;
537-
538- let header = Header {
539- withdrawals_root : Some ( proofs:: calculate_withdrawals_root ( & withdrawals) ) ,
540- ..Default :: default ( )
541- } ;
542-
543- SealedBlock :: new (
544- SealedHeader :: seal ( header) ,
545- BlockBody { withdrawals : Some ( withdrawals) , ..Default :: default ( ) } ,
546- )
547- } ;
548-
549- // Single withdrawal
550- let block: SealedBlock = create_block_with_withdrawals ( & [ 1 ] ) ;
551- assert_eq ! ( validate_block_pre_execution( & block, & chain_spec) , Ok ( ( ) ) ) ;
552-
553- // Multiple increasing withdrawals
554- let block = create_block_with_withdrawals ( & [ 1 , 2 , 3 ] ) ;
555- assert_eq ! ( validate_block_pre_execution( & block, & chain_spec) , Ok ( ( ) ) ) ;
556- let block = create_block_with_withdrawals ( & [ 5 , 6 , 7 , 8 , 9 ] ) ;
557- assert_eq ! ( validate_block_pre_execution( & block, & chain_spec) , Ok ( ( ) ) ) ;
558- let ( _, parent) = mock_block ( ) ;
559-
560- // Withdrawal index should be the last withdrawal index + 1
561- let mut provider = Provider :: new ( Some ( parent) ) ;
562- provider
563- . withdrawals_provider
564- . expect_latest_withdrawal ( )
565- . return_const ( Ok ( Some ( Withdrawal { index : 2 , ..Default :: default ( ) } ) ) ) ;
566- }
567-
568366 #[ test]
569367 fn cancun_block_incorrect_blob_gas_used ( ) {
570368 let chain_spec = ChainSpecBuilder :: mainnet ( ) . cancun_activated ( ) . build ( ) ;
0 commit comments