Skip to content

Commit

Permalink
Merge branch 'safe-global:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ElvisKrop authored Feb 2, 2023
2 parents ab1ea78 + 0eccb7a commit 8b20fdf
Show file tree
Hide file tree
Showing 55 changed files with 1,810 additions and 445 deletions.
15 changes: 15 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
changelog:
categories:
- title: 🏕 Features
labels:
- '*'
exclude:
labels:
- dependencies
- breaking_change
- title: 🛠 Breaking Changes
labels:
- breaking_change
- title: 👒 Dependencies
labels:
- dependencies
71 changes: 0 additions & 71 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

27 changes: 21 additions & 6 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
name: Python CI
on: [push, pull_request]
on:
push:
branches:
- master
- develop
pull_request:
release:
types: [ released ]


jobs:
linting:
Expand All @@ -14,16 +22,22 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: '.pre-commit-config.yaml'
- uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: Install dependencies
run: pip install pre-commit
run: pip install -U pre-commit
- name: Run pre-commit
run: pre-commit run --all-files

test-app:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, "3.10"]
python-version: [3.8, 3.9, "3.10"]
services:
postgres:
image: postgres:13
Expand Down Expand Up @@ -53,12 +67,13 @@ jobs:
env:
PIP_USE_MIRRORS: true
- name: Run tests and coverage
run: coverage run --source=$SOURCE_FOLDER -m py.test -W ignore::DeprecationWarning -rxXs --reruns 3
run: coverage run --source=$SOURCE_FOLDER -m pytest -W ignore::DeprecationWarning -rxXs --reruns 3
env:
SOURCE_FOLDER: gnosis
DJANGO_SETTINGS_MODULE: config.settings.test
ETHEREUM_MAINNET_NODE: ${{ secrets.ETHEREUM_MAINNET_NODE }}
- name: Test setup.py
ETHEREUM_POLYGON_NODE: ${{ secrets.ETHEREUM_POLYGON_NODE }}
- name: Test packaging
run: pip install -e .
- name: Send results to coveralls
run: coveralls --service=github
Expand All @@ -70,7 +85,7 @@ jobs:
needs:
- linting
- test-app
if: startsWith(github.ref, 'refs/tags/')
if: (github.event_name == 'release' && github.event.action == 'released')
steps:
- uses: actions/checkout@v3
- name: Set up Python
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 22.6.0
rev: 22.12.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
rev: 6.0.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: check-docstring-first
- id: check-merge-conflict
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Gnosis Ltd
Copyright (c) 2018 Safe Ecosystem Foundation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.5'

services:
db:
image: postgres:10-alpine
image: postgres:15-alpine
ports:
- "5432:5432"
environment:
Expand Down
10 changes: 10 additions & 0 deletions docs/source/gnosis.eth.eip712.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
gnosis.eth.eip712 package
============================

Module contents
---------------

.. automodule:: gnosis.eth.eip712
:members:
:undoc-members:
:show-inheritance:
41 changes: 41 additions & 0 deletions docs/source/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,47 @@ gnosis.eth.constants
- ``SENTINEL_ADDRESS (0x000...1)``: Used for Gnosis Safe's linked lists (modules, owners...).
- Maximum an minimum values for `R`, `S` and `V` in ethereum signatures.

