diff --git a/nano/core_test/bootstrap_server.cpp b/nano/core_test/bootstrap_server.cpp index 45e493807..391c90eb1 100644 --- a/nano/core_test/bootstrap_server.cpp +++ b/nano/core_test/bootstrap_server.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include diff --git a/nano/core_test/fork_cache.cpp b/nano/core_test/fork_cache.cpp index b11591f2f..91c7d33f6 100644 --- a/nano/core_test/fork_cache.cpp +++ b/nano/core_test/fork_cache.cpp @@ -1,4 +1,5 @@ #include +#include #include #include diff --git a/nano/core_test/message.cpp b/nano/core_test/message.cpp index 12ff989af..3faa468da 100644 --- a/nano/core_test/message.cpp +++ b/nano/core_test/message.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include diff --git a/nano/core_test/message_deserializer.cpp b/nano/core_test/message_deserializer.cpp index 7d65d6528..86cfadc87 100644 --- a/nano/core_test/message_deserializer.cpp +++ b/nano/core_test/message_deserializer.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include diff --git a/nano/core_test/vote_cache.cpp b/nano/core_test/vote_cache.cpp index 916179b6e..348a5b809 100644 --- a/nano/core_test/vote_cache.cpp +++ b/nano/core_test/vote_cache.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include diff --git a/nano/test_common/CMakeLists.txt b/nano/test_common/CMakeLists.txt index 56d6a53a4..35d655cb7 100644 --- a/nano/test_common/CMakeLists.txt +++ b/nano/test_common/CMakeLists.txt @@ -8,6 +8,8 @@ add_library( make_store.cpp network.hpp network.cpp + random.hpp + random.cpp rate_observer.cpp rate_observer.hpp system.hpp diff --git a/nano/test_common/random.cpp b/nano/test_common/random.cpp new file mode 100644 index 000000000..38b1ef856 --- /dev/null +++ b/nano/test_common/random.cpp @@ -0,0 +1,46 @@ +#include +#include + +nano::hash_or_account nano::test::random_hash_or_account () +{ + nano::hash_or_account random_hash; + nano::random_pool::generate_block (random_hash.bytes.data (), random_hash.bytes.size ()); + return random_hash; +} + +nano::block_hash nano::test::random_hash () +{ + return nano::test::random_hash_or_account ().as_block_hash (); +} + +nano::account nano::test::random_account () +{ + return nano::test::random_hash_or_account ().as_account (); +} + +nano::qualified_root nano::test::random_qualified_root () +{ + return { nano::test::random_hash (), nano::test::random_hash () }; +} + +nano::amount nano::test::random_amount () +{ + nano::amount result; + nano::random_pool::generate_block (result.bytes.data (), result.bytes.size ()); + return result; +} + +std::shared_ptr nano::test::random_block () +{ + nano::keypair key; + auto block = std::make_shared ( + nano::test::random_account (), + nano::test::random_hash (), + nano::test::random_account (), + nano::test::random_amount (), + nano::test::random_hash (), + key.prv, + key.pub, + 0); + return block; +} \ No newline at end of file diff --git a/nano/test_common/random.hpp b/nano/test_common/random.hpp new file mode 100644 index 000000000..a1d41c8ee --- /dev/null +++ b/nano/test_common/random.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include +#include + +namespace nano::test +{ +/* + * Random generators + */ +nano::hash_or_account random_hash_or_account (); +nano::block_hash random_hash (); +nano::account random_account (); +nano::qualified_root random_qualified_root (); +nano::amount random_amount (); +std::shared_ptr random_block (); +} \ No newline at end of file diff --git a/nano/test_common/testutil.cpp b/nano/test_common/testutil.cpp index 6e5a33e1c..fd476b627 100644 --- a/nano/test_common/testutil.cpp +++ b/nano/test_common/testutil.cpp @@ -50,23 +50,6 @@ void nano::test::wait_peer_connections (nano::test::system & system_a) wait_peer_count (false); } -nano::hash_or_account nano::test::random_hash_or_account () -{ - nano::hash_or_account random_hash; - nano::random_pool::generate_block (random_hash.bytes.data (), random_hash.bytes.size ()); - return random_hash; -} - -nano::block_hash nano::test::random_hash () -{ - return nano::test::random_hash_or_account ().as_block_hash (); -} - -nano::account nano::test::random_account () -{ - return nano::test::random_hash_or_account ().as_account (); -} - bool nano::test::process (nano::node & node, std::vector> blocks) { auto const transaction = node.ledger.tx_begin_write (); diff --git a/nano/test_common/testutil.hpp b/nano/test_common/testutil.hpp index b0e162f59..7dc58f0b1 100644 --- a/nano/test_common/testutil.hpp +++ b/nano/test_common/testutil.hpp @@ -265,19 +265,6 @@ namespace test void wait_peer_connections (nano::test::system &); - /** - * Generate a random block hash - */ - nano::hash_or_account random_hash_or_account (); - /** - * Generate a random block hash - */ - nano::block_hash random_hash (); - /** - * Generate a random block hash - */ - nano::account random_account (); - /** Convenience function to call `node::process` function for multiple blocks at once. @return true if all blocks were successfully processed and inserted into ledger