Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
gofman8 committed Oct 4, 2024
2 parents 27d20cc + 3f4297c commit 4f8dcce
Show file tree
Hide file tree
Showing 18 changed files with 223 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .env.custom
Original file line number Diff line number Diff line change
@@ -1 +1 @@
APPLICATION_VERSION=2.80.0
APPLICATION_VERSION=2.83.0
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,4 @@ data/
docker-compose.override.yml
.vscode/
src/media/
!src/media/safe_apps/icon_url.jpg
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.12.3-slim
FROM python:3.12.4-slim

# python
ENV PYTHONUNBUFFERED=1
Expand Down
12 changes: 6 additions & 6 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
-r requirements.txt
black==24.4.2
coverage==7.5.1
coverage==7.5.4
factory-boy==3.3.0
Faker==25.1.0
flake8==7.0.0
Faker==25.9.1
flake8==7.1.0
isort==5.13.2
pre-commit==3.7.1
pytest-django==4.8.0
responses==0.25.0
responses==0.25.3

# mypy and PEP 561 stubs
mypy==1.10.0
django-stubs==5.0.0
django-stubs==5.0.2
djangorestframework-stubs==3.15.0
types-requests==2.31.0.20240406
types-requests==2.32.0.20240602
11 changes: 6 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
boto3==1.34.103
boto3==1.34.131
Django==5.0.6
django-cors-headers==4.3.1
djangorestframework==3.15.1
django-cors-headers==4.4.0
djangorestframework==3.15.2
djangorestframework-camel-case==1.4.2
django-storages==1.14.3
django-stubs-ext==5.0.0
django-stubs-ext==5.0.2
drf-yasg[validation]==1.21.7
safe-eth-py[django]==5.8.0
gunicorn==22.0.0
Pillow==10.3.0
psycopg2-binary==2.9.9
requests==2.31.0
requests==2.32.3
web3==6.11.4
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.2 on 2024-06-13 11:11

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("chains", "0041_chain_prices_provider_chain_name_and_more"),
]

operations = [
migrations.AddField(
model_name="chain",
name="balances_provider_chain_name",
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AddField(
model_name="chain",
name="balances_provider_enabled",
field=models.BooleanField(
default=False,
help_text="This flag informs API clients whether the balances provider is enabled for the chain",
),
),
]
45 changes: 45 additions & 0 deletions src/chains/migrations/tests/test_migration_0042.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from django.db.migrations.state import StateApps

from chains.migrations.tests.utils import TestMigrations


class Migration0042TestCase(TestMigrations):
migrate_from = "0041_chain_prices_provider_chain_name_and_more"
migrate_to = "0042_chain_balances_provider_chain_name_and_more"

def setUpBeforeMigration(self, apps: StateApps) -> None:
Chain = apps.get_model("chains", "Chain")
Chain.objects.create(
id=1,
name="Mainnet",
short_name="eth",
description="",
l2=False,
rpc_authentication="API_KEY_PATH",
rpc_uri="https://mainnet.infura.io/v3/",
safe_apps_rpc_authentication="API_KEY_PATH",
safe_apps_rpc_uri="https://mainnet.infura.io/v3/",
block_explorer_uri_address_template="https://etherscan.io/address/{{address}}",
block_explorer_uri_tx_hash_template="https://etherscan.io/tx/{{txHash}}",
currency_name="Ether",
currency_symbol="ETH",
currency_decimals=18,
currency_logo_uri="https://gnosis-safe-token-logos.s3.amazonaws.com/ethereum-eth-logo.png",
transaction_service_uri="http://mainnet-safe-transaction-web.safe.svc.cluster.local",
vpc_transaction_service_uri="",
theme_text_color="#001428",
theme_background_color="#E8E7E6",
ens_registry_address="0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
recommended_master_copy_version="1.3.0",
prices_provider_native_coin="ethereum",
prices_provider_chain_name="ethereum",
hidden=False,
)

def test_new_fields(self) -> None:
Chain = self.apps_registry.get_model("chains", "Chain")

chain = Chain.objects.get(id=1)

self.assertEqual(chain.balances_provider_chain_name, None)
self.assertEqual(chain.balances_provider_enabled, False)
7 changes: 7 additions & 0 deletions src/chains/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ class RpcAuthentication(models.TextChoices):
max_length=255, null=True, blank=True
)
prices_provider_chain_name = models.CharField(max_length=255, null=True, blank=True)
balances_provider_chain_name = models.CharField(
max_length=255, null=True, blank=True
)
balances_provider_enabled = models.BooleanField(
default=False,
help_text="This flag informs API clients whether the balances provider is enabled for the chain",
)
hidden = models.BooleanField(default=False)

