|
22 | 22 | #include <streams.h>
|
23 | 23 | #include <test/util/transaction_utils.h>
|
24 | 24 | #include <util/strencodings.h>
|
| 25 | +#include <util/string.h> |
25 | 26 | #include <validation.h>
|
26 | 27 |
|
27 | 28 | #include <functional>
|
@@ -230,6 +231,21 @@ BOOST_AUTO_TEST_CASE(tx_valid)
|
230 | 231 | if (!CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues, ~verify_flags, txdata, strTest, /* expect_valid */ true)) {
|
231 | 232 | BOOST_ERROR("Tx unexpectedly failed: " << strTest);
|
232 | 233 | }
|
| 234 | + |
| 235 | + // Backwards compatibility of script verification flags: Removing any flag(s) should not invalidate a valid transaction |
| 236 | + for (size_t i = 0; i < mapFlagNames.size(); ++i) { |
| 237 | + // Removing individual flags |
| 238 | + unsigned int flags = TrimFlags(~(verify_flags | (1U << i))); |
| 239 | + if (!CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues, flags, txdata, strTest, /* expect_valid */ true)) { |
| 240 | + BOOST_ERROR("Tx unexpectedly failed with flag " << ToString(i) << " unset: " << strTest); |
| 241 | + } |
| 242 | + // Removing random combinations of flags |
| 243 | + flags = TrimFlags(~(verify_flags | (unsigned int)InsecureRandBits(mapFlagNames.size()))); |
| 244 | + if (!CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues, flags, txdata, strTest, /* expect_valid */ true)) { |
| 245 | + BOOST_ERROR("Tx unexpectedly failed with random flags " << ToString(flags) << ": " << strTest); |
| 246 | + } |
| 247 | + } |
| 248 | + |
233 | 249 | // Check that flags are maximal: transaction should fail if any unset flags are set.
|
234 | 250 | for (auto flags_excluding_one: ExcludeIndividualFlags(verify_flags)) {
|
235 | 251 | if (!CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues, ~flags_excluding_one, txdata, strTest, /* expect_valid */ false)) {
|
@@ -302,6 +318,21 @@ BOOST_AUTO_TEST_CASE(tx_invalid)
|
302 | 318 | if (!CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues, verify_flags, txdata, strTest, /* expect_valid */ false)) {
|
303 | 319 | BOOST_ERROR("Tx unexpectedly passed: " << strTest);
|
304 | 320 | }
|
| 321 | + |
| 322 | + // Backwards compatibility of script verification flags: Adding any flag(s) should not validate an invalid transaction |
| 323 | + for (size_t i = 0; i < mapFlagNames.size(); i++) { |
| 324 | + unsigned int flags = FillFlags(verify_flags | (1U << i)); |
| 325 | + // Adding individual flags |
| 326 | + if (!CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues, flags, txdata, strTest, /* expect_valid */ false)) { |
| 327 | + BOOST_ERROR("Tx unexpectedly passed with flag " << ToString(i) << " set: " << strTest); |
| 328 | + } |
| 329 | + // Adding random combinations of flags |
| 330 | + flags = FillFlags(verify_flags | (unsigned int)InsecureRandBits(mapFlagNames.size())); |
| 331 | + if (!CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues, flags, txdata, strTest, /* expect_valid */ false)) { |
| 332 | + BOOST_ERROR("Tx unexpectedly passed with random flags " << ToString(flags) << ": " << strTest); |
| 333 | + } |
| 334 | + } |
| 335 | + |
305 | 336 | // Check that flags are minimal: transaction should succeed if any set flags are unset.
|
306 | 337 | for (auto flags_excluding_one: ExcludeIndividualFlags(verify_flags)) {
|
307 | 338 | if (!CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues, flags_excluding_one, txdata, strTest, /* expect_valid */ true)) {
|
|
0 commit comments