Skip to content

Commit

Permalink
Merge 4d41101 into 91e0848
Browse files Browse the repository at this point in the history
  • Loading branch information
Uxio0 committed Jul 11, 2022
2 parents 91e0848 + 4d41101 commit 5eb3cbc
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 9 deletions.
5 changes: 3 additions & 2 deletions gnosis/eth/multicall.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@ class Multicall:
ADDRESSES = {
EthereumNetwork.MAINNET: "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696",
EthereumNetwork.ARBITRUM: "0x021CeAC7e681dBCE9b5039d2535ED97590eB395c",
EthereumNetwork.AVALANCHE: "0xAbeC56f92a89eEe33F5194Ca4151DD59785c2C74",
EthereumNetwork.BINANCE: "0xed386Fe855C1EFf2f843B910923Dd8846E45C5A4",
EthereumNetwork.FANTOM: "0xD98e3dBE5950Ca8Ce5a4b59630a5652110403E5c",
EthereumNetwork.GOERLI: "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696",
EthereumNetwork.KOVAN: "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696",
EthereumNetwork.MATIC: "0xed386Fe855C1EFf2f843B910923Dd8846E45C5A4",
EthereumNetwork.MUMBAI: "0xed386Fe855C1EFf2f843B910923Dd8846E45C5A4",
EthereumNetwork.OPTIMISTIC: "0x2DC0E2aa608532Da689e89e237dF582B783E552C",
EthereumNetwork.RINKEBY: "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696",
EthereumNetwork.ROPSTEN: "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696",
EthereumNetwork.XDAI: "0x08612d3C4A5Dfe2FaaFaFe6a4ff712C2dC675bF7",
EthereumNetwork.FANTOM: "0xD98e3dBE5950Ca8Ce5a4b59630a5652110403E5c",
EthereumNetwork.AVALANCHE: "0xAbeC56f92a89eEe33F5194Ca4151DD59785c2C74",
}

def __init__(
Expand Down
12 changes: 11 additions & 1 deletion gnosis/eth/tests/test_ethereum_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from .mocks.mock_trace_block import trace_block_2191709_mock, trace_block_13191781_mock
from .mocks.mock_trace_filter import trace_filter_mock_1
from .mocks.mock_trace_transaction import trace_transaction_mocks
from .utils import just_test_if_mainnet_node
from .utils import deploy_example_erc20, just_test_if_mainnet_node


class TestERC20Module(EthereumTestCaseMixin, TestCase):
Expand Down Expand Up @@ -1221,6 +1221,16 @@ def test_get_blocks(self):
self.assertEqual(len(block["parentHash"]), 32)
self.assertGreaterEqual(len(block["transactions"]), 0)

def test_is_contract(self):
self.assertFalse(
self.ethereum_client.is_contract(self.ethereum_test_account.address)
)

erc20 = deploy_example_erc20(
self.ethereum_client.w3, 2, self.ethereum_test_account.address
)
self.assertTrue(self.ethereum_client.is_contract(erc20.address))

def test_is_eip1559_supported(self):
self.assertFalse(self.ethereum_client.is_eip1559_supported())

Expand Down
30 changes: 25 additions & 5 deletions gnosis/safe/multi_send.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from enum import Enum
from logging import getLogger
from typing import List, Union
from typing import List, Optional, Union

from eth_account.signers.local import LocalAccount
from eth_typing import ChecksumAddress
from hexbytes import HexBytes
from web3 import Web3

Expand Down Expand Up @@ -164,16 +165,35 @@ def _decode_multisend_old_transaction(

class MultiSend:
dummy_w3 = Web3()
MULTISEND_ADDRESSES = (
"0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761",
"0x998739BFdAAdde7C933B942a68053933098f9EDa",
)

def __init__(self, address: str, ethereum_client: EthereumClient):
assert fast_is_checksum_address(address), (
"%s proxy factory address not valid" % address
)
def __init__(
self, ethereum_client: EthereumClient, address: Optional[ChecksumAddress] = None
):

self.address = address
self.ethereum_client = ethereum_client
self.w3 = ethereum_client.w3

if address:
assert fast_is_checksum_address(address), (
"%s proxy factory address not valid" % address
)
else:
# Try to detect Multisend address if not provided
for address in self.MULTISEND_ADDRESSES:
if ethereum_client.is_contract(address):
self.address = address
break

if not self.address:
raise ValueError(
f"Cannot find a MultiSend contract for chainId={self.ethereum_client.get_chain_id()}"
)

@classmethod
def from_bytes(cls, encoded_multisend_txs: Union[str, bytes]) -> List[MultiSendTx]:
"""
Expand Down
4 changes: 3 additions & 1 deletion gnosis/safe/tests/safe_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ def setUpClass(cls):
cls.multi_send_contract = get_multi_send_contract(
cls.w3, _contract_addresses["multi_send"]
)
cls.multi_send = MultiSend(cls.multi_send_contract.address, cls.ethereum_client)
cls.multi_send = MultiSend(
cls.ethereum_client, address=cls.multi_send_contract.address
)

def build_test_safe(
self,
Expand Down
18 changes: 18 additions & 0 deletions gnosis/safe/tests/test_multi_send.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
import logging
from unittest import mock

from django.test import TestCase

from eth_account import Account
from hexbytes import HexBytes

from gnosis.eth import EthereumClient

from ..multi_send import MultiSend, MultiSendOperation, MultiSendTx
from .safe_test_case import SafeTestCaseMixin

logger = logging.getLogger(__name__)


class TestMultiSend(SafeTestCaseMixin, TestCase):
def test_multisend_init(self):
# Should try to detect the contract address
with self.assertRaisesMessage(
ValueError, "Cannot find a MultiSend contract for chainId=1337"
):
MultiSend(self.ethereum_client)

with mock.patch.object(EthereumClient, "is_contract", return_value=True):
multisend = MultiSend(self.ethereum_client)
self.assertEqual(multisend.address, multisend.MULTISEND_ADDRESSES[0])

random_address = Account.create().address
multisend = MultiSend(self.ethereum_client, address=random_address)
self.assertEqual(multisend.address, random_address)

def test_multi_send_tx_from_bytes(self):
operation = MultiSendOperation.DELEGATE_CALL
address = Account.create().address
Expand Down

0 comments on commit 5eb3cbc

Please sign in to comment.