Introduce nano::test::print_all_receivable_entries()

This prints all entries in the pending table.
Intended to be used for learning and unit test debugging.

Also intoduce ostream operator << for pending_key and pending_info.
This commit is contained in:
Dimitrios Siganos 2024-04-12 23:45:57 +09:00
commit 7c106bc74a
3 changed files with 31 additions and 0 deletions

View file

@ -30,6 +30,13 @@ public:
nano::account source{};
nano::amount amount{ 0 };
nano::epoch epoch{ nano::epoch::epoch_0 };
friend std::ostream & operator<< (std::ostream & os, const nano::pending_info & info)
{
const int epoch = nano::normalized_epoch (info.epoch);
os << "Source: " << info.source << ", Amount: " << info.amount.to_string_dec () << " Epoch: " << epoch;
return os;
}
};
class pending_key final
{
@ -42,6 +49,12 @@ public:
nano::account const & key () const;
nano::account account{};
nano::block_hash hash{ 0 };
friend std::ostream & operator<< (std::ostream & os, const nano::pending_key & key)
{
os << "Account: " << key.account << ", Hash: " << key.hash;
return os;
}
};
// This class iterates receivable enttries for an account
class receivable_iterator

View file

@ -7,6 +7,7 @@
#include <nano/node/scheduler/priority.hpp>
#include <nano/node/transport/fake.hpp>
#include <nano/secure/ledger.hpp>
#include <nano/secure/pending_info.hpp>
#include <nano/store/block.hpp>
#include <nano/test_common/system.hpp>
#include <nano/test_common/testutil.hpp>
@ -300,6 +301,18 @@ uint64_t nano::test::account_height (nano::node const & node, nano::account cons
return height_info.height;
}
void nano::test::print_all_receivable_entries (const nano::store::component & store)
{
std::cout << "Printing all receivable entries:\n";
auto const tx = store.tx_begin_read ();
auto const end = store.pending.end ();
for (auto i = store.pending.begin (tx); i != end; ++i)
{
std::cout << "Key: " << i->first << std::endl;
std::cout << "Info: " << i->second << std::endl;
}
}
void nano::test::print_all_account_info (const nano::ledger & ledger)
{
std::cout << "Printing all account info:\n";

View file

@ -418,6 +418,11 @@ namespace test
*/
uint64_t account_height (nano::node const & node, nano::account const & acc);
/**
* \brief Debugging function to print all entries in the pending table. Intended to be used to debug unit tests.
*/
void print_all_receivable_entries (const nano::store::component & store);
/**
* \brief Debugging function to print all accounts in a ledger. Intended to be used to debug unit tests.
*/