]> Git Repo - VerusCoin.git/blame - src/gtest/test_upgrades.cpp
Build fix
[VerusCoin.git] / src / gtest / test_upgrades.cpp
CommitLineData
f52da911
JG
1#include <gtest/gtest.h>
2
3#include "chainparams.h"
4#include "consensus/upgrades.h"
5
149d69e3
JG
6#include <boost/optional.hpp>
7
f52da911
JG
8class UpgradesTest : public ::testing::Test {
9protected:
10 virtual void SetUp() {
11 }
12
13 virtual void TearDown() {
14 // Revert to default
15 UpdateNetworkUpgradeParameters(Consensus::UPGRADE_TESTDUMMY, Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT);
16 }
17};
18
19TEST_F(UpgradesTest, NetworkUpgradeState) {
20 SelectParams(CBaseChainParams::REGTEST);
21 const Consensus::Params& params = Params().GetConsensus();
22
23 // Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT
24 EXPECT_EQ(
25 NetworkUpgradeState(0, params, Consensus::UPGRADE_TESTDUMMY),
26 UPGRADE_DISABLED);
27 EXPECT_EQ(
28 NetworkUpgradeState(1000000, params, Consensus::UPGRADE_TESTDUMMY),
29 UPGRADE_DISABLED);
30
31 UpdateNetworkUpgradeParameters(Consensus::UPGRADE_TESTDUMMY, Consensus::NetworkUpgrade::ALWAYS_ACTIVE);
32
33 EXPECT_EQ(
34 NetworkUpgradeState(0, params, Consensus::UPGRADE_TESTDUMMY),
35 UPGRADE_ACTIVE);
36 EXPECT_EQ(
37 NetworkUpgradeState(1000000, params, Consensus::UPGRADE_TESTDUMMY),
38 UPGRADE_ACTIVE);
39
40 int nActivationHeight = 100;
41 UpdateNetworkUpgradeParameters(Consensus::UPGRADE_TESTDUMMY, nActivationHeight);
42
43 EXPECT_EQ(
44 NetworkUpgradeState(0, params, Consensus::UPGRADE_TESTDUMMY),
45 UPGRADE_PENDING);
46 EXPECT_EQ(
47 NetworkUpgradeState(nActivationHeight - 1, params, Consensus::UPGRADE_TESTDUMMY),
48 UPGRADE_PENDING);
49 EXPECT_EQ(
50 NetworkUpgradeState(nActivationHeight, params, Consensus::UPGRADE_TESTDUMMY),
51 UPGRADE_ACTIVE);
52 EXPECT_EQ(
53 NetworkUpgradeState(1000000, params, Consensus::UPGRADE_TESTDUMMY),
54 UPGRADE_ACTIVE);
55}
56
57TEST_F(UpgradesTest, CurrentEpoch) {
58 SelectParams(CBaseChainParams::REGTEST);
59 const Consensus::Params& params = Params().GetConsensus();
60 auto nBranchId = NetworkUpgradeInfo[Consensus::UPGRADE_TESTDUMMY].nBranchId;
61
62 // Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT
63 EXPECT_EQ(CurrentEpoch(0, params), Consensus::BASE_SPROUT);
64 EXPECT_EQ(CurrentEpochBranchId(0, params), 0);
65 EXPECT_EQ(CurrentEpoch(1000000, params), Consensus::BASE_SPROUT);
66 EXPECT_EQ(CurrentEpochBranchId(1000000, params), 0);
67
68 UpdateNetworkUpgradeParameters(Consensus::UPGRADE_TESTDUMMY, Consensus::NetworkUpgrade::ALWAYS_ACTIVE);
69
70 EXPECT_EQ(CurrentEpoch(0, params), Consensus::UPGRADE_TESTDUMMY);
71 EXPECT_EQ(CurrentEpochBranchId(0, params), nBranchId);
72 EXPECT_EQ(CurrentEpoch(1000000, params), Consensus::UPGRADE_TESTDUMMY);
73 EXPECT_EQ(CurrentEpochBranchId(1000000, params), nBranchId);
74
75 int nActivationHeight = 100;
76 UpdateNetworkUpgradeParameters(Consensus::UPGRADE_TESTDUMMY, nActivationHeight);
77
78 EXPECT_EQ(CurrentEpoch(0, params), Consensus::BASE_SPROUT);
79 EXPECT_EQ(CurrentEpochBranchId(0, params), 0);
80 EXPECT_EQ(CurrentEpoch(nActivationHeight - 1, params), Consensus::BASE_SPROUT);
81 EXPECT_EQ(CurrentEpochBranchId(nActivationHeight - 1, params), 0);
82 EXPECT_EQ(CurrentEpoch(nActivationHeight, params), Consensus::UPGRADE_TESTDUMMY);
83 EXPECT_EQ(CurrentEpochBranchId(nActivationHeight, params), nBranchId);
84 EXPECT_EQ(CurrentEpoch(1000000, params), Consensus::UPGRADE_TESTDUMMY);
85 EXPECT_EQ(CurrentEpochBranchId(1000000, params), nBranchId);
86}
87
88TEST_F(UpgradesTest, IsActivationHeight) {
89 SelectParams(CBaseChainParams::REGTEST);
90 const Consensus::Params& params = Params().GetConsensus();
91
92 // Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT
93 EXPECT_FALSE(IsActivationHeight(-1, params, Consensus::UPGRADE_TESTDUMMY));
94 EXPECT_FALSE(IsActivationHeight(0, params, Consensus::UPGRADE_TESTDUMMY));
95 EXPECT_FALSE(IsActivationHeight(1, params, Consensus::UPGRADE_TESTDUMMY));
96 EXPECT_FALSE(IsActivationHeight(1000000, params, Consensus::UPGRADE_TESTDUMMY));
97
98 UpdateNetworkUpgradeParameters(Consensus::UPGRADE_TESTDUMMY, Consensus::NetworkUpgrade::ALWAYS_ACTIVE);
99
100 EXPECT_FALSE(IsActivationHeight(-1, params, Consensus::UPGRADE_TESTDUMMY));
101 EXPECT_TRUE(IsActivationHeight(0, params, Consensus::UPGRADE_TESTDUMMY));
102 EXPECT_FALSE(IsActivationHeight(1, params, Consensus::UPGRADE_TESTDUMMY));
103 EXPECT_FALSE(IsActivationHeight(1000000, params, Consensus::UPGRADE_TESTDUMMY));
104
105 int nActivationHeight = 100;
106 UpdateNetworkUpgradeParameters(Consensus::UPGRADE_TESTDUMMY, nActivationHeight);
107
108 EXPECT_FALSE(IsActivationHeight(-1, params, Consensus::UPGRADE_TESTDUMMY));
109 EXPECT_FALSE(IsActivationHeight(0, params, Consensus::UPGRADE_TESTDUMMY));
110 EXPECT_FALSE(IsActivationHeight(1, params, Consensus::UPGRADE_TESTDUMMY));
111 EXPECT_FALSE(IsActivationHeight(nActivationHeight - 1, params, Consensus::UPGRADE_TESTDUMMY));
112 EXPECT_TRUE(IsActivationHeight(nActivationHeight, params, Consensus::UPGRADE_TESTDUMMY));
113 EXPECT_FALSE(IsActivationHeight(nActivationHeight + 1, params, Consensus::UPGRADE_TESTDUMMY));
114 EXPECT_FALSE(IsActivationHeight(1000000, params, Consensus::UPGRADE_TESTDUMMY));
115}
116
117TEST_F(UpgradesTest, IsActivationHeightForAnyUpgrade) {
118 SelectParams(CBaseChainParams::REGTEST);
119 const Consensus::Params& params = Params().GetConsensus();
120
121 // Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT
122 EXPECT_FALSE(IsActivationHeightForAnyUpgrade(-1, params));
123 EXPECT_FALSE(IsActivationHeightForAnyUpgrade(0, params));
124 EXPECT_FALSE(IsActivationHeightForAnyUpgrade(1, params));
125 EXPECT_FALSE(IsActivationHeightForAnyUpgrade(1000000, params));
126
127 UpdateNetworkUpgradeParameters(Consensus::UPGRADE_TESTDUMMY, Consensus::NetworkUpgrade::ALWAYS_ACTIVE);
128
129 EXPECT_FALSE(IsActivationHeightForAnyUpgrade(-1, params));
130 EXPECT_TRUE(IsActivationHeightForAnyUpgrade(0, params));
131 EXPECT_FALSE(IsActivationHeightForAnyUpgrade(1, params));
132 EXPECT_FALSE(IsActivationHeightForAnyUpgrade(1000000, params));
133
134 int nActivationHeight = 100;
135 UpdateNetworkUpgradeParameters(Consensus::UPGRADE_TESTDUMMY, nActivationHeight);
136
137 EXPECT_FALSE(IsActivationHeightForAnyUpgrade(-1, params));
138 EXPECT_FALSE(IsActivationHeightForAnyUpgrade(0, params));
139 EXPECT_FALSE(IsActivationHeightForAnyUpgrade(1, params));
140 EXPECT_FALSE(IsActivationHeightForAnyUpgrade(nActivationHeight - 1, params));
141 EXPECT_TRUE(IsActivationHeightForAnyUpgrade(nActivationHeight, params));
142 EXPECT_FALSE(IsActivationHeightForAnyUpgrade(nActivationHeight + 1, params));
143 EXPECT_FALSE(IsActivationHeightForAnyUpgrade(1000000, params));
144}
149d69e3 145
07d3f947
JG
146TEST_F(UpgradesTest, NextEpoch) {
147 SelectParams(CBaseChainParams::REGTEST);
148 const Consensus::Params& params = Params().GetConsensus();
149
150 // Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT
151 EXPECT_EQ(NextEpoch(-1, params), boost::none);
152 EXPECT_EQ(NextEpoch(0, params), boost::none);
153 EXPECT_EQ(NextEpoch(1, params), boost::none);
154 EXPECT_EQ(NextEpoch(1000000, params), boost::none);
155
156 UpdateNetworkUpgradeParameters(Consensus::UPGRADE_TESTDUMMY, Consensus::NetworkUpgrade::ALWAYS_ACTIVE);
157
158 EXPECT_EQ(NextEpoch(-1, params), boost::none);
159 EXPECT_EQ(NextEpoch(0, params), boost::none);
160 EXPECT_EQ(NextEpoch(1, params), boost::none);
161 EXPECT_EQ(NextEpoch(1000000, params), boost::none);
162
163 int nActivationHeight = 100;
164 UpdateNetworkUpgradeParameters(Consensus::UPGRADE_TESTDUMMY, nActivationHeight);
165
166 EXPECT_EQ(NextEpoch(-1, params), boost::none);
167 EXPECT_EQ(NextEpoch(0, params), static_cast<int>(Consensus::UPGRADE_TESTDUMMY));
168 EXPECT_EQ(NextEpoch(1, params), static_cast<int>(Consensus::UPGRADE_TESTDUMMY));
169 EXPECT_EQ(NextEpoch(nActivationHeight - 1, params), static_cast<int>(Consensus::UPGRADE_TESTDUMMY));
170 EXPECT_EQ(NextEpoch(nActivationHeight, params), boost::none);
171 EXPECT_EQ(NextEpoch(nActivationHeight + 1, params), boost::none);
172 EXPECT_EQ(NextEpoch(1000000, params), boost::none);
173}
174
149d69e3
JG
175TEST_F(UpgradesTest, NextActivationHeight) {
176 SelectParams(CBaseChainParams::REGTEST);
177 const Consensus::Params& params = Params().GetConsensus();
178
179 // Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT
180 EXPECT_EQ(NextActivationHeight(-1, params), boost::none);
181 EXPECT_EQ(NextActivationHeight(0, params), boost::none);
182 EXPECT_EQ(NextActivationHeight(1, params), boost::none);
183 EXPECT_EQ(NextActivationHeight(1000000, params), boost::none);
184
185 UpdateNetworkUpgradeParameters(Consensus::UPGRADE_TESTDUMMY, Consensus::NetworkUpgrade::ALWAYS_ACTIVE);
186
187 EXPECT_EQ(NextActivationHeight(-1, params), boost::none);
188 EXPECT_EQ(NextActivationHeight(0, params), boost::none);
189 EXPECT_EQ(NextActivationHeight(1, params), boost::none);
190 EXPECT_EQ(NextActivationHeight(1000000, params), boost::none);
191
192 int nActivationHeight = 100;
193 UpdateNetworkUpgradeParameters(Consensus::UPGRADE_TESTDUMMY, nActivationHeight);
194
195 EXPECT_EQ(NextActivationHeight(-1, params), boost::none);
196 EXPECT_EQ(NextActivationHeight(0, params), nActivationHeight);
197 EXPECT_EQ(NextActivationHeight(1, params), nActivationHeight);
198 EXPECT_EQ(NextActivationHeight(nActivationHeight - 1, params), nActivationHeight);
199 EXPECT_EQ(NextActivationHeight(nActivationHeight, params), boost::none);
200 EXPECT_EQ(NextActivationHeight(nActivationHeight + 1, params), boost::none);
201 EXPECT_EQ(NextActivationHeight(1000000, params), boost::none);
202}
This page took 0.238485 seconds and 4 git commands to generate.