@@ -57,82 +57,45 @@ def test_get_logs_when_rpc_result_is_empty(self, mock_post):
5757 self .assertEqual (mock_post .call_count , 1 )
5858 self .assertEqual (logs , empty_response )
5959
60- @patch ("l1_client.requests.post" )
61- def test_get_timestamp_of_block_retries_after_failure_and_succeeds (self , mock_post ):
62- request_exception = requests .RequestException ("some error" )
63-
64- successful_response = Mock ()
65- successful_response .raise_for_status .return_value = None
66- successful_response .json .return_value = {"result" : {"timestamp" : "0x20" }} # 32
67-
68- mock_post .side_effect = [request_exception , successful_response ]
69-
70- client = L1Client (api_key = "api_key" )
71- result = client .get_timestamp_of_block (
72- block_number = L1TestUtils .BLOCK_NUMBER_HEX ,
73- )
74-
75- self .assertEqual (mock_post .call_count , 2 )
76- self .assertEqual (result , 32 )
77-
78- @patch ("l1_client.requests.post" )
79- def test_get_timestamp_of_block_returns_none_when_rpc_result_is_empty (self , mock_post ):
80- response_ok = Mock ()
81- response_ok .raise_for_status .return_value = None
82- response_ok .json .return_value = {"result" : None }
83-
84- mock_post .return_value = response_ok
85-
86- client = L1Client (api_key = "api_key" )
87- result = client .get_timestamp_of_block (
88- block_number = L1TestUtils .BLOCK_NUMBER_HEX ,
89- )
90-
91- self .assertEqual (mock_post .call_count , 1 )
92- self .assertIsNone (result )
93-
9460 @patch ("l1_client.requests.post" )
9561 def test_get_block_by_number_retries_after_failure_and_succeeds (self , mock_post ):
9662 request_exception = requests .RequestException ("some error" )
97- block_info = {
98- "number" : L1TestUtils .BLOCK_NUMBER_HEX ,
99- "timestamp" : "0x5f5e100" ,
100- }
10163
10264 successful_response = Mock ()
10365 successful_response .raise_for_status .return_value = None
104- successful_response .json .return_value = { "result" : block_info }
66+ successful_response .json .return_value = L1TestUtils . BLOCK_RPC_RESPONSE
10567
10668 mock_post .side_effect = [request_exception , successful_response ]
10769
10870 client = L1Client (api_key = "api_key" )
10971 result = client .get_block_by_number (L1TestUtils .BLOCK_NUMBER_HEX )
11072
11173 self .assertEqual (mock_post .call_count , 2 )
112- self .assertEqual (result , block_info )
74+ self .assertEqual (result , L1TestUtils . BLOCK_RPC_RESPONSE )
11375
11476 @patch ("l1_client.requests.post" )
11577 def test_get_block_by_number_returns_none_when_rpc_result_is_empty (self , mock_post ):
78+ empty_response = L1TestUtils .block_rpc_response_with_block (None )
11679 response_ok = Mock ()
11780 response_ok .raise_for_status .return_value = None
118- response_ok .json .return_value = { "result" : None }
81+ response_ok .json .return_value = empty_response
11982
12083 mock_post .return_value = response_ok
12184
12285 client = L1Client (api_key = "api_key" )
12386 result = client .get_block_by_number (block_number = L1TestUtils .BLOCK_NUMBER_HEX )
12487
12588 self .assertEqual (mock_post .call_count , 1 )
126- self .assertIsNone (result )
89+ self .assertEqual (result , empty_response )
12790
12891 @patch .object (L1Client , "get_block_by_number" )
12992 def test_get_timestamp_of_block_returns_int_timestamp (self , mock_get_block_by_number ):
130- mock_get_block_by_number .return_value = { "timestamp" : "0x5f5e100" }
93+ mock_get_block_by_number .return_value = L1TestUtils . BLOCK_RPC_RESPONSE
13194
13295 client = L1Client (api_key = "api_key" )
13396 result = client .get_timestamp_of_block (L1TestUtils .BLOCK_NUMBER_HEX )
13497
135- self .assertEqual (result , int ( "0x5f5e100" , 16 ) )
98+ self .assertEqual (result , L1TestUtils . BLOCK_TIMESTAMP )
13699 mock_get_block_by_number .assert_called_once_with (L1TestUtils .BLOCK_NUMBER_HEX )
137100
138101 @patch .object (L1Client , "get_block_by_number" )
@@ -146,6 +109,17 @@ def test_get_timestamp_of_block_returns_none_when_block_not_found(
146109
147110 self .assertIsNone (result )
148111
112+ @patch .object (L1Client , "get_block_by_number" )
113+ def test_get_timestamp_of_block_returns_none_when_result_is_none (
114+ self , mock_get_block_by_number
115+ ):
116+ mock_get_block_by_number .return_value = L1TestUtils .block_rpc_response_with_block (None )
117+
118+ client = L1Client (api_key = "api_key" )
119+ result = client .get_timestamp_of_block (block_number = L1TestUtils .BLOCK_NUMBER_HEX )
120+
121+ self .assertIsNone (result )
122+
149123 def test_decode_log_success (self ):
150124 result = L1Client .decode_log_response (L1TestUtils .LOG )
151125
0 commit comments