Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an extra is_hex_integer() function in validate.py and added extra condition to convert the hex_integer into a string hex_address #2127

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added tests/integration/geth-1.10.6-fixture.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/integration/go_ethereum/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

KEYFILE_PW = 'web3py-test'

GETH_FIXTURE_ZIP = 'geth-1.10.8-fixture.zip'
GETH_FIXTURE_ZIP = 'geth-1.10.6-fixture.zip'


@pytest.fixture(scope='module')
Expand Down
11 changes: 10 additions & 1 deletion web3/_utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,30 @@ def is_not_address_string(value: Any) -> bool:
is_checksum_address(value) and not is_hex_address(value))


def is_hex_integer(value: Any) -> bool:
return (is_integer(value) and not is_string(value) and not is_bytes(value) and not
is_checksum_address(value) and not is_hex_address(value))


def validate_address(value: Any) -> None:
"""
Helper function for validating an address
"""
if is_hex_integer(value):
value = str(value)

if is_not_address_string(value):
if not is_valid_ens_name(value):
raise InvalidAddress(f"ENS name: '{value}' is invalid.")
return

if is_bytes(value):
if not is_binary_address(value):
raise InvalidAddress("Address must be 20 bytes when input type is bytes", value)
return

if not isinstance(value, str):
raise TypeError('Address {} must be provided as a string'.format(value))
raise TypeError('Address {} must be provided as a string or a hex'.format(value))
if not is_hex_address(value):
raise InvalidAddress("Address must be 20 bytes, as a hex string with a 0x prefix", value)
if not is_checksum_address(value):
Expand Down