mirror of
https://github.com/monero-project/monero.git
synced 2024-12-25 17:59:28 -05:00
hardfork: fix get_next_version()
This commit is contained in:
parent
7e30eadb32
commit
98cf62cc45
@ -394,9 +394,9 @@ uint8_t HardFork::get_next_version() const
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(lock);
|
||||
uint64_t height = db.height();
|
||||
for (unsigned int n = heights.size() - 1; n > 0; --n) {
|
||||
if (height >= heights[n].height) {
|
||||
return heights[n < heights.size() - 1 ? n + 1 : n].version;
|
||||
for (auto i = heights.rbegin(); i != heights.rend(); ++i) {
|
||||
if (height >= i->height) {
|
||||
return (i == heights.rbegin() ? i : (i - 1))->version;
|
||||
}
|
||||
}
|
||||
return original_version;
|
||||
|
@ -256,6 +256,35 @@ TEST(check_for_height, Success)
|
||||
}
|
||||
}
|
||||
|
||||
TEST(get, next_version)
|
||||
{
|
||||
TestDB db;
|
||||
HardFork hf(db);
|
||||
|
||||
ASSERT_TRUE(hf.add_fork(1, 0, 0));
|
||||
ASSERT_TRUE(hf.add_fork(2, 5, 1));
|
||||
ASSERT_TRUE(hf.add_fork(4, 10, 2));
|
||||
hf.init();
|
||||
|
||||
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, crypto::hash());
|
||||
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, crypto::hash());
|
||||
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, crypto::hash());
|
||||
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(states, Success)
|
||||
{
|
||||
TestDB db;
|
||||
|
Loading…
Reference in New Issue
Block a user