Skip to content

Commit

Permalink
Convert unit tests to directly confirm blocks
Browse files Browse the repository at this point in the history
Convert active_transactions.confirm_frontier to direct confirmation.
Convert active_transactions.keep_local to direct confirmation.
Convert bootstrap_processor.lazy_hash_pruning to direct confirmation.
Convert bootstrap_processor.lazy_hash_pruning to direct confirmation.
Convert frontier_req.confirmed_frontier to direct confirmation.
Convert election.continuous_voting to direct confirmation.
Convert node.vote_by_hash_bundle to direct confirmation.
Convert node.epoch_conflict_confirm to direct confirmation.
Convert node.rollback_vote_self to direct confirmation.
Convert optimistic_scheduler.activate_one to direct confirmation.
Convert optimistic_scheduler.under_gap_threshold to direct confirmation.
Convert rpc.receivable_unconfirmed to direct confirmation.
Convert rpc.history_pruning to direct confirmation.
Convert rpc.accounts_receivable_confirmed to direct confirmation.
Convert rpc.block_confirmed to direct confirmation.
  • Loading branch information
clemahieu committed May 6, 2024
1 parent eaf86e7 commit 1205538
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 49 deletions.
12 changes: 2 additions & 10 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ TEST (active_transactions, confirm_frontier)
// we cannot use the same block instance on 2 different nodes, so make a copy
auto send_copy = builder.make_block ().from (*send).build ();
ASSERT_TRUE (nano::test::process (node1, { send_copy }));
ASSERT_TRUE (nano::test::start_elections (system, node1, { send_copy }));
ASSERT_TIMELY (5s, nano::test::confirmed (node1, { send_copy }));
nano::test::confirm (node1.ledger, send_copy);
}

// The rep crawler would otherwise request confirmations in order to find representatives
Expand Down Expand Up @@ -192,14 +191,7 @@ TEST (active_transactions, keep_local)
ASSERT_NE (nullptr, send6);

// force-confirm blocks
for (auto const & block : { send1, send2, send3, send4, send5, send6 })
{
std::shared_ptr<nano::election> election{};
ASSERT_TIMELY (5s, (election = node.active.election (block->qualified_root ())) != nullptr);
node.process_confirmed (nano::election_status{ block });
election->force_confirm ();
ASSERT_TIMELY (5s, node.block_confirmed (block->hash ()));
}
nano::test::confirm (node.ledger, send6);

nano::state_block_builder builder{};
const auto receive1 = builder.make_block ()
Expand Down
16 changes: 4 additions & 12 deletions nano/core_test/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -955,8 +955,7 @@ TEST (bootstrap_processor, lazy_hash_pruning)

std::vector<std::shared_ptr<nano::block>> blocks = { send1, receive1, change1, change2, send2, receive2, send3, receive3 };
ASSERT_TRUE (nano::test::process (*node0, blocks));
ASSERT_TRUE (nano::test::start_elections (system, *node0, blocks, true));
ASSERT_TIMELY (5s, nano::test::confirmed (*node0, blocks));
nano::test::confirm (node0->ledger, blocks);

config.peering_port = system.get_available_port ();
auto node1 = system.make_disconnected_node (config, node_flags);
Expand All @@ -969,12 +968,7 @@ TEST (bootstrap_processor, lazy_hash_pruning)
ASSERT_TIMELY (5s, nano::test::exists (*node1, { send1, receive1, change1, change2 }));

// Confirm last block to prune previous
ASSERT_TRUE (nano::test::start_elections (system, *node1, { send1, receive1, change1, change2 }, true));
ASSERT_TIMELY (5s, node1->block_confirmed (send1->hash ()));
ASSERT_TIMELY (5s, node1->block_confirmed (receive1->hash ()));
ASSERT_TIMELY (5s, node1->block_confirmed (change1->hash ()));
ASSERT_TIMELY (5s, node1->block_confirmed (change2->hash ()));
ASSERT_TIMELY (5s, node1->active.empty ());
nano::test::confirm (node1->ledger, { send1, receive1, change1, change2 });
ASSERT_EQ (5, node1->ledger.block_count ());
ASSERT_EQ (5, node1->ledger.cemented_count ());

