From f79f7a5fec98ff22a8cc6d4de30ecdd3f2578eb9 Mon Sep 17 00:00:00 2001 From: Uxio Fuentefria <6909403+Uxio0@users.noreply.github.com> Date: Tue, 6 Feb 2024 17:42:44 +0100 Subject: [PATCH] Accept zero address as `to` when posting transactions - Closes #1830 --- .../history/serializers.py | 1 + .../history/tests/test_views.py | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/safe_transaction_service/history/serializers.py b/safe_transaction_service/history/serializers.py index ae5bfda5b..abb5db622 100644 --- a/safe_transaction_service/history/serializers.py +++ b/safe_transaction_service/history/serializers.py @@ -147,6 +147,7 @@ def save(self, **kwargs): class SafeMultisigTransactionSerializer(SafeMultisigTxSerializerV1): + to = EthereumAddressField(allow_zero_address=True, allow_sentinel_address=True) contract_transaction_hash = Sha3HashField() sender = EthereumAddressField() # TODO Make signature mandatory diff --git a/safe_transaction_service/history/tests/test_views.py b/safe_transaction_service/history/tests/test_views.py index 4e0a78ea7..d8c75694e 100644 --- a/safe_transaction_service/history/tests/test_views.py +++ b/safe_transaction_service/history/tests/test_views.py @@ -1407,6 +1407,54 @@ def test_post_multisig_transactions(self): ) self.assertEqual(response.status_code, status.HTTP_422_UNPROCESSABLE_ENTITY) + def test_post_multisig_transaction_with_zero_to(self): + safe_owner_1 = Account.create() + safe = self.deploy_test_safe(owners=[safe_owner_1.address]) + safe_address = safe.address + + response = self.client.get( + reverse("v1:history:multisig-transactions", args=(safe_address,)), + format="json", + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data["count"], 0) + + data = { + "to": NULL_ADDRESS, + "value": 100000000000000000, + "data": None, + "operation": 0, + "nonce": 0, + "safeTxGas": 0, + "baseGas": 0, + "gasPrice": 0, + "gasToken": "0x0000000000000000000000000000000000000000", + "refundReceiver": "0x0000000000000000000000000000000000000000", + # "contractTransactionHash": "0x1c2c77b29086701ccdda7836c399112a9b715c6a153f6c8f75c84da4297f60d3", + "sender": safe_owner_1.address, + } + safe_tx = safe.build_multisig_tx( + data["to"], + data["value"], + data["data"], + data["operation"], + data["safeTxGas"], + data["baseGas"], + data["gasPrice"], + data["gasToken"], + data["refundReceiver"], + safe_nonce=data["nonce"], + ) + data["contractTransactionHash"] = safe_tx.safe_tx_hash.hex() + response = self.client.post( + reverse("v1:history:multisig-transactions", args=(safe_address,)), + format="json", + data=data, + ) + self.assertEqual(response.status_code, status.HTTP_201_CREATED) + multisig_transaction_db = MultisigTransaction.objects.first() + self.assertFalse(multisig_transaction_db.trusted) + def test_post_multisig_transaction_with_1271_signature(self): account = Account.create() safe_owner = self.deploy_test_safe(owners=[account.address])