Skip to content

Commit

Permalink
Migrate from deprecated fields
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook committed Dec 10, 2024
1 parent e8ba384 commit d3a0dd1
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 47 deletions.
4 changes: 2 additions & 2 deletions src/chains/migrations/0008_chain_ens_registry_address.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Django 3.2.5 on 2021-07-08 11:48

import gnosis.eth.django.models
import safe_eth.eth.django.models
from django.db import migrations


Expand All @@ -13,7 +13,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name="chain",
name="ens_registry_address",
field=gnosis.eth.django.models.EthereumAddressField(
field=safe_eth.eth.django.models.EthereumAddressField(
blank=True, null=True
), # type: ignore[no-untyped-call]
),
Expand Down
4 changes: 2 additions & 2 deletions src/chains/migrations/0012_chain_gas_price_fixed_wei.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Django 3.2.5 on 2021-07-14 09:18

import gnosis.eth.django.models
import safe_eth.eth.django.models
from django.db import migrations


Expand All @@ -16,7 +16,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name="chain",
name="gas_price_fixed_wei",
field=gnosis.eth.django.models.Uint256Field( # type: ignore[no-untyped-call]
field=safe_eth.eth.django.models.Uint256Field( # type: ignore[no-untyped-call]
blank=True, null=True, verbose_name="Fixed gas price (wei)"
),
),
Expand Down
4 changes: 2 additions & 2 deletions src/chains/migrations/0023_create_gas_price_model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Django 3.2.6 on 2021-09-01 12:38

