From 61159268745413f4c273f6dc058df77b0924f555 Mon Sep 17 00:00:00 2001 From: Uxio Fuentefria <6909403+Uxio0@users.noreply.github.com> Date: Fri, 15 Mar 2024 11:58:29 +0100 Subject: [PATCH] Remove deprecated classes --- gnosis/eth/django/tests/models.py | 10 --- gnosis/eth/django/tests/test_models.py | 117 +++++++------------------ 2 files changed, 32 insertions(+), 95 deletions(-) diff --git a/gnosis/eth/django/tests/models.py b/gnosis/eth/django/tests/models.py index 0b2497459..76a027907 100644 --- a/gnosis/eth/django/tests/models.py +++ b/gnosis/eth/django/tests/models.py @@ -1,20 +1,14 @@ from django.db import models from ..models import ( - EthereumAddressField, EthereumAddressV2Field, Keccak256Field, - Sha3HashField, Uint32Field, Uint96Field, Uint256Field, ) -class EthereumAddress(models.Model): - value = EthereumAddressField(null=True) - - class EthereumAddressV2(models.Model): value = EthereumAddressV2Field(null=True) @@ -31,9 +25,5 @@ class Uint32(models.Model): value = Uint32Field(null=True) -class Sha3Hash(models.Model): - value = Sha3HashField(null=True) - - class Keccak256Hash(models.Model): value = Keccak256Field(null=True) diff --git a/gnosis/eth/django/tests/test_models.py b/gnosis/eth/django/tests/test_models.py index b4046e3b4..d556b7ee6 100644 --- a/gnosis/eth/django/tests/test_models.py +++ b/gnosis/eth/django/tests/test_models.py @@ -1,6 +1,6 @@ from django.core.exceptions import ValidationError from django.core.serializers import serialize -from django.db import DataError, transaction +from django.db import transaction from django.test import TestCase from eth_account import Account @@ -8,53 +8,43 @@ from ...constants import NULL_ADDRESS, SENTINEL_ADDRESS from ...utils import fast_is_checksum_address, fast_keccak_text -from .models import ( - EthereumAddress, - EthereumAddressV2, - Keccak256Hash, - Sha3Hash, - Uint32, - Uint96, - Uint256, -) +from .models import EthereumAddressV2, Keccak256Hash, Uint32, Uint96, Uint256 faker = Faker() class TestModels(TestCase): def test_ethereum_address_field(self): - for EthereumAddressModel in (EthereumAddress, EthereumAddressV2): - with self.subTest(EthereumAddressModel=EthereumAddressModel): - address = Account.create().address - self.assertTrue(fast_is_checksum_address(address)) - ethereum_address = EthereumAddressModel.objects.create(value=address) - ethereum_address.refresh_from_db() - self.assertTrue(fast_is_checksum_address(ethereum_address.value)) - self.assertEqual(address, ethereum_address.value) - - # Test addresses - for addresss in ( - None, - NULL_ADDRESS, - SENTINEL_ADDRESS, - Account.create().address, - ): - with self.subTest(special_address=addresss): - EthereumAddressModel.objects.create(value=addresss) - self.assertEqual( - EthereumAddressModel.objects.get(value=addresss).value, - addresss, - ) - - with self.assertRaisesMessage( - ValidationError, - '"0x23" value must be an EIP55 checksummed address.', - ): - with transaction.atomic(): - EthereumAddressModel.objects.create(value="0x23") - - ethereum_address = EthereumAddressModel(value=Account.create().address) - self.assertIsNone(ethereum_address.full_clean()) + address = Account.create().address + self.assertTrue(fast_is_checksum_address(address)) + ethereum_address = EthereumAddressV2.objects.create(value=address) + ethereum_address.refresh_from_db() + self.assertTrue(fast_is_checksum_address(ethereum_address.value)) + self.assertEqual(address, ethereum_address.value) + + # Test addresses + for addresss in ( + None, + NULL_ADDRESS, + SENTINEL_ADDRESS, + Account.create().address, + ): + with self.subTest(special_address=addresss): + EthereumAddressV2.objects.create(value=addresss) + self.assertEqual( + EthereumAddressV2.objects.get(value=addresss).value, + addresss, + ) + + with self.assertRaisesMessage( + ValidationError, + '"0x23" value must be an EIP55 checksummed address.', + ): + with transaction.atomic(): + EthereumAddressV2.objects.create(value="0x23") + + ethereum_address = EthereumAddressV2(value=Account.create().address) + self.assertIsNone(ethereum_address.full_clean()) def test_uint256_field(self): for value in [ @@ -115,35 +105,6 @@ def test_uint32_field(self): with self.assertRaises(ValidationError): Uint32.objects.create(value=-2) - def test_sha3_hash_field(self): - value_hexbytes = fast_keccak_text(faker.name()) - value_hex_with_0x: str = value_hexbytes.hex() - value_hex_without_0x: str = value_hex_with_0x[2:] - value: bytes = bytes(value_hexbytes) - - values = [value, value_hex_without_0x, value_hex_with_0x, value_hexbytes] - - for v in values: - sha3_hash = Sha3Hash.objects.create(value=v) - sha3_hash.refresh_from_db() - self.assertEqual(sha3_hash.value, value_hex_with_0x) - - for v in values: - self.assertEqual(Sha3Hash.objects.filter(value=v).count(), len(values)) - - # Hash null - sha3_hash = Sha3Hash.objects.create(value=None) - sha3_hash.refresh_from_db() - self.assertIsNone(sha3_hash.value) - - # Hash too big - value_hex_invalid: str = "0x" + value_hex_without_0x + "a" - with self.assertRaisesMessage( - DataError, "value too long for type character varying(64)" - ): - with transaction.atomic(): - Sha3Hash.objects.create(value=value_hex_invalid) - def test_keccak256_field(self): value_hexbytes = fast_keccak_text(faker.name()) value_hex_with_0x: str = value_hexbytes.hex() @@ -205,13 +166,6 @@ def test_serialize_keccak256_field_to_json(self): # hexvalue should be in serialized data self.assertIn(hexvalue, serialized) - def test_serialize_ethereum_address_field_to_json(self): - address: str = "0x5aFE3855358E112B5647B952709E6165e1c1eEEe" - EthereumAddress.objects.create(value=address) - serialized = serialize("json", EthereumAddress.objects.all()) - # address should be in serialized data - self.assertIn(address, serialized) - def test_serialize_ethereum_address_v2_field_to_json(self): address: str = "0x5aFE3855358E112B5647B952709E6165e1c1eEEe" EthereumAddressV2.objects.create(value=address) @@ -225,10 +179,3 @@ def test_serialize_uint256_field_to_json(self): serialized = serialize("json", Uint256.objects.all()) # value should be in serialized data self.assertIn(str(value), serialized) - - def test_serialize_sha3_hash_to_json(self): - hash = fast_keccak_text("testSerializer") - Sha3Hash.objects.create(value=hash) - serialized = serialize("json", Sha3Hash.objects.all()) - # hash should be in serialized data - self.assertIn(hash.hex(), serialized)