Electroneum
Loading...
Searching...
No Matches
output_distribution.cpp File Reference
#include "gtest/gtest.h"
#include "misc_log_ex.h"
#include "rpc/rpc_handler.h"
#include "blockchain_db/blockchain_db.h"
#include "cryptonote_core/cryptonote_core.h"
#include "cryptonote_core/tx_pool.h"
#include "cryptonote_core/blockchain.h"
#include "blockchain_db/testdb.h"
Include dependency graph for output_distribution.cpp:

Go to the source code of this file.

Functions

bool get_output_distribution (uint64_t amount, uint64_t from, uint64_t to, uint64_t &start_height, std::vector< uint64_t > &distribution, uint64_t &base)
crypto::hash get_block_hash (uint64_t height)
 TEST (output_distribution, extend)
 TEST (output_distribution, one)
 TEST (output_distribution, full_cumulative)
 TEST (output_distribution, full_noncumulative)
 TEST (output_distribution, part_cumulative)
 TEST (output_distribution, part_noncumulative)

Function Documentation

◆ get_block_hash()

crypto::hash get_block_hash ( uint64_t height)

Definition at line 94 of file output_distribution.cpp.

95{
97 *((uint64_t*)&hash) = height;
98 return hash;
99}
uint64_t height
POD_CLASS hash
Definition hash.h:50
unsigned __int64 uint64_t
Definition stdint.h:136
Here is the caller graph for this function:

◆ get_output_distribution()

bool get_output_distribution ( uint64_t amount,
uint64_t from,
uint64_t to,
uint64_t & start_height,
std::vector< uint64_t > & distribution,
uint64_t & base )

Definition at line 77 of file output_distribution.cpp.

78{
79 std::unique_ptr<cryptonote::Blockchain> bc;
81 bc.reset(new cryptonote::Blockchain(txpool));
82 struct get_test_options {
83 const std::pair<uint8_t, uint64_t> hard_forks[2];
84 const cryptonote::test_options test_options = {
86 };
87 get_test_options():hard_forks{std::make_pair((uint8_t)1, (uint64_t)0), std::make_pair((uint8_t)0, (uint64_t)0)}{}
88 } opts;
89 cryptonote::Blockchain *blockchain = bc.get();
90 bool r = blockchain->init(new TestDB(test_distribution_size), cryptonote::FAKECHAIN, true, &opts.test_options, 0, NULL);
91 return r && bc->get_output_distribution(amount, from, to, start_height, distribution, base);
92}
bool init(BlockchainDB *db, const network_type nettype=MAINNET, bool offline=false, const cryptonote::test_options *test_options=NULL, difficulty_type fixed_difficulty=0, const GetCheckpointsCallback &get_checkpoints=nullptr, bool ignore_bsig=false, bool fallback_to_pow=false)
Initialize the Blockchain state.
Transaction pool, handles transactions which are not part of a block.
Definition tx_pool.h:95
unsigned char uint8_t
Definition stdint.h:124
const std::pair< uint8_t, uint64_t > hard_forks[2]
Definition chaingen.h:698
const cryptonote::test_options test_options
Definition chaingen.h:699
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TEST() [1/6]

TEST ( output_distribution ,
extend  )

Definition at line 101 of file output_distribution.cpp.

