Skip to content

Commit

Permalink
Merge pull request #70 from carver/backward-compatible-ValidationError
Browse files Browse the repository at this point in the history
Expose ValidationError for backwards compatibility
  • Loading branch information
carver authored Apr 22, 2020
2 parents 6b75457 + 4fa966c commit 1e87d35
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions eth_keys/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# This exposes the eth-utils exception for backwards compatibility,
# for any library that catches eth_keys.exceptions.ValidationError
from eth_utils import ValidationError # noqa: F401


class BadSignature(Exception):
pass
14 changes: 10 additions & 4 deletions tests/core/test_key_and_signature_datastructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from eth_keys import KeyAPI
from eth_keys.backends import NativeECCBackend
from eth_keys.exceptions import ValidationError as EthKeysValidationErrorCopy


MSG = b'message'
Expand Down Expand Up @@ -155,12 +156,17 @@ def test_compressed_bytes_conversion(key_api, private_key):
assert key_api.PublicKey.from_compressed_bytes(compressed_bytes) == public_key


def test_compressed_bytes_validation(key_api, private_key):
@pytest.mark.parametrize('validation_error', (ValidationError, EthKeysValidationErrorCopy))
def test_compressed_bytes_validation(key_api, private_key, validation_error):
valid_key = private_key.public_key.to_compressed_bytes()

with pytest.raises(ValidationError):
with pytest.raises(validation_error):
key_api.PublicKey.from_compressed_bytes(valid_key + b"\x00")
with pytest.raises(ValidationError):
with pytest.raises(validation_error):
key_api.PublicKey.from_compressed_bytes(valid_key[:-1])
with pytest.raises(ValidationError):
with pytest.raises(validation_error):
key_api.PublicKey.from_compressed_bytes(b"\x04" + valid_key[1:])


def test_validation_error_is_from_eth_utils():
assert EthKeysValidationErrorCopy is ValidationError

0 comments on commit 1e87d35

Please sign in to comment.