import django.db.models.deletion
import gnosis.eth.django.models
import safe_eth.eth.django.models
from django.apps.registry import Apps
from django.db import migrations, models
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
Expand Down Expand Up @@ -58,7 +58,7 @@ class Migration(migrations.Migration):
),
(
"fixed_wei_value",
gnosis.eth.django.models.Uint256Field( # type: ignore[no-untyped-call]
safe_eth.eth.django.models.Uint256Field( # type: ignore[no-untyped-call]
blank=True, null=True, verbose_name="Fixed gas price (wei)"
),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Django 4.2.3 on 2023-08-14 15:24

import gnosis.eth.django.models
import safe_eth.eth.django.models
from django.db import migrations


Expand All @@ -13,14 +13,14 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name="gasprice",
name="max_fee_per_gas",
field=gnosis.eth.django.models.Uint256Field( # type: ignore[no-untyped-call]
field=safe_eth.eth.django.models.Uint256Field( # type: ignore[no-untyped-call]
blank=True, null=True, verbose_name="Max fee per gas (wei)"
),
),
migrations.AddField(
model_name="gasprice",
name="max_priority_fee_per_gas",
field=gnosis.eth.django.models.Uint256Field( # type: ignore[no-untyped-call]
field=safe_eth.eth.django.models.Uint256Field( # type: ignore[no-untyped-call]
blank=True, null=True, verbose_name="Max priority fee per gas (wei)"
),
),
Expand Down
20 changes: 10 additions & 10 deletions src/chains/migrations/0043_chain_create_call_address_and_more.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Django 5.0.6 on 2024-07-10 14:14

import gnosis.eth.django.models
import safe_eth.eth.django.models
from django.db import migrations


Expand All @@ -14,63 +14,63 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name="chain",
name="create_call_address",
field=gnosis.eth.django.models.EthereumAddressField(
field=safe_eth.eth.django.models.EthereumAddressField(
blank=True, null=True
), # type: ignore[no-untyped-call]
),
migrations.AddField(
model_name="chain",
name="fallback_handler_address",
field=gnosis.eth.django.models.EthereumAddressField(
field=safe_eth.eth.django.models.EthereumAddressField(
blank=True, null=True
), # type: ignore[no-untyped-call]
),
migrations.AddField(
model_name="chain",
name="multi_send_address",
field=gnosis.eth.django.models.EthereumAddressField(
field=safe_eth.eth.django.models.EthereumAddressField(
blank=True, null=True
), # type: ignore[no-untyped-call]
),
migrations.AddField(
model_name="chain",
name="multi_send_call_only_address",
field=gnosis.eth.django.models.EthereumAddressField(
field=safe_eth.eth.django.models.EthereumAddressField(
blank=True, null=True
), # type: ignore[no-untyped-call]
),
migrations.AddField(
model_name="chain",
name="safe_proxy_factory_address",
field=gnosis.eth.django.models.EthereumAddressField(
field=safe_eth.eth.django.models.EthereumAddressField(
blank=True, null=True
), # type: ignore[no-untyped-call]
),
migrations.AddField(
model_name="chain",
name="safe_singleton_address",
field=gnosis.eth.django.models.EthereumAddressField(
field=safe_eth.eth.django.models.EthereumAddressField(
blank=True, null=True
), # type: ignore[no-untyped-call]
),
migrations.AddField(
model_name="chain",
name="sign_message_lib_address",
field=gnosis.eth.django.models.EthereumAddressField(
field=safe_eth.eth.django.models.EthereumAddressField(
blank=True, null=True
), # type: ignore[no-untyped-call]
),
migrations.AddField(
model_name="chain",
name="simulate_tx_accessor_address",
field=gnosis.eth.django.models.EthereumAddressField(
field=safe_eth.eth.django.models.EthereumAddressField(
blank=True, null=True
), # type: ignore[no-untyped-call]
),
migrations.AddField(
model_name="chain",
name="safe_web_authn_signer_factory_address",
field=gnosis.eth.django.models.EthereumAddressField(
field=safe_eth.eth.django.models.EthereumAddressField(
blank=True, null=True
), # type: ignore[no-untyped-call]
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Generated by Django 5.1.4 on 2024-12-10 09:34

import safe_eth.eth.django.models
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('chains', '0045_populate_feature_description'),
]

operations = [
migrations.AlterField(
model_name='chain',
name='create_call_address',
field=safe_eth.eth.django.models.EthereumAddressBinaryField(blank=True, null=True),
),
migrations.AlterField(
model_name='chain',
name='ens_registry_address',
field=safe_eth.eth.django.models.EthereumAddressBinaryField(blank=True, null=True),
),
migrations.AlterField(
model_name='chain',
name='fallback_handler_address',
field=safe_eth.eth.django.models.EthereumAddressBinaryField(blank=True, null=True),
),
migrations.AlterField(
model_name='chain',
name='multi_send_address',
field=safe_eth.eth.django.models.EthereumAddressBinaryField(blank=True, null=True),
),
migrations.AlterField(
model_name='chain',
name='multi_send_call_only_address',
field=safe_eth.eth.django.models.EthereumAddressBinaryField(blank=True, null=True),
),
migrations.AlterField(
model_name='chain',
name='safe_proxy_factory_address',
field=safe_eth.eth.django.models.EthereumAddressBinaryField(blank=True, null=True),
),
migrations.AlterField(
model_name='chain',
name='safe_singleton_address',
field=safe_eth.eth.django.models.EthereumAddressBinaryField(blank=True, null=True),
),
migrations.AlterField(
model_name='chain',
name='safe_web_authn_signer_factory_address',
field=safe_eth.eth.django.models.EthereumAddressBinaryField(blank=True, null=True),
),
migrations.AlterField(
model_name='chain',
name='sign_message_lib_address',
field=safe_eth.eth.django.models.EthereumAddressBinaryField(blank=True, null=True),
),
migrations.AlterField(
model_name='chain',
name='simulate_tx_accessor_address',
field=safe_eth.eth.django.models.EthereumAddressBinaryField(blank=True, null=True),
),
]
22 changes: 11 additions & 11 deletions src/chains/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.core.validators import RegexValidator
from django.db import models
from django.db.models import QuerySet
from gnosis.eth.django.models import EthereumAddressField, Uint256Field
from safe_eth.eth.django.models import EthereumAddressBinaryField, Uint256Field

HEX_ARGB_REGEX = re.compile("^#[0-9a-fA-F]{6}$")

Expand Down Expand Up @@ -135,7 +135,7 @@ class RpcAuthentication(models.TextChoices):
default="#000000",
help_text="Please use the following format: <em>#RRGGBB</em>.",
)
ens_registry_address = EthereumAddressField(null=True, blank=True) # type: ignore[no-untyped-call]
ens_registry_address = EthereumAddressBinaryField(null=True, blank=True) # type: ignore[no-untyped-call]
recommended_master_copy_version = models.CharField(
max_length=255, validators=[sem_ver_validator]
)
Expand All @@ -151,15 +151,15 @@ class RpcAuthentication(models.TextChoices):
help_text="This flag informs API clients whether the balances provider is enabled for the chain",
)
hidden = models.BooleanField(default=False)
safe_singleton_address = EthereumAddressField(null=True, blank=True) # type: ignore[no-untyped-call]
safe_proxy_factory_address = EthereumAddressField(null=True, blank=True) # type: ignore[no-untyped-call]
multi_send_address = EthereumAddressField(null=True, blank=True) # type: ignore[no-untyped-call]
multi_send_call_only_address = EthereumAddressField(null=True, blank=True) # type: ignore[no-untyped-call]
fallback_handler_address = EthereumAddressField(null=True, blank=True) # type: ignore[no-untyped-call]
sign_message_lib_address = EthereumAddressField(null=True, blank=True) # type: ignore[no-untyped-call]
create_call_address = EthereumAddressField(null=True, blank=True) # type: ignore[no-untyped-call]
simulate_tx_accessor_address = EthereumAddressField(null=True, blank=True) # type: ignore[no-untyped-call]
safe_web_authn_signer_factory_address = EthereumAddressField(
safe_singleton_address = EthereumAddressBinaryField(null=True, blank=True) # type: ignore[no-untyped-call]
safe_proxy_factory_address = EthereumAddressBinaryField(null=True, blank=True) # type: ignore[no-untyped-call]
multi_send_address = EthereumAddressBinaryField(null=True, blank=True) # type: ignore[no-untyped-call]
multi_send_call_only_address = EthereumAddressBinaryField(null=True, blank=True) # type: ignore[no-untyped-call]
fallback_handler_address = EthereumAddressBinaryField(null=True, blank=True) # type: ignore[no-untyped-call]
sign_message_lib_address = EthereumAddressBinaryField(null=True, blank=True) # type: ignore[no-untyped-call]
create_call_address = EthereumAddressBinaryField(null=True, blank=True) # type: ignore[no-untyped-call]
simulate_tx_accessor_address = EthereumAddressBinaryField(null=True, blank=True) # type: ignore[no-untyped-call]
safe_web_authn_signer_factory_address = EthereumAddressBinaryField(
null=True, blank=True
) # type: ignore[no-untyped-call]

Expand Down
2 changes: 1 addition & 1 deletion src/chains/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Any

from drf_yasg.utils import swagger_serializer_method
from gnosis.eth.django.serializers import EthereumAddressField
from safe_eth.eth.django.serializers import EthereumAddressField
from rest_framework import serializers
from rest_framework.exceptions import APIException
from rest_framework.utils.serializer_helpers import ReturnDict
Expand Down
26 changes: 11 additions & 15 deletions src/chains/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_null_oracle_gas_oracle_with_null_fixed_gas_price(self) -> None:
def test_big_number() -> None:
gas_price = GasPriceFactory.create(
oracle_uri=None,
fixed_wei_value="115792089237316195423570985008687907853269984665640564039457584007913129639935",
fixed_wei_value=115792089237316195423570985008687907853269984665640564039457584007913129639935,
)

gas_price.full_clean()
Expand All @@ -96,17 +96,17 @@ def test_only_fixed1559_defined() -> None:
gas_price = GasPriceFactory.create(
oracle_uri=None,
fixed_wei_value=None,
max_fee_per_gas="100000",
max_priority_fee_per_gas="1000",
max_fee_per_gas=100000,
max_priority_fee_per_gas=1000,
)

gas_price.full_clean()

def test_fixed_and_fixed1559_defined(self) -> None:
gas_price = GasPriceFactory.create(
fixed_wei_value="100000",
max_fee_per_gas="100000",
max_priority_fee_per_gas="1000",
fixed_wei_value=100000,
max_fee_per_gas=100000,
max_priority_fee_per_gas=1000,
)

with self.assertRaises(ValidationError):
Expand All @@ -116,9 +116,9 @@ def test_fixed_and_fixed1559_and_oracle_defined(self) -> None:
gas_price = GasPriceFactory.create(
oracle_uri=self.faker.url(),
oracle_parameter="fake parameter",
fixed_wei_value="100000",
max_fee_per_gas="100000",
max_priority_fee_per_gas="1000",
fixed_wei_value=100000,
max_fee_per_gas=100000,
max_priority_fee_per_gas=1000,
)

with self.assertRaises(ValidationError):
Expand Down Expand Up @@ -217,12 +217,8 @@ def test_invalid_addresses(self) -> None:

for invalid_address in param_list:
with self.subTest(msg=f"Invalid address {invalid_address} should throw"):
with self.assertRaises(
(
# normalize_address from gnosis-py throws a generic Exception if the address is not valid
Exception,
)
):
with self.assertRaises(ValidationError):
print(invalid_address)
chain = ChainFactory.create(ens_registry_address=invalid_address)
# run validators
chain.full_clean()
Expand Down
2 changes: 1 addition & 1 deletion src/chains/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def test_fixed_gas_256_bit(self) -> None:
chain = ChainFactory.create(id=1)
GasPriceFactory.create(
chain=chain,
fixed_wei_value="115792089237316195423570985008687907853269984665640564039457584007913129639935",
fixed_wei_value=115792089237316195423570985008687907853269984665640564039457584007913129639935,
)
url = reverse("v1:chains:detail", args=[1])
expected_oracle_json_payload = [
Expand Down

0 comments on commit d3a0dd1

Please sign in to comment.