from __future__ import annotations

import hashlib

from botindex_aar.hash import hash_input, hash_output, sha256


def test_sha256_matches_hashlib() -> None:
    assert sha256(b"abc") == hashlib.sha256(b"abc").digest()


def test_hash_output_string_digest() -> None:
    result = hash_output("abc")
    assert result.alg == "sha256"
    assert result.digest == "ungWv48Bz-pBQUDeXa4iI7ADYaOWF3qctBD_YfIAFa0"


def test_hash_input_canonicalized_digest() -> None:
    result = hash_input({"b": 1, "a": 2, "nested": {"z": 0, "y": [3, {"b": 2, "a": 1}]}})
    assert result.alg == "sha256"
    assert result.digest == "WMp5KcCXKZ68aTP4RRbMHMcHjfmNrdy6IgQHg8-ghgU"
