Skip to content

Commit

Permalink
Increase coverage (#279)
Browse files Browse the repository at this point in the history
*  Use TransactionServiceApi from safe-eth-py
* Add tests for entrypoint 
* Add test for SafeLexer
* Add tests for safe completer and utils
* Add test for safe_creator
* Remove pyfiglet (replace by art, due to Python 3.8 not supported anymore)
* Check safe-cli package is valid before release
* Add tx service operator delegate tests
* Add test for submit_signatures
* Split argparse validators into file
* Add mock files for tx service
* Test some missing functions for tx service operator
* Remove old gnosis tx service test
* Add missing docs
* Remove redundant information
  • Loading branch information
Uxio0 committed Oct 20, 2023
1 parent 2fadb42 commit 09e8507
Show file tree
Hide file tree
Showing 33 changed files with 1,503 additions and 513 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:
run: |
python -m pip install --upgrade setuptools wheel twine
python setup.py sdist bdist_wheel
twine check dist/*
twine upload dist/*
env:
TWINE_USERNAME: __token__
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
art==6.1
colorama==0.4.6
packaging>=23.1
prompt_toolkit==3.0.39
pyfiglet==1.0.0
pygments==2.16.1
requests==2.31.0
safe-eth-py==6.0.0b2
Expand Down
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.

78 changes: 78 additions & 0 deletions safe_cli/argparse_validators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import argparse
from binascii import Error

from eth_account import Account
from eth_typing import ChecksumAddress
from hexbytes import HexBytes
from web3 import Web3


def check_positive_integer(number: str) -> int:
"""
Positive integer validator for Argparse
:param number:
:return: Positive integer
"""
number = int(number)
if number <= 0:
raise argparse.ArgumentTypeError(
f"{number} is not a valid threshold. Must be > 0"
)
return number


def check_ethereum_address(address: str) -> ChecksumAddress:
"""
Ethereum address validator for Argparse
:param address:
:return: Checksummed ethereum address
"""
if not Web3.is_checksum_address(address):
raise argparse.ArgumentTypeError(
f"{address} is not a valid checksummed ethereum address"
)
return ChecksumAddress(address)


def check_private_key(private_key: str) -> str:
"""
Ethereum private key validator for ArgParse
:param private_key: Ethereum Private key
:return: Ethereum Private key
"""
try:
Account.from_key(private_key)
except (ValueError, Error): # TODO Report `Error` exception as a bug of eth_account
raise argparse.ArgumentTypeError(f"{private_key} is not a valid private key")
return private_key


def check_hex_str(hex_str: str) -> HexBytes:
"""
Hexadecimal string validator for Argparse
:param hex_str:
:return: HexBytes from the provided hex string
"""
try:
return HexBytes(hex_str)
except ValueError:
raise argparse.ArgumentTypeError(f"{hex_str} is not a valid hexadecimal string")


def check_keccak256_hash(hex_str: str) -> HexBytes:
"""
Hexadecimal keccak256 validator for Argparse
:param hex_str:
:return: HexBytes from the provided hex string
"""
hex_str_bytes = check_hex_str(hex_str)
if len(hex_str_bytes) != 32:
raise argparse.ArgumentTypeError(
f"{hex_str} is not a valid keccak256 hash hexadecimal string"
)
return hex_str_bytes
Loading

0 comments on commit 09e8507

Please sign in to comment.