@@ -10,7 +10,6 @@ use reth::primitives::RecoveredBlock;
1010use reth_e2e_test_utils:: testsuite:: actions:: Action ;
1111use reth_e2e_test_utils:: transaction:: TransactionTestContext ;
1212use reth_node_api:: { Block , PayloadAttributes } ;
13- use reth_optimism_node:: utils:: optimism_payload_attributes;
1413use reth_optimism_node:: OpPayloadAttributes ;
1514use reth_optimism_payload_builder:: payload_id_optimism;
1615use reth_optimism_primitives:: OpTransactionSigned ;
@@ -27,7 +26,7 @@ use world_chain_node::context::FlashblocksContext;
2726use world_chain_test:: node:: { raw_pbh_bundle_bytes, tx} ;
2827use world_chain_test:: utils:: signer;
2928
30- use crate :: setup:: { setup, CHAIN_SPEC } ;
29+ use crate :: setup:: { optimism_payload_attributes , setup, CHAIN_SPEC } ;
3130
3231#[ tokio:: test]
3332async fn test_can_build_pbh_payload ( ) -> eyre:: Result < ( ) > {
@@ -354,90 +353,122 @@ async fn test_flashblocks() -> eyre::Result<()> {
354353 Ok ( ( ) )
355354}
356355
357- // #[tokio::test(flavor = "multi_thread")]
358- // async fn test_eth_api_receipt() -> eyre::Result<()> {
359- // reth_tracing::init_test_tracing();
360- // let (_, nodes, _tasks, mut env) =
361- // setup::<FlashblocksContext>(3, optimism_payload_attributes).await?;
362-
363- // let ext_context = nodes[0].ext_context.clone();
364-
365- // let block_hash = nodes[0].node.block_hash(0);
366-
367- // let authorization_generator = move |attrs: OpPayloadAttributes| {
368- // let authorizer_sk = SigningKey::from_bytes(&[0; 32]);
369-
370- // let payload_id = payload_id_optimism(&block_hash, &attrs, 3);
371-
372- // Authorization::new(
373- // payload_id,
374- // attrs.timestamp(),
375- // &authorizer_sk,
376- // ext_context
377- // .flashblocks_handle
378- // .builder_sk()
379- // .unwrap()
380- // .verifying_key(),
381- // )
382- // };
383-
384- // let timestamp = std::time::SystemTime::now()
385- // .duration_since(std::time::UNIX_EPOCH)
386- // .unwrap()
387- // .as_secs();
388-
389- // let (sender, _) = tokio::sync::mpsc::channel(1);
390-
391- // // Compose a Mine Block action with an eth_getTransactionReceipt action
392- // let attributes = OpPayloadAttributes {
393- // payload_attributes: alloy_rpc_types_engine::PayloadAttributes {
394- // timestamp,
395- // prev_randao: B256::random(),
396- // suggested_fee_recipient: Address::random(),
397- // withdrawals: Some(vec![]),
398- // parent_beacon_block_root: Some(B256::ZERO),
399- // },
400- // transactions: Some(vec![crate::setup::TX_SET_L1_BLOCK.into()]),
401- // no_tx_pool: Some(false),
402- // eip_1559_params: Some(b64!("0000000800000008")),
403- // gas_limit: Some(30_000_000),
404- // };
405-
406- // let mock_tx =
407- // TransactionTestContext::transfer_tx(nodes[0].node.inner.chain_spec().chain_id(), signer(0))
408- // .await;
409-
410- // let raw_tx: Bytes = mock_tx.encoded_2718().into();
411-
412- // nodes[0].node.rpc.inject_tx(raw_tx.clone()).await?;
413-
414- // let mine_block = crate::actions::AssertMineBlock::new(
415- // 0,
416- // vec![raw_tx],
417- // Some(B256::ZERO),
418- // attributes,
419- // authorization_generator,
420- // std::time::Duration::from_millis(2000),
421- // true,
422- // false,
423- // sender,
424- // )
425- // .await;
426-
427- // let (tx, mut rx) = tokio::sync::mpsc::channel(1);
428-
429- // // 200ms backoff should be enough time to fetch the pending receipt
430- // let transaction_receipt =
431- // crate::actions::EthGetTransactionReceipt::new(*mock_tx.hash(), vec![0, 1, 2], 230, tx);
432-
433- // let mut action = crate::actions::EthApiAction::new(mine_block, transaction_receipt);
434- // action.execute(&mut env).await?;
435-
436- // let _receipts = rx.recv().await.expect("should receive receipts");
437- // info!("Receipts: {:?}", _receipts);
438- // // TODO: Assertions once EthApi is fixed
439- // Ok(())
440- // }
356+ #[ tokio:: test( flavor = "multi_thread" ) ]
357+ async fn test_eth_api_receipt ( ) -> eyre:: Result < ( ) > {
358+ reth_tracing:: init_test_tracing ( ) ;
359+ let ( _, nodes, _tasks, mut env) =
360+ setup :: < FlashblocksContext > ( 3 , optimism_payload_attributes) . await ?;
361+
362+ let ext_context = nodes[ 0 ] . ext_context . clone ( ) ;
363+
364+ let block_hash = nodes[ 0 ] . node . block_hash ( 0 ) ;
365+
366+ let authorization_generator = move |attrs : OpPayloadAttributes | {
367+ let authorizer_sk = SigningKey :: from_bytes ( & [ 0 ; 32 ] ) ;
368+
369+ let payload_id = payload_id_optimism ( & block_hash, & attrs, 3 ) ;
370+
371+ Authorization :: new (
372+ payload_id,
373+ attrs. timestamp ( ) ,
374+ & authorizer_sk,
375+ ext_context
376+ . flashblocks_handle
377+ . builder_sk ( )
378+ . unwrap ( )
379+ . verifying_key ( ) ,
380+ )
381+ } ;
382+
383+ let timestamp = std:: time:: SystemTime :: now ( )
384+ . duration_since ( std:: time:: UNIX_EPOCH )
385+ . unwrap ( )
386+ . as_secs ( ) ;
387+
388+ let ( sender, _) = tokio:: sync:: mpsc:: channel ( 1 ) ;
389+
390+ // Compose a Mine Block action with an eth_getTransactionReceipt action
391+ let attributes = OpPayloadAttributes {
392+ payload_attributes : alloy_rpc_types_engine:: PayloadAttributes {
393+ timestamp,
394+ prev_randao : B256 :: random ( ) ,
395+ suggested_fee_recipient : Address :: random ( ) ,
396+ withdrawals : Some ( vec ! [ ] ) ,
397+ parent_beacon_block_root : Some ( B256 :: ZERO ) ,
398+ } ,
399+ transactions : Some ( vec ! [ crate :: setup:: TX_SET_L1_BLOCK . clone( ) ] ) ,
400+ no_tx_pool : Some ( false ) ,
401+ eip_1559_params : Some ( b64 ! ( "0000000800000008" ) ) ,
402+ gas_limit : Some ( 30_000_000 ) ,
403+ min_base_fee : None ,
404+ } ;
405+
406+ let mock_tx =
407+ TransactionTestContext :: transfer_tx ( nodes[ 0 ] . node . inner . chain_spec ( ) . chain_id ( ) , signer ( 0 ) )
408+ . await ;
409+
410+ let raw_tx: Bytes = mock_tx. encoded_2718 ( ) . into ( ) ;
411+
412+ nodes[ 0 ] . node . rpc . inject_tx ( raw_tx. clone ( ) ) . await ?;
413+
414+ let mine_block = crate :: actions:: AssertMineBlock :: new (
415+ 0 ,
416+ vec ! [ ] ,
417+ None ,
418+ attributes,
419+ authorization_generator,
420+ std:: time:: Duration :: from_millis ( 2000 ) ,
421+ true ,
422+ false ,
423+ sender,
424+ )
425+ . await ;
426+
427+ let ( tx, mut rx) = tokio:: sync:: mpsc:: channel ( 1 ) ;
428+
429+ let transaction_receipt =
430+ crate :: actions:: EthGetTransactionReceipt :: new ( * mock_tx. hash ( ) , vec ! [ 0 , 1 , 2 ] , 230 , tx) ;
431+
432+ let mut action = crate :: actions:: EthApiAction :: new ( mine_block, transaction_receipt) ;
433+ action. execute ( & mut env) . await ?;
434+
435+ let receipts = rx. recv ( ) . await . expect ( "should receive receipts" ) ;
436+ info ! ( "Receipts: {:?}" , receipts) ;
437+
438+ assert_eq ! (
439+ receipts. len( ) ,
440+ 3 ,
441+ "Should receive receipts from all 3 nodes"
442+ ) ;
443+
444+ for ( idx, receipt_opt) in receipts. iter ( ) . enumerate ( ) {
445+ assert ! (
446+ receipt_opt. is_some( ) ,
447+ "Node {} should return a receipt" ,
448+ idx
449+ ) ;
450+ }
451+
452+ let receipts: Vec < _ > = receipts. into_iter ( ) . map ( |r| r. unwrap ( ) ) . collect ( ) ;
453+
454+ for ( idx, receipt) in receipts. iter ( ) . enumerate ( ) {
455+ assert ! (
456+ receipt. inner. inner. status( ) ,
457+ "Transaction should succeed on node {}" ,
458+ idx
459+ ) ;
460+ }
461+
462+ for ( idx, receipt) in receipts. iter ( ) . enumerate ( ) . skip ( 1 ) {
463+ assert_eq ! (
464+ receipt, & receipts[ 0 ] ,
465+ "Node {} receipt doesn't match node 0" ,
466+ idx
467+ ) ;
468+ }
469+
470+ Ok ( ( ) )
471+ }
441472
442473#[ tokio:: test( flavor = "multi_thread" ) ]
443474async fn test_eth_api_call ( ) -> eyre:: Result < ( ) > {
0 commit comments