From 449c87399dd1d26adb66bda38c263876419ee8b4 Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Tue, 30 Jan 2024 16:59:36 +0100 Subject: [PATCH] Use the make_vote function in unit tests (#4410) --- nano/core_test/active_transactions.cpp | 10 +++++----- nano/core_test/conflicts.cpp | 6 +++--- nano/core_test/ledger.cpp | 20 ++++++++++---------- nano/core_test/message.cpp | 4 ++-- nano/core_test/network.cpp | 4 ++-- nano/core_test/node.cpp | 8 ++++---- nano/core_test/vote_processor.cpp | 6 +++--- nano/core_test/websocket.cpp | 2 +- nano/rpc_test/rpc.cpp | 2 +- 9 files changed, 31 insertions(+), 31 deletions(-) diff --git a/nano/core_test/active_transactions.cpp b/nano/core_test/active_transactions.cpp index a5ab31b488..74e3250871 100644 --- a/nano/core_test/active_transactions.cpp +++ b/nano/core_test/active_transactions.cpp @@ -362,7 +362,7 @@ TEST (active_transactions, inactive_votes_cache_existing_vote) ASSERT_NE (nullptr, election); ASSERT_GT (node.weight (key.pub), node.minimum_principal_weight ()); // Insert vote - auto vote1 (std::make_shared (key.pub, key.prv, nano::vote::timestamp_min * 1, 0, std::vector (1, send->hash ()))); + auto vote1 = nano::test::make_vote (key, { send }, nano::vote::timestamp_min * 1, 0); node.vote_processor.vote (vote1, std::make_shared (node, node)); ASSERT_TIMELY_EQ (5s, election->votes ().size (), 2); ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::vote_new)); @@ -425,10 +425,10 @@ TEST (active_transactions, inactive_votes_cache_multiple_votes) ASSERT_TIMELY (5s, nano::test::exists (node, { send1, send2, open })); // Process votes - auto vote1 (std::make_shared (key1.pub, key1.prv, 0, 0, std::vector (1, send1->hash ()))); + auto vote1 = nano::test::make_vote (key1, { send1 }, 0, 0); node.vote_processor.vote (vote1, std::make_shared (node, node)); - auto vote2 (std::make_shared (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, 0, 0, std::vector (1, send1->hash ()))); + auto vote2 = nano::test::make_vote (nano::dev::genesis_key, { send1 }, 0, 0); node.vote_processor.vote (vote2, std::make_shared (node, node)); ASSERT_TIMELY (5s, node.vote_cache.find (send1->hash ())); @@ -941,7 +941,7 @@ TEST (active_transactions, fork_replacement_tally) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (latest)) .build_shared (); - auto vote (std::make_shared (keys[i].pub, keys[i].prv, 0, 0, std::vector{ fork->hash () })); + auto vote = nano::test::make_vote (keys[i], { fork }, 0, 0); node1.vote_processor.vote (vote, std::make_shared (node1, node1)); node1.vote_processor.flush (); node1.process_active (fork); @@ -986,7 +986,7 @@ TEST (active_transactions, fork_replacement_tally) ASSERT_FALSE (blocks1.find (send_last->hash ()) != blocks1.end ()); // Process vote for correct block & replace existing lowest tally block - auto vote (std::make_shared (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, 0, 0, std::vector{ send_last->hash () })); + auto vote = nano::test::make_vote (nano::dev::genesis_key, { send_last }, 0, 0); node1.vote_processor.vote (vote, std::make_shared (node1, node1)); node1.vote_processor.flush (); // ensure vote arrives before the block diff --git a/nano/core_test/conflicts.cpp b/nano/core_test/conflicts.cpp index 4232edb429..3a74dfaf70 100644 --- a/nano/core_test/conflicts.cpp +++ b/nano/core_test/conflicts.cpp @@ -152,7 +152,7 @@ TEST (vote_uniquer, vbh_one) .build_shared (); std::vector hashes; hashes.push_back (block->hash ()); - auto vote1 (std::make_shared (key.pub, key.prv, 0, 0, hashes)); + auto vote1 = nano::test::make_vote (key, { hashes }, 0, 0); auto vote2 (std::make_shared (*vote1)); ASSERT_EQ (vote1, uniquer.unique (vote1)); ASSERT_EQ (vote1, uniquer.unique (vote2)); @@ -187,8 +187,8 @@ TEST (vote_uniquer, vbh_two) .build_shared (); std::vector hashes2; hashes2.push_back (block2->hash ()); - auto vote1 (std::make_shared (key.pub, key.prv, 0, 0, hashes1)); - auto vote2 (std::make_shared (key.pub, key.prv, 0, 0, hashes2)); + auto vote1 = nano::test::make_vote (key, { hashes1 }, 0, 0); + auto vote2 = nano::test::make_vote (key, { hashes2 }, 0, 0); ASSERT_EQ (vote1, uniquer.unique (vote1)); ASSERT_EQ (vote2, uniquer.unique (vote2)); } diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index efe7a05ab0..88f7c6d756 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -919,7 +919,7 @@ TEST (votes, check_signature) ASSERT_TIMELY (5s, node1.active.election (send1->qualified_root ())); auto election1 = node1.active.election (send1->qualified_root ()); ASSERT_EQ (1, election1->votes ().size ()); - auto vote1 (std::make_shared (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_min * 1, 0, std::vector{ send1->hash () })); + auto vote1 = nano::test::make_vote (nano::dev::genesis_key, { send1 }, nano::vote::timestamp_min * 1, 0); vote1->signature.bytes[0] ^= 1; ASSERT_EQ (nano::vote_code::invalid, node1.vote_processor.vote_blocking (vote1, std::make_shared (node1, node1))); vote1->signature.bytes[0] ^= 1; @@ -948,9 +948,9 @@ TEST (votes, add_one) ASSERT_TIMELY (5s, node1.active.election (send1->qualified_root ())); auto election1 = node1.active.election (send1->qualified_root ()); ASSERT_EQ (1, election1->votes ().size ()); - auto vote1 (std::make_shared (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_min * 1, 0, std::vector{ send1->hash () })); + auto vote1 = nano::test::make_vote (nano::dev::genesis_key, { send1 }, nano::vote::timestamp_min * 1, 0); ASSERT_EQ (nano::vote_code::vote, node1.active.vote (vote1)); - auto vote2 (std::make_shared (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_min * 2, 0, std::vector{ send1->hash () })); + auto vote2 = nano::test::make_vote (nano::dev::genesis_key, { send1 }, nano::vote::timestamp_min * 2, 0); ASSERT_EQ (nano::vote_code::vote, node1.active.vote (vote2)); ASSERT_EQ (2, election1->votes ().size ()); auto votes1 (election1->votes ()); @@ -989,7 +989,7 @@ TEST (votes, add_existing) node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ()); ASSERT_TIMELY (5s, node1.active.election (send1->qualified_root ())); auto election1 = node1.active.election (send1->qualified_root ()); - auto vote1 (std::make_shared (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_min * 1, 0, std::vector{ send1->hash () })); + auto vote1 = nano::test::make_vote (nano::dev::genesis_key, { send1 }, nano::vote::timestamp_min * 1, 0); ASSERT_EQ (nano::vote_code::vote, node1.active.vote (vote1)); // Block is already processed from vote ASSERT_TRUE (node1.active.publish (send1)); @@ -1007,7 +1007,7 @@ TEST (votes, add_existing) node1.work_generate_blocking (*send2); ASSERT_FALSE (node1.active.publish (send2)); ASSERT_TIMELY (5s, node1.active.active (*send2)); - auto vote2 (std::make_shared (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_min * 2, 0, std::vector{ send2->hash () })); + auto vote2 = nano::test::make_vote (nano::dev::genesis_key, { send2 }, nano::vote::timestamp_min * 2, 0); // Pretend we've waited the timeout auto vote_info1 = election1->get_last_vote (nano::dev::genesis_key.pub); vote_info1.time = std::chrono::steady_clock::now () - std::chrono::seconds (20); @@ -1048,7 +1048,7 @@ TEST (votes, add_old) node1.start_election (send1); ASSERT_TIMELY (5s, node1.active.election (send1->qualified_root ())); auto election1 = node1.active.election (send1->qualified_root ()); - auto vote1 (std::make_shared (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_min * 2, 0, std::vector{ send1->hash () })); + auto vote1 = nano::test::make_vote (nano::dev::genesis_key, { send1 }, nano::vote::timestamp_min * 2, 0); auto channel (std::make_shared (node1, node1)); node1.vote_processor.vote_blocking (vote1, channel); nano::keypair key2; @@ -1111,13 +1111,13 @@ TEST (votes, DISABLED_add_old_different_account) ASSERT_NE (nullptr, election2); ASSERT_EQ (1, election1->votes ().size ()); ASSERT_EQ (1, election2->votes ().size ()); - auto vote1 (std::make_shared (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_min * 2, 0, std::vector{ send1->hash () })); + auto vote1 = nano::test::make_vote (nano::dev::genesis_key, { send1 }, nano::vote::timestamp_min * 2, 0); auto channel (std::make_shared (node1, node1)); auto vote_result1 (node1.vote_processor.vote_blocking (vote1, channel)); ASSERT_EQ (nano::vote_code::vote, vote_result1); ASSERT_EQ (2, election1->votes ().size ()); ASSERT_EQ (1, election2->votes ().size ()); - auto vote2 (std::make_shared (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_min * 1, 0, std::vector{ send2->hash () })); + auto vote2 = nano::test::make_vote (nano::dev::genesis_key, { send2 }, nano::vote::timestamp_min * 1, 0); auto vote_result2 (node1.vote_processor.vote_blocking (vote2, channel)); ASSERT_EQ (nano::vote_code::vote, vote_result2); ASSERT_EQ (2, election1->votes ().size ()); @@ -1153,7 +1153,7 @@ TEST (votes, add_cooldown) node1.start_election (send1); ASSERT_TIMELY (5s, node1.active.election (send1->qualified_root ())); auto election1 = node1.active.election (send1->qualified_root ()); - auto vote1 (std::make_shared (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_min * 1, 0, std::vector{ send1->hash () })); + auto vote1 = nano::test::make_vote (nano::dev::genesis_key, { send1 }, nano::vote::timestamp_min * 1, 0); auto channel (std::make_shared (node1, node1)); node1.vote_processor.vote_blocking (vote1, channel); nano::keypair key2; @@ -1166,7 +1166,7 @@ TEST (votes, add_cooldown) .work (0) .build_shared (); node1.work_generate_blocking (*send2); - auto vote2 (std::make_shared (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_min * 2, 0, std::vector{ send2->hash () })); + auto vote2 = nano::test::make_vote (nano::dev::genesis_key, { send2 }, nano::vote::timestamp_min * 2, 0); node1.vote_processor.vote_blocking (vote2, channel); ASSERT_EQ (2, election1->votes ().size ()); auto votes (election1->votes ()); diff --git a/nano/core_test/message.cpp b/nano/core_test/message.cpp index c26e359a45..024cf03f7f 100644 --- a/nano/core_test/message.cpp +++ b/nano/core_test/message.cpp @@ -165,7 +165,7 @@ TEST (message, confirm_ack_hash_serialization) hashes.push_back (block->hash ()); } nano::keypair representative1; - auto vote (std::make_shared (representative1.pub, representative1.prv, 0, 0, hashes)); + auto vote = nano::test::make_vote (representative1, { hashes }, 0, 0); nano::confirm_ack con1{ nano::dev::network_params.network, vote }; std::vector bytes; { @@ -206,7 +206,7 @@ TEST (message, confirm_ack_hash_serialization_v2) } nano::keypair representative1; - auto vote (std::make_shared (representative1.pub, representative1.prv, 0, 0, hashes)); + auto vote = nano::test::make_vote (representative1, { hashes }, 0, 0); nano::confirm_ack con1{ nano::dev::network_params.network, vote }; std::vector bytes; { diff --git a/nano/core_test/network.cpp b/nano/core_test/network.cpp index fdc49ccd8d..d2ab36df39 100644 --- a/nano/core_test/network.cpp +++ b/nano/core_test/network.cpp @@ -369,7 +369,7 @@ TEST (receivable_processor, confirm_insufficient_pos) ASSERT_EQ (nano::process_result::progress, node1.process (*block1).code); node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ()); nano::keypair key1; - auto vote (std::make_shared (key1.pub, key1.prv, 0, 0, std::vector{ block1->hash () })); + auto vote = nano::test::make_vote (key1, { block1 }, 0, 0); nano::confirm_ack con1{ nano::dev::network_params.network, vote }; auto channel1 = std::make_shared (node1, node1); node1.network.inbound (con1, channel1); @@ -391,7 +391,7 @@ TEST (receivable_processor, confirm_sufficient_pos) node1.work_generate_blocking (*block1); ASSERT_EQ (nano::process_result::progress, node1.process (*block1).code); node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ()); - auto vote (std::make_shared (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, 0, 0, std::vector{ block1->hash () })); + auto vote = nano::test::make_vote (nano::dev::genesis_key, { block1 }, 0, 0); nano::confirm_ack con1{ nano::dev::network_params.network, vote }; auto channel1 = std::make_shared (node1, node1); node1.network.inbound (con1, channel1); diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index 1b9a1edb4e..a007a3bed3 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -2461,7 +2461,7 @@ TEST (node, local_votes_cache_fork) .build_shared (); ASSERT_EQ (nano::process_result::progress, node1.process (*send1).code); // Cache vote - auto vote (std::make_shared (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, 0, 0, std::vector (1, send1->hash ()))); + auto vote = nano::test::make_vote (nano::dev::genesis_key, { send1 }, 0, 0); node1.vote_processor.vote (vote, std::make_shared (node1)); node1.history.add (send1->root (), send1->hash (), vote); auto votes2 (node1.history.votes (send1->root (), send1->hash ())); @@ -2675,7 +2675,7 @@ TEST (node, DISABLED_vote_by_hash_epoch_block_republish) node1.active.publish (epoch1); std::vector vote_blocks; vote_blocks.push_back (epoch1->hash ()); - auto vote (std::make_shared (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, 0, 0, vote_blocks)); + auto vote = nano::test::make_vote (nano::dev::genesis_key, { vote_blocks }, 0, 0); ASSERT_TRUE (node1.active.active (*send1)); ASSERT_TRUE (node2.active.active (*send1)); node1.vote_processor.vote (vote, std::make_shared (node1)); @@ -2810,8 +2810,8 @@ TEST (node, DISABLED_fork_invalid_block_signature) .build_shared (); auto send2_corrupt (std::make_shared (*send2)); send2_corrupt->signature = nano::signature (123); - auto vote (std::make_shared (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, 0, 0, std::vector{ send2->hash () })); - auto vote_corrupt (std::make_shared (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, 0, 0, std::vector{ send2_corrupt->hash () })); + auto vote = nano::test::make_vote (nano::dev::genesis_key, { send2 }, 0, 0); + auto vote_corrupt = nano::test::make_vote (nano::dev::genesis_key, { send2_corrupt }, 0, 0); node1.process_active (send1); ASSERT_TIMELY (5s, node1.block (send1->hash ())); diff --git a/nano/core_test/vote_processor.cpp b/nano/core_test/vote_processor.cpp index 210db3cd17..bd33093ac3 100644 --- a/nano/core_test/vote_processor.cpp +++ b/nano/core_test/vote_processor.cpp @@ -14,7 +14,7 @@ TEST (vote_processor, codes) nano::test::system system (1); auto & node (*system.nodes[0]); auto blocks = nano::test::setup_chain (system, node, 1, nano::dev::genesis_key, false); - auto vote (std::make_shared (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_min * 1, 0, std::vector{ blocks[0]->hash () })); + auto vote = nano::test::make_vote (nano::dev::genesis_key, { blocks[0] }, nano::vote::timestamp_min * 1, 0); auto vote_invalid = std::make_shared (*vote); vote_invalid->signature.bytes[0] ^= 1; auto channel (std::make_shared (node, node)); @@ -90,7 +90,7 @@ TEST (vote_processor, no_capacity) node_flags.vote_processor_capacity = 0; auto & node (*system.add_node (node_flags)); nano::keypair key; - auto vote (std::make_shared (key.pub, key.prv, nano::vote::timestamp_min * 1, 0, std::vector{ nano::dev::genesis->hash () })); + auto vote = nano::test::make_vote (key, { nano::dev::genesis }, nano::vote::timestamp_min * 1, 0); auto channel (std::make_shared (node, node)); ASSERT_TRUE (node.vote_processor.vote (vote, channel)); } @@ -102,7 +102,7 @@ TEST (vote_processor, overflow) node_flags.vote_processor_capacity = 1; auto & node (*system.add_node (node_flags)); nano::keypair key; - auto vote (std::make_shared (key.pub, key.prv, nano::vote::timestamp_min * 1, 0, std::vector{ nano::dev::genesis->hash () })); + auto vote = nano::test::make_vote (key, { nano::dev::genesis }, nano::vote::timestamp_min * 1, 0); auto channel (std::make_shared (node, node)); auto start_time = std::chrono::system_clock::now (); diff --git a/nano/core_test/websocket.cpp b/nano/core_test/websocket.cpp index f069c6539c..5a010d684d 100644 --- a/nano/core_test/websocket.cpp +++ b/nano/core_test/websocket.cpp @@ -673,7 +673,7 @@ TEST (websocket, vote_options_type) ASSERT_TIMELY (5s, ack_ready); // Custom made votes for simplicity - auto vote (std::make_shared (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, 0, 0, std::vector{ nano::dev::genesis->hash () })); + auto vote = nano::test::make_vote (nano::dev::genesis_key, { nano::dev::genesis }, 0, 0); nano::websocket::message_builder builder; auto msg (builder.vote_received (vote, nano::vote_code::replay)); node1->websocket.server->broadcast (msg); diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 166f5e6cc9..291e0036fd 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -5803,7 +5803,7 @@ TEST (rpc, memory_stats) .build_shared (); std::vector hashes; hashes.push_back (block->hash ()); - auto vote (std::make_shared (key.pub, key.prv, 0, 0, hashes)); + auto vote = nano::test::make_vote (key, { hashes }, 0, 0); node->vote_uniquer.unique (vote); boost::property_tree::ptree request; request.put ("action", "stats");