Skip to content

Commit

Permalink
fix(ape-test): add support for signing eip712 messages (#1965)
Browse files Browse the repository at this point in the history
* test: update test for eip712 signing in test account to fail

* fix(ape-test): add support for signing eip712 messages to TestAccount
  • Loading branch information
fubuloubu authored Mar 14, 2024
1 parent ee4a3a6 commit e36aea4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/ape_test/accounts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Any, Iterator, List, Optional

from eip712.messages import EIP712Message
from eth_account import Account as EthAccount
from eth_account.messages import SignableMessage, encode_defunct
from eth_utils import to_bytes
Expand Down Expand Up @@ -110,6 +111,9 @@ def sign_message(self, msg: Any, **signer_options) -> Optional[MessageSignature]
elif isinstance(msg, int):
msg = HexBytes(msg).hex()
msg = encode_defunct(hexstr=msg)
elif isinstance(msg, EIP712Message):
# Convert EIP712Message to SignableMessage for handling below
msg = msg.signable_message

# Process SignableMessage
if isinstance(msg, SignableMessage):
Expand Down
5 changes: 2 additions & 3 deletions tests/functional/test_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ def test_recover_signer(signer, message):

def test_sign_eip712_message(signer):
foo = Foo(signer.address) # type: ignore[call-arg]
message = foo.signable_message
signature = signer.sign_message(message)
assert signer.check_signature(message, signature)
signature = signer.sign_message(foo)
assert signer.check_signature(foo, signature)


def test_sign_message_with_prompts(runner, keyfile_account, message):
Expand Down

0 comments on commit e36aea4

Please sign in to comment.