1
0
Fork 0
forked from lthn/blockchain
blockchain/tests/unit_tests/wallet_chain_shortener_test.cpp

60 lines
1.5 KiB
C++
Raw Permalink Normal View History

// Copyright (c) 2019 Zano Project
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <algorithm>
#include "gtest/gtest.h"
#include "currency_core/block_chain_shortener.h"
TEST(block_chain_shortener, block_chain_shortener)
{
uint64_t counter = 0;
block_chain_shortener ws;
for (counter = 1; counter != 1000000; counter++)
{
crypto::hash id_ = AUTO_VAL_INIT(id_);
*((uint64_t*)&id_) = counter;
ws.push_new_block_id(id_, counter);
}
2020-05-01 13:25:28 +02:00
std::list<crypto::hash> short_chain1;
ws.get_short_chain_history(short_chain1);
for(auto& id: short_chain1)
{
LOG_PRINT_L0("{" << *((uint64_t*)&id) << "}{" << counter - *((uint64_t*)&id) << "}" << ENDL);
}
2020-04-30 23:21:14 +02:00
ws.detach(counter - 10000);
2020-05-01 13:25:28 +02:00
std::list<crypto::hash> short_chain2;
ws.get_short_chain_history(short_chain2);
for (auto& id : short_chain2)
2020-04-30 23:21:14 +02:00
{
LOG_PRINT_L0("{" << *((uint64_t*)&id) << "}{" << counter - *((uint64_t*)&id) << "}" << ENDL);
}
2020-05-29 22:13:52 +02:00
for (counter = counter - 10000; counter != 1000000; counter++)
2020-04-30 23:21:14 +02:00
{
crypto::hash id_ = AUTO_VAL_INIT(id_);
*((uint64_t*)&id_) = counter;
ws.push_new_block_id(id_, counter);
}
2020-05-01 13:25:28 +02:00
std::list<crypto::hash> short_chain3;
ws.get_short_chain_history(short_chain3);
for (auto& id : short_chain3)
2020-04-30 23:21:14 +02:00
{
LOG_PRINT_L0("{" << *((uint64_t*)&id) << "}{" << counter - *((uint64_t*)&id) << "}" << ENDL);
}
LOG_PRINT_L0("Finished");
2020-05-01 13:25:28 +02:00
ASSERT_EQ(short_chain3.size(), short_chain1.size());
ASSERT_EQ(short_chain3, short_chain1);
}