gnosis.eth.eip712
~~~~~~~~~~~~~~~~~~~~
.. code-block:: python
from gnosis.eth.eip712 import eip712_encode_hash
types = {'EIP712Domain': [{'name': 'name', 'type': 'string'},
{'name': 'version', 'type': 'string'},
{'name': 'chainId', 'type': 'uint256'},
{'name': 'verifyingContract', 'type': 'address'}],
'Mailbox': [{'name': 'owner', 'type': 'address'},
{'name': 'messages', 'type': 'Message[]'}],
'Message': [{'name': 'sender', 'type': 'address'},
{'name': 'subject', 'type': 'string'},
{'name': 'isSpam', 'type': 'bool'},
{'name': 'body', 'type': 'string'}]}
msgs = [{'sender': ADDRESS,
'subject': 'Hello World',
'body': 'The sparrow flies at midnight.',
'isSpam': False},
{'sender': ADDRESS,
'subject': 'You may have already Won! :dumb-emoji:',
'body': 'Click here for sweepstakes!',
'isSpam': True}]
mailbox = {'owner': ADDRESS,
'messages': msgs}
payload = {'types': types,
'primaryType': 'Mailbox',
'domain': {'name': 'MyDApp',
'version': '3.0',
'chainId': 41,
'verifyingContract': ADDRESS},
'message': mailbox}
eip712_hash = eip712_encode_hash(payload)
gnosis.eth.oracles
~~~~~~~~~~~~~~~~~~
Price oracles for Uniswap, UniswapV2, Kyber, SushiSwap, Aave, Balancer, Curve, Mooniswap, Yearn...
Expand Down
10 changes: 10 additions & 0 deletions gnosis/eth/clients/blockscout_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ class BlockscoutClient:
EthereumNetwork.ENERGY_WEB_CHAIN: "https://explorer.energyweb.org/",
EthereumNetwork.VOLTA: "https://volta-explorer.energyweb.org/",
EthereumNetwork.OLYMPUS: "https://explorer.polis.tech",
EthereumNetwork.BOBA_NETWORK_BOBABEAM: "https://blockexplorer.bobabeam.boba.network/",
EthereumNetwork.BOBA_RINKEBY: "https://blockexplorer.rinkeby.boba.network/",
EthereumNetwork.BOBA: "https://blockexplorer.boba.network/",
EthereumNetwork.GATHER_DEVNET: "https://devnet-explorer.gather.network/",
EthereumNetwork.GATHER_TESTNET: "https://testnet-explorer.gather.network/",
EthereumNetwork.GATHER_MAINNET: "https://explorer.gather.network/",
EthereumNetwork.METIS_TESTNET: "https://stardust-explorer.metis.io/",
EthereumNetwork.METIS_GOERLI_TESTNET: "https://goerli.explorer.metisdevops.link/",
EthereumNetwork.METIS: "https://andromeda-explorer.metis.io/",
EthereumNetwork.FUSE_MAINNET: "https://explorer.fuse.io/",
EthereumNetwork.VELAS_MAINNET: "https://evmexplorer.velas.com/",
Expand All @@ -48,6 +50,14 @@ class BlockscoutClient:
EthereumNetwork.KARURA_NETWORK_TESTNET: "https://blockscout.karura.network/",
EthereumNetwork.ACALA_NETWORK_TESTNET: "https://blockscout.mandala.acala.network/",
EthereumNetwork.ASTAR: "https://blockscout.com/astar/",
EthereumNetwork.EVMOS_MAINNET: "https://evm.evmos.org",
EthereumNetwork.EVMOS_TESTNET: "https://evm.evmos.dev",
EthereumNetwork.RABBIT: "https://rabbit.analogscan.com",
EthereumNetwork.KCC_MAINNET: "https://scan.kcc.io/",
EthereumNetwork.KCC_TESTNET: "https://scan-testnet.kcc.network/",
EthereumNetwork.ARBITRUM: "https://explorer.arbitrum.io",
EthereumNetwork.ARBITRUM_NOVA: "https://nova-explorer.arbitrum.io",
EthereumNetwork.ARBITRUM_GOERLI: "https://goerli-rollup-explorer.arbitrum.io",
}

