fixed unit tests; fixed core tests; fixed performance tests; added fix to prevent change in block reward split (thanks Akil); added prelim code for spend authority proof - not complete / working
This commit is contained in:
@@ -84,7 +84,7 @@ TEST(AddressFromTXT, Failure)
|
||||
|
||||
TEST(AddressFromURL, Success)
|
||||
{
|
||||
const std::string addr = FULMO_DONATION_ADDR;
|
||||
const std::string addr = SALVIUM_DONATION_ADDR;
|
||||
|
||||
bool dnssec_result = false;
|
||||
|
||||
|
||||
@@ -274,8 +274,9 @@ TYPED_TEST(BlockchainDBTest, AddBlock)
|
||||
// no blocks have been added yet (because genesis has no parent).
|
||||
//ASSERT_THROW(this->m_db->add_block(this->m_blocks[1], t_sizes[1], t_sizes[1], t_diffs[1], t_coins[1], this->m_txs[1]), BLOCK_PARENT_DNE);
|
||||
|
||||
ASSERT_NO_THROW(this->m_db->add_block(this->m_blocks[0], t_sizes[0], t_sizes[0], t_diffs[0], t_coins[0], this->m_txs[0]));
|
||||
ASSERT_NO_THROW(this->m_db->add_block(this->m_blocks[1], t_sizes[1], t_sizes[1], t_diffs[1], t_coins[1], this->m_txs[1]));
|
||||
cryptonote::yield_block_info ybi;
|
||||
ASSERT_NO_THROW(this->m_db->add_block(this->m_blocks[0], t_sizes[0], t_sizes[0], t_diffs[0], t_coins[0], this->m_txs[0], cryptonote::FAKECHAIN, ybi));
|
||||
ASSERT_NO_THROW(this->m_db->add_block(this->m_blocks[1], t_sizes[1], t_sizes[1], t_diffs[1], t_coins[1], this->m_txs[1], cryptonote::FAKECHAIN, ybi));
|
||||
|
||||
block b;
|
||||
ASSERT_TRUE(this->m_db->block_exists(get_block_hash(this->m_blocks[0].first)));
|
||||
@@ -288,7 +289,7 @@ TYPED_TEST(BlockchainDBTest, AddBlock)
|
||||
ASSERT_TRUE(compare_blocks(this->m_blocks[0].first, b));
|
||||
|
||||
// assert that we can't add the same block twice
|
||||
ASSERT_THROW(this->m_db->add_block(this->m_blocks[0], t_sizes[0], t_sizes[0], t_diffs[0], t_coins[0], this->m_txs[0]), TX_EXISTS);
|
||||
ASSERT_THROW(this->m_db->add_block(this->m_blocks[0], t_sizes[0], t_sizes[0], t_diffs[0], t_coins[0], this->m_txs[0], cryptonote::FAKECHAIN, ybi), TX_EXISTS);
|
||||
|
||||
for (auto& h : this->m_blocks[0].first.tx_hashes)
|
||||
{
|
||||
@@ -314,14 +315,15 @@ TYPED_TEST(BlockchainDBTest, RetrieveBlockData)
|
||||
|
||||
db_wtxn_guard guard(this->m_db);
|
||||
|
||||
ASSERT_NO_THROW(this->m_db->add_block(this->m_blocks[0], t_sizes[0], t_sizes[0], t_diffs[0], t_coins[0], this->m_txs[0]));
|
||||
cryptonote::yield_block_info ybi;
|
||||
ASSERT_NO_THROW(this->m_db->add_block(this->m_blocks[0], t_sizes[0], t_sizes[0], t_diffs[0], t_coins[0], this->m_txs[0], cryptonote::FAKECHAIN, ybi));
|
||||
|
||||
ASSERT_EQ(t_sizes[0], this->m_db->get_block_weight(0));
|
||||
ASSERT_EQ(t_diffs[0], this->m_db->get_block_cumulative_difficulty(0));
|
||||
ASSERT_EQ(t_diffs[0], this->m_db->get_block_difficulty(0));
|
||||
ASSERT_EQ(t_coins[0], this->m_db->get_block_already_generated_coins(0));
|
||||
|
||||
ASSERT_NO_THROW(this->m_db->add_block(this->m_blocks[1], t_sizes[1], t_sizes[1], t_diffs[1], t_coins[1], this->m_txs[1]));
|
||||
ASSERT_NO_THROW(this->m_db->add_block(this->m_blocks[1], t_sizes[1], t_sizes[1], t_diffs[1], t_coins[1], this->m_txs[1], cryptonote::FAKECHAIN, ybi));
|
||||
ASSERT_EQ(t_diffs[1] - t_diffs[0], this->m_db->get_block_difficulty(1));
|
||||
|
||||
ASSERT_HASH_EQ(get_block_hash(this->m_blocks[0].first), this->m_db->get_block_hash_from_height(0));
|
||||
|
||||
@@ -72,10 +72,10 @@ TEST(Crypto, Ostream)
|
||||
EXPECT_TRUE(is_formatted<crypto::hash8>());
|
||||
EXPECT_TRUE(is_formatted<crypto::hash>());
|
||||
EXPECT_TRUE(is_formatted<crypto::public_key>());
|
||||
EXPECT_TRUE(is_formatted<crypto::secret_key>());
|
||||
EXPECT_TRUE(is_formatted<crypto::signature>());
|
||||
EXPECT_TRUE(is_formatted<crypto::key_derivation>());
|
||||
EXPECT_TRUE(is_formatted<crypto::key_image>());
|
||||
EXPECT_TRUE(is_formatted<rct::key>());
|
||||
}
|
||||
|
||||
TEST(Crypto, null_keys)
|
||||
|
||||
@@ -47,14 +47,18 @@ namespace
|
||||
class TestDB: public cryptonote::BaseTestDB {
|
||||
public:
|
||||
virtual uint64_t height() const override { return blocks.size(); }
|
||||
virtual void add_block( const block& blk
|
||||
virtual void add_block( const cryptonote::block& blk
|
||||
, size_t block_weight
|
||||
, uint64_t long_term_block_weight
|
||||
, const difficulty_type& cumulative_difficulty
|
||||
, const cryptonote::difficulty_type& cumulative_difficulty
|
||||
, const uint64_t& coins_generated
|
||||
, uint64_t num_rct_outs
|
||||
, oracle::asset_type_counts& cum_rct_by_asset_type
|
||||
, const crypto::hash& blk_hash
|
||||
, uint64_t slippage_total
|
||||
, uint64_t yield_total
|
||||
, const cryptonote::network_type nettype
|
||||
, cryptonote::yield_block_info& ybi
|
||||
) override {
|
||||
blocks.push_back(blk);
|
||||
}
|
||||
@@ -99,6 +103,7 @@ TEST(major, Only)
|
||||
TestDB db;
|
||||
HardFork hf(db, 1, 0, 0, 0, 1, 0); // no voting
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type;
|
||||
cryptonote::yield_block_info ybi;
|
||||
|
||||
// v h t
|
||||
ASSERT_TRUE(hf.add_fork(1, 0, 0));
|
||||
@@ -109,20 +114,20 @@ TEST(major, Only)
|
||||
ASSERT_FALSE(hf.add(mkblock(0, 2), 0));
|
||||
ASSERT_FALSE(hf.add(mkblock(2, 2), 0));
|
||||
ASSERT_TRUE(hf.add(mkblock(1, 2), 0));
|
||||
db.add_block(mkblock(1, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash());
|
||||
db.add_block(mkblock(1, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, cryptonote::FAKECHAIN, ybi);
|
||||
|
||||
// block height 1, only version 1 is accepted
|
||||
ASSERT_FALSE(hf.add(mkblock(0, 2), 1));
|
||||
ASSERT_FALSE(hf.add(mkblock(2, 2), 1));
|
||||
ASSERT_TRUE(hf.add(mkblock(1, 2), 1));
|
||||
db.add_block(mkblock(1, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash());
|
||||
db.add_block(mkblock(1, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, cryptonote::FAKECHAIN, ybi);
|
||||
|
||||
// block height 2, only version 2 is accepted
|
||||
ASSERT_FALSE(hf.add(mkblock(0, 2), 2));
|
||||
ASSERT_FALSE(hf.add(mkblock(1, 2), 2));
|
||||
ASSERT_FALSE(hf.add(mkblock(3, 2), 2));
|
||||
ASSERT_TRUE(hf.add(mkblock(2, 2), 2));
|
||||
db.add_block(mkblock(2, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash());
|
||||
db.add_block(mkblock(2, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, cryptonote::FAKECHAIN, ybi);
|
||||
}
|
||||
|
||||
TEST(empty_hardforks, Success)
|
||||
@@ -130,6 +135,7 @@ TEST(empty_hardforks, Success)
|
||||
TestDB db;
|
||||
HardFork hf(db);
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type;
|
||||
cryptonote::yield_block_info ybi;
|
||||
|
||||
ASSERT_TRUE(hf.add_fork(1, 0, 0));
|
||||
hf.init();
|
||||
@@ -137,7 +143,7 @@ TEST(empty_hardforks, Success)
|
||||
ASSERT_TRUE(hf.get_state(time(NULL) + 3600*24*400) == HardFork::Ready);
|
||||
|
||||
for (uint64_t h = 0; h <= 10; ++h) {
|
||||
db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash());
|
||||
db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
|
||||
}
|
||||
ASSERT_EQ(hf.get(0), 1);
|
||||
@@ -164,6 +170,7 @@ TEST(check_for_height, Success)
|
||||
TestDB db;
|
||||
HardFork hf(db, 1, 0, 0, 0, 1, 0); // no voting
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type;
|
||||
cryptonote::yield_block_info ybi;
|
||||
|
||||
ASSERT_TRUE(hf.add_fork(1, 0, 0));
|
||||
ASSERT_TRUE(hf.add_fork(2, 5, 1));
|
||||
@@ -172,14 +179,14 @@ TEST(check_for_height, Success)
|
||||
for (uint64_t h = 0; h <= 4; ++h) {
|
||||
ASSERT_TRUE(hf.check_for_height(mkblock(1, 1), h));
|
||||
ASSERT_FALSE(hf.check_for_height(mkblock(2, 2), h)); // block version is too high
|
||||
db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash());
|
||||
db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
|
||||
}
|
||||
|
||||
for (uint64_t h = 5; h <= 10; ++h) {
|
||||
ASSERT_FALSE(hf.check_for_height(mkblock(1, 1), h)); // block version is too low
|
||||
ASSERT_TRUE(hf.check_for_height(mkblock(2, 2), h));
|
||||
db.add_block(mkblock(hf, h, 2), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash());
|
||||
db.add_block(mkblock(hf, h, 2), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
|
||||
}
|
||||
}
|
||||
@@ -189,6 +196,7 @@ TEST(get, next_version)
|
||||
TestDB db;
|
||||
HardFork hf(db);
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type;
|
||||
cryptonote::yield_block_info ybi;
|
||||
|
||||
ASSERT_TRUE(hf.add_fork(1, 0, 0));
|
||||
ASSERT_TRUE(hf.add_fork(2, 5, 1));
|
||||
@@ -197,19 +205,19 @@ TEST(get, next_version)
|
||||
|
||||
for (uint64_t h = 0; h <= 4; ++h) {
|
||||
ASSERT_EQ(2, hf.get_next_version());
|
||||
db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash());
|
||||
db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
|
||||
}
|
||||
|
||||
for (uint64_t h = 5; h <= 9; ++h) {
|
||||
ASSERT_EQ(4, hf.get_next_version());
|
||||
db.add_block(mkblock(hf, h, 2), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash());
|
||||
db.add_block(mkblock(hf, h, 2), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
|
||||
}
|
||||
|
||||
for (uint64_t h = 10; h <= 15; ++h) {
|
||||
ASSERT_EQ(4, hf.get_next_version());
|
||||
db.add_block(mkblock(hf, h, 4), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash());
|
||||
db.add_block(mkblock(hf, h, 4), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
|
||||
}
|
||||
}
|
||||
@@ -243,6 +251,7 @@ TEST(steps_asap, Success)
|
||||
TestDB db;
|
||||
HardFork hf(db, 1,0,1,1,1);
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type;
|
||||
cryptonote::yield_block_info ybi;
|
||||
|
||||
// v h t
|
||||
ASSERT_TRUE(hf.add_fork(1, 0, 0));
|
||||
@@ -252,7 +261,7 @@ TEST(steps_asap, Success)
|
||||
hf.init();
|
||||
|
||||
for (uint64_t h = 0; h < 10; ++h) {
|
||||
db.add_block(mkblock(hf, h, 9), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash());
|
||||
db.add_block(mkblock(hf, h, 9), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
|
||||
}
|
||||
|
||||
@@ -273,6 +282,7 @@ TEST(steps_1, Success)
|
||||
TestDB db;
|
||||
HardFork hf(db, 1,0,1,1,1);
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type;
|
||||
cryptonote::yield_block_info ybi;
|
||||
|
||||
ASSERT_TRUE(hf.add_fork(1, 0, 0));
|
||||
for (int n = 1 ; n < 10; ++n)
|
||||
@@ -280,7 +290,7 @@ TEST(steps_1, Success)
|
||||
hf.init();
|
||||
|
||||
for (uint64_t h = 0 ; h < 10; ++h) {
|
||||
db.add_block(mkblock(hf, h, h+1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash());
|
||||
db.add_block(mkblock(hf, h, h+1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
|
||||
}
|
||||
|
||||
@@ -295,7 +305,8 @@ TEST(reorganize, Same)
|
||||
TestDB db;
|
||||
HardFork hf(db, 1, 0, 1, 1, history, 100);
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type;
|
||||
|
||||
cryptonote::yield_block_info ybi;
|
||||
|
||||
// v h t
|
||||
ASSERT_TRUE(hf.add_fork(1, 0, 0));
|
||||
ASSERT_TRUE(hf.add_fork(4, 2, 1));
|
||||
@@ -306,7 +317,7 @@ TEST(reorganize, Same)
|
||||
// index 0 1 2 3 4 5 6 7 8 9
|
||||
static const uint8_t block_versions[] = { 1, 1, 4, 4, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 };
|
||||
for (uint64_t h = 0; h < 20; ++h) {
|
||||
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash());
|
||||
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
|
||||
}
|
||||
|
||||
@@ -325,6 +336,7 @@ TEST(reorganize, Changed)
|
||||
TestDB db;
|
||||
HardFork hf(db, 1, 0, 1, 1, 4, 100);
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type;
|
||||
cryptonote::yield_block_info ybi;
|
||||
|
||||
// v h t
|
||||
ASSERT_TRUE(hf.add_fork(1, 0, 0));
|
||||
@@ -338,7 +350,7 @@ TEST(reorganize, Changed)
|
||||
static const uint8_t block_versions[] = { 1, 1, 4, 4, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 };
|
||||
static const uint8_t expected_versions[] = { 1, 1, 1, 1, 1, 1, 4, 4, 7, 7, 9, 9, 9, 9, 9, 9 };
|
||||
for (uint64_t h = 0; h < 16; ++h) {
|
||||
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash());
|
||||
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE (hf.add(db.get_block_from_height(h), h));
|
||||
}
|
||||
|
||||
@@ -358,7 +370,7 @@ TEST(reorganize, Changed)
|
||||
ASSERT_EQ(db.height(), 3);
|
||||
hf.reorganize_from_block_height(2);
|
||||
for (uint64_t h = 3; h < 16; ++h) {
|
||||
db.add_block(mkblock(hf, h, block_versions_new[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash());
|
||||
db.add_block(mkblock(hf, h, block_versions_new[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, cryptonote::FAKECHAIN, ybi);
|
||||
bool ret = hf.add(db.get_block_from_height(h), h);
|
||||
ASSERT_EQ (ret, h < 15);
|
||||
}
|
||||
@@ -372,6 +384,7 @@ TEST(reorganize, Changed)
|
||||
TEST(voting, threshold)
|
||||
{
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type;
|
||||
cryptonote::yield_block_info ybi;
|
||||
for (int threshold = 87; threshold <= 88; ++threshold) {
|
||||
TestDB db;
|
||||
HardFork hf(db, 1, 0, 1, 1, 8, threshold);
|
||||
@@ -383,7 +396,7 @@ TEST(voting, threshold)
|
||||
|
||||
for (uint64_t h = 0; h <= 8; ++h) {
|
||||
uint8_t v = 1 + !!(h % 8);
|
||||
db.add_block(mkblock(hf, h, v), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash());
|
||||
db.add_block(mkblock(hf, h, v), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, cryptonote::FAKECHAIN, ybi);
|
||||
bool ret = hf.add(db.get_block_from_height(h), h);
|
||||
if (h >= 8 && threshold == 87) {
|
||||
// for threshold 87, we reach the treshold at height 7, so from height 8, hard fork to version 2, but 8 tries to add 1
|
||||
@@ -402,6 +415,7 @@ TEST(voting, threshold)
|
||||
TEST(voting, different_thresholds)
|
||||
{
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type;
|
||||
cryptonote::yield_block_info ybi;
|
||||
for (int threshold = 87; threshold <= 88; ++threshold) {
|
||||
TestDB db;
|
||||
HardFork hf(db, 1, 0, 1, 1, 4, 50); // window size 4
|
||||
@@ -418,7 +432,7 @@ TEST(voting, different_thresholds)
|
||||
static const uint8_t expected_versions[] = { 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4 };
|
||||
|
||||
for (uint64_t h = 0; h < sizeof(block_versions) / sizeof(block_versions[0]); ++h) {
|
||||
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash());
|
||||
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, cryptonote::FAKECHAIN, ybi);
|
||||
bool ret = hf.add(db.get_block_from_height(h), h);
|
||||
ASSERT_EQ(ret, true);
|
||||
}
|
||||
@@ -433,6 +447,7 @@ TEST(voting, info)
|
||||
TestDB db;
|
||||
HardFork hf(db, 1, 0, 1, 1, 4, 50); // window size 4, default threshold 50%
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type;
|
||||
cryptonote::yield_block_info ybi;
|
||||
|
||||
// v h ts
|
||||
ASSERT_TRUE(hf.add_fork(1, 0, 0));
|
||||
@@ -472,7 +487,7 @@ TEST(voting, info)
|
||||
ASSERT_EQ(expected_thresholds[h], threshold);
|
||||
ASSERT_EQ(4, voting);
|
||||
|
||||
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash());
|
||||
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
|
||||
}
|
||||
}
|
||||
@@ -536,7 +551,8 @@ TEST(reorganize, changed)
|
||||
do { \
|
||||
cryptonote::block b = mkblock(hf, h, v); \
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type; \
|
||||
db.add_block(b, 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash()); \
|
||||
cryptonote::yield_block_info ybi; \
|
||||
db.add_block(b, 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, cryptonote::FAKECHAIN, ybi); \
|
||||
ASSERT_##a(hf.add(b, h)); \
|
||||
} while(0)
|
||||
#define ADD_TRUE(v, h) ADD(v, h, TRUE)
|
||||
|
||||
@@ -59,6 +59,10 @@ public:
|
||||
, uint64_t num_rct_outs
|
||||
, oracle::asset_type_counts& cum_rct_by_asset_type
|
||||
, const crypto::hash& blk_hash
|
||||
, uint64_t slippage_total
|
||||
, uint64_t yield_total
|
||||
, const cryptonote::network_type nettype
|
||||
, cryptonote::yield_block_info& ybi
|
||||
) override {
|
||||
blocks.push_back({block_weight, long_term_block_weight});
|
||||
}
|
||||
@@ -107,16 +111,10 @@ static uint32_t lcg()
|
||||
|
||||
}
|
||||
|
||||
struct BlockchainAndPool
|
||||
{
|
||||
cryptonote::tx_memory_pool txpool;
|
||||
cryptonote::Blockchain bc;
|
||||
BlockchainAndPool(): txpool(bc), bc(txpool) {}
|
||||
};
|
||||
|
||||
#define PREFIX_WINDOW(hf_version,window) \
|
||||
BlockchainAndPool bap; \
|
||||
cryptonote::Blockchain *bc = &bap.bc; \
|
||||
cryptonote::BlockchainAndPool bap; \
|
||||
cryptonote::Blockchain *bc = &bap.blockchain; \
|
||||
cryptonote::yield_block_info ybi; \
|
||||
struct get_test_options { \
|
||||
const std::pair<uint8_t, uint64_t> hard_forks[3]; \
|
||||
const cryptonote::test_options test_options = { \
|
||||
@@ -148,7 +146,7 @@ TEST(long_term_block_weight, identical_before_fork)
|
||||
{
|
||||
size_t w = h < CRYPTONOTE_REWARD_BLOCKS_WINDOW ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : bc->get_current_cumulative_block_weight_limit();
|
||||
uint64_t ltw = bc->get_next_long_term_block_weight(w);
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {}, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
|
||||
}
|
||||
for (uint64_t h = 0; h < 10 * TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW; ++h)
|
||||
@@ -165,7 +163,7 @@ TEST(long_term_block_weight, identical_after_fork_before_long_term_window)
|
||||
{
|
||||
size_t w = h < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : bc->get_current_cumulative_block_weight_limit();
|
||||
uint64_t ltw = bc->get_next_long_term_block_weight(w);
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {}, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
|
||||
}
|
||||
for (uint64_t h = 0; h < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW; ++h)
|
||||
@@ -182,7 +180,7 @@ TEST(long_term_block_weight, ceiling_at_30000000)
|
||||
{
|
||||
size_t w = h < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : bc->get_current_cumulative_block_weight_limit();
|
||||
uint64_t ltw = bc->get_next_long_term_block_weight(w);
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {}, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
|
||||
}
|
||||
ASSERT_EQ(bc->get_current_cumulative_block_weight_median(), 15000000);
|
||||
@@ -197,7 +195,7 @@ TEST(long_term_block_weight, multi_pop)
|
||||
{
|
||||
size_t w = h < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : bc->get_current_cumulative_block_weight_limit();
|
||||
uint64_t ltw = bc->get_next_long_term_block_weight(w);
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {}, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
|
||||
}
|
||||
|
||||
@@ -209,7 +207,7 @@ TEST(long_term_block_weight, multi_pop)
|
||||
{
|
||||
size_t w = bc->get_current_cumulative_block_weight_limit();
|
||||
uint64_t ltw = bc->get_next_long_term_block_weight(w);
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {}, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
|
||||
}
|
||||
|
||||
@@ -231,7 +229,7 @@ TEST(long_term_block_weight, multiple_updates)
|
||||
{
|
||||
size_t w = h < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : bc->get_current_cumulative_block_weight_limit();
|
||||
uint64_t ltw = bc->get_next_long_term_block_weight(w);
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {}, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
|
||||
const uint64_t effective_median = bc->get_current_cumulative_block_weight_median();
|
||||
const uint64_t effective_limit = bc->get_current_cumulative_block_weight_limit();
|
||||
@@ -255,7 +253,7 @@ TEST(long_term_block_weight, pop_invariant_max)
|
||||
{
|
||||
size_t w = bc->get_db().height() < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : bc->get_current_cumulative_block_weight_limit();
|
||||
uint64_t ltw = bc->get_next_long_term_block_weight(w);
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {}, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
|
||||
}
|
||||
|
||||
@@ -283,7 +281,7 @@ TEST(long_term_block_weight, pop_invariant_max)
|
||||
{
|
||||
size_t w = bc->get_db().height() < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : bc->get_current_cumulative_block_weight_limit();
|
||||
uint64_t ltw = bc->get_next_long_term_block_weight(w);
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, bc->get_db().height(), bc->get_db().height(), {});
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, bc->get_db().height(), bc->get_db().height(), {}, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
|
||||
}
|
||||
|
||||
@@ -305,7 +303,7 @@ TEST(long_term_block_weight, pop_invariant_random)
|
||||
uint32_t r = lcg();
|
||||
size_t w = bc->get_db().height() < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : (r % bc->get_current_cumulative_block_weight_limit());
|
||||
uint64_t ltw = bc->get_next_long_term_block_weight(w);
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {}, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
|
||||
}
|
||||
|
||||
@@ -340,7 +338,7 @@ TEST(long_term_block_weight, pop_invariant_random)
|
||||
uint32_t r = lcg();
|
||||
size_t w = bc->get_db().height() < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : (r % bc->get_current_cumulative_block_weight_limit());
|
||||
uint64_t ltw = bc->get_next_long_term_block_weight(w);
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, bc->get_db().height(), bc->get_db().height(), {});
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, bc->get_db().height(), bc->get_db().height(), {}, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
|
||||
const uint64_t effective_median = bc->get_current_cumulative_block_weight_median();
|
||||
const uint64_t effective_limit = bc->get_current_cumulative_block_weight_limit();
|
||||
@@ -368,7 +366,7 @@ TEST(long_term_block_weight, long_growth_spike_and_drop)
|
||||
{
|
||||
size_t w = CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5;
|
||||
uint64_t ltw = bc->get_next_long_term_block_weight(w);
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {}, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE(bc->update_next_cumulative_weight_limit(&long_term_effective_median_block_weight));
|
||||
}
|
||||
ASSERT_EQ(long_term_effective_median_block_weight, 300000);
|
||||
@@ -380,7 +378,7 @@ TEST(long_term_block_weight, long_growth_spike_and_drop)
|
||||
float t = h / float(365 * 720 * TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW / 100000);
|
||||
size_t w = 300000 + t * 30000;
|
||||
uint64_t ltw = bc->get_next_long_term_block_weight(w);
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {}, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE(bc->update_next_cumulative_weight_limit(&long_term_effective_median_block_weight));
|
||||
}
|
||||
ASSERT_GT(long_term_effective_median_block_weight, 300000 * 1.07);
|
||||
@@ -391,7 +389,7 @@ TEST(long_term_block_weight, long_growth_spike_and_drop)
|
||||
{
|
||||
size_t w = bc->get_current_cumulative_block_weight_limit();
|
||||
uint64_t ltw = bc->get_next_long_term_block_weight(w);
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {}, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE(bc->update_next_cumulative_weight_limit(&long_term_effective_median_block_weight));
|
||||
}
|
||||
ASSERT_GT(long_term_effective_median_block_weight, 300000 * 1.07);
|
||||
@@ -402,7 +400,7 @@ TEST(long_term_block_weight, long_growth_spike_and_drop)
|
||||
{
|
||||
size_t w = bc->get_current_cumulative_block_weight_median() * .25;
|
||||
uint64_t ltw = bc->get_next_long_term_block_weight(w);
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
|
||||
bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {}, cryptonote::FAKECHAIN, ybi);
|
||||
ASSERT_TRUE(bc->update_next_cumulative_weight_limit(&long_term_effective_median_block_weight));
|
||||
}
|
||||
ASSERT_GT(long_term_effective_median_block_weight, 300000 * 1.07);
|
||||
|
||||
+37
-42
@@ -555,8 +555,6 @@ TEST(i2p_address, invalid)
|
||||
EXPECT_TRUE(net::i2p_address::make(".b32.i2p:").has_error());
|
||||
EXPECT_TRUE(net::i2p_address::make(b32_i2p + 1).has_error());
|
||||
EXPECT_TRUE(net::i2p_address::make(boost::string_ref{b32_i2p, sizeof(b32_i2p) - 2}).has_error());
|
||||
EXPECT_TRUE(net::i2p_address::make(std::string{b32_i2p} + ":65536").has_error());
|
||||
EXPECT_TRUE(net::i2p_address::make(std::string{b32_i2p} + ":-1").has_error());
|
||||
|
||||
std::string i2p{b32_i2p};
|
||||
i2p.at(10) = 1;
|
||||
@@ -570,7 +568,7 @@ TEST(i2p_address, unblockable_types)
|
||||
ASSERT_NE(nullptr, i2p.host_str());
|
||||
EXPECT_STREQ("<unknown i2p host>", i2p.host_str());
|
||||
EXPECT_STREQ("<unknown i2p host>", i2p.str().c_str());
|
||||
EXPECT_EQ(0u, i2p.port());
|
||||
EXPECT_EQ(1u, i2p.port());
|
||||
EXPECT_TRUE(i2p.is_unknown());
|
||||
EXPECT_FALSE(i2p.is_local());
|
||||
EXPECT_FALSE(i2p.is_loopback());
|
||||
@@ -581,7 +579,7 @@ TEST(i2p_address, unblockable_types)
|
||||
ASSERT_NE(nullptr, i2p.host_str());
|
||||
EXPECT_STREQ("<unknown i2p host>", i2p.host_str());
|
||||
EXPECT_STREQ("<unknown i2p host>", i2p.str().c_str());
|
||||
EXPECT_EQ(0u, i2p.port());
|
||||
EXPECT_EQ(1u, i2p.port());
|
||||
EXPECT_TRUE(i2p.is_unknown());
|
||||
EXPECT_FALSE(i2p.is_local());
|
||||
EXPECT_FALSE(i2p.is_loopback());
|
||||
@@ -596,14 +594,14 @@ TEST(i2p_address, valid)
|
||||
const auto address1 = net::i2p_address::make(b32_i2p);
|
||||
|
||||
ASSERT_TRUE(address1.has_value());
|
||||
EXPECT_EQ(0u, address1->port());
|
||||
EXPECT_EQ(1u, address1->port());
|
||||
EXPECT_STREQ(b32_i2p, address1->host_str());
|
||||
EXPECT_STREQ(b32_i2p, address1->str().c_str());
|
||||
EXPECT_TRUE(address1->is_blockable());
|
||||
|
||||
net::i2p_address address2{*address1};
|
||||
|
||||
EXPECT_EQ(0u, address2.port());
|
||||
EXPECT_EQ(1u, address2.port());
|
||||
EXPECT_STREQ(b32_i2p, address2.host_str());
|
||||
EXPECT_STREQ(b32_i2p, address2.str().c_str());
|
||||
EXPECT_TRUE(address2.is_blockable());
|
||||
@@ -620,9 +618,9 @@ TEST(i2p_address, valid)
|
||||
|
||||
address2 = MONERO_UNWRAP(net::i2p_address::make(std::string{b32_i2p_2} + ":6545"));
|
||||
|
||||
EXPECT_EQ(6545, address2.port());
|
||||
EXPECT_EQ(1u, address2.port());
|
||||
EXPECT_STREQ(b32_i2p_2, address2.host_str());
|
||||
EXPECT_EQ(std::string{b32_i2p_2} + ":6545", address2.str().c_str());
|
||||
EXPECT_EQ(std::string{b32_i2p_2}, address2.str().c_str());
|
||||
EXPECT_TRUE(address2.is_blockable());
|
||||
EXPECT_FALSE(address2.equal(*address1));
|
||||
EXPECT_FALSE(address1->equal(address2));
|
||||
@@ -635,22 +633,22 @@ TEST(i2p_address, valid)
|
||||
EXPECT_FALSE(address2.less(*address1));
|
||||
EXPECT_TRUE(address1->less(address2));
|
||||
|
||||
net::i2p_address address3 = MONERO_UNWRAP(net::i2p_address::make(std::string{b32_i2p} + ":", 65535));
|
||||
net::i2p_address address3 = MONERO_UNWRAP(net::i2p_address::make(std::string{b32_i2p} + ":65535"));
|
||||
|
||||
EXPECT_EQ(65535, address3.port());
|
||||
EXPECT_EQ(1u, address3.port());
|
||||
EXPECT_STREQ(b32_i2p, address3.host_str());
|
||||
EXPECT_EQ(std::string{b32_i2p} + ":65535", address3.str().c_str());
|
||||
EXPECT_EQ(std::string{b32_i2p}, address3.str().c_str());
|
||||
EXPECT_TRUE(address3.is_blockable());
|
||||
EXPECT_FALSE(address3.equal(*address1));
|
||||
EXPECT_FALSE(address1->equal(address3));
|
||||
EXPECT_FALSE(address3 == *address1);
|
||||
EXPECT_FALSE(*address1 == address3);
|
||||
EXPECT_TRUE(address3 != *address1);
|
||||
EXPECT_TRUE(*address1 != address3);
|
||||
EXPECT_TRUE(address3.equal(*address1));
|
||||
EXPECT_TRUE(address1->equal(address3));
|
||||
EXPECT_TRUE(address3 == *address1);
|
||||
EXPECT_TRUE(*address1 == address3);
|
||||
EXPECT_FALSE(address3 != *address1);
|
||||
EXPECT_FALSE(*address1 != address3);
|
||||
EXPECT_TRUE(address3.is_same_host(*address1));
|
||||
EXPECT_TRUE(address1->is_same_host(address3));
|
||||
EXPECT_FALSE(address3.less(*address1));
|
||||
EXPECT_TRUE(address1->less(address3));
|
||||
EXPECT_FALSE(address1->less(address3));
|
||||
|
||||
EXPECT_FALSE(address3.equal(address2));
|
||||
EXPECT_FALSE(address2.equal(address3));
|
||||
@@ -666,8 +664,8 @@ TEST(i2p_address, valid)
|
||||
|
||||
TEST(i2p_address, generic_network_address)
|
||||
{
|
||||
const epee::net_utils::network_address i2p1{MONERO_UNWRAP(net::i2p_address::make(b32_i2p, 8080))};
|
||||
const epee::net_utils::network_address i2p2{MONERO_UNWRAP(net::i2p_address::make(b32_i2p, 8080))};
|
||||
const epee::net_utils::network_address i2p1{MONERO_UNWRAP(net::i2p_address::make(b32_i2p))};
|
||||
const epee::net_utils::network_address i2p2{MONERO_UNWRAP(net::i2p_address::make(b32_i2p))};
|
||||
const epee::net_utils::network_address ip{epee::net_utils::ipv4_network_address{100, 200}};
|
||||
|
||||
EXPECT_EQ(i2p1, i2p2);
|
||||
@@ -675,7 +673,7 @@ TEST(i2p_address, generic_network_address)
|
||||
EXPECT_LT(ip, i2p1);
|
||||
|
||||
EXPECT_STREQ(b32_i2p, i2p1.host_str().c_str());
|
||||
EXPECT_EQ(std::string{b32_i2p} + ":8080", i2p1.str());
|
||||
EXPECT_STREQ(b32_i2p, i2p1.str().c_str());
|
||||
EXPECT_EQ(epee::net_utils::address_type::i2p, i2p1.get_type_id());
|
||||
EXPECT_EQ(epee::net_utils::address_type::i2p, i2p2.get_type_id());
|
||||
EXPECT_EQ(epee::net_utils::address_type::ipv4, ip.get_type_id());
|
||||
@@ -703,11 +701,11 @@ TEST(i2p_address, epee_serializev_b32)
|
||||
{
|
||||
epee::byte_slice buffer{};
|
||||
{
|
||||
test_command_i2p command{MONERO_UNWRAP(net::i2p_address::make(b32_i2p, 10))};
|
||||
test_command_i2p command{MONERO_UNWRAP(net::i2p_address::make(b32_i2p))};
|
||||
EXPECT_FALSE(command.i2p.is_unknown());
|
||||
EXPECT_NE(net::i2p_address{}, command.i2p);
|
||||
EXPECT_STREQ(b32_i2p, command.i2p.host_str());
|
||||
EXPECT_EQ(10u, command.i2p.port());
|
||||
EXPECT_EQ(1u, command.i2p.port());
|
||||
|
||||
epee::serialization::portable_storage stg{};
|
||||
EXPECT_TRUE(command.store(stg));
|
||||
@@ -719,7 +717,7 @@ TEST(i2p_address, epee_serializev_b32)
|
||||
EXPECT_TRUE(command.i2p.is_unknown());
|
||||
EXPECT_EQ(net::i2p_address{}, command.i2p);
|
||||
EXPECT_STREQ(net::i2p_address::unknown_str(), command.i2p.host_str());
|
||||
EXPECT_EQ(0u, command.i2p.port());
|
||||
EXPECT_EQ(1u, command.i2p.port());
|
||||
|
||||
epee::serialization::portable_storage stg{};
|
||||
EXPECT_TRUE(stg.load_from_binary(epee::to_span(buffer)));
|
||||
@@ -728,7 +726,7 @@ TEST(i2p_address, epee_serializev_b32)
|
||||
EXPECT_FALSE(command.i2p.is_unknown());
|
||||
EXPECT_NE(net::i2p_address{}, command.i2p);
|
||||
EXPECT_STREQ(b32_i2p, command.i2p.host_str());
|
||||
EXPECT_EQ(10u, command.i2p.port());
|
||||
EXPECT_EQ(1u, command.i2p.port());
|
||||
|
||||
// make sure that exceeding max buffer doesn't destroy i2p_address::_load
|
||||
{
|
||||
@@ -747,7 +745,7 @@ TEST(i2p_address, epee_serializev_b32)
|
||||
EXPECT_TRUE(command.i2p.is_unknown());
|
||||
EXPECT_EQ(net::i2p_address{}, command.i2p);
|
||||
EXPECT_STRNE(b32_i2p, command.i2p.host_str());
|
||||
EXPECT_EQ(0u, command.i2p.port());
|
||||
EXPECT_EQ(1u, command.i2p.port());
|
||||
}
|
||||
|
||||
TEST(i2p_address, epee_serialize_unknown)
|
||||
@@ -758,7 +756,7 @@ TEST(i2p_address, epee_serialize_unknown)
|
||||
EXPECT_TRUE(command.i2p.is_unknown());
|
||||
EXPECT_EQ(net::i2p_address{}, command.i2p);
|
||||
EXPECT_STREQ(net::i2p_address::unknown_str(), command.i2p.host_str());
|
||||
EXPECT_EQ(0u, command.i2p.port());
|
||||
EXPECT_EQ(1u, command.i2p.port());
|
||||
|
||||
epee::serialization::portable_storage stg{};
|
||||
EXPECT_TRUE(command.store(stg));
|
||||
@@ -770,7 +768,7 @@ TEST(i2p_address, epee_serialize_unknown)
|
||||
EXPECT_TRUE(command.i2p.is_unknown());
|
||||
EXPECT_EQ(net::i2p_address{}, command.i2p);
|
||||
EXPECT_STRNE(b32_i2p, command.i2p.host_str());
|
||||
EXPECT_EQ(0u, command.i2p.port());
|
||||
EXPECT_EQ(1u, command.i2p.port());
|
||||
|
||||
epee::serialization::portable_storage stg{};
|
||||
EXPECT_TRUE(stg.load_from_binary(epee::to_span(buffer)));
|
||||
@@ -779,7 +777,7 @@ TEST(i2p_address, epee_serialize_unknown)
|
||||
EXPECT_TRUE(command.i2p.is_unknown());
|
||||
EXPECT_EQ(net::i2p_address{}, command.i2p);
|
||||
EXPECT_STREQ(net::i2p_address::unknown_str(), command.i2p.host_str());
|
||||
EXPECT_EQ(0u, command.i2p.port());
|
||||
EXPECT_EQ(1u, command.i2p.port());
|
||||
|
||||
// make sure that exceeding max buffer doesn't destroy i2p_address::_load
|
||||
{
|
||||
@@ -798,18 +796,18 @@ TEST(i2p_address, epee_serialize_unknown)
|
||||
EXPECT_TRUE(command.i2p.is_unknown());
|
||||
EXPECT_EQ(net::i2p_address{}, command.i2p);
|
||||
EXPECT_STRNE(b32_i2p, command.i2p.host_str());
|
||||
EXPECT_EQ(0u, command.i2p.port());
|
||||
EXPECT_EQ(1u, command.i2p.port());
|
||||
}
|
||||
|
||||
TEST(i2p_address, boost_serialize_b32)
|
||||
{
|
||||
std::string buffer{};
|
||||
{
|
||||
const net::i2p_address i2p = MONERO_UNWRAP(net::i2p_address::make(b32_i2p, 10));
|
||||
const net::i2p_address i2p = MONERO_UNWRAP(net::i2p_address::make(b32_i2p));
|
||||
EXPECT_FALSE(i2p.is_unknown());
|
||||
EXPECT_NE(net::i2p_address{}, i2p);
|
||||
EXPECT_STREQ(b32_i2p, i2p.host_str());
|
||||
EXPECT_EQ(10u, i2p.port());
|
||||
EXPECT_EQ(1u, i2p.port());
|
||||
|
||||
std::ostringstream stream{};
|
||||
{
|
||||
@@ -824,7 +822,7 @@ TEST(i2p_address, boost_serialize_b32)
|
||||
EXPECT_TRUE(i2p.is_unknown());
|
||||
EXPECT_EQ(net::i2p_address{}, i2p);
|
||||
EXPECT_STREQ(net::i2p_address::unknown_str(), i2p.host_str());
|
||||
EXPECT_EQ(0u, i2p.port());
|
||||
EXPECT_EQ(1u, i2p.port());
|
||||
|
||||
std::istringstream stream{buffer};
|
||||
boost::archive::portable_binary_iarchive archive{stream};
|
||||
@@ -833,7 +831,7 @@ TEST(i2p_address, boost_serialize_b32)
|
||||
EXPECT_FALSE(i2p.is_unknown());
|
||||
EXPECT_NE(net::i2p_address{}, i2p);
|
||||
EXPECT_STREQ(b32_i2p, i2p.host_str());
|
||||
EXPECT_EQ(10u, i2p.port());
|
||||
EXPECT_EQ(1u, i2p.port());
|
||||
}
|
||||
|
||||
TEST(i2p_address, boost_serialize_unknown)
|
||||
@@ -844,7 +842,7 @@ TEST(i2p_address, boost_serialize_unknown)
|
||||
EXPECT_TRUE(i2p.is_unknown());
|
||||
EXPECT_EQ(net::i2p_address::unknown(), i2p);
|
||||
EXPECT_STREQ(net::i2p_address::unknown_str(), i2p.host_str());
|
||||
EXPECT_EQ(0u, i2p.port());
|
||||
EXPECT_EQ(1u, i2p.port());
|
||||
|
||||
std::ostringstream stream{};
|
||||
{
|
||||
@@ -859,7 +857,7 @@ TEST(i2p_address, boost_serialize_unknown)
|
||||
EXPECT_TRUE(i2p.is_unknown());
|
||||
EXPECT_EQ(net::i2p_address{}, i2p);
|
||||
EXPECT_STREQ(net::i2p_address::unknown_str(), i2p.host_str());
|
||||
EXPECT_EQ(0u, i2p.port());
|
||||
EXPECT_EQ(1u, i2p.port());
|
||||
|
||||
std::istringstream stream{buffer};
|
||||
boost::archive::portable_binary_iarchive archive{stream};
|
||||
@@ -868,7 +866,7 @@ TEST(i2p_address, boost_serialize_unknown)
|
||||
EXPECT_TRUE(i2p.is_unknown());
|
||||
EXPECT_EQ(net::i2p_address::unknown(), i2p);
|
||||
EXPECT_STREQ(net::i2p_address::unknown_str(), i2p.host_str());
|
||||
EXPECT_EQ(0u, i2p.port());
|
||||
EXPECT_EQ(1u, i2p.port());
|
||||
}
|
||||
|
||||
TEST(get_network_address, i2p)
|
||||
@@ -884,16 +882,13 @@ TEST(get_network_address, i2p)
|
||||
ASSERT_TRUE(bool(address));
|
||||
EXPECT_EQ(epee::net_utils::address_type::i2p, address->get_type_id());
|
||||
EXPECT_STREQ(b32_i2p, address->host_str().c_str());
|
||||
EXPECT_EQ(std::string{b32_i2p} + ":1000", address->str());
|
||||
EXPECT_EQ(std::string{b32_i2p}, address->str());
|
||||
|
||||
address = net::get_network_address(std::string{b32_i2p} + ":2000", 1000);
|
||||
ASSERT_TRUE(bool(address));
|
||||
EXPECT_EQ(epee::net_utils::address_type::i2p, address->get_type_id());
|
||||
EXPECT_STREQ(b32_i2p, address->host_str().c_str());
|
||||
EXPECT_EQ(std::string{b32_i2p} + ":2000", address->str());
|
||||
|
||||
address = net::get_network_address(std::string{b32_i2p} + ":65536", 1000);
|
||||
EXPECT_EQ(net::error::invalid_port, address);
|
||||
EXPECT_EQ(std::string{b32_i2p}, address->str());
|
||||
}
|
||||
|
||||
TEST(get_network_address, ipv4)
|
||||
|
||||
@@ -433,6 +433,7 @@ TEST(cryptonote_protocol_handler, race_condition)
|
||||
const block_t &block,
|
||||
const stat::chain &stat
|
||||
){
|
||||
cryptonote::yield_block_info ybi;
|
||||
core.get_blockchain_storage().get_db().batch_start({}, {});
|
||||
core.get_blockchain_storage().get_db().add_block(
|
||||
{block, cryptonote::block_to_blob(block)},
|
||||
@@ -442,7 +443,9 @@ TEST(cryptonote_protocol_handler, race_condition)
|
||||
),
|
||||
stat.diff,
|
||||
stat.reward,
|
||||
{}
|
||||
{},
|
||||
cryptonote::FAKECHAIN,
|
||||
ybi
|
||||
);
|
||||
core.get_blockchain_storage().get_db().batch_stop();
|
||||
};
|
||||
|
||||
@@ -30,10 +30,7 @@
|
||||
#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"
|
||||
|
||||
static const uint64_t test_distribution[32] = {
|
||||
@@ -77,9 +74,6 @@ public:
|
||||
|
||||
bool get_output_distribution(uint64_t amount, std::string asset_type, uint64_t from, uint64_t to, uint64_t &start_height, std::vector<uint64_t> &distribution, uint64_t &base, uint64_t &num_spendable_global_outs)
|
||||
{
|
||||
std::unique_ptr<cryptonote::Blockchain> bc;
|
||||
cryptonote::tx_memory_pool txpool(*bc);
|
||||
bc.reset(new cryptonote::Blockchain(txpool));
|
||||
struct get_test_options {
|
||||
const std::pair<uint8_t, uint64_t> hard_forks[2];
|
||||
const cryptonote::test_options test_options = {
|
||||
@@ -87,9 +81,9 @@ bool get_output_distribution(uint64_t amount, std::string asset_type, uint64_t f
|
||||
};
|
||||
get_test_options():hard_forks{std::make_pair((uint8_t)1, (uint64_t)0), std::make_pair((uint8_t)0, (uint64_t)0)}{}
|
||||
} opts;
|
||||
cryptonote::Blockchain *blockchain = bc.get();
|
||||
bool r = blockchain->init(new TestDB(test_distribution_size), cryptonote::FAKECHAIN, true, &opts.test_options, 0, NULL);
|
||||
return r && bc->get_output_distribution(amount, "FULM", from, to, start_height, distribution, base, num_spendable_global_outs);
|
||||
cryptonote::BlockchainAndPool bap;
|
||||
bool r = bap.blockchain.init(new TestDB(test_distribution_size), cryptonote::FAKECHAIN, true, &opts.test_options, 0, NULL);
|
||||
return r && bap.blockchain.get_output_distribution(amount, asset_type, from, to, start_height, distribution, base, num_spendable_global_outs);
|
||||
}
|
||||
|
||||
crypto::hash get_block_hash(uint64_t height)
|
||||
@@ -103,32 +97,32 @@ TEST(output_distribution, extend)
|
||||
{
|
||||
boost::optional<cryptonote::rpc::output_distribution_data> res;
|
||||
|
||||
res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, "FULM", 28, 29, ::get_block_hash, false, test_distribution_size);
|
||||
res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, "SAL", 28, 29, ::get_block_hash, false, test_distribution_size);
|
||||
ASSERT_TRUE(res != boost::none);
|
||||
ASSERT_EQ(res->distribution.size(), 2);
|
||||
ASSERT_EQ(res->distribution, std::vector<uint64_t>({5, 0}));
|
||||
|
||||
res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, "FULM", 28, 29, ::get_block_hash, true, test_distribution_size);
|
||||
res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, "SAL", 28, 29, ::get_block_hash, true, test_distribution_size);
|
||||
ASSERT_TRUE(res != boost::none);
|
||||
ASSERT_EQ(res->distribution.size(), 2);
|
||||
ASSERT_EQ(res->distribution, std::vector<uint64_t>({55, 55}));
|
||||
|
||||
res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, "FULM", 28, 30, ::get_block_hash, false, test_distribution_size);
|
||||
res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, "SAL", 28, 30, ::get_block_hash, false, test_distribution_size);
|
||||
ASSERT_TRUE(res != boost::none);
|
||||
ASSERT_EQ(res->distribution.size(), 3);
|
||||
ASSERT_EQ(res->distribution, std::vector<uint64_t>({5, 0, 2}));
|
||||
|
||||
res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, "FULM", 28, 30, ::get_block_hash, true, test_distribution_size);
|
||||
res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, "SAL", 28, 30, ::get_block_hash, true, test_distribution_size);
|
||||
ASSERT_TRUE(res != boost::none);
|
||||
ASSERT_EQ(res->distribution.size(), 3);
|
||||
ASSERT_EQ(res->distribution, std::vector<uint64_t>({55, 55, 57}));
|
||||
|
||||
res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, "FULM", 28, 31, ::get_block_hash, false, test_distribution_size);
|
||||
res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, "SAL", 28, 31, ::get_block_hash, false, test_distribution_size);
|
||||
ASSERT_TRUE(res != boost::none);
|
||||
ASSERT_EQ(res->distribution.size(), 4);
|
||||
ASSERT_EQ(res->distribution, std::vector<uint64_t>({5, 0, 2, 3}));
|
||||
|
||||
res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, "FULM", 28, 31, ::get_block_hash, true, test_distribution_size);
|
||||
res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, "SAL", 28, 31, ::get_block_hash, true, test_distribution_size);
|
||||
ASSERT_TRUE(res != boost::none);
|
||||
ASSERT_EQ(res->distribution.size(), 4);
|
||||
ASSERT_EQ(res->distribution, std::vector<uint64_t>({55, 55, 57, 60}));
|
||||
@@ -138,7 +132,7 @@ TEST(output_distribution, one)
|
||||
{
|
||||
boost::optional<cryptonote::rpc::output_distribution_data> res;
|
||||
|
||||
res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, "FULM", 0, 0, ::get_block_hash, false, test_distribution_size);
|
||||
res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, "SAL", 0, 0, ::get_block_hash, false, test_distribution_size);
|
||||
ASSERT_TRUE(res != boost::none);
|
||||
ASSERT_EQ(res->distribution.size(), 1);
|
||||
ASSERT_EQ(res->distribution.back(), 0);
|
||||
@@ -148,7 +142,7 @@ TEST(output_distribution, full_cumulative)
|
||||
{
|
||||
boost::optional<cryptonote::rpc::output_distribution_data> res;
|
||||
|
||||
res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, "FULM", 0, 31, ::get_block_hash, true, test_distribution_size);
|
||||
res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, "SAL", 0, 31, ::get_block_hash, true, test_distribution_size);
|
||||
ASSERT_TRUE(res != boost::none);
|
||||
ASSERT_EQ(res->distribution.size(), 32);
|
||||
ASSERT_EQ(res->distribution.back(), 60);
|
||||
@@ -158,7 +152,7 @@ TEST(output_distribution, full_noncumulative)
|
||||
{
|
||||
boost::optional<cryptonote::rpc::output_distribution_data> res;
|
||||
|
||||
res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, "FULM", 0, 31, ::get_block_hash, false, test_distribution_size);
|
||||
res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, "SAL", 0, 31, ::get_block_hash, false, test_distribution_size);
|
||||
ASSERT_TRUE(res != boost::none);
|
||||
ASSERT_EQ(res->distribution.size(), 32);
|
||||
for (size_t i = 0; i < 32; ++i)
|
||||
@@ -169,7 +163,7 @@ TEST(output_distribution, part_cumulative)
|
||||
{
|
||||
boost::optional<cryptonote::rpc::output_distribution_data> res;
|
||||
|
||||
res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, "FULM", 4, 8, ::get_block_hash, true, test_distribution_size);
|
||||
res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, "SAL", 4, 8, ::get_block_hash, true, test_distribution_size);
|
||||
ASSERT_TRUE(res != boost::none);
|
||||
ASSERT_EQ(res->distribution.size(), 5);
|
||||
ASSERT_EQ(res->distribution, std::vector<uint64_t>({0, 1, 6, 7, 11}));
|
||||
@@ -179,7 +173,7 @@ TEST(output_distribution, part_noncumulative)
|
||||
{
|
||||
boost::optional<cryptonote::rpc::output_distribution_data> res;
|
||||
|
||||
res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, "FULM", 4, 8, ::get_block_hash, false, test_distribution_size);
|
||||
res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, "SAL", 4, 8, ::get_block_hash, false, test_distribution_size);
|
||||
ASSERT_TRUE(res != boost::none);
|
||||
ASSERT_EQ(res->distribution.size(), 5);
|
||||
ASSERT_EQ(res->distribution, std::vector<uint64_t>({0, 1, 5, 1, 4}));
|
||||
|
||||
@@ -42,19 +42,12 @@ TEST(pricing_record, verify_serialization)
|
||||
oracle::pricing_record pr;
|
||||
oracle::pricing_record pr1;
|
||||
pr.pr_version = 1;
|
||||
pr.height = 1234;
|
||||
pr.supply = {100000,0};
|
||||
pr.timestamp = 1632401454;
|
||||
pr.spot = COIN<<1;
|
||||
pr.moving_average = (COIN * 3) >> 2;
|
||||
memset(pr.signature, 0, 64);
|
||||
pr.assets = {};
|
||||
pr.signature = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
|
||||
/*
|
||||
oracle::pricing_record_entry foo;
|
||||
foo.first = "FULM";
|
||||
foo.second.first = 2;
|
||||
foo.second.second = 3;
|
||||
pr.assets.push_back(foo);
|
||||
*/
|
||||
|
||||
std::string blob;
|
||||
ASSERT_TRUE(serialization::dump_binary(pr, blob));
|
||||
ASSERT_TRUE(serialization::parse_binary(blob, pr1));
|
||||
|
||||
@@ -345,10 +345,10 @@ TEST(ringct, range_proofs)
|
||||
ASSERT_TRUE(ok);
|
||||
|
||||
cryptonote::transaction_type tx_type = cryptonote::transaction_type::TRANSFER;
|
||||
std::string in_asset_type = "FULM";
|
||||
std::string in_asset_type = "SAL";
|
||||
std::vector<std::string> destination_asset_types;
|
||||
for (size_t i = 0; i < destinations.size(); ++i)
|
||||
destination_asset_types.push_back("FULM");
|
||||
destination_asset_types.push_back("SAL");
|
||||
|
||||
//compute rct data with mixin 3
|
||||
rctSig s = genRctSimple(rct::zero(), sc, pc, destinations, tx_type, in_asset_type, destination_asset_types, inamounts, amounts, amount_keys, 0, 3, rct_config, hw::get_device("default"));
|
||||
@@ -416,10 +416,10 @@ TEST(ringct, range_proofs_with_fee)
|
||||
const rct::RCTConfig rct_config { RangeProofBorromean, 0 };
|
||||
|
||||
cryptonote::transaction_type tx_type = cryptonote::transaction_type::TRANSFER;
|
||||
std::string in_asset_type = "FULM";
|
||||
std::string in_asset_type = "SAL";
|
||||
std::vector<std::string> destination_asset_types;
|
||||
for (size_t i = 0; i < destinations.size(); ++i)
|
||||
destination_asset_types.push_back("FULM");
|
||||
destination_asset_types.push_back("SAL");
|
||||
|
||||
//compute rct data with mixin 3
|
||||
rctSig s = genRctSimple(rct::zero(), sc, pc, destinations, tx_type, in_asset_type, destination_asset_types, inamounts, amounts, amount_keys, 1, 3, rct_config, hw::get_device("default"));
|
||||
@@ -499,10 +499,10 @@ TEST(ringct, simple)
|
||||
|
||||
const rct::RCTConfig rct_config { RangeProofBorromean, 0 };
|
||||
cryptonote::transaction_type tx_type = cryptonote::transaction_type::TRANSFER;
|
||||
std::string in_asset_type = "FULM";
|
||||
std::string in_asset_type = "SAL";
|
||||
std::vector<std::string> destination_asset_types;
|
||||
for (size_t i = 0; i < destinations.size(); ++i)
|
||||
destination_asset_types.push_back("FULM");
|
||||
destination_asset_types.push_back("SAL");
|
||||
|
||||
rctSig s = genRctSimple(message, sc, pc, destinations, tx_type, in_asset_type, destination_asset_types, inamounts, outamounts, amount_keys, txnfee, 2, rct_config, hw::get_device("default"));
|
||||
|
||||
@@ -567,10 +567,10 @@ static rct::rctSig make_sample_simple_rct_sig(int n_inputs, const uint64_t input
|
||||
|
||||
const rct::RCTConfig rct_config { RangeProofBorromean, 0 };
|
||||
cryptonote::transaction_type tx_type = cryptonote::transaction_type::TRANSFER;
|
||||
std::string in_asset_type = "FULM";
|
||||
std::string in_asset_type = "SAL";
|
||||
std::vector<std::string> destination_asset_types;
|
||||
for (size_t i = 0; i < destinations.size(); ++i)
|
||||
destination_asset_types.push_back("FULM");
|
||||
destination_asset_types.push_back("SAL");
|
||||
|
||||
return genRctSimple(rct::zero(), sc, pc, destinations, tx_type, in_asset_type, destination_asset_types, inamounts, outamounts, amount_keys, fee, 3, rct_config, hw::get_device("default"));
|
||||
}
|
||||
@@ -1291,3 +1291,39 @@ TEST(ringct, aggregated)
|
||||
ASSERT_TRUE(verRctSemanticsSimple(s[n]));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ringct, pr_proof)
|
||||
{
|
||||
// Create a random commitment with 0 amount
|
||||
int success = 0, failure = 0;
|
||||
for (size_t i=0; i<1000; i++) {
|
||||
key Sk = skGen();
|
||||
sc_reduce32(Sk.bytes);
|
||||
key C;
|
||||
genC(C, Sk, i%100 ? 0 : i%99);
|
||||
zk_proof proof = PRProof_Gen(Sk);
|
||||
if (PRProof_Ver(C, proof))
|
||||
success++;
|
||||
else
|
||||
failure++;
|
||||
}
|
||||
ASSERT_EQ(failure, 9);
|
||||
}
|
||||
|
||||
TEST(ringct, sa_proof)
|
||||
{
|
||||
// Create a random commitment with 0 amount
|
||||
int success = 0, failure = 0;
|
||||
for (size_t i=0; i<1000; i++) {
|
||||
key Sk = skGen();
|
||||
sc_reduce32(Sk.bytes);
|
||||
key C;
|
||||
genC(C, Sk, i%100 ? 0 : i%99);
|
||||
zk_proof proof = PRProof_Gen(Sk);
|
||||
if (PRProof_Ver(C, proof))
|
||||
success++;
|
||||
else
|
||||
failure++;
|
||||
}
|
||||
ASSERT_EQ(failure, 9);
|
||||
}
|
||||
|
||||
@@ -50,9 +50,6 @@ public:
|
||||
}
|
||||
|
||||
#define PREFIX_WINDOW(hf_version,window) \
|
||||
std::unique_ptr<cryptonote::Blockchain> bc; \
|
||||
cryptonote::tx_memory_pool txpool(*bc); \
|
||||
bc.reset(new cryptonote::Blockchain(txpool)); \
|
||||
struct get_test_options { \
|
||||
const std::pair<uint8_t, uint64_t> hard_forks[3]; \
|
||||
const cryptonote::test_options test_options = { \
|
||||
@@ -61,7 +58,9 @@ public:
|
||||
}; \
|
||||
get_test_options(): hard_forks{std::make_pair(1, (uint64_t)0), std::make_pair((uint8_t)hf_version, (uint64_t)1), std::make_pair((uint8_t)0, (uint64_t)0)} {} \
|
||||
} opts; \
|
||||
cryptonote::Blockchain *blockchain = bc.get(); \
|
||||
cryptonote::BlockchainAndPool bap; \
|
||||
cryptonote::Blockchain *blockchain = &bap.blockchain; \
|
||||
cryptonote::Blockchain *bc = blockchain; \
|
||||
bool r = blockchain->init(new TestDB(), cryptonote::FAKECHAIN, true, &opts.test_options, 0, NULL); \
|
||||
ASSERT_TRUE(r)
|
||||
|
||||
|
||||
@@ -59,9 +59,7 @@ struct Struct
|
||||
};
|
||||
|
||||
template <class Archive>
|
||||
struct serializer<Archive, Struct>
|
||||
{
|
||||
static bool serialize(Archive &ar, Struct &s) {
|
||||
static bool do_serialize(Archive &ar, Struct &s) {
|
||||
ar.begin_object();
|
||||
ar.tag("a");
|
||||
ar.serialize_int(s.a);
|
||||
@@ -71,8 +69,7 @@ struct serializer<Archive, Struct>
|
||||
ar.serialize_blob(s.blob, sizeof(s.blob));
|
||||
ar.end_object();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
struct Struct1
|
||||
{
|
||||
@@ -122,6 +119,22 @@ bool try_parse(const string &blob)
|
||||
return serialization::parse_binary(blob, s1);
|
||||
}
|
||||
|
||||
namespace example_namespace
|
||||
{
|
||||
struct ADLExampleStruct
|
||||
{
|
||||
std::string msg;
|
||||
};
|
||||
template <class Archive>
|
||||
static bool do_serialize(Archive &ar, ADLExampleStruct &aes)
|
||||
{
|
||||
ar.begin_object();
|
||||
FIELD_N("custom_fieldname", aes.msg);
|
||||
ar.end_object();
|
||||
return ar.good();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Serialization, BinaryArchiveInts) {
|
||||
uint64_t x = 0xff00000000, x1;
|
||||
|
||||
@@ -1094,7 +1107,7 @@ TEST(Serialization, portability_signed_tx)
|
||||
ASSERT_TRUE(ptx.selected_transfers.front() == 2);
|
||||
// ptx.{key_images, tx_key}
|
||||
ASSERT_TRUE(ptx.key_images == "<6c3cd6af97c4070a7aef9b1344e7463e29c7cd245076fdb65da447a34da3ca76> ");
|
||||
ASSERT_TRUE(epee::string_tools::pod_to_hex(ptx.tx_key) == "0100000000000000000000000000000000000000000000000000000000000000");
|
||||
ASSERT_TRUE(epee::string_tools::pod_to_hex(unwrap(unwrap(ptx.tx_key))) == "0100000000000000000000000000000000000000000000000000000000000000");
|
||||
// ptx.dests
|
||||
ASSERT_TRUE(ptx.dests.size() == 1);
|
||||
ASSERT_TRUE(ptx.dests[0].amount == 1400000000000);
|
||||
@@ -1183,3 +1196,15 @@ TEST(Serialization, difficulty_type)
|
||||
|
||||
ASSERT_EQ(v_original, v_unserialized);
|
||||
}
|
||||
|
||||
TEST(Serialization, adl_free_function)
|
||||
{
|
||||
std::stringstream ss;
|
||||
json_archive<true> ar(ss);
|
||||
const std::string msg = "Howdy, World!";
|
||||
example_namespace::ADLExampleStruct aes{msg};
|
||||
ASSERT_TRUE(serialization::serialize(ar, aes));
|
||||
// VVVVVVVVVVVVVVVVVVVVVVVVVV weird string serialization artifact
|
||||
const std::string expected = "{\"custom_fieldname\": " + std::to_string(msg.size()) + '"' + epee::string_tools::buff_to_hex_nodelimer(msg) + "\"}";
|
||||
EXPECT_EQ(expected, ss.str());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user