diff --git a/nano/core_test/bootstrap.cpp b/nano/core_test/bootstrap.cpp index ae3cb1471c..aeaeec51fb 100644 --- a/nano/core_test/bootstrap.cpp +++ b/nano/core_test/bootstrap.cpp @@ -1327,7 +1327,6 @@ TEST (bootstrap_processor, lazy_pruning_missing_block) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (nano::dev::genesis->hash ())) .build (); - node1->process_active (send1); // send from genesis to key2 auto send2 = builder @@ -1340,7 +1339,6 @@ TEST (bootstrap_processor, lazy_pruning_missing_block) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (send1->hash ())) .build (); - node1->process_active (send2); // open account key1 auto open = builder @@ -1351,7 +1349,6 @@ TEST (bootstrap_processor, lazy_pruning_missing_block) .sign (key1.prv, key1.pub) .work (*system.work.generate (key1.pub)) .build (); - node1->process_active (open); // open account key2 auto state_open = builder @@ -1365,11 +1362,13 @@ TEST (bootstrap_processor, lazy_pruning_missing_block) .work (*system.work.generate (key2.pub)) .build (); - node1->process_active (state_open); - ASSERT_TIMELY (5s, node1->block (state_open->hash ()) != nullptr); - // Confirm last block to prune previous - ASSERT_TRUE (nano::test::start_elections (system, *node1, { send1, send2, open, state_open }, true)); - ASSERT_TIMELY (5s, nano::test::confirmed (*node1, { send2, open, state_open })); + // add the blocks without starting elections because elections publish blocks + // and the publishing would interefere with the testing + std::vector> const blocks{ send1, send2, open, state_open }; + ASSERT_TRUE (nano::test::process (*node1, blocks)); + ASSERT_TIMELY (5s, nano::test::exists (*node1, blocks)); + nano::test::force_confirm (node1->ledger, blocks); + ASSERT_TIMELY (5s, nano::test::confirmed (*node1, blocks)); ASSERT_EQ (5, node1->ledger.block_count ()); ASSERT_EQ (5, node1->ledger.cemented_count ()); diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index e301ba5f07..4ca2bb3da1 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -1594,3 +1594,9 @@ std::unique_ptr nano::ledger::collect_container_ composite->add_component (cache.rep_weights.collect_container_info ("rep_weights")); return composite; } + +void nano::ledger::force_confirm (secure::write_transaction const & transaction, nano::block const & block) +{ + release_assert (*constants.genesis == *constants.nano_dev_genesis); + confirm (transaction, block); +} \ No newline at end of file diff --git a/nano/secure/ledger.hpp b/nano/secure/ledger.hpp index 465b029eac..db7a7a6ae1 100644 --- a/nano/secure/ledger.hpp +++ b/nano/secure/ledger.hpp @@ -117,5 +117,8 @@ class ledger final std::optional> receivable_lower_bound (secure::transaction const & tx, nano::account const & account, nano::block_hash const & hash) const; void initialize (nano::generate_cache_flags const &); void confirm (secure::write_transaction const & transaction, nano::block const & block); + +public: // Only used in tests + void force_confirm (secure::write_transaction const & transaction, nano::block const & block); }; } diff --git a/nano/test_common/testutil.cpp b/nano/test_common/testutil.cpp index b5dfe5c200..9e1469afa0 100644 --- a/nano/test_common/testutil.cpp +++ b/nano/test_common/testutil.cpp @@ -121,6 +121,14 @@ bool nano::test::exists (nano::node & node, std::vector> const blocks) +{ + for (auto const block : blocks) + { + ledger.force_confirm (ledger.tx_begin_write (), *block); + } +} + bool nano::test::block_or_pruned_all_exists (nano::node & node, std::vector hashes) { auto transaction = node.ledger.tx_begin_read (); diff --git a/nano/test_common/testutil.hpp b/nano/test_common/testutil.hpp index 77c848d8fb..5712cba734 100644 --- a/nano/test_common/testutil.hpp +++ b/nano/test_common/testutil.hpp @@ -321,6 +321,12 @@ namespace test * @return true if all blocks are fully processed and inserted in the ledger, false otherwise */ bool exists (nano::node & node, std::vector> blocks); + /* + * Convenience function to confirm/cement a block in the ledger by setting the confirmation + * height of the account to be the height of the block. + * The blocks are confirmed in the order that they are given. + */ + void force_confirm (nano::ledger & ledger, std::vector> const blocks); /* * Convenience function to check whether *all* of the hashes exists in node ledger or in the pruned table. * @return true if all blocks are fully processed and inserted in the ledger, false otherwise