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

Expose ValidationError for backwards compatibility #70

Merged
merged 1 commit into from
Apr 22, 2020
Merged
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
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