Skip to content

Commit

Permalink
checkpoint: into main from release/2.4.4 @ b353a39 (#18670)
Browse files Browse the repository at this point in the history
Source hash: b353a39
Remaining commits: 0
  • Loading branch information
Starttoaster authored Oct 4, 2024
2 parents 2efb374 + f3a0240 commit 54ad7b4
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions chia/_tests/core/data_layer/test_data_layer_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ def definition(left_hash: bytes32, right_hash: bytes32) -> bytes32:
assert definition(left_hash=left_hash, right_hash=right_hash) == reference


def get_random_bytes(length: int, r: Random) -> bytes:
if length == 0:
return b""

return r.getrandbits(length * 8).to_bytes(length, "big")


def test_leaf_hash(seeded_random: Random) -> None:
def definition(key: bytes, value: bytes) -> bytes32:
return SerializedProgram.to((key, value)).get_tree_hash()
Expand All @@ -169,12 +176,14 @@ def definition(key: bytes, value: bytes) -> bytes32:
length = 0
else:
length = seeded_random.randrange(100)
key = seeded_random.getrandbits(length * 8).to_bytes(length, "big")

key = get_random_bytes(length=length, r=seeded_random)

if cycle in (1, 2):
length = 0
else:
length = seeded_random.randrange(100)
value = seeded_random.getrandbits(length * 8).to_bytes(length, "big")
value = get_random_bytes(length=length, r=seeded_random)
reference = definition(key=key, value=value)
data.append((key, value, reference))

Expand All @@ -197,7 +206,7 @@ def definition(key: bytes) -> bytes32:
length = 0
else:
length = seeded_random.randrange(100)
key = seeded_random.getrandbits(length * 8).to_bytes(length, "big")
key = get_random_bytes(length=length, r=seeded_random)
reference = definition(key=key)
data.append((key, reference))

Expand Down

0 comments on commit 54ad7b4

Please sign in to comment.