Skip to content

Commit

Permalink
Merge commit 'b353a398fef5d04e0da45de8310e322aaddd6cef' into checkpoi…
Browse files Browse the repository at this point in the history
…nt/main_from_release_2.4.4_b353a398fef5d04e0da45de8310e322aaddd6cef
  • Loading branch information
AmineKhaldi committed Oct 4, 2024
2 parents 81824c9 + b353a39 commit f3a0240
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 f3a0240

Please sign in to comment.