@@ -4,41 +4,49 @@ mod tests {
44 use alloy:: consensus:: { SignableTransaction , TxEip1559 , TxEnvelope } ;
55 use alloy:: signers:: { local:: PrivateKeySigner , SignerSync } ;
66 use alloy_primitives:: { bytes, Address , TxKind , U256 } ;
7-
87 use builder:: config:: BuilderConfig ;
98 use builder:: tasks:: { block:: BlockBuilder , tx_poller} ;
10- use reqwest :: Url ;
9+ use eyre :: Result ;
1110
1211 #[ ignore = "integration test" ]
1312 #[ tokio:: test]
14- async fn test_tx_roundtrip ( ) {
15- // create a new test environment
16- let ( _, config) = setup_test_builder ( ) . await ;
13+ async fn test_tx_roundtrip ( ) -> Result < ( ) > {
14+ // Create a new test environment
15+ let ( _, config) = setup_test_builder ( ) . await ?;
16+
17+ // Post a transaction to the cache
18+ post_tx ( & config) . await ?;
19+
20+ // Create a new poller
21+ let mut poller = tx_poller:: TxPoller :: new ( & config) ;
1722
18- // post a tx to the cache
19- post_tx ( config . clone ( ) ) . await ;
23+ // Fetch transactions the pool
24+ let transactions = poller . check_tx_pool ( ) . await ? ;
2025
21- // assert that we parsed at least one transaction
22- let got = tx_poller:: TxPoller :: new ( & config) . check_tx_pool ( ) . await . unwrap ( ) ;
23- assert ! ( !got. is_empty( ) ) ;
26+ // Ensure at least one transaction exists
27+ assert ! ( !transactions. is_empty( ) ) ;
28+
29+ Ok ( ( ) )
2430 }
2531
26- async fn post_tx ( config : BuilderConfig ) {
27- // create a new test environment
32+ async fn post_tx ( config : & BuilderConfig ) -> Result < ( ) > {
2833 let client = reqwest:: Client :: new ( ) ;
29-
30- // create a new signed test transaction
3134 let wallet = PrivateKeySigner :: random ( ) ;
32- let tx_envelope = new_test_tx ( & wallet) ;
35+ let tx_envelope = new_test_tx ( & wallet) ?;
36+
37+ let url = format ! ( "{}/transactions" , config. tx_pool_url) ;
38+ let response = client. post ( & url) . json ( & tx_envelope) . send ( ) . await ?;
3339
34- let url: Url = Url :: parse ( & config. tx_pool_url ) . unwrap ( ) . join ( "add" ) . unwrap ( ) ;
40+ if !response. status ( ) . is_success ( ) {
41+ let error_text = response. text ( ) . await ?;
42+ eyre:: bail!( "Failed to post transaction: {}" , error_text) ;
43+ }
3544
36- // send that transaction to ensure there is at least one tx in pool to parse
37- let _ = client. post ( url) . json ( & tx_envelope) . send ( ) . await . unwrap ( ) ;
45+ Ok ( ( ) )
3846 }
3947
40- // returns a new signed test transaction with blank values
41- fn new_test_tx ( wallet : & PrivateKeySigner ) -> TxEnvelope {
48+ // Returns a new signed test transaction with default values
49+ fn new_test_tx ( wallet : & PrivateKeySigner ) -> Result < TxEnvelope > {
4250 let tx = TxEip1559 {
4351 chain_id : 17001 ,
4452 nonce : 1 ,
@@ -50,38 +58,34 @@ mod tests {
5058 input : bytes ! ( "" ) ,
5159 ..Default :: default ( )
5260 } ;
53- let tx_hash = wallet. sign_hash_sync ( & tx. signature_hash ( ) ) . unwrap ( ) ;
54- TxEnvelope :: Eip1559 ( tx. into_signed ( tx_hash ) )
61+ let signature = wallet. sign_hash_sync ( & tx. signature_hash ( ) ) ? ;
62+ Ok ( TxEnvelope :: Eip1559 ( tx. into_signed ( signature ) ) )
5563 }
5664
57- // sets up a block builder with test values
58- async fn setup_test_builder ( ) -> ( BlockBuilder , BuilderConfig ) {
65+ // Sets up a block builder with test values
66+ async fn setup_test_builder ( ) -> Result < ( BlockBuilder , BuilderConfig ) > {
5967 let config = BuilderConfig {
6068 host_chain_id : 17000 ,
6169 ru_chain_id : 17001 ,
62- host_rpc_url : "http://rpc.api.signet.sh" . into ( ) ,
63- zenith_address : Address :: from_str ( "0x0000000000000000000000000000000000000000" )
64- . unwrap ( ) ,
70+ host_rpc_url : "http://rpc.holesky.signet.sh" . into ( ) ,
71+ zenith_address : Address :: default ( ) ,
6572 quincey_url : "http://localhost:8080" . into ( ) ,
6673 builder_port : 8080 ,
6774 sequencer_key : None ,
6875 builder_key : "0000000000000000000000000000000000000000000000000000000000000000" . into ( ) ,
6976 incoming_transactions_buffer : 1 ,
7077 block_confirmation_buffer : 1 ,
71- builder_rewards_address : Address :: from_str (
72- "0x0000000000000000000000000000000000000000" ,
73- )
74- . unwrap ( ) ,
78+ builder_rewards_address : Address :: default ( ) ,
7579 rollup_block_gas_limit : 100_000 ,
76- tx_pool_url : "http://localhost:9000" . into ( ) ,
80+ tx_pool_url : "http://localhost:9000/ " . into ( ) ,
7781 tx_pool_cache_duration : 5 ,
7882 tx_pool_poll_interval : 5 ,
7983 oauth_client_id : "some_client_id" . into ( ) ,
8084 oauth_client_secret : "some_client_secret" . into ( ) ,
8185 oauth_authenticate_url : "http://localhost:8080" . into ( ) ,
8286 oauth_token_url : "http://localhost:8080" . into ( ) ,
83- oauth_audience : "some_audience " . into ( ) ,
87+ oauth_audience : "https://transactions.holesky.signet.sh " . into ( ) ,
8488 } ;
85- ( BlockBuilder :: new ( & config) , config)
89+ Ok ( ( BlockBuilder :: new ( & config) , config) )
8690 }
8791}
0 commit comments