Skip to content

Commit 01013f5

Browse files
committed
Simplify tx validation tests
1 parent 2dd6f80 commit 01013f5

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/test/txvalidationcache_tests.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup)
101101
// should fail.
102102
// Capture this interaction with the upgraded_nop argument: set it when evaluating
103103
// any script flag that is implemented as an upgraded NOP code.
104-
void ValidateCheckInputsForAllFlags(CMutableTransaction &tx, uint32_t failing_flags, bool add_to_cache, bool upgraded_nop)
104+
void ValidateCheckInputsForAllFlags(CMutableTransaction &tx, uint32_t failing_flags, bool add_to_cache)
105105
{
106106
PrecomputedTransactionData txdata(tx);
107107
// If we add many more flags, this loop can get too expensive, but we can
@@ -122,12 +122,6 @@ void ValidateCheckInputsForAllFlags(CMutableTransaction &tx, uint32_t failing_fl
122122
// CheckInputs should succeed iff test_flags doesn't intersect with
123123
// failing_flags
124124
bool expected_return_value = !(test_flags & failing_flags);
125-
if (expected_return_value && upgraded_nop) {
126-
// If the script flag being tested corresponds to an upgraded NOP,
127-
// then script execution should fail if DISCOURAGE_UPGRADABLE_NOPS
128-
// is set.
129-
expected_return_value = !(test_flags & SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS);
130-
}
131125
BOOST_CHECK_EQUAL(ret, expected_return_value);
132126

133127
// Test the caching
@@ -213,7 +207,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
213207
// not present. Don't add these checks to the cache, so that we can
214208
// test later that block validation works fine in the absence of cached
215209
// successes.
216-
ValidateCheckInputsForAllFlags(spend_tx, SCRIPT_VERIFY_DERSIG | SCRIPT_VERIFY_LOW_S | SCRIPT_VERIFY_STRICTENC, false, false);
210+
ValidateCheckInputsForAllFlags(spend_tx, SCRIPT_VERIFY_DERSIG | SCRIPT_VERIFY_LOW_S | SCRIPT_VERIFY_STRICTENC, false);
217211

218212
// And if we produce a block with this tx, it should be valid (DERSIG not
219213
// enabled yet), even though there's no cache entry.
@@ -238,7 +232,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
238232
std::vector<unsigned char> vchSig2(p2pk_scriptPubKey.begin(), p2pk_scriptPubKey.end());
239233
invalid_under_p2sh_tx.vin[0].scriptSig << vchSig2;
240234

241-
ValidateCheckInputsForAllFlags(invalid_under_p2sh_tx, SCRIPT_VERIFY_P2SH, true, false);
235+
ValidateCheckInputsForAllFlags(invalid_under_p2sh_tx, SCRIPT_VERIFY_P2SH, true);
242236
}
243237

244238
// Test CHECKLOCKTIMEVERIFY
@@ -261,7 +255,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
261255
vchSig.push_back((unsigned char)SIGHASH_ALL);
262256
invalid_with_cltv_tx.vin[0].scriptSig = CScript() << vchSig << 101;
263257

264-
ValidateCheckInputsForAllFlags(invalid_with_cltv_tx, SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY, true, true);
258+
ValidateCheckInputsForAllFlags(invalid_with_cltv_tx, SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY, true);
265259

266260
// Make it valid, and check again
267261
invalid_with_cltv_tx.vin[0].scriptSig = CScript() << vchSig << 100;
@@ -289,7 +283,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
289283
vchSig.push_back((unsigned char)SIGHASH_ALL);
290284
invalid_with_csv_tx.vin[0].scriptSig = CScript() << vchSig << 101;
291285

292-
ValidateCheckInputsForAllFlags(invalid_with_csv_tx, SCRIPT_VERIFY_CHECKSEQUENCEVERIFY, true, true);
286+
ValidateCheckInputsForAllFlags(invalid_with_csv_tx, SCRIPT_VERIFY_CHECKSEQUENCEVERIFY, true);
293287

294288
// Make it valid, and check again
295289
invalid_with_csv_tx.vin[0].scriptSig = CScript() << vchSig << 100;
@@ -318,11 +312,11 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
318312
UpdateTransaction(valid_with_witness_tx, 0, sigdata);
319313

320314
// This should be valid under all script flags.
321-
ValidateCheckInputsForAllFlags(valid_with_witness_tx, 0, true, false);
315+
ValidateCheckInputsForAllFlags(valid_with_witness_tx, 0, true);
322316

323317
// Remove the witness, and check that it is now invalid.
324318
valid_with_witness_tx.vin[0].scriptWitness.SetNull();
325-
ValidateCheckInputsForAllFlags(valid_with_witness_tx, SCRIPT_VERIFY_WITNESS, true, false);
319+
ValidateCheckInputsForAllFlags(valid_with_witness_tx, SCRIPT_VERIFY_WITNESS, true);
326320
}
327321

328322
{
@@ -347,7 +341,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
347341
}
348342

349343
// This should be valid under all script flags
350-
ValidateCheckInputsForAllFlags(tx, 0, true, false);
344+
ValidateCheckInputsForAllFlags(tx, 0, true);
351345

352346
// Check that if the second input is invalid, but the first input is
353347
// valid, the transaction is not cached.

0 commit comments

Comments
 (0)