Skip to content

Commit

Permalink
Add some more tests for version 0x00 of EIP 191
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhargavasomu committed Mar 7, 2019
1 parent 81438a2 commit 9043d76
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions tests/core/test_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,41 @@ def test_eth_account_sign(acct, message, key, expected_bytes, expected_hash, v,
assert account.signHash(msghash) == signed


def test_eth_account_sign_data_with_intended_validator(acct):
@pytest.mark.parametrize(
'message, message_type',
(
("hello world", "text"),
(b'hello world', "primitive"),
("68656c6c6f20776f726c64", "hexstr"),
)
)
def test_eth_account_sign_data_with_intended_validator(message, message_type, acct):
account = acct.create()

kwargs = {message_type: message}

with pytest.raises(TypeError):
# Raise TypeError if the address is more than 20 bytes
defunct_hash_message(
**kwargs,
signature_version=b'\x00',
version_specific_data=account.address + "12345",
)
with pytest.raises(TypeError):
# Raise TypeError if the address is less than 20 bytes
defunct_hash_message(
**kwargs,
signature_version=b'\x00',
version_specific_data=account.address[:-10],
)

hashed_msg = defunct_hash_message(
text="hello world",
**kwargs,
signature_version=b'\x00',
version_specific_data=account.address,
)
signed = acct.signHash(hashed_msg, account.privateKey)

new_addr = Account.recoverHash(hashed_msg, signature=signed.signature)
new_addr = acct.recoverHash(hashed_msg, signature=signed.signature)
assert new_addr == account.address


Expand Down

0 comments on commit 9043d76

Please sign in to comment.