aboutsummaryrefslogtreecommitdiff
path: root/tests/unit_tests/hardfork.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit_tests/hardfork.cpp')
-rw-r--r--tests/unit_tests/hardfork.cpp101
1 files changed, 57 insertions, 44 deletions
diff --git a/tests/unit_tests/hardfork.cpp b/tests/unit_tests/hardfork.cpp
index 1f6ef5bf0..254dece54 100644
--- a/tests/unit_tests/hardfork.cpp
+++ b/tests/unit_tests/hardfork.cpp
@@ -135,6 +135,7 @@ private:
static cryptonote::block mkblock(uint8_t version)
{
cryptonote::block b;
+ b.major_version = version;
b.minor_version = version;
return b;
}
@@ -144,7 +145,7 @@ TEST(empty_hardforks, Success)
TestDB db;
HardFork hf(db);
- ASSERT_TRUE(hf.add(1, 0, 0));
+ ASSERT_TRUE(hf.add_fork(1, 0, 0));
hf.init();
ASSERT_TRUE(hf.get_state(time(NULL)) == HardFork::Ready);
ASSERT_TRUE(hf.get_state(time(NULL) + 3600*24*400) == HardFork::Ready);
@@ -163,13 +164,13 @@ TEST(ordering, Success)
TestDB db;
HardFork hf(db);
- ASSERT_TRUE(hf.add(2, 2, 1));
- ASSERT_FALSE(hf.add(3, 3, 1));
- ASSERT_FALSE(hf.add(3, 2, 2));
- ASSERT_FALSE(hf.add(2, 3, 2));
- ASSERT_TRUE(hf.add(3, 10, 2));
- ASSERT_TRUE(hf.add(4, 20, 3));
- ASSERT_FALSE(hf.add(5, 5, 4));
+ ASSERT_TRUE(hf.add_fork(2, 2, 1));
+ ASSERT_FALSE(hf.add_fork(3, 3, 1));
+ ASSERT_FALSE(hf.add_fork(3, 2, 2));
+ ASSERT_FALSE(hf.add_fork(2, 3, 2));
+ ASSERT_TRUE(hf.add_fork(3, 10, 2));
+ ASSERT_TRUE(hf.add_fork(4, 20, 3));
+ ASSERT_FALSE(hf.add_fork(5, 5, 4));
}
TEST(states, Success)
@@ -177,8 +178,8 @@ TEST(states, Success)
TestDB db;
HardFork hf(db);
- ASSERT_TRUE(hf.add(1, 0, 0));
- ASSERT_TRUE(hf.add(2, BLOCKS_PER_YEAR, SECONDS_PER_YEAR));
+ ASSERT_TRUE(hf.add_fork(1, 0, 0));
+ ASSERT_TRUE(hf.add_fork(2, BLOCKS_PER_YEAR, SECONDS_PER_YEAR));
ASSERT_TRUE(hf.get_state(0) == HardFork::Ready);
ASSERT_TRUE(hf.get_state(SECONDS_PER_YEAR / 2) == HardFork::Ready);
@@ -186,7 +187,7 @@ TEST(states, Success)
ASSERT_TRUE(hf.get_state(SECONDS_PER_YEAR + (HardFork::DEFAULT_UPDATE_TIME + HardFork::DEFAULT_FORKED_TIME) / 2) == HardFork::UpdateNeeded);
ASSERT_TRUE(hf.get_state(SECONDS_PER_YEAR + HardFork::DEFAULT_FORKED_TIME * 2) == HardFork::LikelyForked);
- ASSERT_TRUE(hf.add(3, BLOCKS_PER_YEAR * 5, SECONDS_PER_YEAR * 5));
+ ASSERT_TRUE(hf.add_fork(3, BLOCKS_PER_YEAR * 5, SECONDS_PER_YEAR * 5));
ASSERT_TRUE(hf.get_state(0) == HardFork::Ready);
ASSERT_TRUE(hf.get_state(SECONDS_PER_YEAR / 2) == HardFork::Ready);
@@ -201,10 +202,10 @@ TEST(steps_asap, Success)
HardFork hf(db, 1,0,1,1,1);
// v h t
- ASSERT_TRUE(hf.add(1, 0, 0));
- ASSERT_TRUE(hf.add(4, 2, 1));
- ASSERT_TRUE(hf.add(7, 4, 2));
- ASSERT_TRUE(hf.add(9, 6, 3));
+ ASSERT_TRUE(hf.add_fork(1, 0, 0));
+ ASSERT_TRUE(hf.add_fork(4, 2, 1));
+ ASSERT_TRUE(hf.add_fork(7, 4, 2));
+ ASSERT_TRUE(hf.add_fork(9, 6, 3));
hf.init();
for (uint64_t h = 0; h < 10; ++h) {
@@ -229,9 +230,9 @@ TEST(steps_1, Success)
TestDB db;
HardFork hf(db, 1,0,1,1,1);
- ASSERT_TRUE(hf.add(1, 0, 0));
+ ASSERT_TRUE(hf.add_fork(1, 0, 0));
for (int n = 1 ; n < 10; ++n)
- ASSERT_TRUE(hf.add(n+1, n, n));
+ ASSERT_TRUE(hf.add_fork(n+1, n, n));
hf.init();
for (uint64_t h = 0 ; h < 10; ++h) {
@@ -251,10 +252,10 @@ TEST(reorganize, Same)
HardFork hf(db, 1, 0, 1, 1, history, 100);
// v h t
- ASSERT_TRUE(hf.add(1, 0, 0));
- ASSERT_TRUE(hf.add(4, 2, 1));
- ASSERT_TRUE(hf.add(7, 4, 2));
- ASSERT_TRUE(hf.add(9, 6, 3));
+ ASSERT_TRUE(hf.add_fork(1, 0, 0));
+ ASSERT_TRUE(hf.add_fork(4, 2, 1));
+ ASSERT_TRUE(hf.add_fork(7, 4, 2));
+ ASSERT_TRUE(hf.add_fork(9, 6, 3));
hf.init();
// index 0 1 2 3 4 5 6 7 8 9
@@ -270,6 +271,10 @@ TEST(reorganize, Same)
uint8_t version = hh >= history ? block_versions[hh - history] : 1;
ASSERT_EQ(hf.get(hh), version);
}
+ ASSERT_EQ(hf.get_start_height(1), 0);
+ ASSERT_EQ(hf.get_start_height(4), 2 + history);
+ ASSERT_EQ(hf.get_start_height(7), 4 + history);
+ ASSERT_EQ(hf.get_start_height(9), 6 + history);
}
}
}
@@ -281,15 +286,15 @@ TEST(reorganize, Changed)
HardFork hf(db, 1, 0, 1, 1, 4, 100);
// v h t
- ASSERT_TRUE(hf.add(1, 0, 0));
- ASSERT_TRUE(hf.add(4, 2, 1));
- ASSERT_TRUE(hf.add(7, 4, 2));
- ASSERT_TRUE(hf.add(9, 6, 3));
+ ASSERT_TRUE(hf.add_fork(1, 0, 0));
+ ASSERT_TRUE(hf.add_fork(4, 2, 1));
+ ASSERT_TRUE(hf.add_fork(7, 4, 2));
+ ASSERT_TRUE(hf.add_fork(9, 6, 3));
hf.init();
- // fork 4 7 9
- // 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 };
+ // fork 4 7 9
+ // 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 };
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(block_versions[h]), 0, 0, 0, crypto::hash());
@@ -301,6 +306,10 @@ TEST(reorganize, Changed)
for (int hh = 0; hh < 16; ++hh) {
ASSERT_EQ(hf.get(hh), expected_versions[hh]);
}
+ ASSERT_EQ(hf.get_start_height(1), 0);
+ ASSERT_EQ(hf.get_start_height(4), 6);
+ ASSERT_EQ(hf.get_start_height(7), 8);
+ ASSERT_EQ(hf.get_start_height(9), 10);
}
// delay a bit for 9, and go back to 1 to check it stays at 9
@@ -321,6 +330,10 @@ TEST(reorganize, Changed)
for (int hh = 0; hh < 15; ++hh) {
ASSERT_EQ(hf.get(hh), expected_versions_new[hh]);
}
+ ASSERT_EQ(hf.get_start_height(1), 0);
+ ASSERT_EQ(hf.get_start_height(4), 6);
+ ASSERT_EQ(hf.get_start_height(7), 11);
+ ASSERT_EQ(hf.get_start_height(9), 14);
}
TEST(voting, threshold)
@@ -330,8 +343,8 @@ TEST(voting, threshold)
HardFork hf(db, 1, 0, 1, 1, 8, threshold);
// v h t
- ASSERT_TRUE(hf.add(1, 0, 0));
- ASSERT_TRUE(hf.add(2, 2, 1));
+ ASSERT_TRUE(hf.add_fork(1, 0, 0));
+ ASSERT_TRUE(hf.add_fork(2, 2, 1));
hf.init();
for (uint64_t h = 0; h <= 8; ++h) {
@@ -359,10 +372,10 @@ TEST(voting, different_thresholds)
HardFork hf(db, 1, 0, 1, 1, 4, 50); // window size 4
// v h t
- ASSERT_TRUE(hf.add(1, 0, 0));
- ASSERT_TRUE(hf.add(2, 5, 0, 1)); // asap
- ASSERT_TRUE(hf.add(3, 10, 100, 2)); // all votes
- ASSERT_TRUE(hf.add(4, 15, 3)); // default 50% votes
+ ASSERT_TRUE(hf.add_fork(1, 0, 0));
+ ASSERT_TRUE(hf.add_fork(2, 5, 0, 1)); // asap
+ ASSERT_TRUE(hf.add_fork(3, 10, 100, 2)); // all votes
+ ASSERT_TRUE(hf.add_fork(4, 15, 3)); // default 50% votes
hf.init();
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
@@ -386,8 +399,8 @@ TEST(new_blocks, denied)
HardFork hf(db, 1, 0, 1, 1, 4, 50);
// v h t
- ASSERT_TRUE(hf.add(1, 0, 0));
- ASSERT_TRUE(hf.add(2, 2, 1));
+ ASSERT_TRUE(hf.add_fork(1, 0, 0));
+ ASSERT_TRUE(hf.add_fork(2, 2, 1));
hf.init();
ASSERT_TRUE(hf.add(mkblock(1), 0));
@@ -411,8 +424,8 @@ TEST(new_version, early)
HardFork hf(db, 1, 0, 1, 1, 4, 50);
// v h t
- ASSERT_TRUE(hf.add(1, 0, 0));
- ASSERT_TRUE(hf.add(2, 4, 1));
+ ASSERT_TRUE(hf.add_fork(1, 0, 0));
+ ASSERT_TRUE(hf.add_fork(2, 4, 1));
hf.init();
ASSERT_TRUE(hf.add(mkblock(2), 0));
@@ -433,9 +446,9 @@ TEST(reorganize, changed)
HardFork hf(db, 1, 0, 1, 1, 4, 50);
// v h t
- ASSERT_TRUE(hf.add(1, 0, 0));
- ASSERT_TRUE(hf.add(2, 2, 1));
- ASSERT_TRUE(hf.add(3, 5, 2));
+ ASSERT_TRUE(hf.add_fork(1, 0, 0));
+ ASSERT_TRUE(hf.add_fork(2, 2, 1));
+ ASSERT_TRUE(hf.add_fork(3, 5, 2));
hf.init();
#define ADD(v, h, a) \
@@ -487,9 +500,9 @@ TEST(get, higher)
HardFork hf(db, 1, 0, 1, 1, 4, 50);
// v h t
- ASSERT_TRUE(hf.add(1, 0, 0));
- ASSERT_TRUE(hf.add(2, 2, 1));
- ASSERT_TRUE(hf.add(3, 5, 2));
+ ASSERT_TRUE(hf.add_fork(1, 0, 0));
+ ASSERT_TRUE(hf.add_fork(2, 2, 1));
+ ASSERT_TRUE(hf.add_fork(3, 5, 2));
hf.init();
ASSERT_EQ(hf.get_ideal_version(0), 1);