Skip to content

Commit

Permalink
Remove pyethereum dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Uxio0 committed Mar 23, 2022
1 parent 70583c8 commit 3820bca
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
steps:
- name: Setup and run ganache
run: |
docker run --detach --publish 8545:8545 --network-alias ganache -e DOCKER=true trufflesuite/ganache-cli:latest --defaultBalanceEther 10000 --gasLimit 10000000 -a 30 --noVMErrorsOnRPCResponse --chainId 1337 --networkId 1337 -d
docker run --detach --publish 8545:8545 --network-alias ganache -e DOCKER=true trufflesuite/ganache:latest --defaultBalanceEther 10000 --gasLimit 10000000 -a 30 --chain.chainId 1337 --chain.networkId 1337 -d
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ services:

ganache:
image: trufflesuite/ganache-cli
command: -d --defaultBalanceEther 10000 -a 10 --noVMErrorsOnRPCResponse --gasLimit 10000000 --host 0.0.0.0 --chainId 1337 --networkId 1337
command: -d --defaultBalanceEther 10000 --gasLimit 10000000 -a 30 --chain.chainId 1337 --chain.networkId 1337
ports:
- "8545:8545"
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ djangorestframework==3.13.1
djangorestframework-camel-case==1.3.0
docutils==0.18.1
drf-yasg[validation]==1.20.0
ethereum==2.3.2
gnosis-py[django]==3.9.0
gunicorn[gevent]==20.1.0
hexbytes==0.2.2
Expand Down
14 changes: 6 additions & 8 deletions safe_relay_service/relay/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

from celery import app
from celery.utils.log import get_task_logger
from ethereum.utils import check_checksum, checksum_encode, mk_contract_address
from redis.exceptions import LockError
from web3 import Web3

from gnosis.eth import EthereumClientProvider, TransactionAlreadyImported
from gnosis.eth.constants import NULL_ADDRESS
from gnosis.eth.utils import mk_contract_address

from safe_relay_service.gas_station.gas_station import GasStationProvider

Expand Down Expand Up @@ -60,12 +61,9 @@ def fund_deployer_task(self, safe_address: str, retry: bool = True) -> None:
payment = safe_creation.payment

# These asserts just to make sure we are not wasting money
assert check_checksum(safe_address)
assert check_checksum(deployer_address)
assert (
checksum_encode(mk_contract_address(sender=deployer_address, nonce=0))
== safe_address
)
assert Web3.isChecksumAddress(safe_address)
assert Web3.isChecksumAddress(deployer_address)
assert mk_contract_address(deployer_address, 0) == safe_address
assert payment > 0

redis = RedisRepository().redis
Expand Down Expand Up @@ -360,7 +358,7 @@ def deploy_create2_safe_task(self, safe_address: str, retry: bool = True) -> Non
:param retry: if True, retries are allowed, otherwise don't retry
"""

assert check_checksum(safe_address)
assert Web3.isChecksumAddress(safe_address)

redis = RedisRepository().redis
lock_name = f"locks:deploy_create2_safe:{safe_address}"
Expand Down
8 changes: 3 additions & 5 deletions safe_relay_service/relay/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import factory.fuzzy
from eth_account import Account
from ethereum.utils import checksum_encode, mk_contract_address
from factory.django import DjangoModelFactory
from hexbytes import HexBytes
from web3 import Web3
Expand All @@ -19,6 +18,7 @@
SIGNATURE_V_MAX_VALUE,
SIGNATURE_V_MIN_VALUE,
)
from gnosis.eth.utils import mk_contract_address

from ..models import (
BannedSigner,
Expand Down Expand Up @@ -52,7 +52,7 @@ class Meta:
safe = factory.SubFactory(
SafeContractFactory,
address=factory.LazyAttribute(
lambda o: checksum_encode(mk_contract_address(o.factory_parent.deployer, 0))
lambda o: mk_contract_address(o.factory_parent.deployer, 0)
),
)
funder = factory.LazyFunction(lambda: Account.create().address)
Expand Down Expand Up @@ -82,9 +82,7 @@ class Meta:
safe = factory.SubFactory(
SafeContractFactory,
address=factory.LazyAttribute(
lambda o: checksum_encode(
mk_contract_address(o.factory_parent.proxy_factory, 0)
)
lambda o: mk_contract_address(o.factory_parent.proxy_factory, 0)
),
)
master_copy = factory.LazyFunction(lambda: Account.create().address)
Expand Down
7 changes: 5 additions & 2 deletions safe_relay_service/relay/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from django.test import TestCase

from eth_account import Account
from ethereum.transactions import secpk1n
from faker import Faker
from hexbytes import HexBytes

Expand All @@ -25,8 +24,12 @@


class TestSerializers(TestCase):
SECPK1N = (
115792089237316195423570985008687907852837564279074904382605163141518161494337
)

def test_safe_creation_serializer(self):
s = secpk1n // 2
s = self.SECPK1N // 2
owners = [Account.create().address for _ in range(3)]
invalid_checksumed_address = get_eth_address_with_invalid_checksum()

Expand Down
14 changes: 7 additions & 7 deletions safe_relay_service/relay/tests/test_views_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from django.urls import reverse

from eth_account import Account
from ethereum.utils import check_checksum
from faker import Faker
from rest_framework import status
from rest_framework.test import APITestCase
from web3 import Web3

from gnosis.eth.constants import NULL_ADDRESS
from gnosis.eth.utils import get_eth_address_with_invalid_checksum
Expand Down Expand Up @@ -68,8 +68,8 @@ def test_safe_creation(self):
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
response_json = response.json()
safe_address = response_json["safe"]
self.assertTrue(check_checksum(safe_address))
self.assertTrue(check_checksum(response_json["paymentReceiver"]))
self.assertTrue(Web3.isChecksumAddress(safe_address))
self.assertTrue(Web3.isChecksumAddress(response_json["paymentReceiver"]))
self.assertEqual(response_json["paymentToken"], NULL_ADDRESS)
self.assertEqual(
int(response_json["payment"]),
Expand Down Expand Up @@ -129,8 +129,8 @@ def test_safe_creation_with_fixed_cost(self):
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
response_json = response.json()
safe_address = response_json["safe"]
self.assertTrue(check_checksum(safe_address))
self.assertTrue(check_checksum(response_json["paymentReceiver"]))
self.assertTrue(Web3.isChecksumAddress(safe_address))
self.assertTrue(Web3.isChecksumAddress(response_json["paymentReceiver"]))
self.assertEqual(response_json["paymentToken"], NULL_ADDRESS)
self.assertEqual(response_json["payment"], str(fixed_creation_cost))
self.assertGreater(int(response_json["gasEstimated"]), 0)
Expand Down Expand Up @@ -164,8 +164,8 @@ def test_safe_creation_with_payment_token(self):
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
response_json = response.json()
safe_address = response_json["safe"]
self.assertTrue(check_checksum(safe_address))
self.assertTrue(check_checksum(response_json["paymentReceiver"]))
self.assertTrue(Web3.isChecksumAddress(safe_address))
self.assertTrue(Web3.isChecksumAddress(response_json["paymentReceiver"]))
self.assertEqual(response_json["paymentToken"], payment_token)
self.assertEqual(
int(response_json["payment"]),
Expand Down
14 changes: 7 additions & 7 deletions safe_relay_service/relay/tests/test_views_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from django.urls import reverse

from eth_account import Account
from ethereum.utils import check_checksum
from faker import Faker
from rest_framework import status
from rest_framework.test import APITestCase
from web3 import Web3

from gnosis.eth.constants import NULL_ADDRESS
from gnosis.safe import Safe
Expand Down Expand Up @@ -66,8 +66,8 @@ def test_safe_creation(self):
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
response_json = response.json()
safe_address = response_json["safe"]
self.assertTrue(check_checksum(safe_address))
self.assertTrue(check_checksum(response_json["paymentReceiver"]))
self.assertTrue(Web3.isChecksumAddress(safe_address))
self.assertTrue(Web3.isChecksumAddress(response_json["paymentReceiver"]))
self.assertEqual(response_json["paymentToken"], NULL_ADDRESS)
self.assertEqual(
int(response_json["payment"]),
Expand Down Expand Up @@ -125,8 +125,8 @@ def test_safe_creation_with_fixed_cost(self):
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
response_json = response.json()
safe_address = response_json["safe"]
self.assertTrue(check_checksum(safe_address))
self.assertTrue(check_checksum(response_json["paymentReceiver"]))
self.assertTrue(Web3.isChecksumAddress(safe_address))
self.assertTrue(Web3.isChecksumAddress(response_json["paymentReceiver"]))
self.assertEqual(response_json["paymentToken"], NULL_ADDRESS)
self.assertEqual(response_json["payment"], str(fixed_creation_cost))
self.assertGreater(int(response_json["gasEstimated"]), 0)
Expand Down Expand Up @@ -160,8 +160,8 @@ def test_safe_creation_with_payment_token(self):
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
response_json = response.json()
safe_address = response_json["safe"]
self.assertTrue(check_checksum(safe_address))
self.assertTrue(check_checksum(response_json["paymentReceiver"]))
self.assertTrue(Web3.isChecksumAddress(safe_address))
self.assertTrue(Web3.isChecksumAddress(response_json["paymentReceiver"]))
self.assertEqual(response_json["paymentToken"], payment_token)
self.assertEqual(
int(response_json["payment"]),
Expand Down
10 changes: 5 additions & 5 deletions scripts/create_multiple_safes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from urllib.parse import urljoin

import requests
from ethereum.utils import checksum_encode, privtoaddr
from eth_account import Account
from web3 import HTTPProvider, Web3

from gnosis.safe.tests.utils import generate_valid_s
Expand Down Expand Up @@ -58,9 +58,9 @@ def notify_safes():


def deploy_safes(number, owners, private_key):
funder = Account.from_key(private_key)
safes = []
funding_public_key = checksum_encode(privtoaddr(private_key))
funding_nonce = w3.eth.getTransactionCount(funding_public_key, "pending")
funder_nonce = w3.eth.getTransactionCount(funder.address, "pending")
for _ in range(number):
payload_json = generate_payload(owners)
r = requests.post(SAFES_URL, json=payload_json)
Expand All @@ -70,11 +70,11 @@ def deploy_safes(number, owners, private_key):
payment = int(safe_created["payment"])

logging.info("Created safe=%s, need payment=%d", safe_address, payment)
send_eth(private_key, safe_address, payment, funding_nonce)
send_eth(private_key, safe_address, payment, funder_nonce)
logging.info("Sent payment=%s to safe=%s", payment, safe_address)
r = requests.put(get_safes_notify_url(safe_address))
assert r.ok
funding_nonce += 1
funder_nonce += 1
safes.append(safe_address)

with open("safes.txt", mode="a") as safes_file:
Expand Down

0 comments on commit 3820bca

Please sign in to comment.