diff --git a/tests/core/utilities/test_validation.py b/tests/core/utilities/test_validation.py index b44a73a262..c50c5db297 100644 --- a/tests/core/utilities/test_validation.py +++ b/tests/core/utilities/test_validation.py @@ -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), @@ -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), diff --git a/web3/utils/normalizers.py b/web3/utils/normalizers.py index 0d50d2c0fd..7e7d266076 100644 --- a/web3/utils/normalizers.py +++ b/web3/utils/normalizers.py @@ -9,6 +9,9 @@ from eth_utils import ( to_checksum_address, ) +from eth_utils.address import ( + is_binary_address, +) from hexbytes import ( HexBytes, ) @@ -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 diff --git a/web3/utils/rpc_abi.py b/web3/utils/rpc_abi.py index 0881b47185..5145627e3e 100644 --- a/web3/utils/rpc_abi.py +++ b/web3/utils/rpc_abi.py @@ -47,6 +47,8 @@ 'eth_sign': ['address', 'bytes'], # personal 'personal_sendTransaction': TRANSACTION_PARAMS_ABIS, + 'personal_lockAccount': ['address'], + 'personal_unlockAccount': ['address', None, None] } diff --git a/web3/utils/validation.py b/web3/utils/validation.py index bcf09f18d0..b9a2fda5ef 100644 --- a/web3/utils/validation.py +++ b/web3/utils/validation.py @@ -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, @@ -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):