Skip to content

Commit

Permalink
Permitted byte addresses in web3
Browse files Browse the repository at this point in the history
fixed lint and test failures
  • Loading branch information
voith committed Jun 10, 2018
1 parent 70b7ded commit 72e456d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tests/core/utilities/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
(INVALID_CHECKSUM_ADDRESS, validate_address, InvalidAddress),
(NON_CHECKSUM_ADDRESS, validate_address, InvalidAddress),
("NotAddress", validate_address, InvalidAddress),
(b'not string', validate_address, TypeError),
(b'not string', validate_address, InvalidAddress),
('bool', validate_abi_type, None),
('bool[', validate_abi_type, ValueError),
('sbool', validate_abi_type, ValueError),
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_validation(param, validation, expected):
('uint8', -5, TypeError),
('int8', -5, None),
('address', "just a string", InvalidAddress),
('address', b'not even a string', TypeError),
('address', b'not even a string', InvalidAddress),
('address[][]', [[4, 5], [True]], TypeError),
('address[][]', [[ADDRESS]], None),
('address[2][]', [[ADDRESS], [ADDRESS, ADDRESS]], TypeError),
Expand Down
5 changes: 5 additions & 0 deletions web3/utils/normalizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from eth_utils import (
to_checksum_address,
)
from eth_utils.address import (
is_binary_address,
)
from hexbytes import (
HexBytes,
)
Expand Down Expand Up @@ -119,6 +122,8 @@ def abi_bytes_to_bytes(abi_type, data):
def abi_address_to_hex(abi_type, data):
if abi_type == 'address':
validate_address(data)
if is_binary_address(data):
return abi_type, to_checksum_address(data)


@curry
Expand Down
2 changes: 2 additions & 0 deletions web3/utils/rpc_abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
'eth_sign': ['address', 'bytes'],
# personal
'personal_sendTransaction': TRANSACTION_PARAMS_ABIS,
'personal_lockAccount': ['address'],
'personal_unlockAccount': ['address', None, None]
}


Expand Down
6 changes: 6 additions & 0 deletions web3/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from eth_utils import (
function_abi_to_4byte_selector,
is_0x_prefixed,
is_binary_address,
is_boolean,
is_bytes,
is_checksum_address,
Expand Down Expand Up @@ -142,6 +143,11 @@ def validate_address(value):
"""
Helper function for validating an address
"""
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))
if not is_hex_address(value):
Expand Down

0 comments on commit 72e456d

Please sign in to comment.