Skip to content

Commit

Permalink
Last work backup
Browse files Browse the repository at this point in the history
  • Loading branch information
theohax committed Mar 22, 2022
1 parent e0f82b2 commit 29cbd83
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1699,7 +1699,7 @@ TEST (node, unconfirmed_send)

nano::keypair key2{};
nano::node_config node_config2{nano::get_available_port (), system.logging};
node_config2.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled;
// node_config2.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled;

auto & node2 = *system.add_node(node_config2, node_flags);
auto wallet2 = system.wallet (1);
Expand All @@ -1711,23 +1711,16 @@ TEST (node, unconfirmed_send)
std::cout << "send1 = " << send1->hash().to_string() << std::endl;
ASSERT_TIMELY (5s, node1.block_confirmed (send1->hash ()));
ASSERT_TIMELY (5s, node2.block_confirmed (send1->hash ()));
// expect the balance on node2 to have increased, but actually this takes into
// calculation even non-confirmed blocks (which is the case for our receive block)
ASSERT_TIMELY (5s, node2.balance (key2.pub) == 2 * nano::Mxrb_ratio);

// the receive1 (auto-receive) is there (in node2), but it is not confirmed
// wait until receive1 (auto-receive created by wallet) is confirmed
ASSERT_TIMELY(5s, node2.ledger.cache.cemented_count == 3);

// create send2 to send from node2 to node1 and save it to node2's ledger (node1 does not hear about it)
auto const latest = node2.latest (key2.pub);
std::cout << "receive1 (auto) = " << latest.to_string() << std::endl;
ASSERT_FALSE (node2.block_confirmed (latest));
ASSERT_FALSE (node1.block_confirmed (latest));
ASSERT_EQ(node2.ledger.cache.cemented_count, 2);

// so confirm receive1 by help of node1
node2.process_active (node2.block(latest));
ASSERT_TIMELY (5s, node1.block_confirmed (latest));
ASSERT_TIMELY (5s, node2.block_confirmed (latest));
ASSERT_EQ(node2.ledger.cache.cemented_count, 3);

// send from node2 to node1, but node2.process this block, so nobody else learns about it nor confirms it
auto send2 = nano::state_block_builder{}
auto send2 = nano::state_block_builder{}
.make_block ()
.account (key2.pub)
.previous (latest)
Expand All @@ -1742,17 +1735,27 @@ TEST (node, unconfirmed_send)
ASSERT_FALSE (node2.block_confirmed (send2->hash ()));
ASSERT_FALSE (node1.block_confirmed (send2->hash ()));

// expect these to fail
ASSERT_TIMELY (5s, node1.block_confirmed (send2->hash ()));
auto send3 = nano::state_block_builder{}
.make_block ()
.account (key2.pub)
.previous (send2->hash())
.representative (nano::dev::genesis_key.pub)
.balance (0)
.link (nano::dev::genesis->account ())
.sign (key2.prv, key2.pub)
.work (*system.work.generate (send2->hash()))
.build_shared ();
std::cout << "send3 = " << send3->hash().to_string() << std::endl;
node2.process_active (send3);
ASSERT_TIMELY (5s, node2.block_confirmed (send2->hash ()));
ASSERT_TIMELY (5s, node1.block_confirmed (send2->hash ()));
ASSERT_TIMELY (5s, node2.block_confirmed (send3->hash ()));
ASSERT_TIMELY (5s, node1.block_confirmed (send3->hash ()));
ASSERT_TIMELY (5s, node2.ledger.cache.cemented_count == 7);
ASSERT_TIMELY (5s, node1.balance (nano::dev::genesis->account ()) == nano::dev::constants.genesis_amount);

/*
// finally, send the remaining unit back as well, expect that node1 ends up with the balance it had initially
//
auto send3 = wallet2->send_action (key2.pub, nano::dev::genesis->account (), nano::Mxrb_ratio);
ASSERT_TIMELY (5s, node2.block_confirmed (send3->hash ()));
ASSERT_TIMELY (5s, node1.block_confirmed (send3->hash ()));
ASSERT_TIMELY (10s, node1.balance (nano::dev::genesis->account ()) == nano::dev::constants.genesis_amount);
auto send3 = wallet2->send_action (key2.pub, nano::dev::genesis->account (), nano::Mxrb_ratio);
*/
}

Expand Down

0 comments on commit 29cbd83

Please sign in to comment.