diff --git a/test/python/test_instructions.py b/test/python/test_instructions.py index 9669d38d..a77a77c1 100644 --- a/test/python/test_instructions.py +++ b/test/python/test_instructions.py @@ -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()}" diff --git a/test/python/utils/client.py b/test/python/utils/client.py index a3e4be9c..294ae297 100644 --- a/test/python/utils/client.py +++ b/test/python/utils/client.py @@ -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)