Use node reference instead of system.nodes[n] in unit tests more often (#2470)
This commit is contained in:
parent
418b7b0628
commit
475c32e23e
11 changed files with 785 additions and 729 deletions
|
@ -9,19 +9,17 @@ using namespace std::chrono_literals;
|
|||
|
||||
TEST (active_transactions, confirm_one)
|
||||
{
|
||||
nano::system system;
|
||||
nano::node_config node_config (24000, system.logging);
|
||||
auto & node1 = *system.add_node (node_config);
|
||||
nano::system system (1);
|
||||
auto & node1 = *system.nodes[0];
|
||||
// Send and vote for a block before peering with node2
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
auto send (system.wallet (0)->send_action (nano::test_genesis_key.pub, nano::public_key (), node_config.receive_minimum.number ()));
|
||||
auto send (system.wallet (0)->send_action (nano::test_genesis_key.pub, nano::public_key (), node1.config.receive_minimum.number ()));
|
||||
system.deadline_set (5s);
|
||||
while (!node1.active.empty () && !node1.block_confirmed_or_being_confirmed (node1.store.tx_begin_read (), send->hash ()))
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
node_config.peering_port = 24001;
|
||||
auto & node2 = *system.add_node (node_config);
|
||||
auto & node2 = *system.add_node (nano::node_config (nano::get_available_port (), system.logging));
|
||||
system.deadline_set (5s);
|
||||
// Let node2 know about the block
|
||||
while (node2.active.empty ())
|
||||
|
@ -470,7 +468,7 @@ TEST (active_transactions, inactive_votes_cache_existing_vote)
|
|||
ASSERT_GT (node->weight (key.pub), node->minimum_principal_weight ());
|
||||
// Insert vote
|
||||
auto vote1 (std::make_shared<nano::vote> (key.pub, key.prv, 1, std::vector<nano::block_hash> (1, send->hash ())));
|
||||
node->vote_processor.vote (vote1, std::make_shared<nano::transport::channel_udp> (system.nodes[0]->network.udp_channels, system.nodes[0]->network.endpoint (), system.nodes[0]->network_params.protocol.protocol_version));
|
||||
node->vote_processor.vote (vote1, std::make_shared<nano::transport::channel_udp> (node->network.udp_channels, node->network.endpoint (), node->network_params.protocol.protocol_version));
|
||||
system.deadline_set (5s);
|
||||
bool done (false);
|
||||
while (!done)
|
||||
|
@ -480,7 +478,7 @@ TEST (active_transactions, inactive_votes_cache_existing_vote)
|
|||
active_lock.unlock ();
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_EQ (1, system.nodes[0]->stats.count (nano::stat::type::election, nano::stat::detail::vote_new));
|
||||
ASSERT_EQ (1, node->stats.count (nano::stat::type::election, nano::stat::detail::vote_new));
|
||||
nano::lock_guard<std::mutex> active_guard (node->active.mutex);
|
||||
auto last_vote1 (election->last_votes[key.pub]);
|
||||
ASSERT_EQ (send->hash (), last_vote1.hash);
|
||||
|
@ -495,7 +493,7 @@ TEST (active_transactions, inactive_votes_cache_existing_vote)
|
|||
ASSERT_EQ (last_vote1.hash, last_vote2.hash);
|
||||
ASSERT_EQ (last_vote1.sequence, last_vote2.sequence);
|
||||
ASSERT_EQ (last_vote1.time, last_vote2.time);
|
||||
ASSERT_EQ (0, system.nodes[0]->stats.count (nano::stat::type::election, nano::stat::detail::vote_cached));
|
||||
ASSERT_EQ (0, node->stats.count (nano::stat::type::election, nano::stat::detail::vote_cached));
|
||||
}
|
||||
|
||||
TEST (active_transactions, inactive_votes_cache_multiple_votes)
|
||||
|
@ -504,7 +502,7 @@ TEST (active_transactions, inactive_votes_cache_multiple_votes)
|
|||
nano::node_config node_config (nano::get_available_port (), system.logging);
|
||||
node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled;
|
||||
auto node = system.add_node (node_config);
|
||||
nano::block_hash latest (system.nodes[0]->latest (nano::test_genesis_key.pub));
|
||||
nano::block_hash latest (node->latest (nano::test_genesis_key.pub));
|
||||
nano::keypair key1;
|
||||
auto send1 (std::make_shared<nano::send_block> (latest, key1.pub, nano::genesis_amount - 100 * nano::Gxrb_ratio, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (latest)));
|
||||
auto send2 (std::make_shared<nano::send_block> (send1->hash (), key1.pub, 100 * nano::Gxrb_ratio, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (send1->hash ()))); // Decrease genesis weight to prevent election confirmation
|
||||
|
@ -515,31 +513,31 @@ TEST (active_transactions, inactive_votes_cache_multiple_votes)
|
|||
node->block_processor.flush ();
|
||||
// Process votes
|
||||
auto vote1 (std::make_shared<nano::vote> (key1.pub, key1.prv, 0, std::vector<nano::block_hash> (1, send1->hash ())));
|
||||
system.nodes[0]->vote_processor.vote (vote1, std::make_shared<nano::transport::channel_udp> (system.nodes[0]->network.udp_channels, system.nodes[0]->network.endpoint (), system.nodes[0]->network_params.protocol.protocol_version));
|
||||
node->vote_processor.vote (vote1, std::make_shared<nano::transport::channel_udp> (node->network.udp_channels, node->network.endpoint (), node->network_params.protocol.protocol_version));
|
||||
auto vote2 (std::make_shared<nano::vote> (nano::test_genesis_key.pub, nano::test_genesis_key.prv, 0, std::vector<nano::block_hash> (1, send1->hash ())));
|
||||
system.nodes[0]->vote_processor.vote (vote2, std::make_shared<nano::transport::channel_udp> (system.nodes[0]->network.udp_channels, system.nodes[0]->network.endpoint (), system.nodes[0]->network_params.protocol.protocol_version));
|
||||
node->vote_processor.vote (vote2, std::make_shared<nano::transport::channel_udp> (node->network.udp_channels, node->network.endpoint (), node->network_params.protocol.protocol_version));
|
||||
system.deadline_set (5s);
|
||||
while (true)
|
||||
{
|
||||
{
|
||||
nano::lock_guard<std::mutex> active_guard (system.nodes[0]->active.mutex);
|
||||
if (system.nodes[0]->active.find_inactive_votes_cache (send1->hash ()).voters.size () == 2)
|
||||
nano::lock_guard<std::mutex> active_guard (node->active.mutex);
|
||||
if (node->active.find_inactive_votes_cache (send1->hash ()).voters.size () == 2)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_EQ (1, system.nodes[0]->active.inactive_votes_cache_size ());
|
||||
ASSERT_EQ (1, node->active.inactive_votes_cache_size ());
|
||||
// Start election
|
||||
system.nodes[0]->active.start (send1);
|
||||
node->active.start (send1);
|
||||
{
|
||||
nano::lock_guard<std::mutex> active_guard (system.nodes[0]->active.mutex);
|
||||
auto it (system.nodes[0]->active.roots.begin ());
|
||||
ASSERT_NE (system.nodes[0]->active.roots.end (), it);
|
||||
nano::lock_guard<std::mutex> active_guard (node->active.mutex);
|
||||
auto it (node->active.roots.begin ());
|
||||
ASSERT_NE (node->active.roots.end (), it);
|
||||
ASSERT_EQ (3, it->election->last_votes.size ()); // 2 votes and 1 default not_an_acount
|
||||
}
|
||||
ASSERT_EQ (2, system.nodes[0]->stats.count (nano::stat::type::election, nano::stat::detail::vote_cached));
|
||||
ASSERT_EQ (2, node->stats.count (nano::stat::type::election, nano::stat::detail::vote_cached));
|
||||
}
|
||||
|
||||
TEST (active_transactions, update_difficulty)
|
||||
|
|
|
@ -784,17 +784,17 @@ TEST (frontier_req, end)
|
|||
TEST (frontier_req, count)
|
||||
{
|
||||
nano::system system (1);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
auto node1 = system.nodes[0];
|
||||
nano::genesis genesis;
|
||||
// Public key FB93... after genesis in accounts table
|
||||
nano::keypair key1 ("ED5AE0A6505B14B67435C29FD9FEEBC26F597D147BC92F6D795FFAD7AFD3D967");
|
||||
nano::state_block send1 (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, key1.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
|
||||
node1.work_generate_blocking (send1);
|
||||
ASSERT_EQ (nano::process_result::progress, node1.process (send1).code);
|
||||
node1->work_generate_blocking (send1);
|
||||
ASSERT_EQ (nano::process_result::progress, node1->process (send1).code);
|
||||
nano::state_block receive1 (key1.pub, 0, nano::test_genesis_key.pub, nano::Gxrb_ratio, send1.hash (), key1.prv, key1.pub, 0);
|
||||
node1.work_generate_blocking (receive1);
|
||||
ASSERT_EQ (nano::process_result::progress, node1.process (receive1).code);
|
||||
auto connection (std::make_shared<nano::bootstrap_server> (nullptr, system.nodes[0]));
|
||||
node1->work_generate_blocking (receive1);
|
||||
ASSERT_EQ (nano::process_result::progress, node1->process (receive1).code);
|
||||
auto connection (std::make_shared<nano::bootstrap_server> (nullptr, node1));
|
||||
auto req = std::make_unique<nano::frontier_req> ();
|
||||
req->start.clear ();
|
||||
req->age = std::numeric_limits<decltype (req->age)>::max ();
|
||||
|
@ -857,63 +857,65 @@ TEST (bulk, genesis)
|
|||
{
|
||||
nano::system system (1);
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.alarm, system.logging, system.work));
|
||||
ASSERT_FALSE (node1->init_error ());
|
||||
nano::block_hash latest1 (system.nodes[0]->latest (nano::test_genesis_key.pub));
|
||||
nano::block_hash latest2 (node1->latest (nano::test_genesis_key.pub));
|
||||
auto node1 = system.nodes[0];
|
||||
auto node2 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.alarm, system.logging, system.work));
|
||||
ASSERT_FALSE (node2->init_error ());
|
||||
nano::block_hash latest1 (node1->latest (nano::test_genesis_key.pub));
|
||||
nano::block_hash latest2 (node2->latest (nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (latest1, latest2);
|
||||
nano::keypair key2;
|
||||
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, 100));
|
||||
nano::block_hash latest3 (system.nodes[0]->latest (nano::test_genesis_key.pub));
|
||||
nano::block_hash latest3 (node1->latest (nano::test_genesis_key.pub));
|
||||
ASSERT_NE (latest1, latest3);
|
||||
node1->bootstrap_initiator.bootstrap (system.nodes[0]->network.endpoint ());
|
||||
node2->bootstrap_initiator.bootstrap (node1->network.endpoint ());
|
||||
system.deadline_set (10s);
|
||||
while (node1->latest (nano::test_genesis_key.pub) != system.nodes[0]->latest (nano::test_genesis_key.pub))
|
||||
while (node2->latest (nano::test_genesis_key.pub) != node1->latest (nano::test_genesis_key.pub))
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_EQ (node1->latest (nano::test_genesis_key.pub), system.nodes[0]->latest (nano::test_genesis_key.pub));
|
||||
node1->stop ();
|
||||
ASSERT_EQ (node2->latest (nano::test_genesis_key.pub), node1->latest (nano::test_genesis_key.pub));
|
||||
node2->stop ();
|
||||
}
|
||||
|
||||
TEST (bulk, offline_send)
|
||||
{
|
||||
nano::system system (1);
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.alarm, system.logging, system.work));
|
||||
ASSERT_FALSE (node1->init_error ());
|
||||
node1->start ();
|
||||
system.nodes.push_back (node1);
|
||||
auto node1 = system.nodes[0];
|
||||
auto node2 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.alarm, system.logging, system.work));
|
||||
ASSERT_FALSE (node2->init_error ());
|
||||
node2->start ();
|
||||
system.nodes.push_back (node2);
|
||||
nano::keypair key2;
|
||||
auto wallet (node1->wallets.create (nano::random_wallet_id ()));
|
||||
auto wallet (node2->wallets.create (nano::random_wallet_id ()));
|
||||
wallet->insert_adhoc (key2.prv);
|
||||
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ()));
|
||||
ASSERT_NE (std::numeric_limits<nano::uint256_t>::max (), system.nodes[0]->balance (nano::test_genesis_key.pub));
|
||||
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, node1->config.receive_minimum.number ()));
|
||||
ASSERT_NE (std::numeric_limits<nano::uint256_t>::max (), node1->balance (nano::test_genesis_key.pub));
|
||||
// Wait to finish election background tasks
|
||||
system.deadline_set (10s);
|
||||
while (!system.nodes[0]->active.empty ())
|
||||
while (!node1->active.empty ())
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
// Initiate bootstrap
|
||||
node1->bootstrap_initiator.bootstrap (system.nodes[0]->network.endpoint ());
|
||||
node2->bootstrap_initiator.bootstrap (node1->network.endpoint ());
|
||||
// Nodes should find each other
|
||||
do
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
} while (system.nodes[0]->network.empty () || node1->network.empty ());
|
||||
} while (node1->network.empty () || node2->network.empty ());
|
||||
// Send block arrival via bootstrap
|
||||
while (node1->balance (nano::test_genesis_key.pub) == std::numeric_limits<nano::uint256_t>::max ())
|
||||
while (node2->balance (nano::test_genesis_key.pub) == std::numeric_limits<nano::uint256_t>::max ())
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
// Receiving send block
|
||||
system.deadline_set (20s);
|
||||
while (node1->balance (key2.pub) != system.nodes[0]->config.receive_minimum.number ())
|
||||
while (node2->balance (key2.pub) != node1->config.receive_minimum.number ())
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
node1->stop ();
|
||||
node2->stop ();
|
||||
}
|
||||
|
||||
TEST (bulk_pull_account, basics)
|
||||
|
|
|
@ -271,7 +271,7 @@ TEST (confirmation_height, gap_live)
|
|||
nano::system system;
|
||||
nano::node_config node_config (nano::get_available_port (), system.logging);
|
||||
node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled;
|
||||
system.add_node (node_config);
|
||||
auto node1 = system.add_node (node_config);
|
||||
node_config.peering_port = nano::get_available_port ();
|
||||
system.add_node (node_config);
|
||||
nano::keypair destination;
|
||||
|
@ -280,18 +280,18 @@ TEST (confirmation_height, gap_live)
|
|||
|
||||
nano::genesis genesis;
|
||||
auto send1 (std::make_shared<nano::state_block> (nano::genesis_account, genesis.hash (), nano::genesis_account, nano::genesis_amount - nano::Gxrb_ratio, destination.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0));
|
||||
system.nodes[0]->work_generate_blocking (*send1);
|
||||
node1->work_generate_blocking (*send1);
|
||||
auto send2 (std::make_shared<nano::state_block> (nano::genesis_account, send1->hash (), nano::genesis_account, nano::genesis_amount - 2 * nano::Gxrb_ratio, destination.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0));
|
||||
system.nodes[0]->work_generate_blocking (*send2);
|
||||
node1->work_generate_blocking (*send2);
|
||||
auto send3 (std::make_shared<nano::state_block> (nano::genesis_account, send2->hash (), nano::genesis_account, nano::genesis_amount - 3 * nano::Gxrb_ratio, destination.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0));
|
||||
system.nodes[0]->work_generate_blocking (*send3);
|
||||
node1->work_generate_blocking (*send3);
|
||||
|
||||
auto open1 (std::make_shared<nano::open_block> (send1->hash (), destination.pub, destination.pub, destination.prv, destination.pub, 0));
|
||||
system.nodes[0]->work_generate_blocking (*open1);
|
||||
node1->work_generate_blocking (*open1);
|
||||
auto receive1 (std::make_shared<nano::receive_block> (open1->hash (), send2->hash (), destination.prv, destination.pub, 0));
|
||||
system.nodes[0]->work_generate_blocking (*receive1);
|
||||
node1->work_generate_blocking (*receive1);
|
||||
auto receive2 (std::make_shared<nano::receive_block> (receive1->hash (), send3->hash (), destination.prv, destination.pub, 0));
|
||||
system.nodes[0]->work_generate_blocking (*receive2);
|
||||
node1->work_generate_blocking (*receive2);
|
||||
|
||||
for (auto & node : system.nodes)
|
||||
{
|
||||
|
@ -600,9 +600,9 @@ TEST (confirmation_height, conflict_rollback_cemented)
|
|||
sb.open (nano::stringstream_mt_sink{});
|
||||
nano::boost_log_cerr_redirect redirect_cerr (&sb);
|
||||
nano::system system (2);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
auto & node2 (*system.nodes[1]);
|
||||
ASSERT_EQ (1, node1.network.size ());
|
||||
auto node1 (system.nodes[0]);
|
||||
auto node2 (system.nodes[1]);
|
||||
ASSERT_EQ (1, node1->network.size ());
|
||||
nano::keypair key1;
|
||||
nano::genesis genesis;
|
||||
auto send1 (std::make_shared<nano::send_block> (genesis.hash (), key1.pub, nano::genesis_amount - 100, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
|
||||
|
@ -610,36 +610,36 @@ TEST (confirmation_height, conflict_rollback_cemented)
|
|||
nano::keypair key2;
|
||||
auto send2 (std::make_shared<nano::send_block> (genesis.hash (), key2.pub, nano::genesis_amount - 100, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
|
||||
nano::publish publish2 (send2);
|
||||
auto channel1 (node1.network.udp_channels.create (node1.network.endpoint ()));
|
||||
node1.network.process_message (publish1, channel1);
|
||||
node1.block_processor.flush ();
|
||||
auto channel2 (node2.network.udp_channels.create (node1.network.endpoint ()));
|
||||
node2.network.process_message (publish2, channel2);
|
||||
node2.block_processor.flush ();
|
||||
ASSERT_EQ (1, node1.active.size ());
|
||||
ASSERT_EQ (1, node2.active.size ());
|
||||
auto channel1 (node1->network.udp_channels.create (node1->network.endpoint ()));
|
||||
node1->network.process_message (publish1, channel1);
|
||||
node1->block_processor.flush ();
|
||||
auto channel2 (node2->network.udp_channels.create (node1->network.endpoint ()));
|
||||
node2->network.process_message (publish2, channel2);
|
||||
node2->block_processor.flush ();
|
||||
ASSERT_EQ (1, node1->active.size ());
|
||||
ASSERT_EQ (1, node2->active.size ());
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
node1.network.process_message (publish2, channel1);
|
||||
node1.block_processor.flush ();
|
||||
node2.network.process_message (publish1, channel2);
|
||||
node2.block_processor.flush ();
|
||||
nano::unique_lock<std::mutex> lock (node2.active.mutex);
|
||||
auto conflict (node2.active.roots.find (nano::qualified_root (genesis.hash (), genesis.hash ())));
|
||||
ASSERT_NE (node2.active.roots.end (), conflict);
|
||||
node1->network.process_message (publish2, channel1);
|
||||
node1->block_processor.flush ();
|
||||
node2->network.process_message (publish1, channel2);
|
||||
node2->block_processor.flush ();
|
||||
nano::unique_lock<std::mutex> lock (node2->active.mutex);
|
||||
auto conflict (node2->active.roots.find (nano::qualified_root (genesis.hash (), genesis.hash ())));
|
||||
ASSERT_NE (node2->active.roots.end (), conflict);
|
||||
auto votes1 (conflict->election);
|
||||
ASSERT_NE (nullptr, votes1);
|
||||
ASSERT_EQ (1, votes1->last_votes.size ());
|
||||
lock.unlock ();
|
||||
// Force blocks to be cemented on both nodes
|
||||
{
|
||||
auto transaction (system.nodes[0]->store.tx_begin_write ());
|
||||
ASSERT_TRUE (node1.store.block_exists (transaction, publish1.block->hash ()));
|
||||
node1.store.confirmation_height_put (transaction, nano::genesis_account, 2);
|
||||
auto transaction (node1->store.tx_begin_write ());
|
||||
ASSERT_TRUE (node1->store.block_exists (transaction, publish1.block->hash ()));
|
||||
node1->store.confirmation_height_put (transaction, nano::genesis_account, 2);
|
||||
}
|
||||
{
|
||||
auto transaction (system.nodes[1]->store.tx_begin_write ());
|
||||
ASSERT_TRUE (node2.store.block_exists (transaction, publish2.block->hash ()));
|
||||
node2.store.confirmation_height_put (transaction, nano::genesis_account, 2);
|
||||
auto transaction (node2->store.tx_begin_write ());
|
||||
ASSERT_TRUE (node2->store.block_exists (transaction, publish2.block->hash ()));
|
||||
node2->store.confirmation_height_put (transaction, nano::genesis_account, 2);
|
||||
}
|
||||
|
||||
auto rollback_log_entry = boost::str (boost::format ("Failed to roll back %1%") % send2->hash ().to_string ());
|
||||
|
@ -650,15 +650,15 @@ TEST (confirmation_height, conflict_rollback_cemented)
|
|||
ASSERT_NO_ERROR (system.poll ());
|
||||
done = (sb.component ()->str ().find (rollback_log_entry) != std::string::npos);
|
||||
}
|
||||
auto transaction1 (system.nodes[0]->store.tx_begin_read ());
|
||||
auto transaction2 (system.nodes[1]->store.tx_begin_read ());
|
||||
auto transaction1 (node1->store.tx_begin_read ());
|
||||
auto transaction2 (node2->store.tx_begin_read ());
|
||||
lock.lock ();
|
||||
auto winner (*votes1->tally ().begin ());
|
||||
ASSERT_EQ (*publish1.block, *winner.second);
|
||||
ASSERT_EQ (nano::genesis_amount - 100, winner.first);
|
||||
ASSERT_TRUE (node1.store.block_exists (transaction1, publish1.block->hash ()));
|
||||
ASSERT_TRUE (node2.store.block_exists (transaction2, publish2.block->hash ()));
|
||||
ASSERT_FALSE (node2.store.block_exists (transaction2, publish1.block->hash ()));
|
||||
ASSERT_TRUE (node1->store.block_exists (transaction1, publish1.block->hash ()));
|
||||
ASSERT_TRUE (node2->store.block_exists (transaction2, publish2.block->hash ()));
|
||||
ASSERT_FALSE (node2->store.block_exists (transaction2, publish1.block->hash ()));
|
||||
}
|
||||
|
||||
TEST (confirmation_height, observers)
|
||||
|
@ -787,7 +787,7 @@ TEST (confirmation_height, prioritize_frontiers)
|
|||
nano::keypair key2;
|
||||
nano::keypair key3;
|
||||
nano::keypair key4;
|
||||
nano::block_hash latest1 (system.nodes[0]->latest (nano::test_genesis_key.pub));
|
||||
nano::block_hash latest1 (node->latest (nano::test_genesis_key.pub));
|
||||
|
||||
// Send different numbers of blocks all accounts
|
||||
nano::send_block send1 (latest1, key1.pub, node->config.online_weight_minimum.number () + 10000, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (latest1));
|
||||
|
|
|
@ -66,29 +66,31 @@ TEST (gap_cache, comparison)
|
|||
TEST (gap_cache, gap_bootstrap)
|
||||
{
|
||||
nano::system system (2);
|
||||
nano::block_hash latest (system.nodes[0]->latest (nano::test_genesis_key.pub));
|
||||
auto & node1 (*system.nodes[0]);
|
||||
auto & node2 (*system.nodes[1]);
|
||||
nano::block_hash latest (node1.latest (nano::test_genesis_key.pub));
|
||||
nano::keypair key;
|
||||
auto send (std::make_shared<nano::send_block> (latest, key.pub, nano::genesis_amount - 100, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (latest)));
|
||||
{
|
||||
auto transaction (system.nodes[0]->store.tx_begin_write ());
|
||||
ASSERT_EQ (nano::process_result::progress, system.nodes[0]->block_processor.process_one (transaction, send).code);
|
||||
auto transaction (node1.store.tx_begin_write ());
|
||||
ASSERT_EQ (nano::process_result::progress, node1.block_processor.process_one (transaction, send).code);
|
||||
}
|
||||
ASSERT_EQ (nano::genesis_amount - 100, system.nodes[0]->balance (nano::genesis_account));
|
||||
ASSERT_EQ (nano::genesis_amount, system.nodes[1]->balance (nano::genesis_account));
|
||||
ASSERT_EQ (nano::genesis_amount - 100, node1.balance (nano::genesis_account));
|
||||
ASSERT_EQ (nano::genesis_amount, node2.balance (nano::genesis_account));
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
system.wallet (0)->insert_adhoc (key.prv);
|
||||
auto latest_block (system.wallet (0)->send_action (nano::test_genesis_key.pub, key.pub, 100));
|
||||
ASSERT_NE (nullptr, latest_block);
|
||||
ASSERT_EQ (nano::genesis_amount - 200, system.nodes[0]->balance (nano::genesis_account));
|
||||
ASSERT_EQ (nano::genesis_amount, system.nodes[1]->balance (nano::genesis_account));
|
||||
ASSERT_EQ (nano::genesis_amount - 200, node1.balance (nano::genesis_account));
|
||||
ASSERT_EQ (nano::genesis_amount, node2.balance (nano::genesis_account));
|
||||
system.deadline_set (10s);
|
||||
{
|
||||
// The separate publish and vote system doesn't work very well here because it's instantly confirmed.
|
||||
// We help it get the block and vote out here.
|
||||
auto transaction (system.nodes[0]->store.tx_begin_read ());
|
||||
system.nodes[0]->network.flood_block (latest_block);
|
||||
auto transaction (node1.store.tx_begin_read ());
|
||||
node1.network.flood_block (latest_block);
|
||||
}
|
||||
while (system.nodes[1]->balance (nano::genesis_account) != nano::genesis_amount - 200)
|
||||
while (node2.balance (nano::genesis_account) != nano::genesis_amount - 200)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
|
@ -97,23 +99,24 @@ TEST (gap_cache, gap_bootstrap)
|
|||
TEST (gap_cache, two_dependencies)
|
||||
{
|
||||
nano::system system (1);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
nano::keypair key;
|
||||
nano::genesis genesis;
|
||||
auto send1 (std::make_shared<nano::send_block> (genesis.hash (), key.pub, 1, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
|
||||
auto send2 (std::make_shared<nano::send_block> (send1->hash (), key.pub, 0, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (send1->hash ())));
|
||||
auto open (std::make_shared<nano::open_block> (send1->hash (), key.pub, key.pub, key.prv, key.pub, *system.work.generate (key.pub)));
|
||||
ASSERT_EQ (0, system.nodes[0]->gap_cache.size ());
|
||||
system.nodes[0]->block_processor.add (send2, nano::seconds_since_epoch ());
|
||||
system.nodes[0]->block_processor.flush ();
|
||||
ASSERT_EQ (1, system.nodes[0]->gap_cache.size ());
|
||||
system.nodes[0]->block_processor.add (open, nano::seconds_since_epoch ());
|
||||
system.nodes[0]->block_processor.flush ();
|
||||
ASSERT_EQ (2, system.nodes[0]->gap_cache.size ());
|
||||
system.nodes[0]->block_processor.add (send1, nano::seconds_since_epoch ());
|
||||
system.nodes[0]->block_processor.flush ();
|
||||
ASSERT_EQ (0, system.nodes[0]->gap_cache.size ());
|
||||
auto transaction (system.nodes[0]->store.tx_begin_read ());
|
||||
ASSERT_TRUE (system.nodes[0]->store.block_exists (transaction, send1->hash ()));
|
||||
ASSERT_TRUE (system.nodes[0]->store.block_exists (transaction, send2->hash ()));
|
||||
ASSERT_TRUE (system.nodes[0]->store.block_exists (transaction, open->hash ()));
|
||||
ASSERT_EQ (0, node1.gap_cache.size ());
|
||||
node1.block_processor.add (send2, nano::seconds_since_epoch ());
|
||||
node1.block_processor.flush ();
|
||||
ASSERT_EQ (1, node1.gap_cache.size ());
|
||||
node1.block_processor.add (open, nano::seconds_since_epoch ());
|
||||
node1.block_processor.flush ();
|
||||
ASSERT_EQ (2, node1.gap_cache.size ());
|
||||
node1.block_processor.add (send1, nano::seconds_since_epoch ());
|
||||
node1.block_processor.flush ();
|
||||
ASSERT_EQ (0, node1.gap_cache.size ());
|
||||
auto transaction (node1.store.tx_begin_read ());
|
||||
ASSERT_TRUE (node1.store.block_exists (transaction, send1->hash ()));
|
||||
ASSERT_TRUE (node1.store.block_exists (transaction, send2->hash ()));
|
||||
ASSERT_TRUE (node1.store.block_exists (transaction, open->hash ()));
|
||||
}
|
||||
|
|
|
@ -497,44 +497,45 @@ TEST (ledger, open_fork)
|
|||
TEST (system, DISABLED_generate_send_existing)
|
||||
{
|
||||
nano::system system (1);
|
||||
nano::thread_runner runner (system.io_ctx, system.nodes[0]->config.io_threads);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
nano::thread_runner runner (system.io_ctx, node1.config.io_threads);
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
nano::keypair stake_preserver;
|
||||
auto send_block (system.wallet (0)->send_action (nano::genesis_account, stake_preserver.pub, nano::genesis_amount / 3 * 2, true));
|
||||
nano::account_info info1;
|
||||
{
|
||||
auto transaction (system.nodes[0]->store.tx_begin_read ());
|
||||
ASSERT_FALSE (system.nodes[0]->store.account_get (transaction, nano::test_genesis_key.pub, info1));
|
||||
auto transaction (node1.store.tx_begin_read ());
|
||||
ASSERT_FALSE (node1.store.account_get (transaction, nano::test_genesis_key.pub, info1));
|
||||
}
|
||||
std::vector<nano::account> accounts;
|
||||
accounts.push_back (nano::test_genesis_key.pub);
|
||||
system.generate_send_existing (*system.nodes[0], accounts);
|
||||
system.generate_send_existing (node1, accounts);
|
||||
// Have stake_preserver receive funds after generate_send_existing so it isn't chosen as the destination
|
||||
{
|
||||
auto transaction (system.nodes[0]->store.tx_begin_write ());
|
||||
auto transaction (node1.store.tx_begin_write ());
|
||||
auto open_block (std::make_shared<nano::open_block> (send_block->hash (), nano::genesis_account, stake_preserver.pub, stake_preserver.prv, stake_preserver.pub, 0));
|
||||
system.nodes[0]->work_generate_blocking (*open_block);
|
||||
ASSERT_EQ (nano::process_result::progress, system.nodes[0]->ledger.process (transaction, *open_block).code);
|
||||
node1.work_generate_blocking (*open_block);
|
||||
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, *open_block).code);
|
||||
}
|
||||
ASSERT_GT (system.nodes[0]->balance (stake_preserver.pub), system.nodes[0]->balance (nano::genesis_account));
|
||||
ASSERT_GT (node1.balance (stake_preserver.pub), node1.balance (nano::genesis_account));
|
||||
nano::account_info info2;
|
||||
{
|
||||
auto transaction (system.nodes[0]->store.tx_begin_read ());
|
||||
ASSERT_FALSE (system.nodes[0]->store.account_get (transaction, nano::test_genesis_key.pub, info2));
|
||||
auto transaction (node1.store.tx_begin_read ());
|
||||
ASSERT_FALSE (node1.store.account_get (transaction, nano::test_genesis_key.pub, info2));
|
||||
}
|
||||
ASSERT_NE (info1.head, info2.head);
|
||||
system.deadline_set (15s);
|
||||
while (info2.block_count < info1.block_count + 2)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
auto transaction (system.nodes[0]->store.tx_begin_read ());
|
||||
ASSERT_FALSE (system.nodes[0]->store.account_get (transaction, nano::test_genesis_key.pub, info2));
|
||||
auto transaction (node1.store.tx_begin_read ());
|
||||
ASSERT_FALSE (node1.store.account_get (transaction, nano::test_genesis_key.pub, info2));
|
||||
}
|
||||
ASSERT_EQ (info1.block_count + 2, info2.block_count);
|
||||
ASSERT_EQ (info2.balance, nano::genesis_amount / 3);
|
||||
{
|
||||
auto transaction (system.nodes[0]->store.tx_begin_read ());
|
||||
ASSERT_NE (system.nodes[0]->ledger.amount (transaction, info2.head), 0);
|
||||
auto transaction (node1.store.tx_begin_read ());
|
||||
ASSERT_NE (node1.ledger.amount (transaction, info2.head), 0);
|
||||
}
|
||||
system.stop ();
|
||||
runner.join ();
|
||||
|
@ -543,30 +544,31 @@ TEST (system, DISABLED_generate_send_existing)
|
|||
TEST (system, generate_send_new)
|
||||
{
|
||||
nano::system system (1);
|
||||
nano::thread_runner runner (system.io_ctx, system.nodes[0]->config.io_threads);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
nano::thread_runner runner (system.io_ctx, node1.config.io_threads);
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
{
|
||||
auto transaction (system.nodes[0]->store.tx_begin_read ());
|
||||
auto iterator1 (system.nodes[0]->store.latest_begin (transaction));
|
||||
ASSERT_NE (system.nodes[0]->store.latest_end (), iterator1);
|
||||
auto transaction (node1.store.tx_begin_read ());
|
||||
auto iterator1 (node1.store.latest_begin (transaction));
|
||||
ASSERT_NE (node1.store.latest_end (), iterator1);
|
||||
++iterator1;
|
||||
ASSERT_EQ (system.nodes[0]->store.latest_end (), iterator1);
|
||||
ASSERT_EQ (node1.store.latest_end (), iterator1);
|
||||
}
|
||||
nano::keypair stake_preserver;
|
||||
auto send_block (system.wallet (0)->send_action (nano::genesis_account, stake_preserver.pub, nano::genesis_amount / 3 * 2, true));
|
||||
{
|
||||
auto transaction (system.nodes[0]->store.tx_begin_write ());
|
||||
auto transaction (node1.store.tx_begin_write ());
|
||||
auto open_block (std::make_shared<nano::open_block> (send_block->hash (), nano::genesis_account, stake_preserver.pub, stake_preserver.prv, stake_preserver.pub, 0));
|
||||
system.nodes[0]->work_generate_blocking (*open_block);
|
||||
ASSERT_EQ (nano::process_result::progress, system.nodes[0]->ledger.process (transaction, *open_block).code);
|
||||
node1.work_generate_blocking (*open_block);
|
||||
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, *open_block).code);
|
||||
}
|
||||
ASSERT_GT (system.nodes[0]->balance (stake_preserver.pub), system.nodes[0]->balance (nano::genesis_account));
|
||||
ASSERT_GT (node1.balance (stake_preserver.pub), node1.balance (nano::genesis_account));
|
||||
std::vector<nano::account> accounts;
|
||||
accounts.push_back (nano::test_genesis_key.pub);
|
||||
system.generate_send_new (*system.nodes[0], accounts);
|
||||
system.generate_send_new (node1, accounts);
|
||||
nano::account new_account (0);
|
||||
{
|
||||
auto transaction (system.nodes[0]->wallets.tx_begin_read ());
|
||||
auto transaction (node1.wallets.tx_begin_read ());
|
||||
auto iterator2 (system.wallet (0)->store.begin (transaction));
|
||||
if (iterator2->first != nano::test_genesis_key.pub)
|
||||
{
|
||||
|
@ -583,7 +585,7 @@ TEST (system, generate_send_new)
|
|||
ASSERT_FALSE (new_account.is_zero ());
|
||||
}
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes[0]->balance (new_account) == 0)
|
||||
while (node1.balance (new_account) == 0)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
|
@ -959,15 +961,16 @@ TEST (votes, add_cooldown)
|
|||
TEST (ledger, successor)
|
||||
{
|
||||
nano::system system (1);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
nano::keypair key1;
|
||||
nano::genesis genesis;
|
||||
nano::send_block send1 (genesis.hash (), key1.pub, 0, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
|
||||
system.nodes[0]->work_generate_blocking (send1);
|
||||
auto transaction (system.nodes[0]->store.tx_begin_write ());
|
||||
ASSERT_EQ (nano::process_result::progress, system.nodes[0]->ledger.process (transaction, send1).code);
|
||||
ASSERT_EQ (send1, *system.nodes[0]->ledger.successor (transaction, nano::qualified_root (genesis.hash (), nano::root (0))));
|
||||
ASSERT_EQ (*genesis.open, *system.nodes[0]->ledger.successor (transaction, genesis.open->qualified_root ()));
|
||||
ASSERT_EQ (nullptr, system.nodes[0]->ledger.successor (transaction, nano::qualified_root (0)));
|
||||
node1.work_generate_blocking (send1);
|
||||
auto transaction (node1.store.tx_begin_write ());
|
||||
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, send1).code);
|
||||
ASSERT_EQ (send1, *node1.ledger.successor (transaction, nano::qualified_root (genesis.hash (), nano::root (0))));
|
||||
ASSERT_EQ (*genesis.open, *node1.ledger.successor (transaction, genesis.open->qualified_root ()));
|
||||
ASSERT_EQ (nullptr, node1.ledger.successor (transaction, nano::qualified_root (0)));
|
||||
}
|
||||
|
||||
TEST (ledger, fail_change_old)
|
||||
|
@ -2474,6 +2477,7 @@ TEST (ledger, epoch_blocks_fork)
|
|||
TEST (ledger, successor_epoch)
|
||||
{
|
||||
nano::system system (1);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
nano::keypair key1;
|
||||
nano::genesis genesis;
|
||||
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
|
||||
|
@ -2481,14 +2485,14 @@ TEST (ledger, successor_epoch)
|
|||
nano::state_block open (key1.pub, 0, key1.pub, 1, send1.hash (), key1.prv, key1.pub, *pool.generate (key1.pub));
|
||||
nano::state_block change (key1.pub, open.hash (), key1.pub, 1, 0, key1.prv, key1.pub, *pool.generate (open.hash ()));
|
||||
auto open_hash = open.hash ();
|
||||
nano::state_block epoch_open (reinterpret_cast<nano::account const &> (open_hash), 0, 0, 0, system.nodes[0]->ledger.epoch_link (nano::epoch::epoch_1), nano::test_genesis_key.prv, nano::test_genesis_key.pub, *pool.generate (open.hash ()));
|
||||
auto transaction (system.nodes[0]->store.tx_begin_write ());
|
||||
ASSERT_EQ (nano::process_result::progress, system.nodes[0]->ledger.process (transaction, send1).code);
|
||||
ASSERT_EQ (nano::process_result::progress, system.nodes[0]->ledger.process (transaction, open).code);
|
||||
ASSERT_EQ (nano::process_result::progress, system.nodes[0]->ledger.process (transaction, change).code);
|
||||
ASSERT_EQ (nano::process_result::progress, system.nodes[0]->ledger.process (transaction, epoch_open).code);
|
||||
ASSERT_EQ (change, *system.nodes[0]->ledger.successor (transaction, change.qualified_root ()));
|
||||
ASSERT_EQ (epoch_open, *system.nodes[0]->ledger.successor (transaction, epoch_open.qualified_root ()));
|
||||
nano::state_block epoch_open (reinterpret_cast<nano::account const &> (open_hash), 0, 0, 0, node1.ledger.epoch_link (nano::epoch::epoch_1), nano::test_genesis_key.prv, nano::test_genesis_key.pub, *pool.generate (open.hash ()));
|
||||
auto transaction (node1.store.tx_begin_write ());
|
||||
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, send1).code);
|
||||
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, open).code);
|
||||
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, change).code);
|
||||
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, epoch_open).code);
|
||||
ASSERT_EQ (change, *node1.ledger.successor (transaction, change.qualified_root ()));
|
||||
ASSERT_EQ (epoch_open, *node1.ledger.successor (transaction, epoch_open.qualified_root ()));
|
||||
}
|
||||
|
||||
TEST (ledger, block_hash_account_conflict)
|
||||
|
@ -2847,6 +2851,7 @@ TEST (ledger, confirmation_height_not_updated)
|
|||
TEST (ledger, zero_rep)
|
||||
{
|
||||
nano::system system (1);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
nano::genesis genesis;
|
||||
nano::block_builder builder;
|
||||
auto block1 = builder.state ()
|
||||
|
@ -2858,10 +2863,10 @@ TEST (ledger, zero_rep)
|
|||
.sign (nano::test_genesis_key.prv, nano::test_genesis_key.pub)
|
||||
.work (*system.work.generate (genesis.hash ()))
|
||||
.build ();
|
||||
auto transaction (system.nodes[0]->store.tx_begin_write ());
|
||||
ASSERT_EQ (nano::process_result::progress, system.nodes[0]->ledger.process (transaction, *block1).code);
|
||||
ASSERT_EQ (0, system.nodes[0]->ledger.cache.rep_weights.representation_get (nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (nano::genesis_amount, system.nodes[0]->ledger.cache.rep_weights.representation_get (0));
|
||||
auto transaction (node1.store.tx_begin_write ());
|
||||
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, *block1).code);
|
||||
ASSERT_EQ (0, node1.ledger.cache.rep_weights.representation_get (nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (nano::genesis_amount, node1.ledger.cache.rep_weights.representation_get (0));
|
||||
auto block2 = builder.state ()
|
||||
.account (nano::test_genesis_key.pub)
|
||||
.previous (block1->hash ())
|
||||
|
@ -2871,7 +2876,7 @@ TEST (ledger, zero_rep)
|
|||
.sign (nano::test_genesis_key.prv, nano::test_genesis_key.pub)
|
||||
.work (*system.work.generate (block1->hash ()))
|
||||
.build ();
|
||||
ASSERT_EQ (nano::process_result::progress, system.nodes[0]->ledger.process (transaction, *block2).code);
|
||||
ASSERT_EQ (nano::genesis_amount, system.nodes[0]->ledger.cache.rep_weights.representation_get (nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (0, system.nodes[0]->ledger.cache.rep_weights.representation_get (0));
|
||||
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, *block2).code);
|
||||
ASSERT_EQ (nano::genesis_amount, node1.ledger.cache.rep_weights.representation_get (nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (0, node1.ledger.cache.rep_weights.representation_get (0));
|
||||
}
|
||||
|
|
|
@ -72,58 +72,60 @@ TEST (network, self_discard)
|
|||
TEST (network, send_node_id_handshake)
|
||||
{
|
||||
nano::system system (1);
|
||||
ASSERT_EQ (0, system.nodes[0]->network.size ());
|
||||
auto node0 (system.nodes[0]);
|
||||
ASSERT_EQ (0, node0->network.size ());
|
||||
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.alarm, system.logging, system.work));
|
||||
node1->start ();
|
||||
system.nodes.push_back (node1);
|
||||
auto initial (system.nodes[0]->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::in));
|
||||
auto initial (node0->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::in));
|
||||
auto initial_node1 (node1->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::in));
|
||||
auto channel (std::make_shared<nano::transport::channel_udp> (system.nodes[0]->network.udp_channels, node1->network.endpoint (), node1->network_params.protocol.protocol_version));
|
||||
system.nodes[0]->network.send_keepalive (channel);
|
||||
ASSERT_EQ (0, system.nodes[0]->network.size ());
|
||||
auto channel (std::make_shared<nano::transport::channel_udp> (node0->network.udp_channels, node1->network.endpoint (), node1->network_params.protocol.protocol_version));
|
||||
node0->network.send_keepalive (channel);
|
||||
ASSERT_EQ (0, node0->network.size ());
|
||||
ASSERT_EQ (0, node1->network.size ());
|
||||
system.deadline_set (10s);
|
||||
while (node1->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::in) == initial_node1)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_EQ (0, system.nodes[0]->network.size ());
|
||||
ASSERT_EQ (0, node0->network.size ());
|
||||
ASSERT_EQ (1, node1->network.size ());
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes[0]->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::in) < initial + 2)
|
||||
while (node0->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::in) < initial + 2)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_EQ (1, system.nodes[0]->network.size ());
|
||||
ASSERT_EQ (1, node0->network.size ());
|
||||
ASSERT_EQ (1, node1->network.size ());
|
||||
auto list1 (system.nodes[0]->network.list (1));
|
||||
auto list1 (node0->network.list (1));
|
||||
ASSERT_EQ (node1->network.endpoint (), list1[0]->get_endpoint ());
|
||||
auto list2 (node1->network.list (1));
|
||||
ASSERT_EQ (system.nodes[0]->network.endpoint (), list2[0]->get_endpoint ());
|
||||
ASSERT_EQ (node0->network.endpoint (), list2[0]->get_endpoint ());
|
||||
node1->stop ();
|
||||
}
|
||||
|
||||
TEST (network, send_node_id_handshake_tcp)
|
||||
{
|
||||
nano::system system (1);
|
||||
ASSERT_EQ (0, system.nodes[0]->network.size ());
|
||||
auto node0 (system.nodes[0]);
|
||||
ASSERT_EQ (0, node0->network.size ());
|
||||
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.alarm, system.logging, system.work));
|
||||
node1->start ();
|
||||
system.nodes.push_back (node1);
|
||||
auto initial (system.nodes[0]->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::in));
|
||||
auto initial (node0->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::in));
|
||||
auto initial_node1 (node1->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::in));
|
||||
auto initial_keepalive (system.nodes[0]->stats.count (nano::stat::type::message, nano::stat::detail::keepalive, nano::stat::dir::in));
|
||||
std::weak_ptr<nano::node> node_w (system.nodes[0]);
|
||||
system.nodes[0]->network.tcp_channels.start_tcp (node1->network.endpoint (), [node_w](std::shared_ptr<nano::transport::channel> channel_a) {
|
||||
auto initial_keepalive (node0->stats.count (nano::stat::type::message, nano::stat::detail::keepalive, nano::stat::dir::in));
|
||||
std::weak_ptr<nano::node> node_w (node0);
|
||||
node0->network.tcp_channels.start_tcp (node1->network.endpoint (), [node_w](std::shared_ptr<nano::transport::channel> channel_a) {
|
||||
if (auto node_l = node_w.lock ())
|
||||
{
|
||||
node_l->network.send_keepalive (channel_a);
|
||||
}
|
||||
});
|
||||
ASSERT_EQ (0, system.nodes[0]->network.size ());
|
||||
ASSERT_EQ (0, node0->network.size ());
|
||||
ASSERT_EQ (0, node1->network.size ());
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes[0]->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::in) < initial + 2)
|
||||
while (node0->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::in) < initial + 2)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
|
@ -133,7 +135,7 @@ TEST (network, send_node_id_handshake_tcp)
|
|||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
system.deadline_set (5s);
|
||||
while (system.nodes[0]->stats.count (nano::stat::type::message, nano::stat::detail::keepalive, nano::stat::dir::in) < initial_keepalive + 2)
|
||||
while (node0->stats.count (nano::stat::type::message, nano::stat::detail::keepalive, nano::stat::dir::in) < initial_keepalive + 2)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
|
@ -142,21 +144,22 @@ TEST (network, send_node_id_handshake_tcp)
|
|||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_EQ (1, system.nodes[0]->network.size ());
|
||||
ASSERT_EQ (1, node0->network.size ());
|
||||
ASSERT_EQ (1, node1->network.size ());
|
||||
auto list1 (system.nodes[0]->network.list (1));
|
||||
auto list1 (node0->network.list (1));
|
||||
ASSERT_EQ (nano::transport::transport_type::tcp, list1[0]->get_type ());
|
||||
ASSERT_EQ (node1->network.endpoint (), list1[0]->get_endpoint ());
|
||||
auto list2 (node1->network.list (1));
|
||||
ASSERT_EQ (nano::transport::transport_type::tcp, list2[0]->get_type ());
|
||||
ASSERT_EQ (system.nodes[0]->network.endpoint (), list2[0]->get_endpoint ());
|
||||
ASSERT_EQ (node0->network.endpoint (), list2[0]->get_endpoint ());
|
||||
node1->stop ();
|
||||
}
|
||||
|
||||
TEST (network, last_contacted)
|
||||
{
|
||||
nano::system system (1);
|
||||
ASSERT_EQ (0, system.nodes[0]->network.size ());
|
||||
auto node0 (system.nodes[0]);
|
||||
ASSERT_EQ (0, node0->network.size ());
|
||||
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.alarm, system.logging, system.work));
|
||||
node1->start ();
|
||||
system.nodes.push_back (node1);
|
||||
|
@ -165,22 +168,22 @@ TEST (network, last_contacted)
|
|||
system.deadline_set (10s);
|
||||
|
||||
// Wait until the handshake is complete
|
||||
while (system.nodes[0]->network.size () < 1)
|
||||
while (node0->network.size () < 1)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_EQ (system.nodes[0]->network.size (), 1);
|
||||
ASSERT_EQ (node0->network.size (), 1);
|
||||
|
||||
auto channel2 (system.nodes[0]->network.udp_channels.channel (nano::endpoint (boost::asio::ip::address_v6::loopback (), node1->network.endpoint ().port ())));
|
||||
auto channel2 (node0->network.udp_channels.channel (nano::endpoint (boost::asio::ip::address_v6::loopback (), node1->network.endpoint ().port ())));
|
||||
ASSERT_NE (nullptr, channel2);
|
||||
// Make sure last_contact gets updated on receiving a non-handshake message
|
||||
auto timestamp_before_keepalive = channel2->get_last_packet_received ();
|
||||
node1->network.send_keepalive (channel1);
|
||||
while (system.nodes[0]->stats.count (nano::stat::type::message, nano::stat::detail::keepalive, nano::stat::dir::in) < 2)
|
||||
while (node0->stats.count (nano::stat::type::message, nano::stat::detail::keepalive, nano::stat::dir::in) < 2)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_EQ (system.nodes[0]->network.size (), 1);
|
||||
ASSERT_EQ (node0->network.size (), 1);
|
||||
auto timestamp_after_keepalive = channel2->get_last_packet_received ();
|
||||
ASSERT_GT (timestamp_after_keepalive, timestamp_before_keepalive);
|
||||
|
||||
|
@ -190,18 +193,19 @@ TEST (network, last_contacted)
|
|||
TEST (network, multi_keepalive)
|
||||
{
|
||||
nano::system system (1);
|
||||
ASSERT_EQ (0, system.nodes[0]->network.size ());
|
||||
auto node0 (system.nodes[0]);
|
||||
ASSERT_EQ (0, node0->network.size ());
|
||||
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.alarm, system.logging, system.work));
|
||||
ASSERT_FALSE (node1->init_error ());
|
||||
node1->start ();
|
||||
system.nodes.push_back (node1);
|
||||
ASSERT_EQ (0, node1->network.size ());
|
||||
auto channel1 (std::make_shared<nano::transport::channel_udp> (node1->network.udp_channels, system.nodes[0]->network.endpoint (), node1->network_params.protocol.protocol_version));
|
||||
auto channel1 (std::make_shared<nano::transport::channel_udp> (node1->network.udp_channels, node0->network.endpoint (), node1->network_params.protocol.protocol_version));
|
||||
node1->network.send_keepalive (channel1);
|
||||
ASSERT_EQ (0, node1->network.size ());
|
||||
ASSERT_EQ (0, system.nodes[0]->network.size ());
|
||||
ASSERT_EQ (0, node0->network.size ());
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes[0]->network.size () != 1)
|
||||
while (node0->network.size () != 1)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
|
@ -209,10 +213,10 @@ TEST (network, multi_keepalive)
|
|||
ASSERT_FALSE (node2->init_error ());
|
||||
node2->start ();
|
||||
system.nodes.push_back (node2);
|
||||
auto channel2 (std::make_shared<nano::transport::channel_udp> (node2->network.udp_channels, system.nodes[0]->network.endpoint (), node2->network_params.protocol.protocol_version));
|
||||
auto channel2 (std::make_shared<nano::transport::channel_udp> (node2->network.udp_channels, node0->network.endpoint (), node2->network_params.protocol.protocol_version));
|
||||
node2->network.send_keepalive (channel2);
|
||||
system.deadline_set (10s);
|
||||
while (node1->network.size () != 2 || system.nodes[0]->network.size () != 2 || node2->network.size () != 2)
|
||||
while (node1->network.size () != 2 || node0->network.size () != 2 || node2->network.size () != 2)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
|
@ -223,43 +227,47 @@ TEST (network, multi_keepalive)
|
|||
TEST (network, send_discarded_publish)
|
||||
{
|
||||
nano::system system (2);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
auto & node2 (*system.nodes[1]);
|
||||
auto block (std::make_shared<nano::send_block> (1, 1, 2, nano::keypair ().prv, 4, *system.work.generate (nano::root (1))));
|
||||
nano::genesis genesis;
|
||||
{
|
||||
auto transaction (system.nodes[0]->store.tx_begin_read ());
|
||||
system.nodes[0]->network.flood_block (block);
|
||||
ASSERT_EQ (genesis.hash (), system.nodes[0]->ledger.latest (transaction, nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (genesis.hash (), system.nodes[1]->latest (nano::test_genesis_key.pub));
|
||||
auto transaction (node1.store.tx_begin_read ());
|
||||
node1.network.flood_block (block);
|
||||
ASSERT_EQ (genesis.hash (), node1.ledger.latest (transaction, nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (genesis.hash (), node2.latest (nano::test_genesis_key.pub));
|
||||
}
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes[1]->stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::in) == 0)
|
||||
while (node2.stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::in) == 0)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
auto transaction (system.nodes[0]->store.tx_begin_read ());
|
||||
ASSERT_EQ (genesis.hash (), system.nodes[0]->ledger.latest (transaction, nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (genesis.hash (), system.nodes[1]->latest (nano::test_genesis_key.pub));
|
||||
auto transaction (node1.store.tx_begin_read ());
|
||||
ASSERT_EQ (genesis.hash (), node1.ledger.latest (transaction, nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (genesis.hash (), node2.latest (nano::test_genesis_key.pub));
|
||||
}
|
||||
|
||||
TEST (network, send_invalid_publish)
|
||||
{
|
||||
nano::system system (2);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
auto & node2 (*system.nodes[1]);
|
||||
nano::genesis genesis;
|
||||
auto block (std::make_shared<nano::send_block> (1, 1, 20, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (nano::root (1))));
|
||||
{
|
||||
auto transaction (system.nodes[0]->store.tx_begin_read ());
|
||||
system.nodes[0]->network.flood_block (block);
|
||||
ASSERT_EQ (genesis.hash (), system.nodes[0]->ledger.latest (transaction, nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (genesis.hash (), system.nodes[1]->latest (nano::test_genesis_key.pub));
|
||||
auto transaction (node1.store.tx_begin_read ());
|
||||
node1.network.flood_block (block);
|
||||
ASSERT_EQ (genesis.hash (), node1.ledger.latest (transaction, nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (genesis.hash (), node2.latest (nano::test_genesis_key.pub));
|
||||
}
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes[1]->stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::in) == 0)
|
||||
while (node2.stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::in) == 0)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
auto transaction (system.nodes[0]->store.tx_begin_read ());
|
||||
ASSERT_EQ (genesis.hash (), system.nodes[0]->ledger.latest (transaction, nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (genesis.hash (), system.nodes[1]->latest (nano::test_genesis_key.pub));
|
||||
auto transaction (node1.store.tx_begin_read ());
|
||||
ASSERT_EQ (genesis.hash (), node1.ledger.latest (transaction, nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (genesis.hash (), node2.latest (nano::test_genesis_key.pub));
|
||||
}
|
||||
|
||||
TEST (network, send_valid_confirm_ack)
|
||||
|
@ -268,21 +276,23 @@ TEST (network, send_valid_confirm_ack)
|
|||
for (auto & type : types)
|
||||
{
|
||||
nano::system system (2, type);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
auto & node2 (*system.nodes[1]);
|
||||
nano::keypair key2;
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
system.wallet (1)->insert_adhoc (key2.prv);
|
||||
nano::block_hash latest1 (system.nodes[0]->latest (nano::test_genesis_key.pub));
|
||||
nano::block_hash latest1 (node1.latest (nano::test_genesis_key.pub));
|
||||
nano::send_block block2 (latest1, key2.pub, 50, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (latest1));
|
||||
nano::block_hash latest2 (system.nodes[1]->latest (nano::test_genesis_key.pub));
|
||||
system.nodes[0]->process_active (std::make_shared<nano::send_block> (block2));
|
||||
nano::block_hash latest2 (node2.latest (nano::test_genesis_key.pub));
|
||||
node1.process_active (std::make_shared<nano::send_block> (block2));
|
||||
system.deadline_set (10s);
|
||||
// Keep polling until latest block changes
|
||||
while (system.nodes[1]->latest (nano::test_genesis_key.pub) == latest2)
|
||||
while (node2.latest (nano::test_genesis_key.pub) == latest2)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
// Make sure the balance has decreased after processing the block.
|
||||
ASSERT_EQ (50, system.nodes[1]->balance (nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (50, node2.balance (nano::test_genesis_key.pub));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -292,46 +302,49 @@ TEST (network, send_valid_publish)
|
|||
for (auto & type : types)
|
||||
{
|
||||
nano::system system (2, type);
|
||||
system.nodes[0]->bootstrap_initiator.stop ();
|
||||
system.nodes[1]->bootstrap_initiator.stop ();
|
||||
auto & node1 (*system.nodes[0]);
|
||||
auto & node2 (*system.nodes[1]);
|
||||
node1.bootstrap_initiator.stop ();
|
||||
node2.bootstrap_initiator.stop ();
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
nano::keypair key2;
|
||||
system.wallet (1)->insert_adhoc (key2.prv);
|
||||
nano::block_hash latest1 (system.nodes[0]->latest (nano::test_genesis_key.pub));
|
||||
nano::block_hash latest1 (node1.latest (nano::test_genesis_key.pub));
|
||||
nano::send_block block2 (latest1, key2.pub, 50, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (latest1));
|
||||
auto hash2 (block2.hash ());
|
||||
nano::block_hash latest2 (system.nodes[1]->latest (nano::test_genesis_key.pub));
|
||||
system.nodes[1]->process_active (std::make_shared<nano::send_block> (block2));
|
||||
nano::block_hash latest2 (node2.latest (nano::test_genesis_key.pub));
|
||||
node2.process_active (std::make_shared<nano::send_block> (block2));
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes[0]->stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::in) == 0)
|
||||
while (node1.stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::in) == 0)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_NE (hash2, latest2);
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes[1]->latest (nano::test_genesis_key.pub) == latest2)
|
||||
while (node2.latest (nano::test_genesis_key.pub) == latest2)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_EQ (50, system.nodes[1]->balance (nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (50, node2.balance (nano::test_genesis_key.pub));
|
||||
}
|
||||
}
|
||||
|
||||
TEST (network, send_insufficient_work)
|
||||
{
|
||||
nano::system system (2);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
auto & node2 (*system.nodes[1]);
|
||||
auto block (std::make_shared<nano::send_block> (0, 1, 20, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0));
|
||||
nano::publish publish (block);
|
||||
auto node1 (system.nodes[1]->shared ());
|
||||
nano::transport::channel_udp channel (system.nodes[0]->network.udp_channels, system.nodes[1]->network.endpoint (), system.nodes[0]->network_params.protocol.protocol_version);
|
||||
nano::transport::channel_udp channel (node1.network.udp_channels, node2.network.endpoint (), node1.network_params.protocol.protocol_version);
|
||||
channel.send (publish, [](boost::system::error_code const & ec, size_t size) {});
|
||||
ASSERT_EQ (0, system.nodes[0]->stats.count (nano::stat::type::error, nano::stat::detail::insufficient_work));
|
||||
ASSERT_EQ (0, node1.stats.count (nano::stat::type::error, nano::stat::detail::insufficient_work));
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes[1]->stats.count (nano::stat::type::error, nano::stat::detail::insufficient_work) == 0)
|
||||
while (node2.stats.count (nano::stat::type::error, nano::stat::detail::insufficient_work) == 0)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_EQ (1, system.nodes[1]->stats.count (nano::stat::type::error, nano::stat::detail::insufficient_work));
|
||||
ASSERT_EQ (1, node2.stats.count (nano::stat::type::error, nano::stat::detail::insufficient_work));
|
||||
}
|
||||
|
||||
TEST (receivable_processor, confirm_insufficient_pos)
|
||||
|
@ -342,7 +355,6 @@ TEST (receivable_processor, confirm_insufficient_pos)
|
|||
auto block1 (std::make_shared<nano::send_block> (genesis.hash (), 0, 0, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0));
|
||||
node1.work_generate_blocking (*block1);
|
||||
ASSERT_EQ (nano::process_result::progress, node1.process (*block1).code);
|
||||
auto node_l (system.nodes[0]);
|
||||
node1.active.start (block1);
|
||||
nano::keypair key1;
|
||||
auto vote (std::make_shared<nano::vote> (key1.pub, key1.prv, 0, block1));
|
||||
|
@ -358,7 +370,6 @@ TEST (receivable_processor, confirm_sufficient_pos)
|
|||
auto block1 (std::make_shared<nano::send_block> (genesis.hash (), 0, 0, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0));
|
||||
node1.work_generate_blocking (*block1);
|
||||
ASSERT_EQ (nano::process_result::progress, node1.process (*block1).code);
|
||||
auto node_l (system.nodes[0]);
|
||||
node1.active.start (block1);
|
||||
auto vote (std::make_shared<nano::vote> (nano::test_genesis_key.pub, nano::test_genesis_key.prv, 0, block1));
|
||||
nano::confirm_ack con1 (vote);
|
||||
|
@ -371,33 +382,35 @@ TEST (receivable_processor, send_with_receive)
|
|||
for (auto & type : types)
|
||||
{
|
||||
nano::system system (2, type);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
auto & node2 (*system.nodes[1]);
|
||||
auto amount (std::numeric_limits<nano::uint128_t>::max ());
|
||||
nano::keypair key2;
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
nano::block_hash latest1 (system.nodes[0]->latest (nano::test_genesis_key.pub));
|
||||
nano::block_hash latest1 (node1.latest (nano::test_genesis_key.pub));
|
||||
system.wallet (1)->insert_adhoc (key2.prv);
|
||||
auto block1 (std::make_shared<nano::send_block> (latest1, key2.pub, amount - system.nodes[0]->config.receive_minimum.number (), nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (latest1)));
|
||||
ASSERT_EQ (amount, system.nodes[0]->balance (nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (0, system.nodes[0]->balance (key2.pub));
|
||||
ASSERT_EQ (amount, system.nodes[1]->balance (nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (0, system.nodes[1]->balance (key2.pub));
|
||||
system.nodes[0]->process_active (block1);
|
||||
system.nodes[0]->block_processor.flush ();
|
||||
system.nodes[1]->process_active (block1);
|
||||
system.nodes[1]->block_processor.flush ();
|
||||
ASSERT_EQ (amount - system.nodes[0]->config.receive_minimum.number (), system.nodes[0]->balance (nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (0, system.nodes[0]->balance (key2.pub));
|
||||
ASSERT_EQ (amount - system.nodes[0]->config.receive_minimum.number (), system.nodes[1]->balance (nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (0, system.nodes[1]->balance (key2.pub));
|
||||
auto block1 (std::make_shared<nano::send_block> (latest1, key2.pub, amount - node1.config.receive_minimum.number (), nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (latest1)));
|
||||
ASSERT_EQ (amount, node1.balance (nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (0, node1.balance (key2.pub));
|
||||
ASSERT_EQ (amount, node2.balance (nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (0, node2.balance (key2.pub));
|
||||
node1.process_active (block1);
|
||||
node1.block_processor.flush ();
|
||||
node2.process_active (block1);
|
||||
node2.block_processor.flush ();
|
||||
ASSERT_EQ (amount - node1.config.receive_minimum.number (), node1.balance (nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (0, node1.balance (key2.pub));
|
||||
ASSERT_EQ (amount - node1.config.receive_minimum.number (), node2.balance (nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (0, node2.balance (key2.pub));
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes[0]->balance (key2.pub) != system.nodes[0]->config.receive_minimum.number () || system.nodes[1]->balance (key2.pub) != system.nodes[0]->config.receive_minimum.number ())
|
||||
while (node1.balance (key2.pub) != node1.config.receive_minimum.number () || node2.balance (key2.pub) != node1.config.receive_minimum.number ())
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_EQ (amount - system.nodes[0]->config.receive_minimum.number (), system.nodes[0]->balance (nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (system.nodes[0]->config.receive_minimum.number (), system.nodes[0]->balance (key2.pub));
|
||||
ASSERT_EQ (amount - system.nodes[0]->config.receive_minimum.number (), system.nodes[1]->balance (nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (system.nodes[0]->config.receive_minimum.number (), system.nodes[1]->balance (key2.pub));
|
||||
ASSERT_EQ (amount - node1.config.receive_minimum.number (), node1.balance (nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (node1.config.receive_minimum.number (), node1.balance (key2.pub));
|
||||
ASSERT_EQ (amount - node1.config.receive_minimum.number (), node2.balance (nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (node1.config.receive_minimum.number (), node2.balance (key2.pub));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -835,39 +848,40 @@ TEST (tcp_listener, tcp_listener_timeout_node_id_handshake)
|
|||
TEST (network, replace_port)
|
||||
{
|
||||
nano::system system (1);
|
||||
ASSERT_EQ (0, system.nodes[0]->network.size ());
|
||||
auto node0 (system.nodes[0]);
|
||||
ASSERT_EQ (0, node0->network.size ());
|
||||
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.alarm, system.logging, system.work));
|
||||
node1->start ();
|
||||
system.nodes.push_back (node1);
|
||||
{
|
||||
auto channel (system.nodes[0]->network.udp_channels.insert (nano::endpoint (node1->network.endpoint ().address (), 23000), node1->network_params.protocol.protocol_version));
|
||||
auto channel (node0->network.udp_channels.insert (nano::endpoint (node1->network.endpoint ().address (), 23000), node1->network_params.protocol.protocol_version));
|
||||
if (channel)
|
||||
{
|
||||
channel->set_node_id (node1->node_id.pub);
|
||||
}
|
||||
}
|
||||
auto peers_list (system.nodes[0]->network.list (std::numeric_limits<size_t>::max ()));
|
||||
auto peers_list (node0->network.list (std::numeric_limits<size_t>::max ()));
|
||||
ASSERT_EQ (peers_list[0]->get_node_id (), node1->node_id.pub);
|
||||
auto channel (std::make_shared<nano::transport::channel_udp> (system.nodes[0]->network.udp_channels, node1->network.endpoint (), node1->network_params.protocol.protocol_version));
|
||||
system.nodes[0]->network.send_keepalive (channel);
|
||||
auto channel (std::make_shared<nano::transport::channel_udp> (node0->network.udp_channels, node1->network.endpoint (), node1->network_params.protocol.protocol_version));
|
||||
node0->network.send_keepalive (channel);
|
||||
system.deadline_set (5s);
|
||||
while (!system.nodes[0]->network.udp_channels.channel (node1->network.endpoint ()))
|
||||
while (!node0->network.udp_channels.channel (node1->network.endpoint ()))
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
system.deadline_set (5s);
|
||||
while (system.nodes[0]->network.udp_channels.size () > 1)
|
||||
while (node0->network.udp_channels.size () > 1)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_EQ (system.nodes[0]->network.udp_channels.size (), 1);
|
||||
auto list1 (system.nodes[0]->network.list (1));
|
||||
ASSERT_EQ (node0->network.udp_channels.size (), 1);
|
||||
auto list1 (node0->network.list (1));
|
||||
ASSERT_EQ (node1->network.endpoint (), list1[0]->get_endpoint ());
|
||||
auto list2 (node1->network.list (1));
|
||||
ASSERT_EQ (system.nodes[0]->network.endpoint (), list2[0]->get_endpoint ());
|
||||
ASSERT_EQ (node0->network.endpoint (), list2[0]->get_endpoint ());
|
||||
// Remove correct peer (same node ID)
|
||||
system.nodes[0]->network.udp_channels.clean_node_id (nano::endpoint (node1->network.endpoint ().address (), 23000), node1->node_id.pub);
|
||||
ASSERT_EQ (system.nodes[0]->network.udp_channels.size (), 0);
|
||||
node0->network.udp_channels.clean_node_id (nano::endpoint (node1->network.endpoint ().address (), 23000), node1->node_id.pub);
|
||||
ASSERT_EQ (node0->network.udp_channels.size (), 0);
|
||||
node1->stop ();
|
||||
}
|
||||
|
||||
|
|
|
@ -158,16 +158,17 @@ TEST (node, send_single_many_peers)
|
|||
TEST (node, send_out_of_order)
|
||||
{
|
||||
nano::system system (2);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
nano::keypair key2;
|
||||
nano::genesis genesis;
|
||||
nano::send_block send1 (genesis.hash (), key2.pub, std::numeric_limits<nano::uint128_t>::max () - system.nodes[0]->config.receive_minimum.number (), nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ()));
|
||||
nano::send_block send2 (send1.hash (), key2.pub, std::numeric_limits<nano::uint128_t>::max () - system.nodes[0]->config.receive_minimum.number () * 2, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (send1.hash ()));
|
||||
nano::send_block send3 (send2.hash (), key2.pub, std::numeric_limits<nano::uint128_t>::max () - system.nodes[0]->config.receive_minimum.number () * 3, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (send2.hash ()));
|
||||
system.nodes[0]->process_active (std::make_shared<nano::send_block> (send3));
|
||||
system.nodes[0]->process_active (std::make_shared<nano::send_block> (send2));
|
||||
system.nodes[0]->process_active (std::make_shared<nano::send_block> (send1));
|
||||
nano::send_block send1 (genesis.hash (), key2.pub, std::numeric_limits<nano::uint128_t>::max () - node1.config.receive_minimum.number (), nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ()));
|
||||
nano::send_block send2 (send1.hash (), key2.pub, std::numeric_limits<nano::uint128_t>::max () - node1.config.receive_minimum.number () * 2, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (send1.hash ()));
|
||||
nano::send_block send3 (send2.hash (), key2.pub, std::numeric_limits<nano::uint128_t>::max () - node1.config.receive_minimum.number () * 3, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (send2.hash ()));
|
||||
node1.process_active (std::make_shared<nano::send_block> (send3));
|
||||
node1.process_active (std::make_shared<nano::send_block> (send2));
|
||||
node1.process_active (std::make_shared<nano::send_block> (send1));
|
||||
system.deadline_set (10s);
|
||||
while (std::any_of (system.nodes.begin (), system.nodes.end (), [&](std::shared_ptr<nano::node> const & node_a) { return node_a->balance (nano::test_genesis_key.pub) != nano::genesis_amount - system.nodes[0]->config.receive_minimum.number () * 3; }))
|
||||
while (std::any_of (system.nodes.begin (), system.nodes.end (), [&](std::shared_ptr<nano::node> const & node_a) { return node_a->balance (nano::test_genesis_key.pub) != nano::genesis_amount - node1.config.receive_minimum.number () * 3; }))
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
|
@ -176,48 +177,50 @@ TEST (node, send_out_of_order)
|
|||
TEST (node, quick_confirm)
|
||||
{
|
||||
nano::system system (1);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
nano::keypair key;
|
||||
nano::block_hash previous (system.nodes[0]->latest (nano::test_genesis_key.pub));
|
||||
auto genesis_start_balance (system.nodes[0]->balance (nano::test_genesis_key.pub));
|
||||
nano::block_hash previous (node1.latest (nano::test_genesis_key.pub));
|
||||
auto genesis_start_balance (node1.balance (nano::test_genesis_key.pub));
|
||||
system.wallet (0)->insert_adhoc (key.prv);
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
auto send (std::make_shared<nano::send_block> (previous, key.pub, system.nodes[0]->config.online_weight_minimum.number () + 1, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (previous)));
|
||||
system.nodes[0]->process_active (send);
|
||||
auto send (std::make_shared<nano::send_block> (previous, key.pub, node1.config.online_weight_minimum.number () + 1, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (previous)));
|
||||
node1.process_active (send);
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes[0]->balance (key.pub).is_zero ())
|
||||
while (node1.balance (key.pub).is_zero ())
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_EQ (system.nodes[0]->balance (nano::test_genesis_key.pub), system.nodes[0]->config.online_weight_minimum.number () + 1);
|
||||
ASSERT_EQ (system.nodes[0]->balance (key.pub), genesis_start_balance - (system.nodes[0]->config.online_weight_minimum.number () + 1));
|
||||
ASSERT_EQ (node1.balance (nano::test_genesis_key.pub), node1.config.online_weight_minimum.number () + 1);
|
||||
ASSERT_EQ (node1.balance (key.pub), genesis_start_balance - (node1.config.online_weight_minimum.number () + 1));
|
||||
}
|
||||
|
||||
TEST (node, node_receive_quorum)
|
||||
{
|
||||
nano::system system (1);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
nano::keypair key;
|
||||
nano::block_hash previous (system.nodes[0]->latest (nano::test_genesis_key.pub));
|
||||
nano::block_hash previous (node1.latest (nano::test_genesis_key.pub));
|
||||
system.wallet (0)->insert_adhoc (key.prv);
|
||||
auto send (std::make_shared<nano::send_block> (previous, key.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (previous)));
|
||||
system.nodes[0]->process_active (send);
|
||||
node1.process_active (send);
|
||||
system.deadline_set (10s);
|
||||
while (!system.nodes[0]->ledger.block_exists (send->hash ()))
|
||||
while (!node1.ledger.block_exists (send->hash ()))
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
{
|
||||
nano::lock_guard<std::mutex> guard (system.nodes[0]->active.mutex);
|
||||
auto info (system.nodes[0]->active.roots.find (nano::qualified_root (previous, previous)));
|
||||
ASSERT_NE (system.nodes[0]->active.roots.end (), info);
|
||||
nano::lock_guard<std::mutex> guard (node1.active.mutex);
|
||||
auto info (node1.active.roots.find (nano::qualified_root (previous, previous)));
|
||||
ASSERT_NE (node1.active.roots.end (), info);
|
||||
ASSERT_FALSE (info->election->confirmed);
|
||||
ASSERT_EQ (1, info->election->last_votes.size ());
|
||||
}
|
||||
nano::system system2 (1);
|
||||
system2.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
ASSERT_TRUE (system.nodes[0]->balance (key.pub).is_zero ());
|
||||
auto channel (std::make_shared<nano::transport::channel_udp> (system.nodes[0]->network.udp_channels, system2.nodes[0]->network.endpoint (), system.nodes[0]->network_params.protocol.protocol_version));
|
||||
system.nodes[0]->network.send_keepalive (channel);
|
||||
while (system.nodes[0]->balance (key.pub).is_zero ())
|
||||
ASSERT_TRUE (node1.balance (key.pub).is_zero ());
|
||||
auto channel (std::make_shared<nano::transport::channel_udp> (node1.network.udp_channels, system2.nodes[0]->network.endpoint (), node1.network_params.protocol.protocol_version));
|
||||
node1.network.send_keepalive (channel);
|
||||
while (node1.balance (key.pub).is_zero ())
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
ASSERT_NO_ERROR (system2.poll ());
|
||||
|
@ -227,19 +230,20 @@ TEST (node, node_receive_quorum)
|
|||
TEST (node, auto_bootstrap)
|
||||
{
|
||||
nano::system system (1);
|
||||
auto node0 (system.nodes[0]);
|
||||
nano::keypair key2;
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
system.wallet (0)->insert_adhoc (key2.prv);
|
||||
auto send1 (system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ()));
|
||||
auto send1 (system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, node0->config.receive_minimum.number ()));
|
||||
ASSERT_NE (nullptr, send1);
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes[0]->balance (key2.pub) != system.nodes[0]->config.receive_minimum.number ())
|
||||
while (node0->balance (key2.pub) != node0->config.receive_minimum.number ())
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.alarm, system.logging, system.work));
|
||||
ASSERT_FALSE (node1->init_error ());
|
||||
auto channel (std::make_shared<nano::transport::channel_udp> (node1->network.udp_channels, system.nodes[0]->network.endpoint (), node1->network_params.protocol.protocol_version));
|
||||
auto channel (std::make_shared<nano::transport::channel_udp> (node1->network.udp_channels, node0->network.endpoint (), node1->network_params.protocol.protocol_version));
|
||||
node1->network.send_keepalive (channel);
|
||||
node1->start ();
|
||||
system.nodes.push_back (node1);
|
||||
|
@ -249,7 +253,7 @@ TEST (node, auto_bootstrap)
|
|||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
system.deadline_set (10s);
|
||||
while (node1->balance (key2.pub) != system.nodes[0]->config.receive_minimum.number ())
|
||||
while (node1->balance (key2.pub) != node0->config.receive_minimum.number ())
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
|
@ -278,18 +282,19 @@ TEST (node, auto_bootstrap)
|
|||
TEST (node, auto_bootstrap_reverse)
|
||||
{
|
||||
nano::system system (1);
|
||||
auto node0 (system.nodes[0]);
|
||||
nano::keypair key2;
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
system.wallet (0)->insert_adhoc (key2.prv);
|
||||
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.alarm, system.logging, system.work));
|
||||
ASSERT_FALSE (node1->init_error ());
|
||||
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ()));
|
||||
auto channel (std::make_shared<nano::transport::channel_udp> (system.nodes[0]->network.udp_channels, node1->network.endpoint (), system.nodes[0]->network_params.protocol.protocol_version));
|
||||
system.nodes[0]->network.send_keepalive (channel);
|
||||
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, node0->config.receive_minimum.number ()));
|
||||
auto channel (std::make_shared<nano::transport::channel_udp> (node0->network.udp_channels, node1->network.endpoint (), node0->network_params.protocol.protocol_version));
|
||||
node0->network.send_keepalive (channel);
|
||||
node1->start ();
|
||||
system.nodes.push_back (node1);
|
||||
system.deadline_set (10s);
|
||||
while (node1->balance (key2.pub) != system.nodes[0]->config.receive_minimum.number ())
|
||||
while (node1->balance (key2.pub) != node0->config.receive_minimum.number ())
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
|
@ -322,14 +327,14 @@ TEST (node, merge_peers)
|
|||
TEST (node, search_pending)
|
||||
{
|
||||
nano::system system (1);
|
||||
auto node (system.nodes[0]);
|
||||
nano::keypair key2;
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ()));
|
||||
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, node->config.receive_minimum.number ()));
|
||||
system.wallet (0)->insert_adhoc (key2.prv);
|
||||
auto node (system.nodes[0]);
|
||||
ASSERT_FALSE (system.wallet (0)->search_pending ());
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes[0]->balance (key2.pub).is_zero ())
|
||||
while (node->balance (key2.pub).is_zero ())
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
|
@ -338,15 +343,15 @@ TEST (node, search_pending)
|
|||
TEST (node, search_pending_same)
|
||||
{
|
||||
nano::system system (1);
|
||||
auto node (system.nodes[0]);
|
||||
nano::keypair key2;
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ()));
|
||||
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ()));
|
||||
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, node->config.receive_minimum.number ()));
|
||||
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, node->config.receive_minimum.number ()));
|
||||
system.wallet (0)->insert_adhoc (key2.prv);
|
||||
auto node (system.nodes[0]);
|
||||
ASSERT_FALSE (system.wallet (0)->search_pending ());
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes[0]->balance (key2.pub) != 2 * system.nodes[0]->config.receive_minimum.number ())
|
||||
while (node->balance (key2.pub) != 2 * node->config.receive_minimum.number ())
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
|
@ -355,23 +360,23 @@ TEST (node, search_pending_same)
|
|||
TEST (node, search_pending_multiple)
|
||||
{
|
||||
nano::system system (1);
|
||||
auto node (system.nodes[0]);
|
||||
nano::keypair key2;
|
||||
nano::keypair key3;
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
system.wallet (0)->insert_adhoc (key3.prv);
|
||||
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key3.pub, system.nodes[0]->config.receive_minimum.number ()));
|
||||
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key3.pub, node->config.receive_minimum.number ()));
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes[0]->balance (key3.pub).is_zero ())
|
||||
while (node->balance (key3.pub).is_zero ())
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ()));
|
||||
ASSERT_NE (nullptr, system.wallet (0)->send_action (key3.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ()));
|
||||
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, node->config.receive_minimum.number ()));
|
||||
ASSERT_NE (nullptr, system.wallet (0)->send_action (key3.pub, key2.pub, node->config.receive_minimum.number ()));
|
||||
system.wallet (0)->insert_adhoc (key2.prv);
|
||||
auto node (system.nodes[0]);
|
||||
ASSERT_FALSE (system.wallet (0)->search_pending ());
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes[0]->balance (key2.pub) != 2 * system.nodes[0]->config.receive_minimum.number ())
|
||||
while (node->balance (key2.pub) != 2 * node->config.receive_minimum.number ())
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
|
@ -425,20 +430,21 @@ TEST (node, search_pending_confirmed)
|
|||
TEST (node, unlock_search)
|
||||
{
|
||||
nano::system system (1);
|
||||
auto node (system.nodes[0]);
|
||||
nano::keypair key2;
|
||||
nano::uint128_t balance (system.nodes[0]->balance (nano::test_genesis_key.pub));
|
||||
nano::uint128_t balance (node->balance (nano::test_genesis_key.pub));
|
||||
{
|
||||
auto transaction (system.wallet (0)->wallets.tx_begin_write ());
|
||||
system.wallet (0)->store.rekey (transaction, "");
|
||||
}
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ()));
|
||||
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, node->config.receive_minimum.number ()));
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes[0]->balance (nano::test_genesis_key.pub) == balance)
|
||||
while (node->balance (nano::test_genesis_key.pub) == balance)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
while (!system.nodes[0]->active.empty ())
|
||||
while (!node->active.empty ())
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
|
@ -447,13 +453,12 @@ TEST (node, unlock_search)
|
|||
nano::lock_guard<std::recursive_mutex> lock (system.wallet (0)->store.mutex);
|
||||
system.wallet (0)->store.password.value_set (nano::keypair ().prv);
|
||||
}
|
||||
auto node (system.nodes[0]);
|
||||
{
|
||||
auto transaction (system.wallet (0)->wallets.tx_begin_write ());
|
||||
ASSERT_FALSE (system.wallet (0)->enter_password (transaction, ""));
|
||||
}
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes[0]->balance (key2.pub).is_zero ())
|
||||
while (node->balance (key2.pub).is_zero ())
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
|
@ -462,19 +467,20 @@ TEST (node, unlock_search)
|
|||
TEST (node, connect_after_junk)
|
||||
{
|
||||
nano::system system (1);
|
||||
auto node0 (system.nodes[0]);
|
||||
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.alarm, system.logging, system.work));
|
||||
std::vector<uint8_t> junk_buffer;
|
||||
junk_buffer.push_back (0);
|
||||
auto channel1 (std::make_shared<nano::transport::channel_udp> (node1->network.udp_channels, system.nodes[0]->network.endpoint (), node1->network_params.protocol.protocol_version));
|
||||
auto channel1 (std::make_shared<nano::transport::channel_udp> (node1->network.udp_channels, node0->network.endpoint (), node1->network_params.protocol.protocol_version));
|
||||
channel1->send_buffer (nano::shared_const_buffer (std::move (junk_buffer)), nano::stat::detail::bulk_pull, [](boost::system::error_code const &, size_t) {});
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes[0]->stats.count (nano::stat::type::error) == 0)
|
||||
while (node0->stats.count (nano::stat::type::error) == 0)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
node1->start ();
|
||||
system.nodes.push_back (node1);
|
||||
auto channel2 (std::make_shared<nano::transport::channel_udp> (node1->network.udp_channels, system.nodes[0]->network.endpoint (), node1->network_params.protocol.protocol_version));
|
||||
auto channel2 (std::make_shared<nano::transport::channel_udp> (node1->network.udp_channels, node0->network.endpoint (), node1->network_params.protocol.protocol_version));
|
||||
node1->network.send_keepalive (channel2);
|
||||
system.deadline_set (10s);
|
||||
while (node1->network.empty ())
|
||||
|
@ -1212,10 +1218,10 @@ TEST (node, fork_keep)
|
|||
ASSERT_EQ (1, votes1->last_votes.size ());
|
||||
lock.unlock ();
|
||||
{
|
||||
auto transaction0 (system.nodes[0]->store.tx_begin_read ());
|
||||
auto transaction1 (system.nodes[1]->store.tx_begin_read ());
|
||||
ASSERT_TRUE (system.nodes[0]->store.block_exists (transaction0, send1->hash ()));
|
||||
ASSERT_TRUE (system.nodes[1]->store.block_exists (transaction1, send1->hash ()));
|
||||
auto transaction0 (node1.store.tx_begin_read ());
|
||||
auto transaction1 (node2.store.tx_begin_read ());
|
||||
ASSERT_TRUE (node1.store.block_exists (transaction0, send1->hash ()));
|
||||
ASSERT_TRUE (node2.store.block_exists (transaction1, send1->hash ()));
|
||||
}
|
||||
system.deadline_set (1.5min);
|
||||
// Wait until the genesis rep makes a vote
|
||||
|
@ -1223,15 +1229,15 @@ TEST (node, fork_keep)
|
|||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
auto transaction0 (system.nodes[0]->store.tx_begin_read ());
|
||||
auto transaction1 (system.nodes[1]->store.tx_begin_read ());
|
||||
auto transaction0 (node1.store.tx_begin_read ());
|
||||
auto transaction1 (node2.store.tx_begin_read ());
|
||||
// The vote should be in agreement with what we already have.
|
||||
lock.lock ();
|
||||
auto winner (*votes1->tally ().begin ());
|
||||
ASSERT_EQ (*send1, *winner.second);
|
||||
ASSERT_EQ (nano::genesis_amount - 100, winner.first);
|
||||
ASSERT_TRUE (system.nodes[0]->store.block_exists (transaction0, send1->hash ()));
|
||||
ASSERT_TRUE (system.nodes[1]->store.block_exists (transaction1, send1->hash ()));
|
||||
ASSERT_TRUE (node1.store.block_exists (transaction0, send1->hash ()));
|
||||
ASSERT_TRUE (node2.store.block_exists (transaction1, send1->hash ()));
|
||||
}
|
||||
|
||||
TEST (node, fork_flip)
|
||||
|
@ -1268,11 +1274,11 @@ TEST (node, fork_flip)
|
|||
ASSERT_EQ (1, votes1->last_votes.size ());
|
||||
lock.unlock ();
|
||||
{
|
||||
auto transaction (system.nodes[0]->store.tx_begin_read ());
|
||||
auto transaction (node1.store.tx_begin_read ());
|
||||
ASSERT_TRUE (node1.store.block_exists (transaction, publish1.block->hash ()));
|
||||
}
|
||||
{
|
||||
auto transaction (system.nodes[1]->store.tx_begin_read ());
|
||||
auto transaction (node2.store.tx_begin_read ());
|
||||
ASSERT_TRUE (node2.store.block_exists (transaction, publish2.block->hash ()));
|
||||
}
|
||||
system.deadline_set (10s);
|
||||
|
@ -1282,8 +1288,8 @@ TEST (node, fork_flip)
|
|||
ASSERT_NO_ERROR (system.poll ());
|
||||
done = node2.ledger.block_exists (publish1.block->hash ());
|
||||
}
|
||||
auto transaction1 (system.nodes[0]->store.tx_begin_read ());
|
||||
auto transaction2 (system.nodes[1]->store.tx_begin_read ());
|
||||
auto transaction1 (node1.store.tx_begin_read ());
|
||||
auto transaction2 (node2.store.tx_begin_read ());
|
||||
lock.lock ();
|
||||
auto winner (*votes1->tally ().begin ());
|
||||
ASSERT_EQ (*publish1.block, *winner.second);
|
||||
|
@ -1329,11 +1335,11 @@ TEST (node, fork_multi_flip)
|
|||
ASSERT_EQ (1, votes1->last_votes.size ());
|
||||
lock.unlock ();
|
||||
{
|
||||
auto transaction (system.nodes[0]->store.tx_begin_read ());
|
||||
auto transaction (node1.store.tx_begin_read ());
|
||||
ASSERT_TRUE (node1.store.block_exists (transaction, publish1.block->hash ()));
|
||||
}
|
||||
{
|
||||
auto transaction (system.nodes[1]->store.tx_begin_read ());
|
||||
auto transaction (node2.store.tx_begin_read ());
|
||||
ASSERT_TRUE (node2.store.block_exists (transaction, publish2.block->hash ()));
|
||||
ASSERT_TRUE (node2.store.block_exists (transaction, publish3.block->hash ()));
|
||||
}
|
||||
|
@ -1344,8 +1350,8 @@ TEST (node, fork_multi_flip)
|
|||
ASSERT_NO_ERROR (system.poll ());
|
||||
done = node2.ledger.block_exists (publish1.block->hash ());
|
||||
}
|
||||
auto transaction1 (system.nodes[0]->store.tx_begin_read ());
|
||||
auto transaction2 (system.nodes[1]->store.tx_begin_read ());
|
||||
auto transaction1 (node1.store.tx_begin_read ());
|
||||
auto transaction2 (node2.store.tx_begin_read ());
|
||||
lock.lock ();
|
||||
auto winner (*votes1->tally ().begin ());
|
||||
ASSERT_EQ (*publish1.block, *winner.second);
|
||||
|
@ -1470,8 +1476,8 @@ TEST (node, fork_open_flip)
|
|||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
node2.block_processor.flush ();
|
||||
auto transaction1 (system.nodes[0]->store.tx_begin_read ());
|
||||
auto transaction2 (system.nodes[1]->store.tx_begin_read ());
|
||||
auto transaction1 (node1.store.tx_begin_read ());
|
||||
auto transaction2 (node2.store.tx_begin_read ());
|
||||
lock.lock ();
|
||||
auto winner (*votes1->tally ().begin ());
|
||||
ASSERT_EQ (*open1, *winner.second);
|
||||
|
@ -1781,10 +1787,10 @@ TEST (node, DISABLED_bootstrap_no_publish)
|
|||
auto node1 (system1.nodes[0]);
|
||||
nano::keypair key0;
|
||||
// node0 knows about send0 but node1 doesn't.
|
||||
nano::send_block send0 (system0.nodes[0]->latest (nano::test_genesis_key.pub), key0.pub, 500, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
|
||||
nano::send_block send0 (node0->latest (nano::test_genesis_key.pub), key0.pub, 500, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
|
||||
{
|
||||
auto transaction (node0->store.tx_begin_write ());
|
||||
ASSERT_EQ (nano::process_result::progress, system0.nodes[0]->ledger.process (transaction, send0).code);
|
||||
ASSERT_EQ (nano::process_result::progress, node0->ledger.process (transaction, send0).code);
|
||||
}
|
||||
ASSERT_FALSE (node1->bootstrap_initiator.in_progress ());
|
||||
node1->bootstrap_initiator.bootstrap (node0->network.endpoint ());
|
||||
|
@ -1810,11 +1816,11 @@ TEST (node, bootstrap_bulk_push)
|
|||
auto node1 (system1.nodes[0]);
|
||||
nano::keypair key0;
|
||||
// node0 knows about send0 but node1 doesn't.
|
||||
nano::send_block send0 (system0.nodes[0]->latest (nano::test_genesis_key.pub), key0.pub, 500, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
|
||||
nano::send_block send0 (node0->latest (nano::test_genesis_key.pub), key0.pub, 500, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
|
||||
node0->work_generate_blocking (send0);
|
||||
{
|
||||
auto transaction (node0->store.tx_begin_write ());
|
||||
ASSERT_EQ (nano::process_result::progress, system0.nodes[0]->ledger.process (transaction, send0).code);
|
||||
ASSERT_EQ (nano::process_result::progress, node0->ledger.process (transaction, send0).code);
|
||||
}
|
||||
ASSERT_FALSE (node0->bootstrap_initiator.in_progress ());
|
||||
ASSERT_FALSE (node1->bootstrap_initiator.in_progress ());
|
||||
|
@ -1841,7 +1847,7 @@ TEST (node, bootstrap_fork_open)
|
|||
auto node1 = system0.add_node (node_config);
|
||||
system0.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
nano::keypair key0;
|
||||
nano::send_block send0 (system0.nodes[0]->latest (nano::test_genesis_key.pub), key0.pub, nano::genesis_amount - 500, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
|
||||
nano::send_block send0 (node0->latest (nano::test_genesis_key.pub), key0.pub, nano::genesis_amount - 500, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
|
||||
nano::open_block open0 (send0.hash (), 1, key0.pub, key0.prv, key0.pub, 0);
|
||||
nano::open_block open1 (send0.hash (), 2, key0.pub, key0.prv, key0.pub, 0);
|
||||
node0->work_generate_blocking (send0);
|
||||
|
@ -2095,19 +2101,20 @@ TEST (node, no_voting)
|
|||
TEST (node, send_callback)
|
||||
{
|
||||
nano::system system (1);
|
||||
auto & node0 (*system.nodes[0]);
|
||||
nano::keypair key2;
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
system.wallet (0)->insert_adhoc (key2.prv);
|
||||
system.nodes[0]->config.callback_address = "localhost";
|
||||
system.nodes[0]->config.callback_port = 8010;
|
||||
system.nodes[0]->config.callback_target = "/";
|
||||
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ()));
|
||||
node0.config.callback_address = "localhost";
|
||||
node0.config.callback_port = 8010;
|
||||
node0.config.callback_target = "/";
|
||||
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, node0.config.receive_minimum.number ()));
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes[0]->balance (key2.pub).is_zero ())
|
||||
while (node0.balance (key2.pub).is_zero ())
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_EQ (std::numeric_limits<nano::uint128_t>::max () - system.nodes[0]->config.receive_minimum.number (), system.nodes[0]->balance (nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (std::numeric_limits<nano::uint128_t>::max () - node0.config.receive_minimum.number (), node0.balance (nano::test_genesis_key.pub));
|
||||
}
|
||||
|
||||
// Check that votes get replayed back to nodes if they sent an old sequence number.
|
||||
|
@ -2115,18 +2122,20 @@ TEST (node, send_callback)
|
|||
TEST (node, vote_replay)
|
||||
{
|
||||
nano::system system (2);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
auto & node2 (*system.nodes[1]);
|
||||
nano::keypair key;
|
||||
auto open (std::make_shared<nano::open_block> (0, 1, key.pub, key.prv, key.pub, 0));
|
||||
system.nodes[0]->work_generate_blocking (*open);
|
||||
node1.work_generate_blocking (*open);
|
||||
for (auto i (0); i < 11000; ++i)
|
||||
{
|
||||
auto transaction (system.nodes[1]->store.tx_begin_read ());
|
||||
auto vote (system.nodes[1]->store.vote_generate (transaction, nano::test_genesis_key.pub, nano::test_genesis_key.prv, open));
|
||||
auto transaction (node2.store.tx_begin_read ());
|
||||
auto vote (node2.store.vote_generate (transaction, nano::test_genesis_key.pub, nano::test_genesis_key.prv, open));
|
||||
}
|
||||
{
|
||||
auto transaction (system.nodes[0]->store.tx_begin_read ());
|
||||
nano::lock_guard<std::mutex> lock (system.nodes[0]->store.get_cache_mutex ());
|
||||
auto vote (system.nodes[0]->store.vote_current (transaction, nano::test_genesis_key.pub));
|
||||
auto transaction (node1.store.tx_begin_read ());
|
||||
nano::lock_guard<std::mutex> lock (node1.store.get_cache_mutex ());
|
||||
auto vote (node1.store.vote_current (transaction, nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (nullptr, vote);
|
||||
}
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
|
@ -2137,9 +2146,9 @@ TEST (node, vote_replay)
|
|||
while (!done)
|
||||
{
|
||||
auto ec = system.poll ();
|
||||
auto transaction (system.nodes[0]->store.tx_begin_read ());
|
||||
nano::lock_guard<std::mutex> lock (system.nodes[0]->store.get_cache_mutex ());
|
||||
auto vote (system.nodes[0]->store.vote_current (transaction, nano::test_genesis_key.pub));
|
||||
auto transaction (node1.store.tx_begin_read ());
|
||||
nano::lock_guard<std::mutex> lock (node1.store.get_cache_mutex ());
|
||||
auto vote (node1.store.vote_current (transaction, nano::test_genesis_key.pub));
|
||||
done = vote && (vote->sequence >= 10000);
|
||||
ASSERT_NO_ERROR (ec);
|
||||
}
|
||||
|
@ -2215,16 +2224,17 @@ TEST (node, stat_counting)
|
|||
TEST (node, online_reps)
|
||||
{
|
||||
nano::system system (1);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
// 1 sample of minimum weight
|
||||
ASSERT_EQ (system.nodes[0]->config.online_weight_minimum, system.nodes[0]->online_reps.online_stake ());
|
||||
ASSERT_EQ (node1.config.online_weight_minimum, node1.online_reps.online_stake ());
|
||||
auto vote (std::make_shared<nano::vote> ());
|
||||
system.nodes[0]->online_reps.observe (nano::test_genesis_key.pub);
|
||||
node1.online_reps.observe (nano::test_genesis_key.pub);
|
||||
// 1 minimum, 1 maximum
|
||||
system.nodes[0]->online_reps.sample ();
|
||||
ASSERT_EQ (nano::genesis_amount, system.nodes[0]->online_reps.online_stake ());
|
||||
node1.online_reps.sample ();
|
||||
ASSERT_EQ (nano::genesis_amount, node1.online_reps.online_stake ());
|
||||
// 2 minimum, 1 maximum
|
||||
system.nodes[0]->online_reps.sample ();
|
||||
ASSERT_EQ (system.nodes[0]->config.online_weight_minimum, system.nodes[0]->online_reps.online_stake ());
|
||||
node1.online_reps.sample ();
|
||||
ASSERT_EQ (node1.config.online_weight_minimum, node1.online_reps.online_stake ());
|
||||
}
|
||||
|
||||
TEST (node, block_confirm)
|
||||
|
@ -2233,32 +2243,34 @@ TEST (node, block_confirm)
|
|||
for (auto & type : types)
|
||||
{
|
||||
nano::system system (2, type);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
auto & node2 (*system.nodes[1]);
|
||||
nano::genesis genesis;
|
||||
nano::keypair key;
|
||||
system.wallet (1)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
auto send1 (std::make_shared<nano::state_block> (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.nodes[0]->work_generate_blocking (genesis.hash ())));
|
||||
system.nodes[0]->block_processor.add (send1, nano::seconds_since_epoch ());
|
||||
system.nodes[1]->block_processor.add (send1, nano::seconds_since_epoch ());
|
||||
auto send1 (std::make_shared<nano::state_block> (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *node1.work_generate_blocking (genesis.hash ())));
|
||||
node1.block_processor.add (send1, nano::seconds_since_epoch ());
|
||||
node2.block_processor.add (send1, nano::seconds_since_epoch ());
|
||||
system.deadline_set (std::chrono::seconds (5));
|
||||
while (!system.nodes[0]->ledger.block_exists (send1->hash ()) || !system.nodes[1]->ledger.block_exists (send1->hash ()))
|
||||
while (!node1.ledger.block_exists (send1->hash ()) || !node2.ledger.block_exists (send1->hash ()))
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_TRUE (system.nodes[0]->ledger.block_exists (send1->hash ()));
|
||||
ASSERT_TRUE (system.nodes[1]->ledger.block_exists (send1->hash ()));
|
||||
auto send2 (std::make_shared<nano::state_block> (nano::test_genesis_key.pub, send1->hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio * 2, key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.nodes[0]->work_generate_blocking (send1->hash ())));
|
||||
ASSERT_TRUE (node1.ledger.block_exists (send1->hash ()));
|
||||
ASSERT_TRUE (node2.ledger.block_exists (send1->hash ()));
|
||||
auto send2 (std::make_shared<nano::state_block> (nano::test_genesis_key.pub, send1->hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio * 2, key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *node1.work_generate_blocking (send1->hash ())));
|
||||
{
|
||||
auto transaction (system.nodes[0]->store.tx_begin_write ());
|
||||
ASSERT_EQ (nano::process_result::progress, system.nodes[0]->ledger.process (transaction, *send2).code);
|
||||
auto transaction (node1.store.tx_begin_write ());
|
||||
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, *send2).code);
|
||||
}
|
||||
{
|
||||
auto transaction (system.nodes[1]->store.tx_begin_write ());
|
||||
ASSERT_EQ (nano::process_result::progress, system.nodes[1]->ledger.process (transaction, *send2).code);
|
||||
auto transaction (node2.store.tx_begin_write ());
|
||||
ASSERT_EQ (nano::process_result::progress, node2.ledger.process (transaction, *send2).code);
|
||||
}
|
||||
system.nodes[0]->block_confirm (send2);
|
||||
ASSERT_TRUE (system.nodes[0]->active.list_confirmed ().empty ());
|
||||
node1.block_confirm (send2);
|
||||
ASSERT_TRUE (node1.active.list_confirmed ().empty ());
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes[0]->active.list_confirmed ().empty ())
|
||||
while (node1.active.list_confirmed ().empty ())
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
|
@ -2315,27 +2327,28 @@ TEST (node, block_arrival_time)
|
|||
TEST (node, confirm_quorum)
|
||||
{
|
||||
nano::system system (1);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
nano::genesis genesis;
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
// Put greater than online_weight_minimum in pending so quorum can't be reached
|
||||
nano::amount new_balance (system.nodes[0]->config.online_weight_minimum.number () - nano::Gxrb_ratio);
|
||||
auto send1 (std::make_shared<nano::state_block> (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, new_balance, nano::test_genesis_key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.nodes[0]->work_generate_blocking (genesis.hash ())));
|
||||
nano::amount new_balance (node1.config.online_weight_minimum.number () - nano::Gxrb_ratio);
|
||||
auto send1 (std::make_shared<nano::state_block> (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, new_balance, nano::test_genesis_key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *node1.work_generate_blocking (genesis.hash ())));
|
||||
{
|
||||
auto transaction (system.nodes[0]->store.tx_begin_write ());
|
||||
ASSERT_EQ (nano::process_result::progress, system.nodes[0]->ledger.process (transaction, *send1).code);
|
||||
auto transaction (node1.store.tx_begin_write ());
|
||||
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, *send1).code);
|
||||
}
|
||||
system.wallet (0)->send_action (nano::test_genesis_key.pub, nano::test_genesis_key.pub, new_balance.number ());
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes[0]->active.empty ())
|
||||
while (node1.active.empty ())
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
nano::lock_guard<std::mutex> guard (system.nodes[0]->active.mutex);
|
||||
auto info (system.nodes[0]->active.roots.find (nano::qualified_root (send1->hash (), send1->hash ())));
|
||||
ASSERT_NE (system.nodes[0]->active.roots.end (), info);
|
||||
nano::lock_guard<std::mutex> guard (node1.active.mutex);
|
||||
auto info (node1.active.roots.find (nano::qualified_root (send1->hash (), send1->hash ())));
|
||||
ASSERT_NE (node1.active.roots.end (), info);
|
||||
ASSERT_FALSE (info->election->confirmed);
|
||||
ASSERT_EQ (1, info->election->last_votes.size ());
|
||||
ASSERT_EQ (0, system.nodes[0]->balance (nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (0, node1.balance (nano::test_genesis_key.pub));
|
||||
}
|
||||
|
||||
TEST (node, local_votes_cache)
|
||||
|
@ -2489,38 +2502,40 @@ TEST (node, local_votes_cache_generate_new_vote)
|
|||
TEST (node, vote_republish)
|
||||
{
|
||||
nano::system system (2);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
auto & node2 (*system.nodes[1]);
|
||||
nano::keypair key2;
|
||||
system.wallet (1)->insert_adhoc (key2.prv);
|
||||
nano::genesis genesis;
|
||||
auto send1 (std::make_shared<nano::send_block> (genesis.hash (), key2.pub, std::numeric_limits<nano::uint128_t>::max () - system.nodes[0]->config.receive_minimum.number (), nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
|
||||
auto send2 (std::make_shared<nano::send_block> (genesis.hash (), key2.pub, std::numeric_limits<nano::uint128_t>::max () - system.nodes[0]->config.receive_minimum.number () * 2, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
|
||||
system.nodes[0]->process_active (send1);
|
||||
auto send1 (std::make_shared<nano::send_block> (genesis.hash (), key2.pub, std::numeric_limits<nano::uint128_t>::max () - node1.config.receive_minimum.number (), nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
|
||||
auto send2 (std::make_shared<nano::send_block> (genesis.hash (), key2.pub, std::numeric_limits<nano::uint128_t>::max () - node1.config.receive_minimum.number () * 2, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
|
||||
node1.process_active (send1);
|
||||
system.deadline_set (5s);
|
||||
while (!system.nodes[1]->block (send1->hash ()))
|
||||
while (!node2.block (send1->hash ()))
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
system.nodes[0]->active.publish (send2);
|
||||
node1.active.publish (send2);
|
||||
auto vote (std::make_shared<nano::vote> (nano::test_genesis_key.pub, nano::test_genesis_key.prv, 0, send2));
|
||||
ASSERT_TRUE (system.nodes[0]->active.active (*send1));
|
||||
ASSERT_TRUE (system.nodes[1]->active.active (*send1));
|
||||
system.nodes[0]->vote_processor.vote (vote, std::make_shared<nano::transport::channel_udp> (system.nodes[0]->network.udp_channels, system.nodes[0]->network.endpoint (), system.nodes[0]->network_params.protocol.protocol_version));
|
||||
while (!system.nodes[0]->block (send2->hash ()))
|
||||
ASSERT_TRUE (node1.active.active (*send1));
|
||||
ASSERT_TRUE (node2.active.active (*send1));
|
||||
node1.vote_processor.vote (vote, std::make_shared<nano::transport::channel_udp> (node1.network.udp_channels, node1.network.endpoint (), node1.network_params.protocol.protocol_version));
|
||||
while (!node1.block (send2->hash ()))
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
while (!system.nodes[1]->block (send2->hash ()))
|
||||
while (!node2.block (send2->hash ()))
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_FALSE (system.nodes[0]->block (send1->hash ()));
|
||||
ASSERT_FALSE (system.nodes[1]->block (send1->hash ()));
|
||||
ASSERT_FALSE (node1.block (send1->hash ()));
|
||||
ASSERT_FALSE (node2.block (send1->hash ()));
|
||||
system.deadline_set (5s);
|
||||
while (system.nodes[1]->balance (key2.pub) != system.nodes[0]->config.receive_minimum.number () * 2)
|
||||
while (node2.balance (key2.pub) != node1.config.receive_minimum.number () * 2)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
while (system.nodes[0]->balance (key2.pub) != system.nodes[0]->config.receive_minimum.number () * 2)
|
||||
while (node1.balance (key2.pub) != node1.config.receive_minimum.number () * 2)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
|
@ -2564,40 +2579,42 @@ TEST (node, vote_by_hash_republish)
|
|||
for (auto & type : types)
|
||||
{
|
||||
nano::system system (2, type);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
auto & node2 (*system.nodes[1]);
|
||||
nano::keypair key2;
|
||||
system.wallet (1)->insert_adhoc (key2.prv);
|
||||
nano::genesis genesis;
|
||||
auto send1 (std::make_shared<nano::send_block> (genesis.hash (), key2.pub, std::numeric_limits<nano::uint128_t>::max () - system.nodes[0]->config.receive_minimum.number (), nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
|
||||
auto send2 (std::make_shared<nano::send_block> (genesis.hash (), key2.pub, std::numeric_limits<nano::uint128_t>::max () - system.nodes[0]->config.receive_minimum.number () * 2, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
|
||||
system.nodes[0]->process_active (send1);
|
||||
auto send1 (std::make_shared<nano::send_block> (genesis.hash (), key2.pub, std::numeric_limits<nano::uint128_t>::max () - node1.config.receive_minimum.number (), nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
|
||||
auto send2 (std::make_shared<nano::send_block> (genesis.hash (), key2.pub, std::numeric_limits<nano::uint128_t>::max () - node1.config.receive_minimum.number () * 2, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
|
||||
node1.process_active (send1);
|
||||
system.deadline_set (5s);
|
||||
while (!system.nodes[1]->block (send1->hash ()))
|
||||
while (!node2.block (send1->hash ()))
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
system.nodes[0]->active.publish (send2);
|
||||
node1.active.publish (send2);
|
||||
std::vector<nano::block_hash> vote_blocks;
|
||||
vote_blocks.push_back (send2->hash ());
|
||||
auto vote (std::make_shared<nano::vote> (nano::test_genesis_key.pub, nano::test_genesis_key.prv, 0, vote_blocks));
|
||||
ASSERT_TRUE (system.nodes[0]->active.active (*send1));
|
||||
ASSERT_TRUE (system.nodes[1]->active.active (*send1));
|
||||
system.nodes[0]->vote_processor.vote (vote, std::make_shared<nano::transport::channel_udp> (system.nodes[0]->network.udp_channels, system.nodes[0]->network.endpoint (), system.nodes[0]->network_params.protocol.protocol_version));
|
||||
while (!system.nodes[0]->block (send2->hash ()))
|
||||
ASSERT_TRUE (node1.active.active (*send1));
|
||||
ASSERT_TRUE (node2.active.active (*send1));
|
||||
node1.vote_processor.vote (vote, std::make_shared<nano::transport::channel_udp> (node1.network.udp_channels, node1.network.endpoint (), node1.network_params.protocol.protocol_version));
|
||||
while (!node1.block (send2->hash ()))
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
while (!system.nodes[1]->block (send2->hash ()))
|
||||
while (!node2.block (send2->hash ()))
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_FALSE (system.nodes[0]->block (send1->hash ()));
|
||||
ASSERT_FALSE (system.nodes[1]->block (send1->hash ()));
|
||||
ASSERT_FALSE (node1.block (send1->hash ()));
|
||||
ASSERT_FALSE (node2.block (send1->hash ()));
|
||||
system.deadline_set (5s);
|
||||
while (system.nodes[1]->balance (key2.pub) != system.nodes[0]->config.receive_minimum.number () * 2)
|
||||
while (node2.balance (key2.pub) != node1.config.receive_minimum.number () * 2)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
while (system.nodes[0]->balance (key2.pub) != system.nodes[0]->config.receive_minimum.number () * 2)
|
||||
while (node1.balance (key2.pub) != node1.config.receive_minimum.number () * 2)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
|
@ -2607,34 +2624,36 @@ TEST (node, vote_by_hash_republish)
|
|||
TEST (node, vote_by_hash_epoch_block_republish)
|
||||
{
|
||||
nano::system system (2);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
auto & node2 (*system.nodes[1]);
|
||||
nano::keypair key2;
|
||||
system.wallet (1)->insert_adhoc (key2.prv);
|
||||
nano::genesis genesis;
|
||||
auto send1 (std::make_shared<nano::send_block> (genesis.hash (), key2.pub, std::numeric_limits<nano::uint128_t>::max () - system.nodes[0]->config.receive_minimum.number (), nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
|
||||
auto epoch1 (std::make_shared<nano::state_block> (nano::genesis_account, genesis.hash (), nano::genesis_account, nano::genesis_amount, system.nodes[0]->ledger.epoch_link (nano::epoch::epoch_1), nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
|
||||
system.nodes[0]->process_active (send1);
|
||||
auto send1 (std::make_shared<nano::send_block> (genesis.hash (), key2.pub, std::numeric_limits<nano::uint128_t>::max () - node1.config.receive_minimum.number (), nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
|
||||
auto epoch1 (std::make_shared<nano::state_block> (nano::genesis_account, genesis.hash (), nano::genesis_account, nano::genesis_amount, node1.ledger.epoch_link (nano::epoch::epoch_1), nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
|
||||
node1.process_active (send1);
|
||||
system.deadline_set (5s);
|
||||
while (!system.nodes[1]->block (send1->hash ()))
|
||||
while (!node2.block (send1->hash ()))
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
system.nodes[0]->active.publish (epoch1);
|
||||
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::test_genesis_key.pub, nano::test_genesis_key.prv, 0, vote_blocks));
|
||||
ASSERT_TRUE (system.nodes[0]->active.active (*send1));
|
||||
ASSERT_TRUE (system.nodes[1]->active.active (*send1));
|
||||
system.nodes[0]->vote_processor.vote (vote, std::make_shared<nano::transport::channel_udp> (system.nodes[0]->network.udp_channels, system.nodes[0]->network.endpoint (), system.nodes[0]->network_params.protocol.protocol_version));
|
||||
while (!system.nodes[0]->block (epoch1->hash ()))
|
||||
ASSERT_TRUE (node1.active.active (*send1));
|
||||
ASSERT_TRUE (node2.active.active (*send1));
|
||||
node1.vote_processor.vote (vote, std::make_shared<nano::transport::channel_udp> (node1.network.udp_channels, node1.network.endpoint (), node1.network_params.protocol.protocol_version));
|
||||
while (!node1.block (epoch1->hash ()))
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
while (!system.nodes[1]->block (epoch1->hash ()))
|
||||
while (!node2.block (epoch1->hash ()))
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_FALSE (system.nodes[0]->block (send1->hash ()));
|
||||
ASSERT_FALSE (system.nodes[1]->block (send1->hash ()));
|
||||
ASSERT_FALSE (node1.block (send1->hash ()));
|
||||
ASSERT_FALSE (node2.block (send1->hash ()));
|
||||
}
|
||||
|
||||
TEST (node, epoch_conflict_confirm)
|
||||
|
@ -2696,69 +2715,72 @@ TEST (node, epoch_conflict_confirm)
|
|||
TEST (node, fork_invalid_block_signature)
|
||||
{
|
||||
nano::system system (2);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
auto & node2 (*system.nodes[1]);
|
||||
nano::keypair key2;
|
||||
nano::genesis genesis;
|
||||
auto send1 (std::make_shared<nano::send_block> (genesis.hash (), key2.pub, std::numeric_limits<nano::uint128_t>::max () - system.nodes[0]->config.receive_minimum.number (), nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
|
||||
auto send2 (std::make_shared<nano::send_block> (genesis.hash (), key2.pub, std::numeric_limits<nano::uint128_t>::max () - system.nodes[0]->config.receive_minimum.number () * 2, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
|
||||
auto send1 (std::make_shared<nano::send_block> (genesis.hash (), key2.pub, std::numeric_limits<nano::uint128_t>::max () - node1.config.receive_minimum.number (), nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
|
||||
auto send2 (std::make_shared<nano::send_block> (genesis.hash (), key2.pub, std::numeric_limits<nano::uint128_t>::max () - node1.config.receive_minimum.number () * 2, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
|
||||
auto send2_corrupt (std::make_shared<nano::send_block> (*send2));
|
||||
send2_corrupt->signature = nano::signature (123);
|
||||
system.nodes[0]->process_active (send1);
|
||||
node1.process_active (send1);
|
||||
system.deadline_set (5s);
|
||||
while (!system.nodes[0]->block (send1->hash ()))
|
||||
while (!node1.block (send1->hash ()))
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
auto vote (std::make_shared<nano::vote> (nano::test_genesis_key.pub, nano::test_genesis_key.prv, 0, send2));
|
||||
auto vote_corrupt (std::make_shared<nano::vote> (nano::test_genesis_key.pub, nano::test_genesis_key.prv, 0, send2_corrupt));
|
||||
system.nodes[1]->network.flood_vote (vote_corrupt);
|
||||
node2.network.flood_vote (vote_corrupt);
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
system.nodes[1]->network.flood_vote (vote);
|
||||
while (system.nodes[0]->block (send1->hash ()))
|
||||
node2.network.flood_vote (vote);
|
||||
while (node1.block (send1->hash ()))
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
while (!system.nodes[0]->block (send2->hash ()))
|
||||
while (!node1.block (send2->hash ()))
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_EQ (system.nodes[0]->block (send2->hash ())->block_signature (), send2->block_signature ());
|
||||
ASSERT_EQ (node1.block (send2->hash ())->block_signature (), send2->block_signature ());
|
||||
}
|
||||
|
||||
TEST (node, fork_invalid_block_signature_vote_by_hash)
|
||||
{
|
||||
nano::system system (1);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
nano::keypair key2;
|
||||
nano::genesis genesis;
|
||||
auto send1 (std::make_shared<nano::send_block> (genesis.hash (), key2.pub, std::numeric_limits<nano::uint128_t>::max () - system.nodes[0]->config.receive_minimum.number (), nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
|
||||
auto send2 (std::make_shared<nano::send_block> (genesis.hash (), key2.pub, std::numeric_limits<nano::uint128_t>::max () - system.nodes[0]->config.receive_minimum.number () * 2, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
|
||||
auto send1 (std::make_shared<nano::send_block> (genesis.hash (), key2.pub, std::numeric_limits<nano::uint128_t>::max () - node1.config.receive_minimum.number (), nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
|
||||
auto send2 (std::make_shared<nano::send_block> (genesis.hash (), key2.pub, std::numeric_limits<nano::uint128_t>::max () - node1.config.receive_minimum.number () * 2, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
|
||||
auto send2_corrupt (std::make_shared<nano::send_block> (*send2));
|
||||
send2_corrupt->signature = nano::signature (123);
|
||||
system.nodes[0]->process_active (send1);
|
||||
node1.process_active (send1);
|
||||
system.deadline_set (5s);
|
||||
while (!system.nodes[0]->block (send1->hash ()))
|
||||
while (!node1.block (send1->hash ()))
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
system.nodes[0]->active.publish (send2_corrupt);
|
||||
node1.active.publish (send2_corrupt);
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
system.nodes[0]->active.publish (send2);
|
||||
node1.active.publish (send2);
|
||||
std::vector<nano::block_hash> vote_blocks;
|
||||
vote_blocks.push_back (send2->hash ());
|
||||
auto vote (std::make_shared<nano::vote> (nano::test_genesis_key.pub, nano::test_genesis_key.prv, 0, vote_blocks));
|
||||
{
|
||||
auto transaction (system.nodes[0]->store.tx_begin_read ());
|
||||
nano::unique_lock<std::mutex> lock (system.nodes[0]->active.mutex);
|
||||
system.nodes[0]->vote_processor.vote_blocking (transaction, vote, std::make_shared<nano::transport::channel_udp> (system.nodes[0]->network.udp_channels, system.nodes[0]->network.endpoint (), system.nodes[0]->network_params.protocol.protocol_version));
|
||||
auto transaction (node1.store.tx_begin_read ());
|
||||
nano::unique_lock<std::mutex> lock (node1.active.mutex);
|
||||
node1.vote_processor.vote_blocking (transaction, vote, std::make_shared<nano::transport::channel_udp> (node1.network.udp_channels, node1.network.endpoint (), node1.network_params.protocol.protocol_version));
|
||||
}
|
||||
while (system.nodes[0]->block (send1->hash ()))
|
||||
while (node1.block (send1->hash ()))
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
while (!system.nodes[0]->block (send2->hash ()))
|
||||
while (!node1.block (send2->hash ()))
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_EQ (system.nodes[0]->block (send2->hash ())->block_signature (), send2->block_signature ());
|
||||
ASSERT_EQ (node1.block (send2->hash ())->block_signature (), send2->block_signature ());
|
||||
}
|
||||
|
||||
TEST (node, block_processor_signatures)
|
||||
|
@ -2929,14 +2951,15 @@ TEST (node, confirm_back)
|
|||
TEST (node, peers)
|
||||
{
|
||||
nano::system system (1);
|
||||
ASSERT_TRUE (system.nodes.front ()->network.empty ());
|
||||
auto node1 (system.nodes[0]);
|
||||
ASSERT_TRUE (node1->network.empty ());
|
||||
|
||||
auto node (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.alarm, system.logging, system.work));
|
||||
system.nodes.push_back (node);
|
||||
auto node2 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.alarm, system.logging, system.work));
|
||||
system.nodes.push_back (node2);
|
||||
|
||||
auto endpoint = system.nodes.front ()->network.endpoint ();
|
||||
auto endpoint = node1->network.endpoint ();
|
||||
nano::endpoint_key endpoint_key{ endpoint.address ().to_v6 ().to_bytes (), endpoint.port () };
|
||||
auto & store = system.nodes.back ()->store;
|
||||
auto & store = node2->store;
|
||||
{
|
||||
// Add a peer to the database
|
||||
auto transaction (store.tx_begin_write ());
|
||||
|
@ -2946,100 +2969,101 @@ TEST (node, peers)
|
|||
store.peer_put (transaction, nano::endpoint_key{ boost::asio::ip::address_v6::any ().to_bytes (), 55555 });
|
||||
}
|
||||
|
||||
node->start ();
|
||||
node2->start ();
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes.back ()->network.empty () || system.nodes.front ()->network.empty ())
|
||||
while (node2->network.empty () || node1->network.empty ())
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
// Wait to finish TCP node ID handshakes
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes[0]->bootstrap.realtime_count == 0 || system.nodes[1]->bootstrap.realtime_count == 0)
|
||||
while (node1->bootstrap.realtime_count == 0 || node2->bootstrap.realtime_count == 0)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
// Confirm that the peers match with the endpoints we are expecting
|
||||
ASSERT_EQ (1, system.nodes.front ()->network.size ());
|
||||
auto list1 (system.nodes[0]->network.list (2));
|
||||
ASSERT_EQ (system.nodes[1]->network.endpoint (), list1[0]->get_endpoint ());
|
||||
ASSERT_EQ (1, node1->network.size ());
|
||||
auto list1 (node1->network.list (2));
|
||||
ASSERT_EQ (node2->network.endpoint (), list1[0]->get_endpoint ());
|
||||
ASSERT_EQ (nano::transport::transport_type::tcp, list1[0]->get_type ());
|
||||
ASSERT_EQ (1, node->network.size ());
|
||||
auto list2 (system.nodes[1]->network.list (2));
|
||||
ASSERT_EQ (system.nodes[0]->network.endpoint (), list2[0]->get_endpoint ());
|
||||
ASSERT_EQ (1, node2->network.size ());
|
||||
auto list2 (node2->network.list (2));
|
||||
ASSERT_EQ (node1->network.endpoint (), list2[0]->get_endpoint ());
|
||||
ASSERT_EQ (nano::transport::transport_type::tcp, list2[0]->get_type ());
|
||||
// Stop the peer node and check that it is removed from the store
|
||||
system.nodes.front ()->stop ();
|
||||
node1->stop ();
|
||||
|
||||
system.deadline_set (10s);
|
||||
while (system.nodes.back ()->network.size () == 1)
|
||||
while (node2->network.size () == 1)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
|
||||
ASSERT_TRUE (system.nodes.back ()->network.empty ());
|
||||
ASSERT_TRUE (node2->network.empty ());
|
||||
|
||||
// Uncontactable peer should not be stored
|
||||
auto transaction (store.tx_begin_read ());
|
||||
ASSERT_EQ (store.peer_count (transaction), 1);
|
||||
ASSERT_TRUE (store.peer_exists (transaction, endpoint_key));
|
||||
|
||||
node->stop ();
|
||||
node2->stop ();
|
||||
}
|
||||
|
||||
TEST (node, peer_cache_restart)
|
||||
{
|
||||
nano::system system (1);
|
||||
ASSERT_TRUE (system.nodes[0]->network.empty ());
|
||||
auto endpoint = system.nodes[0]->network.endpoint ();
|
||||
auto node1 (system.nodes[0]);
|
||||
ASSERT_TRUE (node1->network.empty ());
|
||||
auto endpoint = node1->network.endpoint ();
|
||||
nano::endpoint_key endpoint_key{ endpoint.address ().to_v6 ().to_bytes (), endpoint.port () };
|
||||
auto path (nano::unique_path ());
|
||||
{
|
||||
auto node (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), path, system.alarm, system.logging, system.work));
|
||||
system.nodes.push_back (node);
|
||||
auto & store = node->store;
|
||||
auto node2 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), path, system.alarm, system.logging, system.work));
|
||||
system.nodes.push_back (node2);
|
||||
auto & store = node2->store;
|
||||
{
|
||||
// Add a peer to the database
|
||||
auto transaction (store.tx_begin_write ());
|
||||
store.peer_put (transaction, endpoint_key);
|
||||
}
|
||||
node->start ();
|
||||
node2->start ();
|
||||
system.deadline_set (10s);
|
||||
while (node->network.empty ())
|
||||
while (node2->network.empty ())
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
// Confirm that the peers match with the endpoints we are expecting
|
||||
auto list (node->network.list (2));
|
||||
ASSERT_EQ (system.nodes[0]->network.endpoint (), list[0]->get_endpoint ());
|
||||
ASSERT_EQ (1, node->network.size ());
|
||||
node->stop ();
|
||||
auto list (node2->network.list (2));
|
||||
ASSERT_EQ (node1->network.endpoint (), list[0]->get_endpoint ());
|
||||
ASSERT_EQ (1, node2->network.size ());
|
||||
node2->stop ();
|
||||
}
|
||||
// Restart node
|
||||
{
|
||||
nano::node_flags node_flags;
|
||||
node_flags.read_only = true;
|
||||
auto node (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), path, system.alarm, system.logging, system.work, node_flags));
|
||||
system.nodes.push_back (node);
|
||||
auto node3 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), path, system.alarm, system.logging, system.work, node_flags));
|
||||
system.nodes.push_back (node3);
|
||||
// Check cached peers after restart
|
||||
node->network.start ();
|
||||
node->add_initial_peers ();
|
||||
node3->network.start ();
|
||||
node3->add_initial_peers ();
|
||||
|
||||
auto & store = node->store;
|
||||
auto & store = node3->store;
|
||||
{
|
||||
auto transaction (store.tx_begin_read ());
|
||||
ASSERT_EQ (store.peer_count (transaction), 1);
|
||||
ASSERT_TRUE (store.peer_exists (transaction, endpoint_key));
|
||||
}
|
||||
system.deadline_set (10s);
|
||||
while (node->network.empty ())
|
||||
while (node3->network.empty ())
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
// Confirm that the peers match with the endpoints we are expecting
|
||||
auto list (node->network.list (2));
|
||||
ASSERT_EQ (system.nodes[0]->network.endpoint (), list[0]->get_endpoint ());
|
||||
ASSERT_EQ (1, node->network.size ());
|
||||
node->stop ();
|
||||
auto list (node3->network.list (2));
|
||||
ASSERT_EQ (node1->network.endpoint (), list[0]->get_endpoint ());
|
||||
ASSERT_EQ (1, node3->network.size ());
|
||||
node3->stop ();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,17 +15,18 @@ TEST (peer_container, empty_peers)
|
|||
TEST (peer_container, no_recontact)
|
||||
{
|
||||
nano::system system (1);
|
||||
nano::network & network (system.nodes[0]->network);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
nano::network & network (node1.network);
|
||||
auto observed_peer (0);
|
||||
auto observed_disconnect (false);
|
||||
nano::endpoint endpoint1 (boost::asio::ip::address_v6::loopback (), 10000);
|
||||
ASSERT_EQ (0, network.size ());
|
||||
network.channel_observer = [&observed_peer](std::shared_ptr<nano::transport::channel>) { ++observed_peer; };
|
||||
system.nodes[0]->network.disconnect_observer = [&observed_disconnect]() { observed_disconnect = true; };
|
||||
auto channel (network.udp_channels.insert (endpoint1, system.nodes[0]->network_params.protocol.protocol_version));
|
||||
node1.network.disconnect_observer = [&observed_disconnect]() { observed_disconnect = true; };
|
||||
auto channel (network.udp_channels.insert (endpoint1, node1.network_params.protocol.protocol_version));
|
||||
ASSERT_EQ (1, network.size ());
|
||||
ASSERT_EQ (channel, network.udp_channels.insert (endpoint1, system.nodes[0]->network_params.protocol.protocol_version));
|
||||
system.nodes[0]->network.cleanup (std::chrono::steady_clock::now () + std::chrono::seconds (5));
|
||||
ASSERT_EQ (channel, network.udp_channels.insert (endpoint1, node1.network_params.protocol.protocol_version));
|
||||
node1.network.cleanup (std::chrono::steady_clock::now () + std::chrono::seconds (5));
|
||||
ASSERT_TRUE (network.empty ());
|
||||
ASSERT_EQ (1, observed_peer);
|
||||
ASSERT_TRUE (observed_disconnect);
|
||||
|
@ -55,25 +56,26 @@ TEST (peer_container, reserved_peers_no_contact)
|
|||
TEST (peer_container, split)
|
||||
{
|
||||
nano::system system (1);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
auto now (std::chrono::steady_clock::now ());
|
||||
nano::endpoint endpoint1 (boost::asio::ip::address_v6::loopback (), 100);
|
||||
nano::endpoint endpoint2 (boost::asio::ip::address_v6::loopback (), 101);
|
||||
auto channel1 (system.nodes[0]->network.udp_channels.insert (endpoint1, 0));
|
||||
auto channel1 (node1.network.udp_channels.insert (endpoint1, 0));
|
||||
ASSERT_NE (nullptr, channel1);
|
||||
system.nodes[0]->network.udp_channels.modify (channel1, [&now](auto channel) {
|
||||
node1.network.udp_channels.modify (channel1, [&now](auto channel) {
|
||||
channel->set_last_packet_received (now - std::chrono::seconds (1));
|
||||
});
|
||||
auto channel2 (system.nodes[0]->network.udp_channels.insert (endpoint2, 0));
|
||||
auto channel2 (node1.network.udp_channels.insert (endpoint2, 0));
|
||||
ASSERT_NE (nullptr, channel2);
|
||||
system.nodes[0]->network.udp_channels.modify (channel2, [&now](auto channel) {
|
||||
node1.network.udp_channels.modify (channel2, [&now](auto channel) {
|
||||
channel->set_last_packet_received (now + std::chrono::seconds (1));
|
||||
});
|
||||
ASSERT_EQ (2, system.nodes[0]->network.size ());
|
||||
ASSERT_EQ (2, system.nodes[0]->network.udp_channels.size ());
|
||||
system.nodes[0]->network.cleanup (now);
|
||||
ASSERT_EQ (1, system.nodes[0]->network.size ());
|
||||
ASSERT_EQ (1, system.nodes[0]->network.udp_channels.size ());
|
||||
auto list (system.nodes[0]->network.list (1));
|
||||
ASSERT_EQ (2, node1.network.size ());
|
||||
ASSERT_EQ (2, node1.network.udp_channels.size ());
|
||||
node1.network.cleanup (now);
|
||||
ASSERT_EQ (1, node1.network.size ());
|
||||
ASSERT_EQ (1, node1.network.udp_channels.size ());
|
||||
auto list (node1.network.list (1));
|
||||
ASSERT_EQ (endpoint2, list[0]->get_endpoint ());
|
||||
}
|
||||
|
||||
|
@ -132,20 +134,21 @@ TEST (peer_container, list_fanout)
|
|||
TEST (peer_container, reachout)
|
||||
{
|
||||
nano::system system (1);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
nano::endpoint endpoint0 (boost::asio::ip::address_v6::loopback (), nano::get_available_port ());
|
||||
// Make sure having been contacted by them already indicates we shouldn't reach out
|
||||
system.nodes[0]->network.udp_channels.insert (endpoint0, system.nodes[0]->network_params.protocol.protocol_version);
|
||||
ASSERT_TRUE (system.nodes[0]->network.reachout (endpoint0));
|
||||
node1.network.udp_channels.insert (endpoint0, node1.network_params.protocol.protocol_version);
|
||||
ASSERT_TRUE (node1.network.reachout (endpoint0));
|
||||
nano::endpoint endpoint1 (boost::asio::ip::address_v6::loopback (), nano::get_available_port ());
|
||||
ASSERT_FALSE (system.nodes[0]->network.reachout (endpoint1));
|
||||
ASSERT_FALSE (node1.network.reachout (endpoint1));
|
||||
// Reaching out to them once should signal we shouldn't reach out again.
|
||||
ASSERT_TRUE (system.nodes[0]->network.reachout (endpoint1));
|
||||
ASSERT_TRUE (node1.network.reachout (endpoint1));
|
||||
// Make sure we don't purge new items
|
||||
system.nodes[0]->network.cleanup (std::chrono::steady_clock::now () - std::chrono::seconds (10));
|
||||
ASSERT_TRUE (system.nodes[0]->network.reachout (endpoint1));
|
||||
node1.network.cleanup (std::chrono::steady_clock::now () - std::chrono::seconds (10));
|
||||
ASSERT_TRUE (node1.network.reachout (endpoint1));
|
||||
// Make sure we purge old items
|
||||
system.nodes[0]->network.cleanup (std::chrono::steady_clock::now () + std::chrono::seconds (10));
|
||||
ASSERT_FALSE (system.nodes[0]->network.reachout (endpoint1));
|
||||
node1.network.cleanup (std::chrono::steady_clock::now () + std::chrono::seconds (10));
|
||||
ASSERT_FALSE (node1.network.reachout (endpoint1));
|
||||
}
|
||||
|
||||
TEST (peer_container, depeer)
|
||||
|
|
|
@ -175,21 +175,22 @@ TEST (wallet, insufficient_spend_one)
|
|||
TEST (wallet, spend_all_one)
|
||||
{
|
||||
nano::system system (1);
|
||||
nano::block_hash latest1 (system.nodes[0]->latest (nano::test_genesis_key.pub));
|
||||
auto & node1 (*system.nodes[0]);
|
||||
nano::block_hash latest1 (node1.latest (nano::test_genesis_key.pub));
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
nano::keypair key2;
|
||||
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, std::numeric_limits<nano::uint128_t>::max ()));
|
||||
nano::account_info info2;
|
||||
{
|
||||
auto transaction (system.nodes[0]->store.tx_begin_read ());
|
||||
system.nodes[0]->store.account_get (transaction, nano::test_genesis_key.pub, info2);
|
||||
auto transaction (node1.store.tx_begin_read ());
|
||||
node1.store.account_get (transaction, nano::test_genesis_key.pub, info2);
|
||||
ASSERT_NE (latest1, info2.head);
|
||||
auto block (system.nodes[0]->store.block_get (transaction, info2.head));
|
||||
auto block (node1.store.block_get (transaction, info2.head));
|
||||
ASSERT_NE (nullptr, block);
|
||||
ASSERT_EQ (latest1, block->previous ());
|
||||
}
|
||||
ASSERT_TRUE (info2.balance.is_zero ());
|
||||
ASSERT_EQ (0, system.nodes[0]->balance (nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (0, node1.balance (nano::test_genesis_key.pub));
|
||||
}
|
||||
|
||||
TEST (wallet, send_async)
|
||||
|
@ -213,7 +214,8 @@ TEST (wallet, send_async)
|
|||
TEST (wallet, spend)
|
||||
{
|
||||
nano::system system (1);
|
||||
nano::block_hash latest1 (system.nodes[0]->latest (nano::test_genesis_key.pub));
|
||||
auto & node1 (*system.nodes[0]);
|
||||
nano::block_hash latest1 (node1.latest (nano::test_genesis_key.pub));
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
nano::keypair key2;
|
||||
// Sending from empty accounts should always be an error. Accounts need to be opened with an open block, not a send block.
|
||||
|
@ -221,15 +223,15 @@ TEST (wallet, spend)
|
|||
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, std::numeric_limits<nano::uint128_t>::max ()));
|
||||
nano::account_info info2;
|
||||
{
|
||||
auto transaction (system.nodes[0]->store.tx_begin_read ());
|
||||
system.nodes[0]->store.account_get (transaction, nano::test_genesis_key.pub, info2);
|
||||
auto transaction (node1.store.tx_begin_read ());
|
||||
node1.store.account_get (transaction, nano::test_genesis_key.pub, info2);
|
||||
ASSERT_NE (latest1, info2.head);
|
||||
auto block (system.nodes[0]->store.block_get (transaction, info2.head));
|
||||
auto block (node1.store.block_get (transaction, info2.head));
|
||||
ASSERT_NE (nullptr, block);
|
||||
ASSERT_EQ (latest1, block->previous ());
|
||||
}
|
||||
ASSERT_TRUE (info2.balance.is_zero ());
|
||||
ASSERT_EQ (0, system.nodes[0]->balance (nano::test_genesis_key.pub));
|
||||
ASSERT_EQ (0, node1.balance (nano::test_genesis_key.pub));
|
||||
}
|
||||
|
||||
TEST (wallet, change)
|
||||
|
@ -656,20 +658,21 @@ TEST (wallet, work)
|
|||
TEST (wallet, work_generate)
|
||||
{
|
||||
nano::system system (1);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
auto wallet (system.wallet (0));
|
||||
nano::uint128_t amount1 (system.nodes[0]->balance (nano::test_genesis_key.pub));
|
||||
nano::uint128_t amount1 (node1.balance (nano::test_genesis_key.pub));
|
||||
uint64_t work1;
|
||||
wallet->insert_adhoc (nano::test_genesis_key.prv);
|
||||
nano::account account1;
|
||||
{
|
||||
auto transaction (system.nodes[0]->wallets.tx_begin_read ());
|
||||
auto transaction (node1.wallets.tx_begin_read ());
|
||||
account1 = system.account (transaction, 0);
|
||||
}
|
||||
nano::keypair key;
|
||||
wallet->send_action (nano::test_genesis_key.pub, key.pub, 100);
|
||||
system.deadline_set (10s);
|
||||
auto transaction (system.nodes[0]->store.tx_begin_read ());
|
||||
while (system.nodes[0]->ledger.account_balance (transaction, nano::test_genesis_key.pub) == amount1)
|
||||
auto transaction (node1.store.tx_begin_read ());
|
||||
while (node1.ledger.account_balance (transaction, nano::test_genesis_key.pub) == amount1)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
|
@ -678,9 +681,9 @@ TEST (wallet, work_generate)
|
|||
while (again)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
auto block_transaction (system.nodes[0]->store.tx_begin_read ());
|
||||
auto block_transaction (node1.store.tx_begin_read ());
|
||||
auto transaction (system.wallet (0)->wallets.tx_begin_read ());
|
||||
again = wallet->store.work_get (transaction, account1, work1) || nano::work_validate (system.nodes[0]->ledger.latest_root (block_transaction, account1), work1);
|
||||
again = wallet->store.work_get (transaction, account1, work1) || nano::work_validate (node1.ledger.latest_root (block_transaction, account1), work1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -153,22 +153,23 @@ TEST (wallets, DISABLED_wallet_create_max)
|
|||
TEST (wallets, reload)
|
||||
{
|
||||
nano::system system (1);
|
||||
auto & node1 (*system.nodes[0]);
|
||||
nano::wallet_id one (1);
|
||||
bool error (false);
|
||||
ASSERT_FALSE (error);
|
||||
ASSERT_EQ (1, system.nodes[0]->wallets.items.size ());
|
||||
ASSERT_EQ (1, node1.wallets.items.size ());
|
||||
{
|
||||
nano::lock_guard<std::mutex> lock_wallet (system.nodes[0]->wallets.mutex);
|
||||
nano::inactive_node node (system.nodes[0]->application_path, nano::get_available_port ());
|
||||
nano::lock_guard<std::mutex> lock_wallet (node1.wallets.mutex);
|
||||
nano::inactive_node node (node1.application_path, nano::get_available_port ());
|
||||
auto wallet (node.node->wallets.create (one));
|
||||
ASSERT_NE (wallet, nullptr);
|
||||
}
|
||||
system.deadline_set (5s);
|
||||
while (system.nodes[0]->wallets.open (one) == nullptr)
|
||||
while (node1.wallets.open (one) == nullptr)
|
||||
{
|
||||
system.poll ();
|
||||
}
|
||||
ASSERT_EQ (2, system.nodes[0]->wallets.items.size ());
|
||||
ASSERT_EQ (2, node1.wallets.items.size ());
|
||||
}
|
||||
|
||||
TEST (wallets, vote_minimum)
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue