tests/test_region.py
910 B · 33 lines · python Raw
1 """Tests for MemoryRegion and RegionSnapshot."""
2
3 from __future__ import annotations
4
5 from pqc_hypervisor_attestation import MemoryRegion, RegionSnapshot
6
7
8 def test_snapshot_hash_is_deterministic() -> None:
9 data = b"hello world"
10 s1 = RegionSnapshot.create("r1", data)
11 s2 = RegionSnapshot.create("r1", data)
12 assert s1.content_hash == s2.content_hash
13 assert s1.size == len(data)
14
15
16 def test_snapshot_hash_changes_with_content() -> None:
17 s1 = RegionSnapshot.create("r1", b"aaaa")
18 s2 = RegionSnapshot.create("r1", b"aaab")
19 assert s1.content_hash != s2.content_hash
20
21
22 def test_memory_region_roundtrip() -> None:
23 region = MemoryRegion(
24 region_id="weights-0",
25 description="Llama-3 weight shard 0",
26 address=0x1000,
27 size=4096,
28 protection="RO",
29 )
30 data = region.to_dict()
31 restored = MemoryRegion(**data)
32 assert restored == region
33