Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
praveen-kaia committed Mar 19, 2024
2 parents 0e79a2a + 030c30c commit 6ad71a2
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 61 deletions.
6 changes: 3 additions & 3 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ coverage==7.4.3
django-stubs==4.2.7
django-test-migrations==1.3.0
factory-boy==3.3.0
faker==24.0.0
mypy==1.8.0
pytest==8.1.0
faker==24.2.0
mypy==1.9.0
pytest==8.1.1
pytest-celery==0.0.0
pytest-django==4.8.0
pytest-env==1.1.3
Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ django-debug-toolbar
django-debug-toolbar-force
django-environ==0.11.2
django-extensions==3.2.3
django-filter==23.5
django-filter==24.1
django-imagekit==5.0.0
django-model-utils==4.4.0
django-redis==5.4.0
Expand All @@ -20,7 +20,7 @@ djangorestframework==3.14.0
djangorestframework-camel-case==1.4.2
docutils==0.20.1
drf-yasg[validation]==1.21.7
firebase-admin==6.4.0
firebase-admin==6.5.0
flower==2.0.1
gunicorn[gevent]==21.2.0
hexbytes==0.3.1
Expand All @@ -30,7 +30,7 @@ pika==1.3.2
pillow==10.2.0
psycogreen==1.0.2
psycopg2==2.9.9
redis==5.0.2
redis==5.0.3
requests==2.31.0
safe-eth-py[django]==6.0.0b18
safe-eth-py[django]==6.0.0b21
web3==6.15.1
2 changes: 1 addition & 1 deletion safe_transaction_service/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "4.35.1"
__version__ = "4.36.0"
__version_info__ = tuple(
int(num) if num.isdigit() else num
for num in __version__.replace("-", ".", 1).split(".")
Expand Down
14 changes: 7 additions & 7 deletions safe_transaction_service/history/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from factory.django import DjangoModelFactory
from factory.fuzzy import FuzzyInteger
from hexbytes import HexBytes
from web3 import Web3

from gnosis.eth.constants import NULL_ADDRESS
from gnosis.eth.utils import fast_keccak_text
from gnosis.safe.safe_signature import SafeSignatureType

from ..models import (
Expand Down Expand Up @@ -53,8 +53,8 @@ class Meta:
gas_limit = factory.fuzzy.FuzzyInteger(100000000, 200000000)
gas_used = factory.fuzzy.FuzzyInteger(100000, 500000)
timestamp = factory.LazyFunction(timezone.now)
block_hash = factory.Sequence(lambda n: Web3.keccak(text=f"block-{n}").hex())
parent_hash = factory.Sequence(lambda n: Web3.keccak(text=f"block{n - 1}").hex())
block_hash = factory.Sequence(lambda n: fast_keccak_text(f"block-{n}").hex())
parent_hash = factory.Sequence(lambda n: fast_keccak_text(f"block{n - 1}").hex())


class EthereumTxFactory(DjangoModelFactory):
Expand All @@ -63,7 +63,7 @@ class Meta:

block = factory.SubFactory(EthereumBlockFactory)
tx_hash = factory.Sequence(
lambda n: Web3.keccak(text=f"ethereum_tx_hash-{n}").hex()
lambda n: fast_keccak_text(f"ethereum_tx_hash-{n}").hex()
)
_from = factory.LazyFunction(lambda: Account.create().address)
gas = factory.fuzzy.FuzzyInteger(1000, 5000)
Expand Down Expand Up @@ -226,7 +226,7 @@ class Meta:
module = factory.LazyFunction(lambda: Account.create().address)
to = factory.LazyFunction(lambda: Account.create().address)
value = FuzzyInteger(low=0, high=10)
data = factory.Sequence(lambda n: Web3.keccak(text=f"module-tx-{n}"))
data = factory.Sequence(lambda n: fast_keccak_text(f"module-tx-{n}"))
operation = FuzzyInteger(low=0, high=1)
failed = False

Expand All @@ -236,7 +236,7 @@ class Meta:
model = MultisigTransaction

safe_tx_hash = factory.Sequence(
lambda n: Web3.keccak(text=f"multisig-tx-{n}").hex()
lambda n: fast_keccak_text(f"multisig-tx-{n}").hex()
)
safe = factory.LazyFunction(lambda: Account.create().address)
ethereum_tx = factory.SubFactory(EthereumTxFactory)
Expand All @@ -263,7 +263,7 @@ class Meta:
ethereum_tx = factory.SubFactory(EthereumTxFactory)
multisig_transaction = factory.SubFactory(MultisigTransactionFactory)
multisig_transaction_hash = factory.Sequence(
lambda n: Web3.keccak(text=f"multisig-confirmation-tx-{n}").hex()
lambda n: fast_keccak_text(f"multisig-confirmation-tx-{n}").hex()
)
owner = factory.LazyFunction(lambda: Account.create().address)
signature = None
Expand Down
4 changes: 2 additions & 2 deletions safe_transaction_service/history/tests/test_index_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

from eth_account import Account
from requests.exceptions import ConnectionError as RequestsConnectionError
from web3 import Web3

from gnosis.eth import EthereumClient
from gnosis.eth.tests.ethereum_test_case import EthereumTestCaseMixin
from gnosis.eth.utils import fast_keccak_text

from ..models import (
EthereumTx,
Expand Down Expand Up @@ -88,7 +88,7 @@ def test_create_or_update_from_tx_hashes_existing(self):

# Test block hash changes
ethereum_tx = ethereum_txs[0]
ethereum_tx.block.block_hash = Web3.keccak(text="aloha")
ethereum_tx.block.block_hash = fast_keccak_text("aloha")
ethereum_tx.block.save(update_fields=["block_hash"])
tx_hash = ethereum_tx.tx_hash

Expand Down
31 changes: 16 additions & 15 deletions safe_transaction_service/history/tests/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

from django_test_migrations.migrator import Migrator
from eth_account import Account
from web3 import Web3

from gnosis.eth.utils import fast_keccak, fast_keccak_text


class TestMigrations(TestCase):
Expand All @@ -25,13 +26,13 @@ def build_ethereum_tx(self, ethereum_block_class, ethereum_tx_class):
gas_limit=2,
gas_used=2,
timestamp=timezone.now(),
block_hash=Web3.keccak(b"34"),
parent_hash=Web3.keccak(b"12"),
block_hash=fast_keccak(b"34"),
parent_hash=fast_keccak(b"12"),
)

return ethereum_tx_class.objects.create(
block=ethereum_block,
tx_hash=Web3.keccak(b"tx-hash"),
tx_hash=fast_keccak(b"tx-hash"),
gas=23000,
gas_price=1,
nonce=0,
Expand All @@ -53,7 +54,7 @@ def test_migration_forward_0068(self):
]
for origin in origins:
MultisigTransactionOld.objects.create(
safe_tx_hash=Web3.keccak(text=f"multisig-tx-{origin}").hex(),
safe_tx_hash=fast_keccak_text(f"multisig-tx-{origin}").hex(),
safe=Account.create().address,
value=0,
operation=0,
Expand All @@ -72,21 +73,21 @@ def test_migration_forward_0068(self):
)

# String should keep string
hash = Web3.keccak(text=f"multisig-tx-{origins[0]}").hex()
hash = fast_keccak_text(f"multisig-tx-{origins[0]}").hex()
self.assertEqual(MultisigTransactionNew.objects.get(pk=hash).origin, origins[0])

# String json should be converted to json
hash = Web3.keccak(text=f"multisig-tx-{origins[1]}").hex()
hash = fast_keccak_text(f"multisig-tx-{origins[1]}").hex()
self.assertEqual(
MultisigTransactionNew.objects.get(pk=hash).origin, json.loads(origins[1])
)

# Empty string should be empty object
hash = Web3.keccak(text=f"multisig-tx-{origins[2]}").hex()
hash = fast_keccak_text(f"multisig-tx-{origins[2]}").hex()
self.assertEqual(MultisigTransactionNew.objects.get(pk=hash).origin, {})

# None should be empty object
hash = Web3.keccak(text=f"multisig-tx-{origins[2]}").hex()
hash = fast_keccak_text(f"multisig-tx-{origins[2]}").hex()
self.assertEqual(MultisigTransactionNew.objects.get(pk=hash).origin, {})

def test_migration_backward_0068(self):
Expand All @@ -99,7 +100,7 @@ def test_migration_backward_0068(self):
origins = ["{ TestString", {"url": "https://example.com", "name": "app"}, {}]
for origin in origins:
MultisigTransactionNew.objects.create(
safe_tx_hash=Web3.keccak(text=f"multisig-tx-{origin}").hex(),
safe_tx_hash=fast_keccak_text(f"multisig-tx-{origin}").hex(),
safe=Account.create().address,
value=0,
operation=0,
Expand All @@ -118,17 +119,17 @@ def test_migration_backward_0068(self):
)

# String should keep string
hash = Web3.keccak(text=f"multisig-tx-{origins[0]}").hex()
hash = fast_keccak_text(f"multisig-tx-{origins[0]}").hex()
self.assertEqual(MultisigTransactionOld.objects.get(pk=hash).origin, origins[0])

# Json should be converted to a string json
hash = Web3.keccak(text=f"multisig-tx-{origins[1]}").hex()
hash = fast_keccak_text(f"multisig-tx-{origins[1]}").hex()
self.assertEqual(
MultisigTransactionOld.objects.get(pk=hash).origin, json.dumps(origins[1])
)

# Empty object should be None
hash = Web3.keccak(text=f"multisig-tx-{origins[2]}").hex()
hash = fast_keccak_text(f"multisig-tx-{origins[2]}").hex()
self.assertEqual(MultisigTransactionOld.objects.get(pk=hash).origin, None)

def test_migration_forward_0069(self):
Expand Down Expand Up @@ -262,7 +263,7 @@ def test_migration_forward_0073_safe_apps_links(self):
MultisigTransaction = new_state.apps.get_model("history", "MultisigTransaction")
for origin in origins:
MultisigTransaction.objects.create(
safe_tx_hash=Web3.keccak(text=f"multisig-tx-{origin}").hex(),
safe_tx_hash=fast_keccak_text(f"multisig-tx-{origin}").hex(),
safe=Account.create().address,
value=0,
operation=0,
Expand Down Expand Up @@ -310,7 +311,7 @@ def test_migration_backward_0073_safe_apps_links(self):
MultisigTransaction = new_state.apps.get_model("history", "MultisigTransaction")
for origin in origins:
MultisigTransaction.objects.create(
safe_tx_hash=Web3.keccak(text=f"multisig-tx-{origin}").hex(),
safe_tx_hash=fast_keccak_text(f"multisig-tx-{origin}").hex(),
safe=Account.create().address,
value=0,
operation=0,
Expand Down
8 changes: 4 additions & 4 deletions safe_transaction_service/history/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from django.utils import timezone

from eth_account import Account
from web3 import Web3

from gnosis.eth.utils import fast_keccak_text
from gnosis.safe.safe_signature import SafeSignatureType

from safe_transaction_service.contracts.models import ContractQuerySet
Expand Down Expand Up @@ -60,7 +60,7 @@

class TestModelSignals(TestCase):
def test_bind_confirmations(self):
safe_tx_hash = Web3.keccak(text="prueba")
safe_tx_hash = fast_keccak_text("prueba")
ethereum_tx = EthereumTxFactory()
MultisigConfirmation.objects.create(
ethereum_tx=ethereum_tx,
Expand All @@ -87,7 +87,7 @@ def test_bind_confirmations(self):
self.assertEqual(multisig_tx.confirmations.count(), 1)

def test_bind_confirmations_reverse(self):
safe_tx_hash = Web3.keccak(text="prueba")
safe_tx_hash = fast_keccak_text("prueba")
ethereum_tx = EthereumTxFactory()
multisig_tx, _ = MultisigTransaction.objects.get_or_create(
safe_tx_hash=safe_tx_hash,
Expand Down Expand Up @@ -1257,7 +1257,7 @@ def test_get_or_create_from_block(self):

# Test block with different block-hash but same block number
mock_block_2 = dict(mock_block)
mock_block_2["hash"] = Web3.keccak(text="another-hash")
mock_block_2["hash"] = fast_keccak_text("another-hash")
self.assertNotEqual(mock_block["hash"], mock_block_2["hash"])
with self.assertRaises(IntegrityError):
EthereumBlock.objects.get_or_create_from_block(mock_block_2)
Expand Down
8 changes: 4 additions & 4 deletions safe_transaction_service/history/tests/test_tx_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

from eth_account import Account
from eth_utils import keccak
from web3 import Web3

from gnosis.eth.ethereum_client import TracingManager
from gnosis.eth.utils import fast_keccak_text
from gnosis.safe.safe_signature import SafeSignatureType
from gnosis.safe.tests.safe_test_case import SafeTestCaseMixin

Expand Down Expand Up @@ -340,7 +340,7 @@ def test_tx_processor_is_failed(self):
ethereum_tx = EthereumTxFactory(logs=logs)
self.assertTrue(tx_processor.is_failed(ethereum_tx, logs[0]["data"]))
self.assertFalse(
tx_processor.is_failed(ethereum_tx, Web3.keccak(text="hola").hex())
tx_processor.is_failed(ethereum_tx, fast_keccak_text("hola").hex())
)

# Event for Safes >= 1.1.1
Expand All @@ -359,7 +359,7 @@ def test_tx_processor_is_failed(self):
ethereum_tx = EthereumTxFactory(logs=logs)
self.assertTrue(tx_processor.is_failed(ethereum_tx, safe_tx_hash))
self.assertFalse(
tx_processor.is_failed(ethereum_tx, Web3.keccak(text="hola").hex())
tx_processor.is_failed(ethereum_tx, fast_keccak_text("hola").hex())
)

# Event for Safes >= 1.4.1
Expand All @@ -378,7 +378,7 @@ def test_tx_processor_is_failed(self):
ethereum_tx = EthereumTxFactory(logs=logs)
self.assertTrue(tx_processor.is_failed(ethereum_tx, safe_tx_hash))
self.assertFalse(
tx_processor.is_failed(ethereum_tx, Web3.keccak(text="hola").hex())
tx_processor.is_failed(ethereum_tx, fast_keccak_text("hola").hex())
)

def test_tx_is_version_breaking_signatures(self):
Expand Down
11 changes: 5 additions & 6 deletions safe_transaction_service/history/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
from rest_framework import status
from rest_framework.exceptions import ErrorDetail
from rest_framework.test import APIRequestFactory, APITestCase, force_authenticate
from web3 import Web3

from gnosis.eth.constants import NULL_ADDRESS
from gnosis.eth.ethereum_client import EthereumClient, TracingManager
from gnosis.eth.utils import fast_is_checksum_address
from gnosis.eth.utils import fast_is_checksum_address, fast_keccak_text
from gnosis.safe import CannotEstimateGas, Safe, SafeOperationEnum
from gnosis.safe.safe_signature import SafeSignature, SafeSignatureType
from gnosis.safe.signatures import signature_to_bytes
Expand Down Expand Up @@ -684,7 +683,7 @@ def test_get_module_transaction(self):
)

def test_get_multisig_confirmation(self):
random_safe_tx_hash = Web3.keccak(text="enxebre").hex()
random_safe_tx_hash = fast_keccak_text("enxebre").hex()
response = self.client.get(
reverse(
"v1:history:multisig-transaction-confirmations",
Expand All @@ -710,7 +709,7 @@ def test_get_multisig_confirmation(self):
self.assertEqual(response.data["count"], 2)

def test_post_multisig_confirmation(self):
random_safe_tx_hash = Web3.keccak(text="enxebre").hex()
random_safe_tx_hash = fast_keccak_text("enxebre").hex()
data = {
"signature": Account.create()
.signHash(random_safe_tx_hash)["signature"]
Expand Down Expand Up @@ -819,7 +818,7 @@ def test_post_multisig_confirmation(self):
self.assertEqual(MultisigConfirmation.objects.count(), 2)

def test_get_multisig_transaction(self):
safe_tx_hash = Web3.keccak(text="gnosis").hex()
safe_tx_hash = fast_keccak_text("gnosis").hex()
response = self.client.get(
reverse("v1:history:multisig-transaction", args=(safe_tx_hash,)),
format="json",
Expand Down Expand Up @@ -903,7 +902,7 @@ def test_get_multisig_transaction(self):

def test_delete_multisig_transaction(self):
owner_account = Account.create()
safe_tx_hash = Web3.keccak(text="random-tx").hex()
safe_tx_hash = fast_keccak_text("random-tx").hex()
url = reverse("v1:history:multisig-transaction", args=(safe_tx_hash,))
data = {"signature": "0x" + "1" * (130 * 2)} # 2 signatures of 65 bytes
response = self.client.delete(url, format="json", data=data)
Expand Down
9 changes: 5 additions & 4 deletions safe_transaction_service/notifications/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from django.test import TestCase

from eth_account import Account
from web3 import Web3

from gnosis.eth.utils import fast_keccak_text

from safe_transaction_service.history.models import (
EthereumTxCallType,
Expand Down Expand Up @@ -91,7 +92,7 @@ def test_send_notification_owner_task(self):
safe_address = safe_contract.address
threshold = 2
owners = [Account.create().address for _ in range(2)]
safe_tx_hash = Web3.keccak(text="hola").hex()
safe_tx_hash = fast_keccak_text("hola").hex()
with self.assertLogs(logger=task_logger) as cm:
self.assertEqual(
send_notification_owner_task.delay(safe_address, safe_tx_hash).result,
Expand Down Expand Up @@ -183,7 +184,7 @@ def test_send_notification_owner_task(self):
self.assertIn("does not require more confirmations", cm.output[0])

def test_send_notification_owner_delegate_task(self):
safe_tx_hash = Web3.keccak(text="aloha").hex()
safe_tx_hash = fast_keccak_text("aloha").hex()
safe_contract = SafeContractFactory()
safe_address = safe_contract.address
safe_status = SafeLastStatusFactory(address=safe_address, threshold=3)
Expand Down Expand Up @@ -218,7 +219,7 @@ def test_send_notification_owner_delegate_task(self):

def test_send_notification_owner_task_called(self):
safe_address = Account.create().address
safe_tx_hash = Web3.keccak(text="hola").hex()
safe_tx_hash = fast_keccak_text("hola").hex()
payload = {
"address": safe_address,
"type": WebHookType.PENDING_MULTISIG_TRANSACTION.name,
Expand Down
Loading

0 comments on commit 6ad71a2

Please sign in to comment.