@@ -45,8 +45,10 @@ const DEPRECATED_GATEWAY_DEPLOY_ACCOUNT_TX_RESPONSE_JSON_PATH: &str =
4545
4646const EXPECTED_TX_HASH : TransactionHash = TransactionHash ( Felt :: ONE ) ;
4747
48+ // TODO(Tsabary): find a better way to allocate different ports to different tests.
49+
4850// The http_server is oblivious to the GateWayOutput type, so we always return invoke.
49- pub fn default_gateway_output ( ) -> GatewayOutput {
51+ fn default_gateway_output ( ) -> GatewayOutput {
5052 GatewayOutput :: Invoke ( InvokeGatewayOutput :: new ( EXPECTED_TX_HASH ) )
5153}
5254
@@ -88,6 +90,28 @@ async fn to_bytes(res: Response) -> Bytes {
8890 res. into_body ( ) . collect ( ) . await . unwrap ( ) . to_bytes ( )
8991}
9092
93+ // TODO(Tsabary): there's a discrepancy with the used `StatusCode` crates: reqwest and hyper. Some
94+ // tests expect the former and some the other, based on the used test utils. Better sort this out
95+ // and make consistent across.
96+
97+ // Uses add_tx_http_client with index 0.
98+ /// Test that an HTTP server with a `allow_new_txs = false` config rejects new transactions.
99+ #[ rstest]
100+ #[ tokio:: test]
101+ async fn allow_new_txs ( ) {
102+ let tx = rpc_invoke_tx ( ) ;
103+
104+ let mock_gateway_client = MockGatewayClient :: new ( ) ;
105+ let mock_config_manager_client = get_mock_config_manager_client ( false ) ;
106+
107+ let http_client = add_tx_http_client ( mock_config_manager_client, mock_gateway_client, 0 ) . await ;
108+
109+ // Send a transaction to the server.
110+ let response = http_client. add_tx ( tx. clone ( ) ) . await ;
111+ let status = response. status ( ) ;
112+ assert_eq ! ( status, reqwest:: StatusCode :: SERVICE_UNAVAILABLE , "{status:?}" ) ;
113+ }
114+
91115#[ tokio:: test]
92116async fn error_into_response ( ) {
93117 let error = HttpServerError :: DeserializationError (
@@ -106,6 +130,7 @@ async fn error_into_response() {
106130 ) ;
107131}
108132
133+ // Uses add_tx_http_client with indices 1,2.
109134#[ traced_test]
110135#[ rstest]
111136#[ case:: add_deprecated_gateway_tx( 0 , deprecated_gateway_invoke_tx( ) ) ]
@@ -127,7 +152,7 @@ async fn record_region_test(#[case] index: u16, #[case] tx: impl GatewayTransact
127152 . times ( 1 )
128153 . return_const ( Ok ( GatewayOutput :: Invoke ( InvokeGatewayOutput :: new ( tx_hash_2) ) ) ) ;
129154
130- let mock_config_manager_client = get_mock_config_manager_client ( ) ;
155+ let mock_config_manager_client = get_mock_config_manager_client ( true ) ;
131156 // TODO(Yael): avoid the hardcoded node offset index, consider dynamic allocation.
132157 let http_client =
133158 add_tx_http_client ( mock_config_manager_client, mock_gateway_client, 1 + index) . await ;
@@ -146,6 +171,7 @@ async fn record_region_test(#[case] index: u16, #[case] tx: impl GatewayTransact
146171 ) ) ;
147172}
148173
174+ // Uses add_tx_http_client with indices 3,4.
149175#[ traced_test]
150176#[ rstest]
151177#[ case:: add_deprecated_gateway_tx( 0 , deprecated_gateway_invoke_tx( ) ) ]
@@ -162,7 +188,7 @@ async fn record_region_gateway_failing_tx(#[case] index: u16, #[case] tx: impl G
162188 ) ) ,
163189 ) ) ;
164190
165- let mock_config_manager_client = get_mock_config_manager_client ( ) ;
191+ let mock_config_manager_client = get_mock_config_manager_client ( true ) ;
166192 let http_client =
167193 add_tx_http_client ( mock_config_manager_client, mock_gateway_client, 3 + index) . await ;
168194
@@ -171,6 +197,7 @@ async fn record_region_gateway_failing_tx(#[case] index: u16, #[case] tx: impl G
171197 assert ! ( !logs_contain( "Recorded transaction transaction_hash=" ) ) ;
172198}
173199
200+ // Uses add_tx_http_client with indices 5,6,7.
174201#[ rstest]
175202#[ case:: add_deprecated_gateway_invoke( 0 , deprecated_gateway_invoke_tx( ) ) ]
176203#[ case:: add_deprecated_gateway_deploy_account( 1 , deprecated_gateway_deploy_account_tx( ) ) ]
@@ -212,7 +239,7 @@ async fn test_response(#[case] index: u16, #[case] tx: impl GatewayTransaction)
212239 expected_internal_err,
213240 ) ) ;
214241
215- let mock_config_manager_client = get_mock_config_manager_client ( ) ;
242+ let mock_config_manager_client = get_mock_config_manager_client ( true ) ;
216243 let http_client =
217244 add_tx_http_client ( mock_config_manager_client, mock_gateway_client, 5 + index) . await ;
218245
@@ -231,6 +258,7 @@ async fn test_response(#[case] index: u16, #[case] tx: impl GatewayTransaction)
231258 assert_eq ! ( error_str, expected_gateway_client_err_str) ;
232259}
233260
261+ // Uses add_tx_http_client with indices 9,10,11.
234262#[ rstest]
235263#[ case:: missing_version(
236264 0 ,
@@ -281,7 +309,7 @@ async fn test_unsupported_tx_version(
281309 }
282310
283311 let mock_gateway_client = MockGatewayClient :: new ( ) ;
284- let mock_config_manager_client = get_mock_config_manager_client ( ) ;
312+ let mock_config_manager_client = get_mock_config_manager_client ( true ) ;
285313 let http_client =
286314 add_tx_http_client ( mock_config_manager_client, mock_gateway_client, 9 + index) . await ;
287315
@@ -291,6 +319,7 @@ async fn test_unsupported_tx_version(
291319 assert_eq ! ( starknet_error, expected_err) ;
292320}
293321
322+ // Uses add_tx_http_client with index 13.
294323#[ tokio:: test]
295324async fn sanitizing_error_message ( ) {
296325 // Set the tx version to be a problematic text.
@@ -302,7 +331,7 @@ async fn sanitizing_error_message() {
302331 tx_object. insert ( "version" . to_string ( ) , Value :: String ( malicious_version. to_string ( ) ) ) . unwrap ( ) ;
303332
304333 let mock_gateway_client = MockGatewayClient :: new ( ) ;
305- let mock_config_manager_client = get_mock_config_manager_client ( ) ;
334+ let mock_config_manager_client = get_mock_config_manager_client ( true ) ;
306335 let http_client = add_tx_http_client ( mock_config_manager_client, mock_gateway_client, 13 ) . await ;
307336
308337 let serialized_err =
0 commit comments