def get_disabled_wallets(self) -> QuerySet["Wallet"]:
Expand Down
11 changes: 11 additions & 0 deletions src/chains/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ class PricesProviderSerializer(serializers.Serializer[Chain]):
chain_name = serializers.CharField(source="prices_provider_chain_name")


class BalancesProviderSerializer(serializers.Serializer[Chain]):
chain_name = serializers.CharField(source="balances_provider_chain_name")
enabled = serializers.BooleanField(source="balances_provider_enabled")


class BaseRpcUriSerializer(serializers.Serializer[Chain]):
authentication = serializers.SerializerMethodField()
value = serializers.SerializerMethodField(method_name="get_rpc_value")
Expand Down Expand Up @@ -162,6 +167,7 @@ class ChainSerializer(serializers.ModelSerializer[Chain]):
block_explorer_uri_template = serializers.SerializerMethodField()
native_currency = serializers.SerializerMethodField()
prices_provider = serializers.SerializerMethodField()
balances_provider = serializers.SerializerMethodField()
transaction_service = serializers.URLField(
source="transaction_service_uri", default=None
)
Expand All @@ -188,6 +194,7 @@ class Meta:
"block_explorer_uri_template",
"native_currency",
"prices_provider",
"balances_provider",
"transaction_service",
"vpc_transaction_service",
"theme",
Expand Down Expand Up @@ -247,3 +254,7 @@ def get_features(self, instance: Chain) -> ReturnDict[Any, Any]:
@swagger_serializer_method(serializer_or_field=PricesProviderSerializer) # type: ignore[misc]
def get_prices_provider(self, instance: Chain) -> ReturnDict[Any, Any]:
return PricesProviderSerializer(instance).data

@swagger_serializer_method(serializer_or_field=BalancesProviderSerializer) # type: ignore[misc]
def get_balances_provider(self, instance: Chain) -> ReturnDict[Any, Any]:
return BalancesProviderSerializer(instance).data
2 changes: 2 additions & 0 deletions src/chains/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class Meta:
recommended_master_copy_version = "1.3.0"
prices_provider_native_coin = factory.Faker("cryptocurrency_code")
prices_provider_chain_name = factory.Faker("company")
balances_provider_chain_name = factory.Faker("company")
balances_provider_enabled = factory.Faker("pybool")
hidden = False


