@@ -4,41 +4,49 @@ mod tests {
4
4
use alloy:: consensus:: { SignableTransaction , TxEip1559 , TxEnvelope } ;
5
5
use alloy:: signers:: { local:: PrivateKeySigner , SignerSync } ;
6
6
use alloy_primitives:: { bytes, Address , TxKind , U256 } ;
7
-
8
7
use builder:: config:: BuilderConfig ;
9
8
use builder:: tasks:: { block:: BlockBuilder , tx_poller} ;
10
- use reqwest :: Url ;
9
+ use eyre :: Result ;
11
10
12
11
#[ ignore = "integration test" ]
13
12
#[ 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) ;
17
22
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 ? ;
20
25
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 ( ( ) )
24
30
}
25
31
26
- async fn post_tx ( config : BuilderConfig ) {
27
- // create a new test environment
32
+ async fn post_tx ( config : & BuilderConfig ) -> Result < ( ) > {
28
33
let client = reqwest:: Client :: new ( ) ;
29
-
30
- // create a new signed test transaction
31
34
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 ?;
33
39
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
+ }
35
44
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 ( ( ) )
38
46
}
39
47
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 > {
42
50
let tx = TxEip1559 {
43
51
chain_id : 17001 ,
44
52
nonce : 1 ,
@@ -50,38 +58,34 @@ mod tests {
50
58
input : bytes ! ( "" ) ,
51
59
..Default :: default ( )
52
60
} ;
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 ) ) )
55
63
}
56
64
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 ) > {
59
67
let config = BuilderConfig {
60
68
host_chain_id : 17000 ,
61
69
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 ( ) ,
65
72
quincey_url : "http://localhost:8080" . into ( ) ,
66
73
builder_port : 8080 ,
67
74
sequencer_key : None ,
68
75
builder_key : "0000000000000000000000000000000000000000000000000000000000000000" . into ( ) ,
69
76
incoming_transactions_buffer : 1 ,
70
77
block_confirmation_buffer : 1 ,
71
- builder_rewards_address : Address :: from_str (
72
- "0x0000000000000000000000000000000000000000" ,
73
- )
74
- . unwrap ( ) ,
78
+ builder_rewards_address : Address :: default ( ) ,
75
79
rollup_block_gas_limit : 100_000 ,
76
- tx_pool_url : "http://localhost:9000" . into ( ) ,
80
+ tx_pool_url : "http://localhost:9000/ " . into ( ) ,
77
81
tx_pool_cache_duration : 5 ,
78
82
tx_pool_poll_interval : 5 ,
79
83
oauth_client_id : "some_client_id" . into ( ) ,
80
84
oauth_client_secret : "some_client_secret" . into ( ) ,
81
85
oauth_authenticate_url : "http://localhost:8080" . into ( ) ,
82
86
oauth_token_url : "http://localhost:8080" . into ( ) ,
83
- oauth_audience : "some_audience " . into ( ) ,
87
+ oauth_audience : "https://transactions.holesky.signet.sh " . into ( ) ,
84
88
} ;
85
- ( BlockBuilder :: new ( & config) , config)
89
+ Ok ( ( BlockBuilder :: new ( & config) , config) )
86
90
}
87
91
}
0 commit comments