Skip to content

Commit d1c85cd

Browse files
committed
Rename tests for consistent naming across test modules
1 parent 6950e19 commit d1c85cd

9 files changed

+140
-147
lines changed

tests/test_bigquery_provider.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class TestInitialization:
6767
"""Tests for the __init__ method."""
6868

6969

70-
def test_initialization_sets_bigquery_options_and_instance_vars(
70+
def test_init_sets_bigquery_options_and_instance_vars(
7171
self, provider: BigQueryProvider, mock_bpd: MagicMock
7272
):
7373
"""
@@ -98,7 +98,7 @@ def test_get_indexer_eligibility_query_matches_snapshot(self, provider: BigQuery
9898
snapshot.assert_match(query, "indexer_eligibility_query.sql")
9999

100100

101-
def test_get_indexer_eligibility_query_with_single_day_range(self, provider: BigQueryProvider):
101+
def test_get_indexer_eligibility_query_handles_single_day_range(self, provider: BigQueryProvider):
102102
"""
103103
Tests that the query is constructed correctly when start and end dates are the same,
104104
covering an edge case for a single-day analysis period.
@@ -108,7 +108,7 @@ def test_get_indexer_eligibility_query_with_single_day_range(self, provider: Big
108108
assert f"BETWEEN '{SINGLE_DATE.strftime('%Y-%m-%d')}' AND '{SINGLE_DATE.strftime('%Y-%m-%d')}'" in query
109109

110110

111-
def test_get_indexer_eligibility_query_with_invalid_date_range(self, provider: BigQueryProvider):
111+
def test_get_indexer_eligibility_query_handles_invalid_date_range(self, provider: BigQueryProvider):
112112
"""
113113
Tests that the query is constructed correctly even with a logically invalid
114114
date range (start > end), which should result in an empty set from BigQuery
@@ -127,7 +127,7 @@ class TestReadGbqDataframe:
127127
"""Tests for the _read_gbq_dataframe method."""
128128

129129

130-
def test_read_gbq_dataframe_success(
130+
def test_read_gbq_dataframe_succeeds_on_happy_path(
131131
self, mock_sleep: MagicMock, provider: BigQueryProvider, mock_bpd: MagicMock
132132
):
133133
"""
@@ -148,7 +148,7 @@ def test_read_gbq_dataframe_success(
148148

149149

150150
@pytest.mark.parametrize("exception_to_raise", RETRYABLE_EXCEPTIONS)
151-
def test_read_gbq_dataframe_on_retryable_error_succeeds(
151+
def test_read_gbq_dataframe_succeeds_after_retrying_on_error(
152152
self, mock_sleep: MagicMock, exception_to_raise: Exception, provider: BigQueryProvider, mock_bpd: MagicMock
153153
):
154154
"""
@@ -170,7 +170,7 @@ def test_read_gbq_dataframe_on_retryable_error_succeeds(
170170
pd.testing.assert_frame_equal(result_df, MOCK_DATAFRAME)
171171

172172

173-
def test_read_gbq_dataframe_on_persistent_error_fails(
173+
def test_read_gbq_dataframe_fails_on_persistent_error(
174174
self, mock_sleep: MagicMock, provider: BigQueryProvider, mock_bpd: MagicMock
175175
):
176176
"""
@@ -191,7 +191,7 @@ def test_read_gbq_dataframe_on_persistent_error_fails(
191191
mock_sleep.assert_not_called()
192192

193193

194-
def test_read_gbq_dataframe_on_non_retryable_error_fails_immediately(
194+
def test_read_gbq_dataframe_fails_immediately_on_non_retryable_error(
195195
self, mock_sleep: MagicMock, provider: BigQueryProvider, mock_bpd: MagicMock
196196
):
197197
"""
@@ -214,7 +214,7 @@ class TestFetchIndexerIssuanceEligibilityData:
214214
"""Tests for the main fetch_indexer_issuance_eligibility_data method."""
215215

216216

217-
def test_fetch_data_happy_path(self, provider: BigQueryProvider):
217+
def test_fetch_indexer_issuance_eligibility_data_succeeds_on_happy_path(self, provider: BigQueryProvider):
218218
"""
219219
Tests the happy path for `fetch_indexer_issuance_eligibility_data`, ensuring it
220220
orchestrates calls correctly and returns the final DataFrame.
@@ -238,7 +238,9 @@ def test_fetch_data_happy_path(self, provider: BigQueryProvider):
238238
pd.testing.assert_frame_equal(result_df, MOCK_DATAFRAME)
239239

240240

241-
def test_fetch_data_with_empty_result_returns_empty_dataframe(self, provider: BigQueryProvider):
241+
def test_fetch_indexer_issuance_eligibility_data_returns_empty_dataframe_on_empty_result(
242+
self, provider: BigQueryProvider
243+
):
242244
"""
243245
Tests that the method gracefully handles and returns an empty DataFrame from BigQuery.
244246
"""
@@ -262,7 +264,9 @@ def test_fetch_data_with_empty_result_returns_empty_dataframe(self, provider: Bi
262264
pd.testing.assert_frame_equal(result_df, MOCK_EMPTY_DATAFRAME)
263265

264266

265-
def test_fetch_data_on_read_error_propagates_exception(self, provider: BigQueryProvider):
267+
def test_fetch_indexer_issuance_eligibility_data_propagates_exception_on_read_error(
268+
self, provider: BigQueryProvider
269+
):
266270
"""
267271
Tests that an exception from `_read_gbq_dataframe` is correctly propagated.
268272
"""

tests/test_blockchain_client.py

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class TestInitializationAndConnection:
8585
"""Tests focusing on the client's initialization and RPC connection logic."""
8686

8787

88-
def test_successful_initialization(self, blockchain_client: BlockchainClient, mock_w3, mock_file):
88+
def test_init_succeeds_on_happy_path(self, blockchain_client: BlockchainClient, mock_w3, mock_file):
8989
"""
9090
Tests that the BlockchainClient initializes correctly on the happy path.
9191
"""
@@ -109,7 +109,7 @@ def test_successful_initialization(self, blockchain_client: BlockchainClient, mo
109109
assert client.contract is not None
110110

111111

112-
def test_initialization_fails_if_abi_not_found(self, mock_w3, mock_slack):
112+
def test_init_fails_if_abi_not_found(self, mock_w3, mock_slack):
113113
"""
114114
Tests that BlockchainClient raises an exception if the ABI file cannot be found.
115115
"""
@@ -127,7 +127,7 @@ def test_initialization_fails_if_abi_not_found(self, mock_w3, mock_slack):
127127
)
128128

129129

130-
def test_rpc_failover_mechanism(self, mock_w3, mock_slack):
130+
def test_init_failover_succeeds_if_primary_rpc_fails(self, mock_w3, mock_slack):
131131
"""
132132
Tests that the client successfully fails over to a secondary RPC if the primary fails.
133133
"""
@@ -159,7 +159,7 @@ def test_rpc_failover_mechanism(self, mock_w3, mock_slack):
159159
assert client.current_rpc_index == 1
160160

161161

162-
def test_connection_error_if_all_rpcs_fail(self, mock_w3, mock_slack):
162+
def test_init_fails_if_all_rpcs_fail(self, mock_w3, mock_slack):
163163
"""
164164
Tests that a ConnectionError is raised if the client cannot connect to any RPC provider.
165165
"""
@@ -184,7 +184,7 @@ def test_connection_error_if_all_rpcs_fail(self, mock_w3, mock_slack):
184184
)
185185

186186

187-
def test_execute_rpc_call_with_failover(self, blockchain_client: BlockchainClient):
187+
def test_execute_rpc_call_failover_succeeds_on_connection_error(self, blockchain_client: BlockchainClient):
188188
"""
189189
Tests that _execute_rpc_call fails over to the next provider if the first one
190190
is unreachable, and sends a Slack notification.
@@ -216,7 +216,7 @@ def test_execute_rpc_call_with_failover(self, blockchain_client: BlockchainClien
216216
assert "Switching from previous RPC" in call_kwargs["message"]
217217

218218

219-
def test_execute_rpc_call_reraises_unexpected_exceptions(self, blockchain_client: BlockchainClient):
219+
def test_execute_rpc_call_reraises_unexpected_exception(self, blockchain_client: BlockchainClient):
220220
"""
221221
Tests that _execute_rpc_call does not attempt to failover on unexpected,
222222
non-network errors and instead re-raises them immediately.
@@ -234,7 +234,7 @@ def test_execute_rpc_call_reraises_unexpected_exceptions(self, blockchain_client
234234
blockchain_client.slack_notifier.send_info_notification.assert_not_called()
235235

236236

237-
def test_initialization_fails_with_empty_rpc_provider_list(self, mock_w3, mock_slack):
237+
def test_init_fails_with_empty_rpc_list(self, mock_w3, mock_slack):
238238
"""
239239
Tests that BlockchainClient raises an exception if initialized with an empty list of RPC providers.
240240
"""
@@ -256,7 +256,7 @@ class TestTransactionLogic:
256256
"""Tests focusing on the helper methods for building and sending a transaction."""
257257

258258

259-
def test_setup_transaction_account_success(self, blockchain_client: BlockchainClient):
259+
def test_setup_transaction_account_succeeds_with_valid_key(self, blockchain_client: BlockchainClient):
260260
"""
261261
Tests that _setup_transaction_account returns the correct address and formatted key
262262
for a valid private key.
@@ -272,9 +272,7 @@ def test_setup_transaction_account_success(self, blockchain_client: BlockchainCl
272272
assert key == MOCK_PRIVATE_KEY
273273

274274

275-
def test_setup_transaction_account_invalid_key_raises_key_validation_error(
276-
self, blockchain_client: BlockchainClient
277-
):
275+
def test_setup_transaction_account_fails_with_invalid_key(self, blockchain_client: BlockchainClient):
278276
"""
279277
Tests that _setup_transaction_account raises KeyValidationError for an invalid key.
280278
"""
@@ -285,7 +283,7 @@ def test_setup_transaction_account_invalid_key_raises_key_validation_error(
285283
blockchain_client._setup_transaction_account("invalid-key")
286284

287285

288-
def test_setup_transaction_account_unexpected_error(self, blockchain_client: BlockchainClient):
286+
def test_setup_transaction_account_fails_on_unexpected_error(self, blockchain_client: BlockchainClient):
289287
"""
290288
Tests that _setup_transaction_account raises a generic exception for unexpected errors.
291289
"""
@@ -296,7 +294,7 @@ def test_setup_transaction_account_unexpected_error(self, blockchain_client: Blo
296294
blockchain_client._setup_transaction_account("any-key")
297295

298296

299-
def test_estimate_transaction_gas_success(self, blockchain_client: BlockchainClient):
297+
def test_estimate_transaction_gas_succeeds_and_adds_buffer(self, blockchain_client: BlockchainClient):
300298
"""
301299
Tests that _estimate_transaction_gas correctly estimates gas and adds a 25% buffer.
302300
"""
@@ -318,7 +316,7 @@ def test_estimate_transaction_gas_success(self, blockchain_client: BlockchainCli
318316
mock_contract_func.return_value.estimate_gas.assert_called_once_with({"from": MOCK_SENDER_ADDRESS})
319317

320318

321-
def test_estimate_transaction_gas_failure(self, blockchain_client: BlockchainClient):
319+
def test_estimate_transaction_gas_fails_on_rpc_error(self, blockchain_client: BlockchainClient):
322320
"""
323321
Tests that _estimate_transaction_gas raises an exception if the RPC call fails.
324322
"""
@@ -336,7 +334,7 @@ def test_estimate_transaction_gas_failure(self, blockchain_client: BlockchainCli
336334
)
337335

338336

339-
def test_determine_transaction_nonce_new(self, blockchain_client: BlockchainClient):
337+
def test_determine_transaction_nonce_fetches_next_nonce_for_new_tx(self, blockchain_client: BlockchainClient):
340338
"""
341339
Tests that the next available nonce is fetched for a new transaction (replace=False).
342340
"""
@@ -352,7 +350,9 @@ def test_determine_transaction_nonce_new(self, blockchain_client: BlockchainClie
352350
blockchain_client.mock_w3_instance.eth.get_transaction_count.assert_called_once_with(MOCK_SENDER_ADDRESS)
353351

354352

355-
def test_determine_transaction_nonce_replace(self, blockchain_client: BlockchainClient):
353+
def test_determine_transaction_nonce_uses_oldest_pending_for_replacement(
354+
self, blockchain_client: BlockchainClient
355+
):
356356
"""
357357
Tests that the nonce of the oldest pending transaction is used for replacement (replace=True).
358358
"""
@@ -375,9 +375,7 @@ def test_determine_transaction_nonce_replace(self, blockchain_client: Blockchain
375375
blockchain_client.mock_w3_instance.eth.get_block.assert_called_once_with("pending", full_transactions=True)
376376

377377

378-
def test_determine_transaction_nonce_replace_no_pending_tx_with_nonce_gap(
379-
self, blockchain_client: BlockchainClient
380-
):
378+
def test_determine_transaction_nonce_falls_back_to_latest_on_nonce_gap(self, blockchain_client: BlockchainClient):
381379
"""
382380
Tests that nonce determination falls back to the latest nonce
383381
if no pending txs are found but a nonce gap exists.
@@ -397,7 +395,7 @@ def test_determine_transaction_nonce_replace_no_pending_tx_with_nonce_gap(
397395
assert blockchain_client.mock_w3_instance.eth.get_transaction_count.call_count == 2
398396

399397

400-
def test_determine_transaction_nonce_replace_no_pending_tx_no_gap_fallback(
398+
def test_determine_transaction_nonce_falls_back_to_standard_if_no_pending_or_gap(
401399
self, blockchain_client: BlockchainClient
402400
):
403401
"""
@@ -421,7 +419,7 @@ def test_determine_transaction_nonce_replace_no_pending_tx_no_gap_fallback(
421419
assert w3_instance.eth.get_transaction_count.call_count == 3
422420

423421

424-
def test_determine_transaction_nonce_replace_handles_errors(self, blockchain_client: BlockchainClient):
422+
def test_determine_transaction_nonce_falls_back_on_error(self, blockchain_client: BlockchainClient):
425423
"""
426424
Tests that nonce determination falls back gracefully if checking for pending
427425
transactions fails.
@@ -440,7 +438,7 @@ def test_determine_transaction_nonce_replace_handles_errors(self, blockchain_cli
440438
w3_instance.eth.get_transaction_count.assert_called()
441439

442440

443-
def test_get_gas_prices_success(self, blockchain_client: BlockchainClient):
441+
def test_get_gas_prices_succeeds_on_happy_path(self, blockchain_client: BlockchainClient):
444442
"""
445443
Tests that _get_gas_prices successfully fetches and returns the base and priority fees.
446444
"""
@@ -459,7 +457,7 @@ def test_get_gas_prices_success(self, blockchain_client: BlockchainClient):
459457
assert max_priority_fee == mock_priority_fee
460458

461459

462-
def test_get_gas_prices_fallback_on_base_fee_error(self, blockchain_client: BlockchainClient):
460+
def test_get_gas_prices_falls_back_on_base_fee_error(self, blockchain_client: BlockchainClient):
463461
"""
464462
Tests that _get_gas_prices falls back to a default base fee if the RPC call fails.
465463
"""
@@ -475,7 +473,7 @@ def test_get_gas_prices_fallback_on_base_fee_error(self, blockchain_client: Bloc
475473
blockchain_client.mock_w3_instance.to_wei.assert_called_once_with(10, "gwei")
476474

477475

478-
def test_get_gas_prices_fallback_on_priority_fee_error(self, blockchain_client: BlockchainClient):
476+
def test_get_gas_prices_falls_back_on_priority_fee_error(self, blockchain_client: BlockchainClient):
479477
"""
480478
Tests that _get_gas_prices falls back to a default priority fee if the RPC call fails.
481479
"""
@@ -500,7 +498,7 @@ def test_get_gas_prices_fallback_on_priority_fee_error(self, blockchain_client:
500498
(True, 420, 20), # Replacement: base*4 + priority*2
501499
],
502500
)
503-
def test_build_transaction_params(
501+
def test_build_transaction_params_builds_correctly(
504502
self,
505503
replace,
506504
expected_max_fee,
@@ -528,7 +526,7 @@ def test_build_transaction_params(
528526
assert tx_params["nonce"] == 1
529527

530528

531-
def test_build_and_sign_transaction_success(self, blockchain_client: BlockchainClient):
529+
def test_build_and_sign_transaction_succeeds_on_happy_path(self, blockchain_client: BlockchainClient):
532530
"""
533531
Tests that _build_and_sign_transaction successfully builds and signs a transaction.
534532
"""
@@ -557,7 +555,7 @@ def test_build_and_sign_transaction_success(self, blockchain_client: BlockchainC
557555
)
558556

559557

560-
def test_build_and_sign_transaction_failure(self, blockchain_client: BlockchainClient):
558+
def test_build_and_sign_transaction_fails_on_build_error(self, blockchain_client: BlockchainClient):
561559
"""
562560
Tests that _build_and_sign_transaction raises an exception if building fails.
563561
"""
@@ -576,7 +574,7 @@ def test_build_and_sign_transaction_failure(self, blockchain_client: BlockchainC
576574
)
577575

578576

579-
def test_send_signed_transaction_success(self, blockchain_client: BlockchainClient):
577+
def test_send_signed_transaction_succeeds_on_happy_path(self, blockchain_client: BlockchainClient):
580578
"""
581579
Tests that a signed transaction is sent and its hash is returned on success.
582580
"""
@@ -600,7 +598,7 @@ def test_send_signed_transaction_success(self, blockchain_client: BlockchainClie
600598
)
601599

602600

603-
def test_send_signed_transaction_raises_exception_when_reverted(self, blockchain_client: BlockchainClient):
601+
def test_send_signed_transaction_fails_if_reverted(self, blockchain_client: BlockchainClient):
604602
"""
605603
Tests that an exception is raised if the transaction is reverted on-chain.
606604
"""
@@ -619,7 +617,7 @@ def test_send_signed_transaction_raises_exception_when_reverted(self, blockchain
619617
blockchain_client._send_signed_transaction(mock_signed_tx)
620618

621619

622-
def test_send_signed_transaction_raises_exception_on_timeout(self, blockchain_client: BlockchainClient):
620+
def test_send_signed_transaction_fails_on_timeout(self, blockchain_client: BlockchainClient):
623621
"""
624622
Tests that an exception is raised if waiting for the transaction receipt times out.
625623
"""
@@ -681,7 +679,7 @@ class TestOrchestrationAndBatching:
681679
"""Tests focusing on the end-to-end orchestration and batch processing logic."""
682680

683681

684-
def test_execute_complete_transaction_happy_path(
682+
def test_execute_complete_transaction_succeeds_on_happy_path(
685683
self,
686684
blockchain_client: BlockchainClient,
687685
mocker: MockerFixture,
@@ -726,7 +724,7 @@ def test_execute_complete_transaction_happy_path(
726724
mock_full_transaction_flow["send"].assert_called_once_with("signed_tx")
727725

728726

729-
def test_execute_complete_transaction_missing_params(self, blockchain_client: BlockchainClient):
727+
def test_execute_complete_transaction_fails_on_missing_params(self, blockchain_client: BlockchainClient):
730728
"""
731729
Tests that _execute_complete_transaction raises ValueError if required parameters are missing.
732730
"""
@@ -738,7 +736,7 @@ def test_execute_complete_transaction_missing_params(self, blockchain_client: Bl
738736
blockchain_client._execute_complete_transaction(incomplete_params)
739737

740738

741-
def test_execute_complete_transaction_invalid_function(self, blockchain_client: BlockchainClient):
739+
def test_execute_complete_transaction_fails_on_invalid_function(self, blockchain_client: BlockchainClient):
742740
"""
743741
Tests that _execute_complete_transaction raises ValueError for a non-existent contract function.
744742
"""
@@ -761,7 +759,7 @@ def test_execute_complete_transaction_invalid_function(self, blockchain_client:
761759
blockchain_client._execute_complete_transaction(params)
762760

763761

764-
def test_send_transaction_to_allow_indexers_orchestration(
762+
def test_send_transaction_to_allow_indexers_calls_execution_method(
765763
self, blockchain_client: BlockchainClient, mocker: MockerFixture
766764
):
767765
"""
@@ -792,7 +790,7 @@ def test_send_transaction_to_allow_indexers_orchestration(
792790
assert call_args["replace"] is False
793791

794792

795-
def test_batch_processing_splits_correctly(self, blockchain_client: BlockchainClient):
793+
def test_batch_allow_indexers_splits_batches_correctly(self, blockchain_client: BlockchainClient):
796794
"""
797795
Tests that the batch processing logic correctly splits a list of addresses
798796
into multiple transactions based on batch size.
@@ -822,7 +820,7 @@ def test_batch_processing_splits_correctly(self, blockchain_client: BlockchainCl
822820
assert blockchain_client.send_transaction_to_allow_indexers.call_args_list[2][0][0] == addresses[4:5]
823821

824822

825-
def test_batch_processing_halts_on_failure(self, blockchain_client: BlockchainClient):
823+
def test_batch_allow_indexers_halts_on_failure(self, blockchain_client: BlockchainClient):
826824
"""
827825
Tests that the batch processing halts immediately if one of the transactions fails.
828826
"""
@@ -849,7 +847,7 @@ def test_batch_processing_halts_on_failure(self, blockchain_client: BlockchainCl
849847
assert blockchain_client.send_transaction_to_allow_indexers.call_count == 2
850848

851849

852-
def test_batch_processing_handles_empty_list(self, blockchain_client: BlockchainClient):
850+
def test_batch_allow_indexers_handles_empty_list(self, blockchain_client: BlockchainClient):
853851
"""
854852
Tests that batch processing handles an empty list of addresses gracefully.
855853
"""

0 commit comments

Comments
 (0)