Expand Down
8 changes: 8 additions & 0 deletions src/chains/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ def test_json_payload_format(self) -> None:
"nativeCoin": chain.prices_provider_native_coin,
"chainName": chain.prices_provider_chain_name,
},
"balancesProvider": {
"chainName": chain.balances_provider_chain_name,
"enabled": chain.balances_provider_enabled,
},
"transactionService": chain.transaction_service_uri,
"vpcTransactionService": chain.vpc_transaction_service_uri,
"theme": {
Expand Down Expand Up @@ -193,6 +197,10 @@ def test_json_payload_format(self) -> None:
"nativeCoin": chain.prices_provider_native_coin,
"chainName": chain.prices_provider_chain_name,
},
"balancesProvider": {
"chainName": chain.balances_provider_chain_name,
"enabled": chain.balances_provider_enabled,
},
"transactionService": chain.transaction_service_uri,
"vpcTransactionService": chain.vpc_transaction_service_uri,
"theme": {
Expand Down
Binary file added src/media/safe_apps/icon_url.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions src/safe_apps/migrations/0013_assign_safeapp_icon_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Associated with migration #0014, ensuring that all SafeApps have an icon_url
# before making it non-nullable. Assigning a value and changing the field to
# non-nullable in the same migration otherwise causes an error.

from django.db import migrations
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.db.models import Q


def assign_missing_default_icon_url(
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
SafeApp = apps.get_model("safe_apps", "SafeApp")
default_icon_url = "safe_apps/icon_url.jpg"

SafeApp.objects.filter(Q(icon_url__isnull=True) | Q(icon_url="")).update(
icon_url=default_icon_url
)


class Migration(migrations.Migration):

dependencies = [
("safe_apps", "0012_rename_visible_safeapp_listed"),
]

operations = [
migrations.RunPython(
assign_missing_default_icon_url, reverse_code=migrations.RunPython.noop
),
]
25 changes: 25 additions & 0 deletions src/safe_apps/migrations/0014_alter_safeapp_icon_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 5.0.6 on 2024-05-31 14:46

from django.db import migrations, models

import safe_apps.models


class Migration(migrations.Migration):

dependencies = [
("safe_apps", "0013_assign_safeapp_icon_url"),
]

operations = [
migrations.AlterField(
model_name="safeapp",
name="icon_url",
field=models.ImageField(
default="safe_apps/icon_url.jpg",
max_length=255,
upload_to=safe_apps.models.safe_app_icon_path,
validators=[safe_apps.models.validate_safe_app_icon_size],
),
),
]
Empty file.
50 changes: 50 additions & 0 deletions src/safe_apps/migrations/tests/test_migration_0013.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from django.db.migrations.state import StateApps

from chains.migrations.tests.utils import TestMigrations


class Migration0013TestCase(TestMigrations):
migrate_from = "0012_rename_visible_safeapp_listed"
migrate_to = "0013_assign_safeapp_icon_url"

def setUpBeforeMigration(self, apps: StateApps) -> None:
SafeApp = apps.get_model("safe_apps", "SafeApp")
SafeApp.objects.create(
app_id=1,
chain_ids=[1],
description="No icon_url",
)

SafeApp.objects.create(
app_id=2,
chain_ids=[1],
icon_url=None,
description="Null icon_url",
)

SafeApp.objects.create(
app_id=3,
chain_ids=[1],
icon_url="",
description="Empty icon_url",
)

SafeApp.objects.create(
app_id=4,
chain_ids=[1],
icon_url="existing/icon_url.jpg",
description="Existing icon_url",
)

def test_icon_url_is_set(self) -> None:
SafeApp = self.apps_registry.get_model("safe_apps", "SafeApp")

app_1 = SafeApp.objects.get(app_id=1)
app_2 = SafeApp.objects.get(app_id=2)
app_3 = SafeApp.objects.get(app_id=3)
app_4 = SafeApp.objects.get(app_id=4)

self.assertEqual(app_1.icon_url.url, "/media/safe_apps/icon_url.jpg")
self.assertEqual(app_2.icon_url.url, "/media/safe_apps/icon_url.jpg")
self.assertEqual(app_3.icon_url.url, "/media/safe_apps/icon_url.jpg")
self.assertEqual(app_4.icon_url.url, "/media/existing/icon_url.jpg")
3 changes: 1 addition & 2 deletions src/safe_apps/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ class AccessControlPolicy(str, Enum):
validators=[validate_safe_app_icon_size],
upload_to=safe_app_icon_path,
max_length=255,
null=True,
blank=True,
default="safe_apps/icon_url.jpg",
)
description = models.CharField(max_length=200)
chain_ids = ArrayField(models.PositiveBigIntegerField())
Expand Down
2 changes: 1 addition & 1 deletion src/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__name__ = "Safe Config Service"
__version__ = "2.80.0"
__version__ = "2.83.0"

0 comments on commit 4f8dcce

Please sign in to comment.