Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaiton committed Nov 4, 2024
1 parent b3cd39d commit 673495c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/agent0/utils/block_before_timestamp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,25 @@ def test_block_number_before_timestamp(fast_chain_fixture: LocalChain):
initial_block_plus_one_time = fast_chain_fixture.block_time()

time_between_blocks = initial_block_plus_one_time - initial_block_time
assert time_between_blocks >= 2
assert time_between_blocks >= 1
fast_chain_fixture.mine_blocks(num_fuzz_runs - 1)
chain_block_number = fast_chain_fixture.block_number()
assert chain_block_number == initial_block_number + num_fuzz_runs

# Start out a few blocks behind the latest
hyperdrive_interface = LocalHyperdrive(fast_chain_fixture, LocalHyperdrive.Config()).interface
for fuzz_iter in range(num_fuzz_runs):
# Grab a random block in the past & get the time
if fuzz_iter == 0: # test an edge case on the first iteration
test_block_number = initial_block_number + 2
test_block_number = initial_block_number + 3
elif fuzz_iter == 1: # test an edge case on the second iteration
test_block_number = chain_block_number - 1
else:
test_block_number = int(np.random.randint(initial_block_number + 2, chain_block_number - 1))
test_block_number = int(np.random.randint(initial_block_number + 3, chain_block_number - 1))
test_block_time = hyperdrive_interface.get_block_timestamp(hyperdrive_interface.get_block(test_block_number))

# Add a random amount of time that is less than the time between blocks
time_delta = int(np.random.randint(0, time_between_blocks - 1))
time_delta = int(np.random.randint(0, time_between_blocks))

# Find the block that was closest to this timestamp
inferred_block_number = block_number_before_timestamp(hyperdrive_interface.web3, test_block_time + time_delta)
Expand All @@ -54,5 +57,3 @@ def test_block_number_before_timestamp(fast_chain_fixture: LocalChain):
assert (
inferred_block_time <= test_block_time
), f"{inferred_block_time=} should be less than or equal to {test_block_time=}."

test_block_number -= np.random.randint(1, 30)

0 comments on commit 673495c

Please sign in to comment.