@@ -85,7 +85,7 @@ class TestInitializationAndConnection:
85
85
"""Tests focusing on the client's initialization and RPC connection logic."""
86
86
87
87
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 ):
89
89
"""
90
90
Tests that the BlockchainClient initializes correctly on the happy path.
91
91
"""
@@ -109,7 +109,7 @@ def test_successful_initialization(self, blockchain_client: BlockchainClient, mo
109
109
assert client .contract is not None
110
110
111
111
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 ):
113
113
"""
114
114
Tests that BlockchainClient raises an exception if the ABI file cannot be found.
115
115
"""
@@ -127,7 +127,7 @@ def test_initialization_fails_if_abi_not_found(self, mock_w3, mock_slack):
127
127
)
128
128
129
129
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 ):
131
131
"""
132
132
Tests that the client successfully fails over to a secondary RPC if the primary fails.
133
133
"""
@@ -159,7 +159,7 @@ def test_rpc_failover_mechanism(self, mock_w3, mock_slack):
159
159
assert client .current_rpc_index == 1
160
160
161
161
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 ):
163
163
"""
164
164
Tests that a ConnectionError is raised if the client cannot connect to any RPC provider.
165
165
"""
@@ -184,7 +184,7 @@ def test_connection_error_if_all_rpcs_fail(self, mock_w3, mock_slack):
184
184
)
185
185
186
186
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 ):
188
188
"""
189
189
Tests that _execute_rpc_call fails over to the next provider if the first one
190
190
is unreachable, and sends a Slack notification.
@@ -216,7 +216,7 @@ def test_execute_rpc_call_with_failover(self, blockchain_client: BlockchainClien
216
216
assert "Switching from previous RPC" in call_kwargs ["message" ]
217
217
218
218
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 ):
220
220
"""
221
221
Tests that _execute_rpc_call does not attempt to failover on unexpected,
222
222
non-network errors and instead re-raises them immediately.
@@ -234,7 +234,7 @@ def test_execute_rpc_call_reraises_unexpected_exceptions(self, blockchain_client
234
234
blockchain_client .slack_notifier .send_info_notification .assert_not_called ()
235
235
236
236
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 ):
238
238
"""
239
239
Tests that BlockchainClient raises an exception if initialized with an empty list of RPC providers.
240
240
"""
@@ -256,7 +256,7 @@ class TestTransactionLogic:
256
256
"""Tests focusing on the helper methods for building and sending a transaction."""
257
257
258
258
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 ):
260
260
"""
261
261
Tests that _setup_transaction_account returns the correct address and formatted key
262
262
for a valid private key.
@@ -272,9 +272,7 @@ def test_setup_transaction_account_success(self, blockchain_client: BlockchainCl
272
272
assert key == MOCK_PRIVATE_KEY
273
273
274
274
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 ):
278
276
"""
279
277
Tests that _setup_transaction_account raises KeyValidationError for an invalid key.
280
278
"""
@@ -285,7 +283,7 @@ def test_setup_transaction_account_invalid_key_raises_key_validation_error(
285
283
blockchain_client ._setup_transaction_account ("invalid-key" )
286
284
287
285
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 ):
289
287
"""
290
288
Tests that _setup_transaction_account raises a generic exception for unexpected errors.
291
289
"""
@@ -296,7 +294,7 @@ def test_setup_transaction_account_unexpected_error(self, blockchain_client: Blo
296
294
blockchain_client ._setup_transaction_account ("any-key" )
297
295
298
296
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 ):
300
298
"""
301
299
Tests that _estimate_transaction_gas correctly estimates gas and adds a 25% buffer.
302
300
"""
@@ -318,7 +316,7 @@ def test_estimate_transaction_gas_success(self, blockchain_client: BlockchainCli
318
316
mock_contract_func .return_value .estimate_gas .assert_called_once_with ({"from" : MOCK_SENDER_ADDRESS })
319
317
320
318
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 ):
322
320
"""
323
321
Tests that _estimate_transaction_gas raises an exception if the RPC call fails.
324
322
"""
@@ -336,7 +334,7 @@ def test_estimate_transaction_gas_failure(self, blockchain_client: BlockchainCli
336
334
)
337
335
338
336
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 ):
340
338
"""
341
339
Tests that the next available nonce is fetched for a new transaction (replace=False).
342
340
"""
@@ -352,7 +350,9 @@ def test_determine_transaction_nonce_new(self, blockchain_client: BlockchainClie
352
350
blockchain_client .mock_w3_instance .eth .get_transaction_count .assert_called_once_with (MOCK_SENDER_ADDRESS )
353
351
354
352
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
+ ):
356
356
"""
357
357
Tests that the nonce of the oldest pending transaction is used for replacement (replace=True).
358
358
"""
@@ -375,9 +375,7 @@ def test_determine_transaction_nonce_replace(self, blockchain_client: Blockchain
375
375
blockchain_client .mock_w3_instance .eth .get_block .assert_called_once_with ("pending" , full_transactions = True )
376
376
377
377
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 ):
381
379
"""
382
380
Tests that nonce determination falls back to the latest nonce
383
381
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(
397
395
assert blockchain_client .mock_w3_instance .eth .get_transaction_count .call_count == 2
398
396
399
397
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 (
401
399
self , blockchain_client : BlockchainClient
402
400
):
403
401
"""
@@ -421,7 +419,7 @@ def test_determine_transaction_nonce_replace_no_pending_tx_no_gap_fallback(
421
419
assert w3_instance .eth .get_transaction_count .call_count == 3
422
420
423
421
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 ):
425
423
"""
426
424
Tests that nonce determination falls back gracefully if checking for pending
427
425
transactions fails.
@@ -440,7 +438,7 @@ def test_determine_transaction_nonce_replace_handles_errors(self, blockchain_cli
440
438
w3_instance .eth .get_transaction_count .assert_called ()
441
439
442
440
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 ):
444
442
"""
445
443
Tests that _get_gas_prices successfully fetches and returns the base and priority fees.
446
444
"""
@@ -459,7 +457,7 @@ def test_get_gas_prices_success(self, blockchain_client: BlockchainClient):
459
457
assert max_priority_fee == mock_priority_fee
460
458
461
459
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 ):
463
461
"""
464
462
Tests that _get_gas_prices falls back to a default base fee if the RPC call fails.
465
463
"""
@@ -475,7 +473,7 @@ def test_get_gas_prices_fallback_on_base_fee_error(self, blockchain_client: Bloc
475
473
blockchain_client .mock_w3_instance .to_wei .assert_called_once_with (10 , "gwei" )
476
474
477
475
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 ):
479
477
"""
480
478
Tests that _get_gas_prices falls back to a default priority fee if the RPC call fails.
481
479
"""
@@ -500,7 +498,7 @@ def test_get_gas_prices_fallback_on_priority_fee_error(self, blockchain_client:
500
498
(True , 420 , 20 ), # Replacement: base*4 + priority*2
501
499
],
502
500
)
503
- def test_build_transaction_params (
501
+ def test_build_transaction_params_builds_correctly (
504
502
self ,
505
503
replace ,
506
504
expected_max_fee ,
@@ -528,7 +526,7 @@ def test_build_transaction_params(
528
526
assert tx_params ["nonce" ] == 1
529
527
530
528
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 ):
532
530
"""
533
531
Tests that _build_and_sign_transaction successfully builds and signs a transaction.
534
532
"""
@@ -557,7 +555,7 @@ def test_build_and_sign_transaction_success(self, blockchain_client: BlockchainC
557
555
)
558
556
559
557
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 ):
561
559
"""
562
560
Tests that _build_and_sign_transaction raises an exception if building fails.
563
561
"""
@@ -576,7 +574,7 @@ def test_build_and_sign_transaction_failure(self, blockchain_client: BlockchainC
576
574
)
577
575
578
576
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 ):
580
578
"""
581
579
Tests that a signed transaction is sent and its hash is returned on success.
582
580
"""
@@ -600,7 +598,7 @@ def test_send_signed_transaction_success(self, blockchain_client: BlockchainClie
600
598
)
601
599
602
600
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 ):
604
602
"""
605
603
Tests that an exception is raised if the transaction is reverted on-chain.
606
604
"""
@@ -619,7 +617,7 @@ def test_send_signed_transaction_raises_exception_when_reverted(self, blockchain
619
617
blockchain_client ._send_signed_transaction (mock_signed_tx )
620
618
621
619
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 ):
623
621
"""
624
622
Tests that an exception is raised if waiting for the transaction receipt times out.
625
623
"""
@@ -681,7 +679,7 @@ class TestOrchestrationAndBatching:
681
679
"""Tests focusing on the end-to-end orchestration and batch processing logic."""
682
680
683
681
684
- def test_execute_complete_transaction_happy_path (
682
+ def test_execute_complete_transaction_succeeds_on_happy_path (
685
683
self ,
686
684
blockchain_client : BlockchainClient ,
687
685
mocker : MockerFixture ,
@@ -726,7 +724,7 @@ def test_execute_complete_transaction_happy_path(
726
724
mock_full_transaction_flow ["send" ].assert_called_once_with ("signed_tx" )
727
725
728
726
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 ):
730
728
"""
731
729
Tests that _execute_complete_transaction raises ValueError if required parameters are missing.
732
730
"""
@@ -738,7 +736,7 @@ def test_execute_complete_transaction_missing_params(self, blockchain_client: Bl
738
736
blockchain_client ._execute_complete_transaction (incomplete_params )
739
737
740
738
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 ):
742
740
"""
743
741
Tests that _execute_complete_transaction raises ValueError for a non-existent contract function.
744
742
"""
@@ -761,7 +759,7 @@ def test_execute_complete_transaction_invalid_function(self, blockchain_client:
761
759
blockchain_client ._execute_complete_transaction (params )
762
760
763
761
764
- def test_send_transaction_to_allow_indexers_orchestration (
762
+ def test_send_transaction_to_allow_indexers_calls_execution_method (
765
763
self , blockchain_client : BlockchainClient , mocker : MockerFixture
766
764
):
767
765
"""
@@ -792,7 +790,7 @@ def test_send_transaction_to_allow_indexers_orchestration(
792
790
assert call_args ["replace" ] is False
793
791
794
792
795
- def test_batch_processing_splits_correctly (self , blockchain_client : BlockchainClient ):
793
+ def test_batch_allow_indexers_splits_batches_correctly (self , blockchain_client : BlockchainClient ):
796
794
"""
797
795
Tests that the batch processing logic correctly splits a list of addresses
798
796
into multiple transactions based on batch size.
@@ -822,7 +820,7 @@ def test_batch_processing_splits_correctly(self, blockchain_client: BlockchainCl
822
820
assert blockchain_client .send_transaction_to_allow_indexers .call_args_list [2 ][0 ][0 ] == addresses [4 :5 ]
823
821
824
822
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 ):
826
824
"""
827
825
Tests that the batch processing halts immediately if one of the transactions fails.
828
826
"""
@@ -849,7 +847,7 @@ def test_batch_processing_halts_on_failure(self, blockchain_client: BlockchainCl
849
847
assert blockchain_client .send_transaction_to_allow_indexers .call_count == 2
850
848
851
849
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 ):
853
851
"""
854
852
Tests that batch processing handles an empty list of addresses gracefully.
855
853
"""
0 commit comments