Skip to content

Commit

Permalink
Tests: add tests for sign
Browse files Browse the repository at this point in the history
  • Loading branch information
spalmer25 committed Jan 17, 2024
1 parent a1d89a2 commit 213d889
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
28 changes: 28 additions & 0 deletions test/python/test_instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
get_setup_app_context_instructions,
get_reset_app_context_instructions
)
from utils.message import RawMessage

TESTS_ROOT_DIR = Path(__file__).parent

Expand Down Expand Up @@ -251,3 +252,30 @@ def test_get_all_hwm(

hwm = client.get_all_hwm()
checker.check_all_hwm(False, main_hwm, None, test_hwm, None, chain, hwm)


@pytest.mark.parametrize("account", [DEFAULT_ACCOUNT])
@pytest.mark.parametrize("with_hash", [False, True])
def test_sign_message(
account: Account,
with_hash: bool,
client: TezosClient,
checker: TezosAPDUChecker,
firmware: Firmware,
navigator: Navigator) -> None:
"""Test the SIGN(_WITH_HASH) instruction."""

chain: int = 0
main_hwm: int = 0
test_hwm: int = 0

instructions = get_setup_app_context_instructions(firmware)

with client.setup_app_context(account, chain, main_hwm, test_hwm):
navigator.navigate(instructions)

tx = RawMessage("0270000007000000000000000000000000000000000000000000000000000000000000000014000000000003000000010000000000000000000000000000000000000000000000000000000000000000")
with client.sign_message(account, tx, with_hash):
pass
data = client.get_async_response()
checker.check_signature(account, tx, with_hash, data)
11 changes: 7 additions & 4 deletions test/python/utils/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,19 @@ def get_all_hwm(self) -> bytes:
@contextmanager
def sign_message(self,
account: Account,
message: Message) -> Generator[None, None, None]:
"""Send the SIGN instruction."""
message: Message,
with_hash: bool = False) -> Generator[None, None, None]:
"""Send the SIGN(_WITH_HASH) instruction."""

ins = Ins.SIGN_WITH_HASH if with_hash else Ins.SIGN

self._exchange(
ins=Ins.SIGN,
ins=ins,
sig_scheme=account.sig_scheme,
payload=account.path)

with self._exchange_async(
ins=Ins.SIGN,
ins=ins,
index=Index.LAST,
payload=message.raw):
yield

0 comments on commit 213d889

Please sign in to comment.