Expand Down Expand Up @@ -1922,8 +1916,7 @@ TEST (frontier_req, confirmed_frontier)
ASSERT_EQ (receive2->hash (), request5->frontier);

// Confirm account before genesis (confirmed only)
ASSERT_TRUE (nano::test::start_elections (system, *node1, { send1, receive1 }, true));
ASSERT_TIMELY (5s, node1->block_confirmed (send1->hash ()) && node1->block_confirmed (receive1->hash ()));
nano::test::confirm (node1->ledger, receive1);
auto connection6 (std::make_shared<nano::transport::tcp_server> (std::make_shared<nano::transport::socket> (*node1, nano::transport::socket_endpoint::server), node1));
auto req6 = std::make_unique<nano::frontier_req> (nano::dev::network_params.network);
req6->start = key_before_genesis.pub;
Expand All @@ -1937,8 +1930,7 @@ TEST (frontier_req, confirmed_frontier)
ASSERT_EQ (receive1->hash (), request6->frontier);

// Confirm account after genesis (confirmed only)
ASSERT_TRUE (nano::test::start_elections (system, *node1, { send2, receive2 }, true));
ASSERT_TIMELY (5s, node1->block_confirmed (send2->hash ()) && node1->block_confirmed (receive2->hash ()));
nano::test::confirm (node1->ledger, receive2);
auto connection7 (std::make_shared<nano::transport::tcp_server> (std::make_shared<nano::transport::socket> (*node1, nano::transport::socket_endpoint::server), node1));
auto req7 = std::make_unique<nano::frontier_req> (nano::dev::network_params.network);
req7->start = key_after_genesis.pub;
Expand Down
3 changes: 1 addition & 2 deletions nano/core_test/election.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,7 @@ TEST (election, continuous_voting)
.build ();

ASSERT_TRUE (nano::test::process (node1, { send1 }));
ASSERT_TRUE (nano::test::start_elections (system, node1, { send1 }, true));
ASSERT_TIMELY (5s, nano::test::confirmed (node1, { send1 }));
nano::test::confirm (node1.ledger, send1);

node1.stats.clear ();

Expand Down
11 changes: 4 additions & 7 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2168,8 +2168,7 @@ TEST (node, vote_by_hash_bundle)
}

// Confirming last block will confirm whole chain and allow us to generate votes for those blocks later
ASSERT_TRUE (nano::test::start_elections (system, node, { blocks.back () }, true));
ASSERT_TIMELY (5s, nano::test::confirmed (node, { blocks.back () }));
nano::test::confirm (node.ledger, blocks.back ());

system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);
nano::keypair key1;
Expand Down Expand Up @@ -2347,8 +2346,7 @@ TEST (node, epoch_conflict_confirm)
ASSERT_TRUE (nano::test::process (node1, { send, send2, open }));

// Confirm open block in node1 to allow generating votes
ASSERT_TRUE (nano::test::start_elections (system, node1, { open }, true));
ASSERT_TIMELY (5s, nano::test::confirmed (node1, { open }));
nano::test::confirm (node1.ledger, open);

// Process initial blocks on node0
ASSERT_TRUE (nano::test::process (node0, { send, send2, open }));
Expand Down Expand Up @@ -3033,8 +3031,7 @@ TEST (node, rollback_vote_self)

// Process and mark the first 2 blocks as confirmed to allow voting
ASSERT_TRUE (nano::test::process (node, { send1, open }));
ASSERT_TRUE (nano::test::start_elections (system, node, { send1, open }, true));
ASSERT_TIMELY_EQ (5s, node.ledger.cemented_count (), 3);
nano::test::confirm (node.ledger, open);

// wait until the rep weights have caught up with the weight transfer
ASSERT_TIMELY_EQ (5s, nano::dev::constants.genesis_amount / 2, node.weight (key.pub));
Expand Down Expand Up @@ -3869,4 +3866,4 @@ TEST (node, process_local_overflow)

auto result = node.process_local (send1);
ASSERT_FALSE (result);
}
}
6 changes: 2 additions & 4 deletions nano/core_test/optimistic_scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ TEST (optimistic_scheduler, activate_one)
auto & [account, blocks] = chains.front ();

