Skip to content

Commit b109bde

Browse files
committed
[test] check that mapFlagNames is up to date
There is no way to iterate through all script verification flags, and it's not guaranteed that every power of 2 is used. Just make sure that all flags in STANDARD_SCRIPT_VERIFY_FLAGS are present in mapFlagNames; this covers all consensus and policy flags. If mapFlagNames has more flags than STANDARD_SCRIPT_VERIFY_FLAGS, that's okay. Nonexistent flags will be caught by the compiler.
1 parent 5d3ced7 commit b109bde

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/test/transaction_tests.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ unsigned int ParseScriptFlags(std::string strFlags)
8282
return flags;
8383
}
8484

85+
// Check that all flags in STANDARD_SCRIPT_VERIFY_FLAGS are present in mapFlagNames.
86+
bool CheckMapFlagNames()
87+
{
88+
unsigned int standard_flags_missing{STANDARD_SCRIPT_VERIFY_FLAGS};
89+
for (const auto& pair : mapFlagNames) {
90+
standard_flags_missing &= ~(pair.second);
91+
}
92+
return standard_flags_missing == 0;
93+
}
94+
8595
std::string FormatScriptFlags(unsigned int flags)
8696
{
8797
if (flags == 0) {
@@ -178,6 +188,7 @@ BOOST_FIXTURE_TEST_SUITE(transaction_tests, BasicTestingSetup)
178188

179189
BOOST_AUTO_TEST_CASE(tx_valid)
180190
{
191+
BOOST_CHECK_MESSAGE(CheckMapFlagNames(), "mapFlagNames is missing a script verification flag");
181192
// Read tests from test/data/tx_valid.json
182193
UniValue tests = read_json(std::string(json_tests::tx_valid, json_tests::tx_valid + sizeof(json_tests::tx_valid)));
183194

0 commit comments

Comments
 (0)