Skip to content

Commit

Permalink
Tests: add tests for hmac
Browse files Browse the repository at this point in the history
  • Loading branch information
spalmer25 committed Jan 19, 2024
1 parent ce81ef7 commit 99a5856
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/python/test_instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,15 @@ def test_sign_message(
assert tx_hash == tx.hash, \
f"Expected hash {tx.hash.hex()} but got {tx_hash.hex()}"
account.check_signature(signature, bytes(tx))


@pytest.mark.parametrize("account", [DEFAULT_ACCOUNT])
def test_hmac(
account: Account,
client: TezosClient) -> None:
"""Test the HMAC instruction."""

message = bytes.fromhex("0123456789abcdef")
data = client.hmac(account, message)
hmac = bytes.fromhex("dde436940ab1602029a49dc77e6263b633fa3567c4d8479820d4f77072369ac1")
assert data == hmac, f"No expected {hmac.hex()} but got {data.hex()}"
14 changes: 14 additions & 0 deletions test/python/utils/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,17 @@ def sign_message_with_hash(self,
data[:Message.HASH_SIZE],
data[Message.HASH_SIZE:]
)

def hmac(self,
account: Account,
message: bytes) -> bytes:
"""Send the HMAC instruction."""

data: bytes = b''
data += bytes(account.path)
data += message

return self._exchange(
ins=Ins.HMAC,
sig_scheme=account.sig_scheme,
payload=data)

0 comments on commit 99a5856

Please sign in to comment.