Skip to content

Commit

Permalink
Fix some tests for Erigon
Browse files Browse the repository at this point in the history
- Erigon changed a little trace format
- Erigon forces EIP-155
  • Loading branch information
Uxio0 committed Jul 5, 2022
1 parent d8d13ad commit 12b4003
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 46 deletions.
1 change: 0 additions & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ jobs:
SOURCE_FOLDER: gnosis
DJANGO_SETTINGS_MODULE: config.settings.test
ETHEREUM_MAINNET_NODE: ${{ secrets.ETHEREUM_MAINNET_NODE }}
ETHEREUM_TEST_NODES_URLS: ${{ secrets.ETHEREUM_TEST_NODES_URLS }}
- name: Test setup.py
run: pip install -e .
- name: Send results to coveralls
Expand Down
6 changes: 0 additions & 6 deletions config/settings/test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

from .base import * # noqa

INSTALLED_APPS += ("gnosis.eth.django.tests",) # noqa
Expand Down Expand Up @@ -27,10 +25,6 @@

ETHEREUM_NODE_URL = "http://localhost:8545"
ETHEREUM_TEST_PRIVATE_KEY = "b0057716d5917badaf911b193b12b910811c1497b5bada8d7711f758981c3773" # Ganache account 9
ETHEREUM_TEST_NODES_URLS = os.environ.get("ETHEREUM_TEST_NODES_URLS")
ETHEREUM_TEST_NODES_URLS = (
ETHEREUM_TEST_NODES_URLS.split(",") if ETHEREUM_TEST_NODES_URLS else []
)

# Ganache fixed seed keys (run ganache with -d)
SAFE_FUNDER_PRIVATE_KEY = (
Expand Down
2 changes: 2 additions & 0 deletions gnosis/eth/ethereum_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
from .ethereum_network import EthereumNetwork, EthereumNetworkNotSupported
from .exceptions import (
BatchCallFunctionFailed,
ChainIdIsRequired,
FromAddressNotFound,
GasLimitExceeded,
InsufficientFunds,
Expand Down Expand Up @@ -120,6 +121,7 @@ def tx_with_exception_handling(func):
:return:
"""
error_with_exception: Dict[str, Exception] = {
"EIP-155": ChainIdIsRequired,
"Transaction with the same hash was already imported": TransactionAlreadyImported,
"replacement transaction underpriced": ReplacementTransactionUnderpriced, # https://github.com/ethereum/go-ethereum/blob/eaccdba4ab310e3fb98edbc4b340b5e7c4d767fd/core/tx_pool.go#L72
"There is another transaction with same nonce in the queue": ReplacementTransactionUnderpriced, # https://github.com/openethereum/openethereum/blob/f1dc6821689c7f47d8fd07dfc0a2c5ad557b98ec/crates/rpc/src/v1/helpers/errors.rs#L374
Expand Down
4 changes: 4 additions & 0 deletions gnosis/eth/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ class EthereumClientException(ValueError):
pass


class ChainIdIsRequired(EthereumClientException):
pass


class TransactionAlreadyImported(EthereumClientException):
pass

Expand Down
7 changes: 3 additions & 4 deletions gnosis/eth/tests/mocks/mock_trace_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@
"result": None,
"subtraces": 0,
"traceAddress": [],
"transactionHash": None,
"transactionPosition": None,
"type": "reward",
},
]
Expand Down Expand Up @@ -181,6 +179,7 @@
"blockHash": "0x8f9809f6012f85803956a419e2e54914dfdebba33e4f7a0d1574b12e92499c0e",
"blockNumber": 13191781,
"error": "Reverted",
"result": None,
"subtraces": 0,
"traceAddress": [],
"transactionHash": "0xbe99757628bfc3d5c7ee4e42c2629ddd13ac52354e6abb189efe5e277dce05b3",
Expand Down Expand Up @@ -747,6 +746,7 @@
"blockHash": "0x8f9809f6012f85803956a419e2e54914dfdebba33e4f7a0d1574b12e92499c0e",
"blockNumber": 13191781,
"error": "Reverted",
"result": None,
"subtraces": 2,
"traceAddress": [],
"transactionHash": "0xfac7403428a8213f3fc296412eb3f259086d80dd83be2d819b574b145b8d4855",
Expand Down Expand Up @@ -889,6 +889,7 @@
"blockHash": "0x8f9809f6012f85803956a419e2e54914dfdebba33e4f7a0d1574b12e92499c0e",
"blockNumber": 13191781,
"error": "Reverted",
"result": None,
"subtraces": 5,
"traceAddress": [],
"transactionHash": "0xd1118a18e43777636ccef0cafa5de58c3b0c6800454606342ba46a662828a8c6",
Expand Down Expand Up @@ -2498,8 +2499,6 @@
"result": None,
"subtraces": 0,
"traceAddress": [],
"transactionHash": None,
"transactionPosition": None,
"type": "reward",
},
]
37 changes: 31 additions & 6 deletions gnosis/eth/tests/test_ethereum_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
SenderAccountNotFoundInNode,
parse_rpc_result_or_raise,
)
from ..exceptions import BatchCallException, InvalidERC20Info
from ..exceptions import BatchCallException, ChainIdIsRequired, InvalidERC20Info
from ..utils import fast_to_checksum_address, get_eth_address_with_key
from .ethereum_test_case import EthereumTestCaseMixin
from .mocks.mock_internal_txs import creation_internal_txs, internal_txs_errored
Expand Down Expand Up @@ -1260,12 +1260,37 @@ def test_estimate_fee_eip1559(self):
self.assertGreater(base_fee_per_gas, 0)
self.assertGreaterEqual(max_priority_fee_per_gas, 0)

def test_send_unsigned_transaction(self):
random_address = Account.create().address
random_sender_account = Account.create()
tx = {
"to": random_address,
"value": 0,
"data": b"",
"gas": 25000,
"gasPrice": self.ethereum_client.w3.eth.gas_price,
}
with self.assertRaises(ChainIdIsRequired):
self.ethereum_client.send_unsigned_transaction(
tx, private_key=random_sender_account.key
)

tx["chainId"] = 1
with self.assertRaises(InsufficientFunds):
self.ethereum_client.send_unsigned_transaction(
tx, private_key=random_sender_account.key
)

def test_trace_block(self):
block_number = 2191709
self.assertEqual(
self.ethereum_client.parity.trace_block(block_number),
trace_block_2191709_mock,
)
block_numbers = [13191781, 2191709]
for block_number, trace_block_mock in zip(
block_numbers, [trace_block_13191781_mock, trace_block_2191709_mock]
):
with self.subTest(block_number=block_number):
self.assertEqual(
self.ethereum_client.parity.trace_block(block_number),
trace_block_mock,
)

def test_trace_blocks(self):
block_numbers = [13191781, 2191709]
Expand Down
29 changes: 0 additions & 29 deletions gnosis/safe/tests/test_real_nodes.py

This file was deleted.

0 comments on commit 12b4003

Please sign in to comment.