-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlibauth_tests.cpp
More file actions
155 lines (128 loc) · 5.62 KB
/
Copy pathlibauth_tests.cpp
File metadata and controls
155 lines (128 loc) · 5.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Copyright (c) 2022-2025 The Bitcoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <chainparams.h>
#include <config.h>
#include <consensus/activation.h>
#include <util/system.h>
#include <validation.h>
#include <test/libauth_testing_setup.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>
#include <cstdlib>
#include <optional>
#include <string>
namespace {
/// Test fixture that can force-enable or disable upgrade9 (cashtokens)
struct Upgrade9OverrideTestingSetup : LibauthTestingSetup {
std::optional<int32_t> upgrade9OriginalOverride;
bool touchedUpgrade9{};
Upgrade9OverrideTestingSetup() {
upgrade9OriginalOverride = g_Upgrade9HeightOverride;
}
~Upgrade9OverrideTestingSetup() override {
if (touchedUpgrade9) {
g_Upgrade9HeightOverride = upgrade9OriginalOverride;
}
}
/// Activates or deactivates upgrade 9 by setting the activation height in the past or future respectively
void SetUpgrade9Active(bool active) {
const auto currentHeight = []{
LOCK(cs_main);
return ::ChainActive().Tip()->nHeight;
}();
auto activationHeight = active ? currentHeight - 1 : currentHeight + 1;
g_Upgrade9HeightOverride = activationHeight;
touchedUpgrade9 = true;
}
};
/// Test fixture that can force-enable or disable upgrade 11 (vmlimits + bigint) as well as upgrade9 (cashtokens)
struct Upgrade11OverrideTestingSetup : Upgrade9OverrideTestingSetup {
std::optional<int32_t> upgrade11OriginalOverride;
bool touchedUpgrade11 = false;
Upgrade11OverrideTestingSetup() {
upgrade11OriginalOverride = g_Upgrade11HeightOverride;
}
~Upgrade11OverrideTestingSetup() override {
if (touchedUpgrade11) {
g_Upgrade11HeightOverride = upgrade11OriginalOverride;
}
}
/// Activates or deactivates upgrade 11 by setting the activation height in the past or future respectively
void SetUpgrade11Active(bool active) {
const auto currentHeight = []{
LOCK(cs_main);
return ::ChainActive().Tip()->nHeight;
}();
auto activationHeight = active ? currentHeight - 1 : currentHeight + 1;
g_Upgrade11HeightOverride = activationHeight;
touchedUpgrade11 = true;
}
};
/// Test fixture that can force-enable or disable upgrade 12 (may2026), as well as upgrade 9 & 11
struct Upgrade12OverrideTestingSetup : Upgrade11OverrideTestingSetup {
std::optional<std::string> optOrigArg12;
bool touchedUpgrade12 = false;
Upgrade12OverrideTestingSetup() {
if (gArgs.IsArgSet("-upgrade12activationtime")) {
optOrigArg12 = gArgs.GetArg("-upgrade12activationtime", "");
}
}
~Upgrade12OverrideTestingSetup() override {
if (touchedUpgrade12) {
gArgs.ClearArg("-upgrade12activationtime");
if (optOrigArg12) {
gArgs.ForceSetArg("-upgrade12activationtime", *optOrigArg12);
}
}
}
/// Activates or deactivates upgrade 11 by setting the activation time in the past or future respectively
void SetUpgrade12Active(bool active) {
if (active) {
gArgs.ForceSetArg("-upgrade12activationtime", "1000000");
} else {
gArgs.ForceSetArg("-upgrade12activationtime", "9223372036854775807");
}
touchedUpgrade12 = true;
}
};
bool ran2022 = false, ran2023 = false, ran2025 = false, ran2026 = false;
} // namespace
// DeVault forked from BCH (ABC 0.20) and does NOT carry BCH's later upgrades — 1E set
// graviton/phonon/upgrade8..12 to far-future sentinels. The libauth suite is the BCH spec
// "regression" test-vector harness for exactly those upgrades (2022/2023/2025/2026), so it
// is not applicable to DeVault and is disabled here.
BOOST_AUTO_TEST_SUITE(libauth_tests, *boost::unit_test::disabled())
BOOST_FIXTURE_TEST_CASE(regression_2022, Upgrade12OverrideTestingSetup) {
SetUpgrade9Active(false); // needs to be forced off for this series of tests
SetUpgrade11Active(false); // also need to ensure upgrade11 is not activated for this series of tests
SetUpgrade12Active(false); // also need to ensure upgrade12 is not activated for this series of tests
RunTestPack("2022");
ran2022 = true;
}
BOOST_FIXTURE_TEST_CASE(regression_2023, Upgrade12OverrideTestingSetup) {
SetUpgrade11Active(false); // need to ensure upgrade11 is not activated for this series of tests
SetUpgrade12Active(false); // need to ensure upgrade12 is not activated for this series of tests
RunTestPack("2023");
ran2023 = true;
}
BOOST_FIXTURE_TEST_CASE(upgrade11_2025, Upgrade12OverrideTestingSetup) {
SetUpgrade11Active(true); // force Upgrade11 (vmlimts + bigint) to be active
SetUpgrade12Active(false); // need to ensure upgrade12 is not activated for this series of tests
RunTestPack("2025");
ran2025 = true;
}
BOOST_FIXTURE_TEST_CASE(upgrade12_2026, Upgrade12OverrideTestingSetup) {
SetUpgrade11Active(true); // ensure Upgrade11 (vmlimts + bigint) is active
SetUpgrade12Active(true); // ensure Upgrade12 (may2026) is active
RunTestPack("2026");
ran2026 = true;
}
// Precondition: This test *requires* that all Libauth test packs have previously completed as part of this
// test_bitcoin run.
BOOST_FIXTURE_TEST_CASE(test_lookup_table, TestingSetup) {
BOOST_REQUIRE(ran2022 && ran2023 && ran2025 && ran2026);
LibauthTestingSetup::ProcessExpectedReasonsTable();
LibauthTestingSetup::ProcessExpectedMetricsTable();
}
BOOST_AUTO_TEST_SUITE_END()