Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the make_vote function in unit tests #4410

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nano::vote> (key.pub, key.prv, nano::vote::timestamp_min * 1, 0, std::vector<nano::block_hash> (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<nano::transport::inproc::channel> (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));
Expand Down Expand Up @@ -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<nano::vote> (key1.pub, key1.prv, 0, 0, std::vector<nano::block_hash> (1, send1->hash ())));
auto vote1 = nano::test::make_vote (key1, { send1 }, 0, 0);
node.vote_processor.vote (vote1, std::make_shared<nano::transport::inproc::channel> (node, node));

auto vote2 (std::make_shared<nano::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, 0, 0, std::vector<nano::block_hash> (1, send1->hash ())));
auto vote2 = nano::test::make_vote (nano::dev::genesis_key, { send1 }, 0, 0);
node.vote_processor.vote (vote2, std::make_shared<nano::transport::inproc::channel> (node, node));

ASSERT_TIMELY (5s, node.vote_cache.find (send1->hash ()));
Expand Down Expand Up @@ -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<nano::vote> (keys[i].pub, keys[i].prv, 0, 0, std::vector<nano::block_hash>{ fork->hash () }));
auto vote = nano::test::make_vote (keys[i], { fork }, 0, 0);
node1.vote_processor.vote (vote, std::make_shared<nano::transport::inproc::channel> (node1, node1));
node1.vote_processor.flush ();
node1.process_active (fork);
Expand Down Expand Up @@ -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::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, 0, 0, std::vector<nano::block_hash>{ 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<nano::transport::inproc::channel> (node1, node1));
node1.vote_processor.flush ();
// ensure vote arrives before the block
Expand Down
6 changes: 3 additions & 3 deletions nano/core_test/conflicts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ TEST (vote_uniquer, vbh_one)
.build_shared ();
std::vector<nano::block_hash> hashes;
hashes.push_back (block->hash ());
auto vote1 (std::make_shared<nano::vote> (key.pub, key.prv, 0, 0, hashes));
auto vote1 = nano::test::make_vote (key, { hashes }, 0, 0);
auto vote2 (std::make_shared<nano::vote> (*vote1));
ASSERT_EQ (vote1, uniquer.unique (vote1));
ASSERT_EQ (vote1, uniquer.unique (vote2));
Expand Down Expand Up @@ -187,8 +187,8 @@ TEST (vote_uniquer, vbh_two)
.build_shared ();
std::vector<nano::block_hash> hashes2;
hashes2.push_back (block2->hash ());
auto vote1 (std::make_shared<nano::vote> (key.pub, key.prv, 0, 0, hashes1));
auto vote2 (std::make_shared<nano::vote> (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));
}
Expand Down
20 changes: 10 additions & 10 deletions nano/core_test/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_min * 1, 0, std::vector<nano::block_hash>{ 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<nano::transport::inproc::channel> (node1, node1)));
vote1->signature.bytes[0] ^= 1;
Expand Down Expand Up @@ -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::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_min * 1, 0, std::vector<nano::block_hash>{ 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::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_min * 2, 0, std::vector<nano::block_hash>{ 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 ());
Expand Down Expand Up @@ -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::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_min * 1, 0, std::vector<nano::block_hash>{ 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));
Expand All @@ -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::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_min * 2, 0, std::vector<nano::block_hash>{ 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);
Expand Down Expand Up @@ -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::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_min * 2, 0, std::vector<nano::block_hash>{ send1->hash () }));
auto vote1 = nano::test::make_vote (nano::dev::genesis_key, { send1 }, nano::vote::timestamp_min * 2, 0);
auto channel (std::make_shared<nano::transport::inproc::channel> (node1, node1));
node1.vote_processor.vote_blocking (vote1, channel);
nano::keypair key2;
Expand Down Expand Up @@ -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::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_min * 2, 0, std::vector<nano::block_hash>{ send1->hash () }));
auto vote1 = nano::test::make_vote (nano::dev::genesis_key, { send1 }, nano::vote::timestamp_min * 2, 0);
auto channel (std::make_shared<nano::transport::inproc::channel> (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::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_min * 1, 0, std::vector<nano::block_hash>{ 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 ());
Expand Down Expand Up @@ -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::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_min * 1, 0, std::vector<nano::block_hash>{ send1->hash () }));
auto vote1 = nano::test::make_vote (nano::dev::genesis_key, { send1 }, nano::vote::timestamp_min * 1, 0);
auto channel (std::make_shared<nano::transport::inproc::channel> (node1, node1));
node1.vote_processor.vote_blocking (vote1, channel);
nano::keypair key2;
Expand All @@ -1166,7 +1166,7 @@ TEST (votes, add_cooldown)
.work (0)
.build_shared ();
node1.work_generate_blocking (*send2);
auto vote2 (std::make_shared<nano::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_min * 2, 0, std::vector<nano::block_hash>{ 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 ());
Expand Down
4 changes: 2 additions & 2 deletions nano/core_test/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ TEST (message, confirm_ack_hash_serialization)
hashes.push_back (block->hash ());
}
nano::keypair representative1;
auto vote (std::make_shared<nano::vote> (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<uint8_t> bytes;
{
Expand Down Expand Up @@ -206,7 +206,7 @@ TEST (message, confirm_ack_hash_serialization_v2)
}

nano::keypair representative1;
auto vote (std::make_shared<nano::vote> (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<uint8_t> bytes;
{
Expand Down
4 changes: 2 additions & 2 deletions nano/core_test/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nano::vote> (key1.pub, key1.prv, 0, 0, std::vector<nano::block_hash>{ 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<nano::transport::inproc::channel> (node1, node1);
node1.network.inbound (con1, channel1);
Expand All @@ -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::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, 0, 0, std::vector<nano::block_hash>{ 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<nano::transport::inproc::channel> (node1, node1);
node1.network.inbound (con1, channel1);
Expand Down
8 changes: 4 additions & 4 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, 0, 0, std::vector<nano::block_hash> (1, send1->hash ())));
auto vote = nano::test::make_vote (nano::dev::genesis_key, { send1 }, 0, 0);
node1.vote_processor.vote (vote, std::make_shared<nano::transport::fake::channel> (node1));
node1.history.add (send1->root (), send1->hash (), vote);
auto votes2 (node1.history.votes (send1->root (), send1->hash ()));
Expand Down Expand Up @@ -2675,7 +2675,7 @@ TEST (node, DISABLED_vote_by_hash_epoch_block_republish)
node1.active.publish (epoch1);
std::vector<nano::block_hash> vote_blocks;
vote_blocks.push_back (epoch1->hash ());
auto vote (std::make_shared<nano::vote> (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<nano::transport::fake::channel> (node1));
Expand Down Expand Up @@ -2810,8 +2810,8 @@ TEST (node, DISABLED_fork_invalid_block_signature)
.build_shared ();
auto send2_corrupt (std::make_shared<nano::send_block> (*send2));
send2_corrupt->signature = nano::signature (123);
auto vote (std::make_shared<nano::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, 0, 0, std::vector<nano::block_hash>{ send2->hash () }));
auto vote_corrupt (std::make_shared<nano::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, 0, 0, std::vector<nano::block_hash>{ 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 ()));
Expand Down
6 changes: 3 additions & 3 deletions nano/core_test/vote_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_min * 1, 0, std::vector<nano::block_hash>{ 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<nano::vote> (*vote);
vote_invalid->signature.bytes[0] ^= 1;
auto channel (std::make_shared<nano::transport::inproc::channel> (node, node));
Expand Down Expand Up @@ -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<nano::vote> (key.pub, key.prv, nano::vote::timestamp_min * 1, 0, std::vector<nano::block_hash>{ 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<nano::transport::inproc::channel> (node, node));
ASSERT_TRUE (node.vote_processor.vote (vote, channel));
}
Expand All @@ -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<nano::vote> (key.pub, key.prv, nano::vote::timestamp_min * 1, 0, std::vector<nano::block_hash>{ 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<nano::transport::inproc::channel> (node, node));
auto start_time = std::chrono::system_clock::now ();

Expand Down
2 changes: 1 addition & 1 deletion nano/core_test/websocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, 0, 0, std::vector<nano::block_hash>{ 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);
Expand Down
2 changes: 1 addition & 1 deletion nano/rpc_test/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5803,7 +5803,7 @@ TEST (rpc, memory_stats)
.build_shared ();
std::vector<nano::block_hash> hashes;
hashes.push_back (block->hash ());
auto vote (std::make_shared<nano::vote> (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");
Expand Down
Loading