Skip to content

Commit

Permalink
fixup! test: assert when wait_until_height skips a block
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesPiechota committed Dec 24, 2024
1 parent 8c810b7 commit 5ece1c4
Show file tree
Hide file tree
Showing 23 changed files with 145 additions and 136 deletions.
4 changes: 2 additions & 2 deletions apps/arweave/src/ar_block.erl
Original file line number Diff line number Diff line change
Expand Up @@ -793,10 +793,10 @@ test_hash_list_gen() ->
[B0] = ar_weave:init([]),
ar_test_node:start(B0),
ar_test_node:mine(),
BI1 = ar_test_node:wait_until_height(1),
BI1 = ar_test_node:wait_until_height(main, 1),
B1 = ar_storage:read_block(hd(BI1)),
ar_test_node:mine(),
BI2 = ar_test_node:wait_until_height(2),
BI2 = ar_test_node:wait_until_height(main, 2),
B2 = ar_storage:read_block(hd(BI2)),
?assertEqual([B0#block.indep_hash], generate_hash_list_for_block(B1, BI2)),
?assertEqual([H || {H, _, _} <- BI1],
Expand Down
10 changes: 5 additions & 5 deletions apps/arweave/src/ar_join.erl
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,9 @@ basic_node_join_test() ->
[B0] = ar_weave:init([]),
ar_test_node:start(B0),
ar_test_node:mine(),
ar_test_node:wait_until_height(1),
ar_test_node:wait_until_height(main, 1),
ar_test_node:mine(),
ar_test_node:wait_until_height(2),
ar_test_node:wait_until_height(main, 2),
ar_test_node:join_on(#{ node => peer1, join_on => main }),
ar_test_node:assert_wait_until_height(peer1, 2)
end}.
Expand All @@ -514,11 +514,11 @@ node_join_test() ->
[B0] = ar_weave:init([]),
ar_test_node:start(B0),
ar_test_node:mine(),
ar_test_node:wait_until_height(1),
ar_test_node:wait_until_height(main, 1),
ar_test_node:mine(),
ar_test_node:wait_until_height(2),
ar_test_node:wait_until_height(main, 2),
ar_test_node:join_on(#{ node => peer1, join_on => main }),
ar_test_node:assert_wait_until_height(peer1, 2),
ar_test_node:mine(peer1),
ar_test_node:wait_until_height(3)
ar_test_node:wait_until_height(main, 3)
end}.
8 changes: 4 additions & 4 deletions apps/arweave/src/ar_node_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -698,9 +698,9 @@ test_block_validation() ->
data => crypto:strong_rand_bytes(10 * 1024 * 1024) }),
ar_test_node:assert_post_tx_to_peer(main, PrevTX),
ar_test_node:mine(),
[_ | _] = ar_test_node:wait_until_height(1),
[_ | _] = ar_test_node:wait_until_height(main, 1),
ar_test_node:mine(),
[{PrevH, _, _} | _ ] = ar_test_node:wait_until_height(2),
[{PrevH, _, _} | _ ] = ar_test_node:wait_until_height(main, 2),
PrevB = ar_node:get_block_shadow_from_cache(PrevH),
BI = ar_node:get_block_index(),
PartitionUpperBound = ar_node:get_partition_upper_bound(BI),
Expand All @@ -710,7 +710,7 @@ test_block_validation() ->
data => crypto:strong_rand_bytes(7 * 1024 * 1024), last_tx => PrevH }),
ar_test_node:assert_post_tx_to_peer(main, TX),
ar_test_node:mine(),
[{H, _, _} | _] = ar_test_node:wait_until_height(3),
[{H, _, _} | _] = ar_test_node:wait_until_height(main, 3),
B = ar_node:get_block_shadow_from_cache(H),
Wallets = #{ ar_wallet:to_address(Pub) => {?AR(200), <<>>} },
?assertEqual(valid, validate(B, PrevB, Wallets, BlockAnchors, RecentTXMap,
Expand Down Expand Up @@ -769,7 +769,7 @@ test_block_validation() ->
BlockAnchors2 = ar_node:get_block_anchors(),
RecentTXMap2 = ar_node:get_recent_txs_map(),
ar_test_node:mine(),
[{H2, _, _} | _ ] = ar_test_node:wait_until_height(4),
[{H2, _, _} | _ ] = ar_test_node:wait_until_height(main, 4),
B2 = ar_node:get_block_shadow_from_cache(H2),
?assertEqual(valid, validate(B2, B, Wallets, BlockAnchors2, RecentTXMap2,
PartitionUpperBound2)).
Expand Down
6 changes: 3 additions & 3 deletions apps/arweave/src/ar_nonce_limiter.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,7 @@ test_reorg_after_join() ->
ar_test_node:mine(peer1),
ar_test_node:assert_wait_until_height(peer1, 1),
ar_test_node:mine(peer1),
ar_test_node:wait_until_height(2).
ar_test_node:wait_until_height(main, 2).

reorg_after_join2_test_() ->
{timeout, 120, fun test_reorg_after_join2/0}.
Expand All @@ -1565,7 +1565,7 @@ test_reorg_after_join2() ->
ar_test_node:assert_wait_until_height(peer1, 1),
ar_test_node:join_on(#{ node => main, join_on => peer1 }),
ar_test_node:mine(),
ar_test_node:wait_until_height(2),
ar_test_node:wait_until_height(main, 2),
ar_test_node:disconnect_from(peer1),
ar_test_node:start_peer(peer1, B0),
ar_test_node:mine(peer1),
Expand All @@ -1574,7 +1574,7 @@ test_reorg_after_join2() ->
ar_test_node:assert_wait_until_height(peer1, 2),
ar_test_node:connect_to_peer(peer1),
ar_test_node:mine(peer1),
ar_test_node:wait_until_height(3).
ar_test_node:wait_until_height(main, 3).

get_step_range_test() ->
?assertEqual(
Expand Down
2 changes: 1 addition & 1 deletion apps/arweave/src/ar_retarget.erl
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ simple_retarget_test_() ->
lists:foreach(
fun(Height) ->
ar_test_node:mine(),
ar_test_node:wait_until_height(Height)
ar_test_node:wait_until_height(main, Height)
end,
lists:seq(1, ?RETARGET_BLOCKS + 1)
),
Expand Down
4 changes: 2 additions & 2 deletions apps/arweave/src/ar_storage.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1333,9 +1333,9 @@ test_store_and_retrieve_block() ->
?assertEqual(B0#block{ size_tagged_txs = unset, txs = TXIDs, reward_history = [],
block_time_history = [], account_tree = undefined }, FetchedB03),
ar_test_node:mine(),
ar_test_node:wait_until_height(1),
ar_test_node:wait_until_height(main, 1),
ar_test_node:mine(),
BI1 = ar_test_node:wait_until_height(2),
BI1 = ar_test_node:wait_until_height(main, 2),
[{_, BlockCount}] = ets:lookup(ar_header_sync, synced_blocks),
ar_util:do_until(
fun() ->
Expand Down
8 changes: 4 additions & 4 deletions apps/arweave/test/ar_coordinated_mining_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ refetch_partitions_test_() ->
test_single_node_one_chunk() ->
[Node, _ExitNode, ValidatorNode] = ar_test_node:start_coordinated(1),
ar_test_node:mine(Node),
BI = ar_test_node:wait_until_height(ValidatorNode, 1),
BI = ar_test_node:wait_until_height(ValidatorNode, 1, false),
{ok, B} = http_get_block(element(1, hd(BI)), ValidatorNode),
?assert(byte_size((B#block.poa)#poa.data_path) > 0),
assert_empty_cache(Node).
Expand All @@ -62,7 +62,7 @@ test_single_node_one_chunk() ->
test_single_node_two_chunk() ->
[Node, _ExitNode, ValidatorNode] = ar_test_node:start_coordinated(1),
ar_test_node:mine(Node),
BI = ar_test_node:wait_until_height(ValidatorNode, 1),
BI = ar_test_node:wait_until_height(ValidatorNode, 1, false),
{ok, B} = http_get_block(element(1, hd(BI)), ValidatorNode),
?assert(byte_size((B#block.poa2)#poa.data_path) > 0),
assert_empty_cache(Node).
Expand Down Expand Up @@ -403,7 +403,7 @@ mine_in_parallel(Miners, ValidatorNode, CurrentHeight) ->
ar_util:pmap(fun(Node) -> ar_test_node:mine(Node) end, Miners),
?debugFmt("Waiting until the validator node (port ~B) advances to height ~B.",
[ar_test_node:peer_port(ValidatorNode), CurrentHeight + 1]),
BIValidator = ar_test_node:wait_until_height(ValidatorNode, CurrentHeight + 1),
BIValidator = ar_test_node:wait_until_height(ValidatorNode, CurrentHeight + 1, false),
%% Since multiple nodes are mining in parallel it's possible that multiple blocks
%% were mined. Get the Validator's current height in cas it's more than CurrentHeight+1.
NewHeight = ar_test_node:remote_call(ValidatorNode, ar_node, get_height, []),
Expand All @@ -417,7 +417,7 @@ mine_in_parallel(Miners, ValidatorNode, CurrentHeight) ->
%% Make sure the miner contains all of the new validator hashes, it's okay if
%% the miner contains *more* hashes since it's possible concurrent blocks were
%% mined between when the Validator checked and now.
BIMiner = ar_test_node:wait_until_height(Node, NewHeight),
BIMiner = ar_test_node:wait_until_height(Node, NewHeight, false),
MinerHashes = [Hash || {Hash, _, _} <- BIMiner],
Message = lists:flatten(io_lib:format(
"Node ~p did not mine the same block as the validator node", [Node])),
Expand Down
26 changes: 13 additions & 13 deletions apps/arweave/test/ar_fork_recovery_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
-include_lib("eunit/include/eunit.hrl").

-import(ar_test_node, [
assert_wait_until_height/2, wait_until_height/1, read_block_when_stored/1]).
assert_wait_until_height/2, wait_until_height/2, read_block_when_stored/1]).

height_plus_one_fork_recovery_test_() ->
{timeout, 240, fun test_height_plus_one_fork_recovery/0}.
Expand All @@ -20,20 +20,20 @@ test_height_plus_one_fork_recovery() ->
ar_test_node:mine(peer1),
assert_wait_until_height(peer1, 1),
ar_test_node:mine(),
wait_until_height(1),
wait_until_height(main, 1),
ar_test_node:mine(),
MainBI = wait_until_height(2),
MainBI = wait_until_height(main, 2),
ar_test_node:connect_to_peer(peer1),
?assertEqual(MainBI, ar_test_node:wait_until_height(peer1, 2)),
ar_test_node:disconnect_from(peer1),
ar_test_node:mine(),
wait_until_height(3),
wait_until_height(main, 3),
ar_test_node:mine(peer1),
assert_wait_until_height(peer1, 3),
ar_test_node:rejoin_on(#{ node => main, join_on => peer1 }),
ar_test_node:mine(peer1),
PeerBI = ar_test_node:wait_until_height(peer1, 4),
?assertEqual(PeerBI, wait_until_height(4)).
?assertEqual(PeerBI, wait_until_height(main, 4)).

height_plus_three_fork_recovery_test_() ->
{timeout, 240, fun test_height_plus_three_fork_recovery/0}.
Expand All @@ -49,18 +49,18 @@ test_height_plus_three_fork_recovery() ->
ar_test_node:mine(peer1),
assert_wait_until_height(peer1, 1),
ar_test_node:mine(),
wait_until_height(1),
wait_until_height(main, 1),
ar_test_node:mine(),
wait_until_height(2),
wait_until_height(main, 2),
ar_test_node:mine(peer1),
assert_wait_until_height(peer1, 2),
ar_test_node:mine(),
wait_until_height(3),
wait_until_height(main, 3),
ar_test_node:mine(peer1),
assert_wait_until_height(peer1, 3),
ar_test_node:connect_to_peer(peer1),
ar_test_node:mine(),
MainBI = wait_until_height(4),
MainBI = wait_until_height(main, 4),
?assertEqual(MainBI, ar_test_node:wait_until_height(peer1, 4)).

missing_txs_fork_recovery_test_() ->
Expand All @@ -82,7 +82,7 @@ test_missing_txs_fork_recovery() ->
ar_test_node:rejoin_on(#{ node => main, join_on => peer1 }),
?assertEqual([], ar_mempool:get_all_txids()),
ar_test_node:mine(peer1),
[{H1, _, _} | _] = wait_until_height(1),
[{H1, _, _} | _] = wait_until_height(main, 1),
?assertEqual(1, length((read_block_when_stored(H1))#block.txs)).

orphaned_txs_are_remined_after_fork_recovery_test_() ->
Expand All @@ -104,9 +104,9 @@ test_orphaned_txs_are_remined_after_fork_recovery() ->
H1TXIDs = (ar_test_node:remote_call(peer1, ar_test_node, read_block_when_stored, [H1]))#block.txs,
?assertEqual([TXID], H1TXIDs),
ar_test_node:mine(),
[{H2, _, _} | _] = wait_until_height(1),
[{H2, _, _} | _] = wait_until_height(main, 1),
ar_test_node:mine(),
[{H3, _, _}, {H2, _, _}, {_, _, _}] = wait_until_height(2),
[{H3, _, _}, {H2, _, _}, {_, _, _}] = wait_until_height(main, 2),
ar_test_node:connect_to_peer(peer1),
?assertMatch([{H3, _, _}, {H2, _, _}, {_, _, _}], ar_test_node:wait_until_height(peer1, 2)),
ar_test_node:mine(peer1),
Expand Down Expand Up @@ -137,7 +137,7 @@ test_invalid_block_with_high_cumulative_difficulty() ->
ar_test_node:mine(peer1),
[{H1, _, _} | _] = ar_test_node:wait_until_height(peer1, 1),
ar_test_node:mine(),
[{H2, _, _} | _] = wait_until_height(1),
[{H2, _, _} | _] = wait_until_height(main, 1),
ar_test_node:connect_to_peer(peer1),
?assertNotEqual(H2, H1),
B1 = read_block_when_stored(H2),
Expand Down
8 changes: 4 additions & 4 deletions apps/arweave/test/ar_header_sync_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-include_lib("eunit/include/eunit.hrl").
-include_lib("kernel/include/file.hrl").

-import(ar_test_node, [sign_v1_tx/3, wait_until_height/1, assert_wait_until_height/2,
-import(ar_test_node, [sign_v1_tx/3, wait_until_height/2, assert_wait_until_height/2,
read_block_when_stored/1, random_v1_data/1
]).

Expand Down Expand Up @@ -52,7 +52,7 @@ test_syncs_headers() ->
#{ data => random_v1_data(10 * 1024), last_tx => ar_test_node:get_tx_anchor(peer1) }),
ar_test_node:assert_post_tx_to_peer(main, NoSpaceTX),
ar_test_node:mine(),
[{NoSpaceH, _, _} | _] = wait_until_height(NoSpaceHeight),
[{NoSpaceH, _, _} | _] = wait_until_height(main, NoSpaceHeight),
timer:sleep(1000),
%% The cleanup is not expected to kick in yet.
NoSpaceB = read_block_when_stored(NoSpaceH),
Expand All @@ -70,7 +70,7 @@ test_syncs_headers() ->
ar_test_node:assert_post_tx_to_peer(main, TX),
ar_test_node:mine(),
[{_, Height}] = ets:lookup(test_syncs_header, height),
[_ | _] = wait_until_height(Height),
[_ | _] = wait_until_height(main, Height),
ets:insert(test_syncs_header, {height, Height + 1}),
unavailable == ar_storage:read_block(NoSpaceH)
andalso ar_storage:read_tx(NoSpaceTX#tx.id) == unavailable
Expand Down Expand Up @@ -110,7 +110,7 @@ post_random_blocks(Wallet, TargetHeight, B0) ->
lists:seq(1, 2)
),
ar_test_node:mine(),
[{H, _, _} | _] = wait_until_height(Height),
[{H, _, _} | _] = wait_until_height(main, Height),
?assertEqual(length(TXs), length((read_block_when_stored(H))#block.txs)),
H
end,
Expand Down
Loading

0 comments on commit 5ece1c4

Please sign in to comment.