// Confirm block towards at the beginning the chain, so gap between confirmation and account frontier is larger than `gap_threshold`
ASSERT_TRUE (nano::test::start_elections (system, node, { blocks.at (11) }, true));
ASSERT_TIMELY (5s, nano::test::confirmed (node, { blocks.at (11) }));
nano::test::confirm (node.ledger, blocks.at (11));

// Ensure unconfirmed account head block gets activated
auto const & block = blocks.back ();
Expand Down Expand Up @@ -95,8 +94,7 @@ TEST (optimistic_scheduler, under_gap_threshold)
auto & [account, blocks] = chains.front ();

// Confirm block towards the end of the chain, so gap between confirmation and account frontier is less than `gap_threshold`
ASSERT_TRUE (nano::test::start_elections (system, node, { blocks.at (55) }, true));
ASSERT_TIMELY (5s, nano::test::confirmed (node, { blocks.at (55) }));
nano::test::confirm (node.ledger, blocks.at (55));

// Manually trigger backlog scan
node.backlog.trigger ();
Expand Down
6 changes: 2 additions & 4 deletions nano/rpc_test/receivable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ TEST (rpc, receivable_unconfirmed)
ASSERT_TRUE (check_block_response_count (system, rpc_ctx, request, 0));
request.put ("include_only_confirmed", "false");
ASSERT_TRUE (check_block_response_count (system, rpc_ctx, request, 1));
ASSERT_TRUE (nano::test::start_elections (system, *node, { block1->hash () }, true));
ASSERT_TIMELY (5s, nano::test::confirmed (*node, { block1 }));
nano::test::confirm (node->ledger, block1);
request.put ("include_only_confirmed", "true");
ASSERT_TRUE (check_block_response_count (system, rpc_ctx, request, 1));
}
Expand Down Expand Up @@ -550,8 +549,7 @@ TEST (rpc, accounts_receivable_confirmed)
ASSERT_TRUE (check_block_response_count (system, rpc_ctx, request, 0));
request.put ("include_only_confirmed", "false");
ASSERT_TRUE (check_block_response_count (system, rpc_ctx, request, 1));
ASSERT_TRUE (nano::test::start_elections (system, *node, { block1->hash () }, true));
ASSERT_TIMELY (5s, nano::test::confirmed (*node, { block1 }));
nano::test::confirm (node->ledger, block1);
request.put ("include_only_confirmed", "true");
ASSERT_TRUE (check_block_response_count (system, rpc_ctx, request, 1));
}
13 changes: 3 additions & 10 deletions nano/rpc_test/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1259,11 +1259,7 @@ TEST (rpc, history_pruning)
ASSERT_TIMELY (5s, nano::test::exists (*node0, blocks));
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);

ASSERT_TRUE (nano::test::start_elections (system, *node0, blocks, true));
ASSERT_TIMELY (5s, node0->block_confirmed (uchange->hash ()));
nano::confirmation_height_info confirmation_height_info;
node0->store.confirmation_height.get (node0->store.tx_begin_read (), nano::dev::genesis_key.pub, confirmation_height_info);
ASSERT_EQ (7, confirmation_height_info.height);
nano::test::confirm (node0->ledger, blocks);

// Prune block "change"
{
Expand Down Expand Up @@ -5889,11 +5885,8 @@ TEST (rpc, block_confirmed)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (latest))
.build ();
node->process_active (send);
ASSERT_TRUE (nano::test::start_elections (system, *node, { send }, true));

// Wait until the confirmation height has been set
ASSERT_TIMELY (5s, node->ledger.confirmed.block_exists_or_pruned (node->ledger.tx_begin_read (), send->hash ()) && !node->confirming_set.exists (send->hash ()));
ASSERT_EQ (nano::block_status::progress, node->ledger.process (node->ledger.tx_begin_write (), send));
nano::test::confirm (node->ledger, send);

// Requesting confirmation for this should now succeed
request.put ("hash", send->hash ().to_string ());
Expand Down

0 comments on commit 1205538

Please sign in to comment.