From bba2da06d696044f99d42589ab5576f980925f34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Fri, 29 Nov 2024 23:16:48 +0100 Subject: [PATCH] Fix rep_self_vote test --- nano/core_test/node.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index c260d5dbe2..ae28caa2cc 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -1285,10 +1285,18 @@ TEST (node, DISABLED_broadcast_elected) TEST (node, rep_self_vote) { nano::test::system system; - nano::node_config node_config (system.get_available_port ()); + + nano::node_flags node_flags; + node_flags.disable_request_loop = true; // Prevent automatic election cleanup + nano::node_config node_config = system.default_config (); node_config.online_weight_minimum = std::numeric_limits::max (); + // Disable automatic election activation node_config.backlog_scan.enable = false; - auto node0 = system.add_node (node_config); + node_config.priority_scheduler.enable = false; + node_config.hinted_scheduler.enable = false; + node_config.optimistic_scheduler.enable = false; + auto node0 = system.add_node (node_config, node_flags); + nano::keypair rep_big; nano::block_builder builder; auto fund_big = builder.send () @@ -1307,15 +1315,19 @@ TEST (node, rep_self_vote) .build (); ASSERT_EQ (nano::block_status::progress, node0->process (fund_big)); ASSERT_EQ (nano::block_status::progress, node0->process (open_big)); + // Confirm both blocks, allowing voting on the upcoming block node0->start_election (node0->block (open_big->hash ())); + std::shared_ptr election; ASSERT_TIMELY (5s, election = node0->active.election (open_big->qualified_root ())); election->force_confirm (); + // Insert representatives into the node to allow voting system.wallet (0)->insert_adhoc (rep_big.prv); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); ASSERT_EQ (system.wallet (0)->wallets.reps ().voting, 2); + auto block0 = builder.send () .previous (fund_big->hash ()) .destination (rep_big.pub) @@ -1324,12 +1336,17 @@ TEST (node, rep_self_vote) .work (*system.work.generate (fund_big->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, node0->process (block0)); + auto & active = node0->active; auto & scheduler = node0->scheduler; + auto election1 = nano::test::start_election (system, *node0, block0->hash ()); ASSERT_NE (nullptr, election1); + // Wait until representatives are activated & make vote ASSERT_TIMELY_EQ (1s, election1->votes ().size (), 3); + + // Election should receive votes from representatives hosted on the same node auto rep_votes (election1->votes ()); ASSERT_NE (rep_votes.end (), rep_votes.find (nano::dev::genesis_key.pub)); ASSERT_NE (rep_votes.end (), rep_votes.find (rep_big.pub));