Skip to content

Commit b9e411f

Browse files
committed
Remove test command
1 parent 1866482 commit b9e411f

File tree

2 files changed

+0
-351
lines changed

2 files changed

+0
-351
lines changed

safe_transaction_service/history/management/commands/safe_contract.py

Lines changed: 0 additions & 157 deletions
This file was deleted.

safe_transaction_service/history/tests/test_commands.py

Lines changed: 0 additions & 194 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
IndexingStatus,
2121
InternalTxDecoded,
2222
ProxyFactory,
23-
SafeContract,
2423
SafeLastStatus,
2524
SafeMasterCopy,
2625
)
@@ -739,196 +738,3 @@ def test_validate_tx_integrity(self):
739738
)
740739
self.assertNotIn("is not matching", text)
741740
self.assertNotIn("is not valid for multisig transaction", text)
742-
743-
@mock.patch(
744-
"safe_transaction_service.history.management.commands.safe_contract.get_auto_ethereum_client"
745-
)
746-
@mock.patch(
747-
"safe_transaction_service.history.management.commands.safe_contract.SafeEventsIndexer"
748-
)
749-
@mock.patch(
750-
"safe_transaction_service.history.management.commands.safe_contract.SafeTxProcessorProvider"
751-
)
752-
def test_safe_contract_add(
753-
self,
754-
mock_tx_processor_provider: MagicMock,
755-
mock_safe_events_indexer: MagicMock,
756-
mock_get_ethereum_client: MagicMock,
757-
):
758-
"""Test adding a SafeContract entry processes events through the indexer."""
759-
command = "safe_contract"
760-
761-
safe_address = Account.create().address
762-
tx_hash = "0x" + "ab" * 32
763-
764-
# Mock the ethereum client and its get_transaction_receipt method
765-
mock_client = MagicMock()
766-
mock_get_ethereum_client.return_value = mock_client
767-
mock_client.get_transaction_receipt.return_value = {
768-
"logs": [{"logIndex": 0, "transactionHash": tx_hash}],
769-
"transactionHash": tx_hash,
770-
}
771-
772-
# Mock indexer instance
773-
mock_indexer_instance = MagicMock()
774-
mock_safe_events_indexer.return_value = mock_indexer_instance
775-
776-
# Mock tx processor
777-
mock_tx_processor = MagicMock()
778-
mock_tx_processor_provider.return_value = mock_tx_processor
779-
780-
self.assertEqual(SafeContract.objects.count(), 0)
781-
782-
# Add SafeContract - command will process through indexer
783-
buf = StringIO()
784-
call_command(command, "add", safe_address, tx_hash, stdout=buf)
785-
output = buf.getvalue()
786-
787-
# Verify get_transaction_receipt was called
788-
mock_client.get_transaction_receipt.assert_called_once()
789-
790-
# Verify SafeEventsIndexer was created with ignored_initiators=set()
791-
mock_safe_events_indexer.assert_called_once()
792-
call_kwargs = mock_safe_events_indexer.call_args.kwargs
793-
self.assertEqual(call_kwargs.get("ignored_initiators"), set())
794-
795-
# Verify process_elements was called on the indexer instance
796-
mock_indexer_instance.process_elements.assert_called_once_with(
797-
[{"logIndex": 0, "transactionHash": tx_hash}]
798-
)
799-
800-
# Verify SafeTxProcessor.process_decoded_transactions was called
801-
mock_tx_processor.process_decoded_transactions.assert_called_once()
802-
803-
self.assertIn("Processing events through SafeEventsIndexer", output)
804-
self.assertIn("Processing decoded transactions to create SafeContract", output)
805-
806-
@mock.patch(
807-
"safe_transaction_service.history.management.commands.safe_contract.get_auto_ethereum_client"
808-
)
809-
def test_safe_contract_add_already_exists(
810-
self, mock_get_ethereum_client: MagicMock
811-
):
812-
"""Test adding a SafeContract that already exists shows warning."""
813-
command = "safe_contract"
814-
815-
safe_contract = SafeContractFactory()
816-
safe_address = safe_contract.address
817-
tx_hash = "0x" + "ab" * 32
818-
819-
self.assertEqual(SafeContract.objects.count(), 1)
820-
821-
# Add same address again (should show warning without fetching)
822-
buf = StringIO()
823-
call_command(command, "add", safe_address, tx_hash, stdout=buf)
824-
output = buf.getvalue()
825-
self.assertIn(
826-
f"SafeContract already exists for address: {safe_address}", output
827-
)
828-
self.assertEqual(SafeContract.objects.count(), 1)
829-
830-
# Should not have called ethereum client
831-
mock_get_ethereum_client.return_value.get_transaction_receipt.assert_not_called()
832-
833-
def test_safe_contract_add_invalid_address(self):
834-
"""Test adding with invalid address shows error."""
835-
command = "safe_contract"
836-
tx_hash = "0x" + "ab" * 32
837-
838-
with self.assertRaises(CommandError) as context:
839-
call_command(command, "add", "invalid-address", tx_hash)
840-
self.assertIn("Invalid Ethereum address", str(context.exception))
841-
842-
def test_safe_contract_add_invalid_tx_hash(self):
843-
"""Test adding with invalid tx hash shows error."""
844-
command = "safe_contract"
845-
address = Account.create().address
846-
847-
with self.assertRaises(CommandError) as context:
848-
call_command(command, "add", address, "invalid-tx-hash")
849-
self.assertIn("Invalid transaction hash", str(context.exception))
850-
851-
@mock.patch(
852-
"safe_transaction_service.history.management.commands.safe_contract.get_auto_ethereum_client"
853-
)
854-
def test_safe_contract_add_nonexistent_tx(
855-
self, mock_get_ethereum_client: MagicMock
856-
):
857-
"""Test adding with non-existent tx hash shows error when receipt not found."""
858-
command = "safe_contract"
859-
address = Account.create().address
860-
fake_tx_hash = "0x" + "a" * 64
861-
862-
# Mock the ethereum client to return None for receipt
863-
mock_client = MagicMock()
864-
mock_get_ethereum_client.return_value = mock_client
865-
mock_client.get_transaction_receipt.return_value = None
866-
867-
with self.assertRaises(CommandError) as context:
868-
call_command(command, "add", address, fake_tx_hash)
869-
self.assertIn("not found", str(context.exception))
870-
871-
@mock.patch(
872-
"safe_transaction_service.history.management.commands.safe_contract.get_auto_ethereum_client"
873-
)
874-
def test_safe_contract_add_no_logs(self, mock_get_ethereum_client: MagicMock):
875-
"""Test adding with tx that has no logs shows error."""
876-
command = "safe_contract"
877-
address = Account.create().address
878-
tx_hash = "0x" + "ab" * 32
879-
880-
# Mock the ethereum client to return receipt with no logs
881-
mock_client = MagicMock()
882-
mock_get_ethereum_client.return_value = mock_client
883-
mock_client.get_transaction_receipt.return_value = {
884-
"logs": [],
885-
"transactionHash": tx_hash,
886-
}
887-
888-
with self.assertRaises(CommandError) as context:
889-
call_command(command, "add", address, tx_hash)
890-
self.assertIn("has no logs", str(context.exception))
891-
892-
def test_safe_contract_remove(self):
893-
"""Test removing SafeContract entries."""
894-
command = "safe_contract"
895-
896-
safe_contract1 = SafeContractFactory()
897-
safe_contract2 = SafeContractFactory()
898-
address1 = safe_contract1.address
899-
address2 = safe_contract2.address
900-
901-
self.assertEqual(SafeContract.objects.count(), 2)
902-
903-
# Remove single address
904-
buf = StringIO()
905-
call_command(command, "remove", address1, stdout=buf)
906-
output = buf.getvalue()
907-
self.assertIn(f"Removed SafeContract: {address1}", output)
908-
self.assertIn("1 removed, 0 not found", output)
909-
self.assertEqual(SafeContract.objects.count(), 1)
910-
self.assertFalse(SafeContract.objects.filter(address=address1).exists())
911-
912-
# Remove non-existent address
913-
buf = StringIO()
914-
call_command(command, "remove", address1, stdout=buf)
915-
output = buf.getvalue()
916-
self.assertIn(f"SafeContract not found: {address1}", output)
917-
self.assertIn("0 removed, 1 not found", output)
918-
919-
# Remove multiple addresses (one exists, one doesn't)
920-
buf = StringIO()
921-
call_command(command, "remove", address1, address2, stdout=buf)
922-
output = buf.getvalue()
923-
self.assertIn(f"SafeContract not found: {address1}", output)
924-
self.assertIn(f"Removed SafeContract: {address2}", output)
925-
self.assertIn("1 removed, 1 not found", output)
926-
self.assertEqual(SafeContract.objects.count(), 0)
927-
928-
def test_safe_contract_no_action(self):
929-
"""Test that missing action shows error."""
930-
command = "safe_contract"
931-
932-
with self.assertRaises(CommandError) as context:
933-
call_command(command)
934-
self.assertIn("Please specify an action", str(context.exception))

0 commit comments

Comments
 (0)