Skip to content

Commit b10ce9a

Browse files
glozowjl2012
andcommitted
[test] check verification flags are minimal/maximal
Co-authored-by: Johnson Lau <[email protected]>
1 parent a260c22 commit b10ce9a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/test/transaction_tests.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ BOOST_AUTO_TEST_CASE(tx_valid)
230230
if (!CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues, ~verify_flags, txdata, strTest, /* expect_valid */ true)) {
231231
BOOST_ERROR("Tx unexpectedly failed: " << strTest);
232232
}
233+
// Check that flags are maximal: transaction should fail if any unset flags are set.
234+
for (auto flags_excluding_one: ExcludeIndividualFlags(verify_flags)) {
235+
if (!CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues, ~flags_excluding_one, txdata, strTest, /* expect_valid */ false)) {
236+
BOOST_ERROR("Too many flags unset: " << strTest);
237+
}
238+
}
233239
}
234240
}
235241
}
@@ -292,9 +298,16 @@ BOOST_AUTO_TEST_CASE(tx_invalid)
292298
PrecomputedTransactionData txdata(tx);
293299
unsigned int verify_flags = ParseScriptFlags(test[2].get_str());
294300

301+
// Not using FillFlags() in the main test, in order to detect invalid verifyFlags combination
295302
if (!CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues, verify_flags, txdata, strTest, /* expect_valid */ false)) {
296303
BOOST_ERROR("Tx unexpectedly passed: " << strTest);
297304
}
305+
// Check that flags are minimal: transaction should succeed if any set flags are unset.
306+
for (auto flags_excluding_one: ExcludeIndividualFlags(verify_flags)) {
307+
if (!CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues, flags_excluding_one, txdata, strTest, /* expect_valid */ true)) {
308+
BOOST_ERROR("Too many flags set: " << strTest);
309+
}
310+
}
298311
}
299312
}
300313
}

0 commit comments

Comments
 (0)