def __init__(self, network: EthereumNetwork):
Expand Down
8 changes: 7 additions & 1 deletion gnosis/eth/clients/etherscan_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,36 @@ class EtherscanClient:
EthereumNetwork.MATIC: "https://polygonscan.com",
EthereumNetwork.OPTIMISTIC: "https://optimistic.etherscan.io",
EthereumNetwork.ARBITRUM: "https://arbiscan.io",
EthereumNetwork.ARBITRUM_NOVA: "https://nova.arbiscan.io",
EthereumNetwork.ARBITRUM_GOERLI: "https://goerli.arbiscan.io",
EthereumNetwork.AVALANCHE: "https://snowtrace.io",
EthereumNetwork.MOON_MOONBEAM: "https://moonscan.io",
EthereumNetwork.MOON_MOONRIVER: "https://moonriver.moonscan.io",
EthereumNetwork.MOON_MOONBASE: "https://moonbase.moonscan.io",
EthereumNetwork.CRONOS_MAINNET: "https://cronoscan.com",
EthereumNetwork.CRONOS_TESTNET: "https://testnet.cronoscan.com",
EthereumNetwork.CELO: "https://celoscan.io",
}

NETWORK_WITH_API_URL = {
EthereumNetwork.MAINNET: "https://api.etherscan.io",
EthereumNetwork.RINKEBY: "https://api-rinkeby.etherscan.io",
EthereumNetwork.ROPSTEN: "https://api-ropsten.etherscan.io",
EthereumNetwork.GOERLI: "https://api-goerli.etherscan.io/",
EthereumNetwork.KOVAN: "https://api-kovan.etherscan.io/",
EthereumNetwork.KOVAN: "https://api-kovan.etherscan.io",
EthereumNetwork.BINANCE: "https://api.bscscan.com",
EthereumNetwork.MATIC: "https://api.polygonscan.com",
EthereumNetwork.OPTIMISTIC: "https://api-optimistic.etherscan.io",
EthereumNetwork.ARBITRUM: "https://api.arbiscan.io",
EthereumNetwork.ARBITRUM_NOVA: "https://api-nova.arbiscan.io",
EthereumNetwork.ARBITRUM_GOERLI: "https://api-goerli.arbiscan.io",
EthereumNetwork.AVALANCHE: "https://api.snowtrace.io",
EthereumNetwork.MOON_MOONBEAM: "https://api-moonbeam.moonscan.io",
EthereumNetwork.MOON_MOONRIVER: "https://api-moonriver.moonscan.io",
EthereumNetwork.MOON_MOONBASE: "https://api-moonbase.moonscan.io",
EthereumNetwork.CRONOS_MAINNET: "https://api.cronoscan.com",
EthereumNetwork.CRONOS_TESTNET: "https://api-testnet.cronoscan.com",
EthereumNetwork.CELO: "https://api.celoscan.io",
}
HTTP_HEADERS = {
"User-Agent": "curl/7.77.0",
Expand Down
3 changes: 3 additions & 0 deletions gnosis/eth/django/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ def get_prep_value(self, value: Union[bytes, str]) -> Optional[bytes]:
if value:
return self._to_bytes(value)

def value_to_string(self, obj):
return str(self.value_from_object(obj))

def to_python(self, value) -> Optional[str]:
if value is not None:
try:
Expand Down
38 changes: 38 additions & 0 deletions gnosis/eth/django/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.core.exceptions import ValidationError
from django.core.serializers import serialize
from django.db import DataError, transaction
from django.test import TestCase

Expand Down Expand Up @@ -146,3 +147,40 @@ def test_keccak256_field(self):
):
with transaction.atomic():
Keccak256Hash.objects.create(value=value_hex_invalid)

def test_serialize_keccak256_field_to_json(self):
hexvalue: str = (
"0xdb5b7c6d3b0cc538a5859afc4674a785d9d111c3835390295f3d3173d41ca8ea"
)
Keccak256Hash.objects.create(value=hexvalue)
serialized = serialize("json", Keccak256Hash.objects.all())
# 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)
serialized = serialize("json", EthereumAddressV2.objects.all())
# address should be in serialized data
self.assertIn(address, serialized)

def test_serialize_uint256_field_to_json(self):
value = 2**260
Uint256.objects.create(value=value)
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 = Web3.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)
Loading

0 comments on commit 8b20fdf

Please sign in to comment.