102{
103 boost::optional<cryptonote::rpc::output_distribution_data> res;
104
106 ASSERT_TRUE(res != boost::none);
107 ASSERT_EQ(res->distribution.size(), 2);
108 ASSERT_EQ(res->distribution, std::vector<uint64_t>({5, 0}));
109
111 ASSERT_TRUE(res != boost::none);
112 ASSERT_EQ(res->distribution.size(), 2);
113 ASSERT_EQ(res->distribution, std::vector<uint64_t>({55, 55}));
114
116 ASSERT_TRUE(res != boost::none);
117 ASSERT_EQ(res->distribution.size(), 3);
118 ASSERT_EQ(res->distribution, std::vector<uint64_t>({5, 0, 2}));
119
121 ASSERT_TRUE(res != boost::none);
122 ASSERT_EQ(res->distribution.size(), 3);
123 ASSERT_EQ(res->distribution, std::vector<uint64_t>({55, 55, 57}));
124
126 ASSERT_TRUE(res != boost::none);
127 ASSERT_EQ(res->distribution.size(), 4);
128 ASSERT_EQ(res->distribution, std::vector<uint64_t>({5, 0, 2, 3}));
129
131 ASSERT_TRUE(res != boost::none);
132 ASSERT_EQ(res->distribution.size(), 4);
133 ASSERT_EQ(res->distribution, std::vector<uint64_t>({55, 55, 57, 60}));
134}
static boost::optional< output_distribution_data > get_output_distribution(const std::function< bool(uint64_t, uint64_t, uint64_t, uint64_t &, std::vector< uint64_t > &, uint64_t &)> &f, uint64_t amount, uint64_t from_height, uint64_t to_height, const std::function< crypto::hash(uint64_t)> &get_hash, bool cumulative, uint64_t blockchain_height)
#define ASSERT_EQ(val1, val2)
Definition gtest.h:1956
#define ASSERT_TRUE(condition)
Definition gtest.h:1865
const char * res
crypto::hash get_block_hash(uint64_t height)
bool get_output_distribution(uint64_t amount, uint64_t from, uint64_t to, uint64_t &start_height, std::vector< uint64_t > &distribution, uint64_t &base)
Here is the call graph for this function:

◆ TEST() [2/6]

TEST ( output_distribution ,
full_cumulative  )

Definition at line 146 of file output_distribution.cpp.

147{
148 boost::optional<cryptonote::rpc::output_distribution_data> res;
149
151 ASSERT_TRUE(res != boost::none);
152 ASSERT_EQ(res->distribution.size(), 32);
153 ASSERT_EQ(res->distribution.back(), 60);
154}
Here is the call graph for this function:

◆ TEST() [3/6]

TEST ( output_distribution ,
full_noncumulative  )

Definition at line 156 of file output_distribution.cpp.

157{
158 boost::optional<cryptonote::rpc::output_distribution_data> res;
159
161 ASSERT_TRUE(res != boost::none);
162 ASSERT_EQ(res->distribution.size(), 32);
163 for (size_t i = 0; i < 32; ++i)
164 ASSERT_EQ(res->distribution[i], test_distribution[i]);
165}
Here is the call graph for this function:

◆ TEST() [4/6]

TEST ( output_distribution ,
one  )

Definition at line 136 of file output_distribution.cpp.

137{
138 boost::optional<cryptonote::rpc::output_distribution_data> res;
139
141 ASSERT_TRUE(res != boost::none);
142 ASSERT_EQ(res->distribution.size(), 1);
143 ASSERT_EQ(res->distribution.back(), 0);
144}
Here is the call graph for this function:

◆ TEST() [5/6]

TEST ( output_distribution ,
part_cumulative  )

Definition at line 167 of file output_distribution.cpp.

168{
169 boost::optional<cryptonote::rpc::output_distribution_data> res;
170
172 ASSERT_TRUE(res != boost::none);
173 ASSERT_EQ(res->distribution.size(), 5);
174 ASSERT_EQ(res->distribution, std::vector<uint64_t>({0, 1, 6, 7, 11}));
175}
Here is the call graph for this function:

◆ TEST() [6/6]

TEST ( output_distribution ,
part_noncumulative  )

Definition at line 177 of file output_distribution.cpp.

178{
179 boost::optional<cryptonote::rpc::output_distribution_data> res;
180
182 ASSERT_TRUE(res != boost::none);
183 ASSERT_EQ(res->distribution.size(), 5);
184 ASSERT_EQ(res->distribution, std::vector<uint64_t>({0, 1, 5, 1, 4}));
185}
Here is the call graph for this function: