aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2015-11-11 11:08:47 +0200
committerRiccardo Spagni <ric@spagni.net>2015-11-11 11:08:54 +0200
commitea7380aa7f3906be6f319044e6ce1d207d1ae576 (patch)
treed18eed234c70ae166640d0de21a956ec74f6263e /tests
parentMerge pull request #475 (diff)
parenthardfork: add a get_ideal_version(uint64_t) function (diff)
downloadmonero-ea7380aa7f3906be6f319044e6ce1d207d1ae576.tar.xz
Merge pull request #481
2f254ff hardfork: add a get_ideal_version(uint64_t) function (moneromooo-monero) 4187e56 hardfork: allow per-fork voting thresholds (moneromooo-monero)
Diffstat (limited to 'tests')
-rw-r--r--tests/unit_tests/hardfork.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/unit_tests/hardfork.cpp b/tests/unit_tests/hardfork.cpp
index f7e4f27e9..1f6ef5bf0 100644
--- a/tests/unit_tests/hardfork.cpp
+++ b/tests/unit_tests/hardfork.cpp
@@ -352,6 +352,34 @@ TEST(voting, threshold)
}
}
+TEST(voting, different_thresholds)
+{
+ for (int threshold = 87; threshold <= 88; ++threshold) {
+ TestDB db;
+ 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
+ hf.init();
+
+ // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
+ static const uint8_t block_versions[] = { 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4 };
+ 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(block_versions[h]), 0, 0, 0, crypto::hash());
+ bool ret = hf.add(db.get_block_from_height(h), h);
+ ASSERT_EQ(ret, true);
+ }
+ for (uint64_t h = 0; h < sizeof(expected_versions) / sizeof(expected_versions[0]); ++h) {
+ ASSERT_EQ(hf.get(h), expected_versions[h]);
+ }
+ }
+}
+
TEST(new_blocks, denied)
{
TestDB db;
@@ -452,3 +480,25 @@ TEST(reorganize, changed)
ASSERT_EQ(hf.get_current_version(), 2); // we did not bump to 3 this time
ASSERT_EQ(hf.get_start_height(3), std::numeric_limits<uint64_t>::max()); // not yet
}
+
+TEST(get, higher)
+{
+ TestDB db;
+ 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));
+ hf.init();
+
+ ASSERT_EQ(hf.get_ideal_version(0), 1);
+ ASSERT_EQ(hf.get_ideal_version(1), 1);
+ ASSERT_EQ(hf.get_ideal_version(2), 2);
+ ASSERT_EQ(hf.get_ideal_version(3), 2);
+ ASSERT_EQ(hf.get_ideal_version(4), 2);
+ ASSERT_EQ(hf.get_ideal_version(5), 3);
+ ASSERT_EQ(hf.get_ideal_version(6), 3);
+ ASSERT_EQ(hf.get_ideal_version(7), 3);
+}
+