Skip to content

Commit

Permalink
USE ADD NODE
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Apr 2, 2024
1 parent a0b4e14 commit 9517707
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 103 deletions.
20 changes: 10 additions & 10 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ TEST (active_transactions, keep_local)

TEST (inactive_votes_cache, basic)
{
nano::test::system system (1);
auto & node = *system.nodes[0];
nano::test::system system;
auto & node = *system.add_node ();
nano::block_hash latest (node.latest (nano::dev::genesis_key.pub));
nano::keypair key;
auto send = nano::send_block_builder ()
Expand All @@ -262,8 +262,8 @@ TEST (inactive_votes_cache, basic)
*/
TEST (inactive_votes_cache, non_final)
{
nano::test::system system (1);
auto & node = *system.nodes[0];
nano::test::system system;
auto & node = *system.add_node ();

auto send = nano::send_block_builder ()
.previous (nano::dev::genesis->hash ())
Expand All @@ -288,8 +288,8 @@ TEST (inactive_votes_cache, non_final)

TEST (inactive_votes_cache, fork)
{
nano::test::system system{ 1 };
auto & node = *system.nodes[0];
nano::test::system system;
auto & node = *system.add_node ();

auto const latest = node.latest (nano::dev::genesis_key.pub);
nano::keypair key{};
Expand Down Expand Up @@ -1033,8 +1033,8 @@ TEST (active_transactions, confirmation_consistency)

TEST (active_transactions, confirm_new)
{
nano::test::system system (1);
auto & node1 = *system.nodes[0];
nano::test::system system;
auto & node1 = *system.add_node ();
auto send = nano::send_block_builder ()
.previous (nano::dev::genesis->hash ())
.destination (nano::public_key ())
Expand Down Expand Up @@ -1258,8 +1258,8 @@ TEST (active_transactions, activate_inactive)

TEST (active_transactions, list_active)
{
nano::test::system system (1);
auto & node = *system.nodes[0];
nano::test::system system;
auto & node = *system.add_node ();

nano::keypair key;
nano::state_block_builder builder;
Expand Down
118 changes: 66 additions & 52 deletions nano/core_test/bootstrap.cpp

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions nano/core_test/bootstrap_ascending.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ TEST (account_sets, saturate_priority)
TEST (bootstrap_ascending, account_base)
{
nano::node_flags flags;
nano::test::system system{ 1, nano::transport::transport_type::tcp, flags };
auto & node0 = *system.nodes[0];
nano::test::system system;
auto & node0 = *system.add_node (flags);
nano::state_block_builder builder;
auto send1 = builder.make_block ()
.account (nano::dev::genesis_key.pub)
Expand All @@ -184,8 +184,8 @@ TEST (bootstrap_ascending, account_base)
TEST (bootstrap_ascending, account_inductive)
{
nano::node_flags flags;
nano::test::system system{ 1, nano::transport::transport_type::tcp, flags };
auto & node0 = *system.nodes[0];
nano::test::system system;
auto & node0 = *system.add_node (flags);
nano::state_block_builder builder;
auto send1 = builder.make_block ()
.account (nano::dev::genesis_key.pub)
Expand Down Expand Up @@ -221,8 +221,8 @@ TEST (bootstrap_ascending, trace_base)
{
nano::node_flags flags;
flags.disable_legacy_bootstrap = true;
nano::test::system system{ 1, nano::transport::transport_type::tcp, flags };
auto & node0 = *system.nodes[0];
nano::test::system system;
auto & node0 = *system.add_node (flags);
nano::keypair key;
nano::state_block_builder builder;
auto send1 = builder.make_block ()
Expand Down
10 changes: 5 additions & 5 deletions nano/core_test/conflicts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ using namespace std::chrono_literals;

TEST (conflicts, start_stop)
{
nano::test::system system (1);
auto & node1 (*system.nodes[0]);
nano::test::system system;
auto & node1 = *system.add_node ();
nano::keypair key1;
nano::block_builder builder;
auto send1 = builder
Expand All @@ -41,8 +41,8 @@ TEST (conflicts, start_stop)

TEST (conflicts, add_existing)
{
nano::test::system system{ 1 };
auto & node1 = *system.nodes[0];
nano::test::system system;
auto & node1 = *system.add_node ();
nano::keypair key1;

// create a send block to send all of the nano supply to key1
Expand Down Expand Up @@ -91,7 +91,7 @@ TEST (conflicts, add_existing)

TEST (conflicts, add_two)
{
nano::test::system system{};
nano::test::system system;
auto const & node = system.add_node ();
nano::keypair key1, key2, key3;
auto gk = nano::dev::genesis_key;
Expand Down
15 changes: 8 additions & 7 deletions nano/core_test/election.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,25 @@ using namespace std::chrono_literals;

TEST (election, construction)
{
nano::test::system system (1);
auto & node = *system.nodes[0];
nano::test::system system;
auto & node = *system.add_node ();
auto election = std::make_shared<nano::election> (
node, nano::dev::genesis, [] (auto const &) {}, [] (auto const &) {}, nano::election_behavior::normal);
}

TEST (election, behavior)
{
nano::test::system system (1);
auto chain = nano::test::setup_chain (system, *system.nodes[0], 1, nano::dev::genesis_key, false);
auto election = nano::test::start_election (system, *system.nodes[0], chain[0]->hash ());
nano::test::system system;
auto & node = *system.add_node ();
auto chain = nano::test::setup_chain (system, node, 1, nano::dev::genesis_key, false);
auto election = nano::test::start_election (system, node, chain[0]->hash ());
ASSERT_NE (nullptr, election);
ASSERT_EQ (nano::election_behavior::normal, election->behavior ());
}

TEST (election, quorum_minimum_flip_success)
{
nano::test::system system{};
nano::test::system system;

nano::node_config node_config = system.default_config ();
node_config.online_weight_minimum = nano::dev::constants.genesis_amount;
Expand Down Expand Up @@ -273,7 +274,7 @@ TEST (election, quorum_minimum_update_weight_before_quorum_checks)

TEST (election, continuous_voting)
{
nano::test::system system{};
nano::test::system system;
auto & node1 = *system.add_node ();
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);

Expand Down
22 changes: 12 additions & 10 deletions nano/core_test/election_scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ using namespace std::chrono_literals;

TEST (election_scheduler, construction)
{
nano::test::system system{ 1 };
nano::test::system system;
}

TEST (election_scheduler, activate_one_timely)
{
nano::test::system system{ 1 };
nano::test::system system;
auto node = system.add_node ();
nano::state_block_builder builder;
auto send1 = builder.make_block ()
.account (nano::dev::genesis_key.pub)
Expand All @@ -31,14 +32,15 @@ TEST (election_scheduler, activate_one_timely)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (nano::dev::genesis->hash ()))
.build ();
system.nodes[0]->ledger.process (system.nodes[0]->store.tx_begin_write (), send1);
system.nodes[0]->scheduler.priority.activate (nano::dev::genesis_key.pub, system.nodes[0]->store.tx_begin_read ());
ASSERT_TIMELY (5s, system.nodes[0]->active.election (send1->qualified_root ()));
node->ledger.process (node->store.tx_begin_write (), send1);
node->scheduler.priority.activate (nano::dev::genesis_key.pub, node->store.tx_begin_read ());
ASSERT_TIMELY (5s, node->active.election (send1->qualified_root ()));
}

TEST (election_scheduler, activate_one_flush)
{
nano::test::system system{ 1 };
nano::test::system system;
auto node = system.add_node ();
nano::state_block_builder builder;
auto send1 = builder.make_block ()
.account (nano::dev::genesis_key.pub)
Expand All @@ -49,9 +51,9 @@ TEST (election_scheduler, activate_one_flush)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (nano::dev::genesis->hash ()))
.build ();
system.nodes[0]->ledger.process (system.nodes[0]->store.tx_begin_write (), send1);
system.nodes[0]->scheduler.priority.activate (nano::dev::genesis_key.pub, system.nodes[0]->store.tx_begin_read ());
ASSERT_TIMELY (5s, system.nodes[0]->active.election (send1->qualified_root ()));
node->ledger.process (node->store.tx_begin_write (), send1);
node->scheduler.priority.activate (nano::dev::genesis_key.pub, node->store.tx_begin_read ());
ASSERT_TIMELY (5s, node->active.election (send1->qualified_root ()));
}

/**
Expand All @@ -71,7 +73,7 @@ TEST (election_scheduler, activate_one_flush)
*/
TEST (election_scheduler, no_vacancy)
{
nano::test::system system{};
nano::test::system system;

nano::node_config config = system.default_config ();
config.active_elections_size = 1;
Expand Down
10 changes: 0 additions & 10 deletions nano/test_common/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@ nano::test::system::system () :
}
}

nano::test::system::system (uint16_t count_a, nano::transport::transport_type type_a, nano::node_flags flags_a) :
system ()
{
nodes.reserve (count_a);
for (uint16_t i (0); i < count_a; ++i)
{
add_node (default_config (), flags_a, type_a);
}
}

nano::test::system::~system ()
{
// Only stop system in destructor to avoid confusing and random bugs when debugging assertions that hit deadline expired condition
Expand Down
5 changes: 2 additions & 3 deletions nano/test_common/system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class system final
{
public:
system ();
system (uint16_t, nano::transport::transport_type = nano::transport::transport_type::tcp, nano::node_flags = nano::node_flags ());
~system ();

void stop ();
Expand Down Expand Up @@ -60,8 +59,8 @@ class system final
* Convenience function to get a reference to a node at given index. Does bound checking.
*/
nano::node & node (std::size_t index) const;
std::shared_ptr<nano::node> add_node (nano::node_flags = nano::node_flags (), nano::transport::transport_type = nano::transport::transport_type::tcp);
std::shared_ptr<nano::node> add_node (nano::node_config const &, nano::node_flags = nano::node_flags (), nano::transport::transport_type = nano::transport::transport_type::tcp, std::optional<nano::keypair> const & rep = std::nullopt);
std::shared_ptr<nano::node> add_node (nano::node_flags = {}, nano::transport::transport_type = nano::transport::transport_type::tcp);
std::shared_ptr<nano::node> add_node (nano::node_config const &, nano::node_flags = {}, nano::transport::transport_type = nano::transport::transport_type::tcp, std::optional<nano::keypair> const & rep = std::nullopt);

// Make an independent node that uses system resources but is not part of the system node list and does not automatically connect to other nodes
std::shared_ptr<nano::node> make_disconnected_node (std::optional<nano::node_config> opt_node_config = std::nullopt, nano::node_flags = nano::node_flags ());
Expand Down

0 comments on commit 9517707

Please sign in to comment.