Skip to content

Commit

Permalink
Increase coverage
Browse files Browse the repository at this point in the history
- Use TransactionServiceApi from safe-eth-py
  • Loading branch information
Uxio0 committed Oct 11, 2023
1 parent 6980c8c commit f16aa08
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 281 deletions.
Empty file removed safe_cli/api/__init__.py
Empty file.
44 changes: 0 additions & 44 deletions safe_cli/api/base_api.py

This file was deleted.

224 changes: 0 additions & 224 deletions safe_cli/api/transaction_service_api.py

This file was deleted.

39 changes: 33 additions & 6 deletions safe_cli/operators/safe_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@
from packaging import version as semantic_version
from prompt_toolkit import HTML, print_formatted_text
from web3 import Web3
from web3.contract import Contract
from web3.exceptions import BadFunctionCallOutput

from gnosis.eth import EthereumClient, EthereumNetwork, TxSpeed
from gnosis.eth import (
EthereumClient,
EthereumNetwork,
EthereumNetworkNotSupported,
TxSpeed,
)
from gnosis.eth.clients import EtherscanClient, EtherscanClientConfigurationProblem
from gnosis.eth.constants import NULL_ADDRESS, SENTINEL_ADDRESS
from gnosis.eth.contracts import (
Expand All @@ -24,9 +30,9 @@
get_safe_V1_1_1_contract,
)
from gnosis.safe import InvalidInternalTx, Safe, SafeOperation, SafeTx
from gnosis.safe.api import TransactionServiceApi
from gnosis.safe.multi_send import MultiSend, MultiSendOperation, MultiSendTx

from safe_cli.api.transaction_service_api import TransactionServiceApi
from safe_cli.ethereum_hd_wallet import get_account_from_words
from safe_cli.safe_addresses import (
get_default_fallback_handler_address,
Expand Down Expand Up @@ -176,7 +182,23 @@ def decorated(self, *args, **kwargs):


class SafeOperator:
def __init__(self, address: str, node_url: str):
address: ChecksumAddress
node_url: str
ethereum_client: EthereumClient
ens: ENS
network: EthereumNetwork
etherscan: Optional[EtherscanClient]
safe_tx_service: Optional[TransactionServiceApi]
safe: Safe
safe_contract: Contract
safe_contract_1_1_0: Contract
accounts: Set[LocalAccount] = set()
default_sender: Optional[LocalAccount]
executed_transactions: List[str]
_safe_cli_info: Optional[SafeCliInfo]
require_all_signatures: bool

def __init__(self, address: ChecksumAddress, node_url: str):
self.address = address
self.node_url = node_url
self.ethereum_client = EthereumClient(self.node_url)
Expand All @@ -186,9 +208,14 @@ def __init__(self, address: str, node_url: str):
self.etherscan = EtherscanClient(self.network)
except EtherscanClientConfigurationProblem:
self.etherscan = None
self.safe_tx_service = TransactionServiceApi.from_ethereum_client(
self.ethereum_client
)

try:
self.safe_tx_service = TransactionServiceApi.from_ethereum_client(
self.ethereum_client
)
except EthereumNetworkNotSupported:
self.safe_tx_service = None

self.safe = Safe(address, self.ethereum_client)
self.safe_contract = self.safe.contract
self.safe_contract_1_1_0 = get_safe_V1_1_1_contract(
Expand Down
6 changes: 3 additions & 3 deletions safe_cli/operators/safe_tx_service_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

from gnosis.eth.contracts import get_erc20_contract
from gnosis.safe import SafeOperation, SafeTx
from gnosis.safe.api import SafeAPIException
from gnosis.safe.multi_send import MultiSend, MultiSendOperation, MultiSendTx

from safe_cli.api.base_api import BaseAPIException
from safe_cli.utils import yes_or_no_question

from .safe_operator import (
Expand Down Expand Up @@ -58,7 +58,7 @@ def add_delegate(self, delegate_address: str, label: str, signer_address: str):
self.address, delegate_address, label, signer_account
)
return True
except BaseAPIException:
except SafeAPIException:
return False

def remove_delegate(self, delegate_address: str, signer_address: str):
Expand All @@ -76,7 +76,7 @@ def remove_delegate(self, delegate_address: str, signer_address: str):
self.address, delegate_address, signer_account
)
return True
except BaseAPIException:
except SafeAPIException:
return False

def submit_signatures(self, safe_tx_hash: bytes) -> bool:
Expand Down
5 changes: 3 additions & 2 deletions safe_cli/prompt_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from prompt_toolkit import HTML, print_formatted_text
from web3 import Web3

from .api.base_api import BaseAPIException
from gnosis.safe.api import SafeAPIException

from .operators.safe_operator import (
AccountNotLoadedException,
ExistingOwnerException,
Expand Down Expand Up @@ -77,7 +78,7 @@ def safe_exception(function):
def wrapper(*args, **kwargs):
try:
return function(*args, **kwargs)
except BaseAPIException as e:
except SafeAPIException as e:
if e.args:
print_formatted_text(HTML(f"<b><ansired>{e.args[0]}</ansired></b>"))
except AccountNotLoadedException as e:
Expand Down
3 changes: 1 addition & 2 deletions tests/api/test_gnosis_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
from unittest import mock

from gnosis.eth import EthereumClient, EthereumNetwork

from safe_cli.api.transaction_service_api import TransactionServiceApi
from gnosis.safe.api import TransactionServiceApi


class TestTransactionService(unittest.TestCase):
Expand Down

0 comments on commit f16aa08

Please sign in to comment.