Skip to content

Commit e197076

Browse files
committed
test: Pass in CoinsTip to ValidateCheckInputsForAllFlags
1 parent 4d99b61 commit e197076

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/test/txvalidationcache_tests.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup)
109109
// should fail.
110110
// Capture this interaction with the upgraded_nop argument: set it when evaluating
111111
// any script flag that is implemented as an upgraded NOP code.
112-
static void ValidateCheckInputsForAllFlags(const CTransaction &tx, uint32_t failing_flags, bool add_to_cache) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
112+
static void ValidateCheckInputsForAllFlags(const CTransaction &tx, uint32_t failing_flags, bool add_to_cache, CCoinsViewCache& active_coins_tip) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
113113
{
114114
PrecomputedTransactionData txdata;
115115
// If we add many more flags, this loop can get too expensive, but we can
@@ -126,7 +126,7 @@ static void ValidateCheckInputsForAllFlags(const CTransaction &tx, uint32_t fail
126126
// WITNESS requires P2SH
127127
test_flags |= SCRIPT_VERIFY_P2SH;
128128
}
129-
bool ret = CheckInputScripts(tx, state, &::ChainstateActive().CoinsTip(), test_flags, true, add_to_cache, txdata, nullptr);
129+
bool ret = CheckInputScripts(tx, state, &active_coins_tip, test_flags, true, add_to_cache, txdata, nullptr);
130130
// CheckInputScripts should succeed iff test_flags doesn't intersect with
131131
// failing_flags
132132
bool expected_return_value = !(test_flags & failing_flags);
@@ -136,13 +136,13 @@ static void ValidateCheckInputsForAllFlags(const CTransaction &tx, uint32_t fail
136136
if (ret && add_to_cache) {
137137
// Check that we get a cache hit if the tx was valid
138138
std::vector<CScriptCheck> scriptchecks;
139-
BOOST_CHECK(CheckInputScripts(tx, state, &::ChainstateActive().CoinsTip(), test_flags, true, add_to_cache, txdata, &scriptchecks));
139+
BOOST_CHECK(CheckInputScripts(tx, state, &active_coins_tip, test_flags, true, add_to_cache, txdata, &scriptchecks));
140140
BOOST_CHECK(scriptchecks.empty());
141141
} else {
142142
// Check that we get script executions to check, if the transaction
143143
// was invalid, or we didn't add to cache.
144144
std::vector<CScriptCheck> scriptchecks;
145-
BOOST_CHECK(CheckInputScripts(tx, state, &::ChainstateActive().CoinsTip(), test_flags, true, add_to_cache, txdata, &scriptchecks));
145+
BOOST_CHECK(CheckInputScripts(tx, state, &active_coins_tip, test_flags, true, add_to_cache, txdata, &scriptchecks));
146146
BOOST_CHECK_EQUAL(scriptchecks.size(), tx.vin.size());
147147
}
148148
}
@@ -218,7 +218,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
218218
// not present. Don't add these checks to the cache, so that we can
219219
// test later that block validation works fine in the absence of cached
220220
// successes.
221-
ValidateCheckInputsForAllFlags(CTransaction(spend_tx), SCRIPT_VERIFY_DERSIG | SCRIPT_VERIFY_LOW_S | SCRIPT_VERIFY_STRICTENC, false);
221+
ValidateCheckInputsForAllFlags(CTransaction(spend_tx), SCRIPT_VERIFY_DERSIG | SCRIPT_VERIFY_LOW_S | SCRIPT_VERIFY_STRICTENC, false, ::ChainstateActive().CoinsTip());
222222
}
223223

224224
// And if we produce a block with this tx, it should be valid (DERSIG not
@@ -244,7 +244,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
244244
std::vector<unsigned char> vchSig2(p2pk_scriptPubKey.begin(), p2pk_scriptPubKey.end());
245245
invalid_under_p2sh_tx.vin[0].scriptSig << vchSig2;
246246

247-
ValidateCheckInputsForAllFlags(CTransaction(invalid_under_p2sh_tx), SCRIPT_VERIFY_P2SH, true);
247+
ValidateCheckInputsForAllFlags(CTransaction(invalid_under_p2sh_tx), SCRIPT_VERIFY_P2SH, true, ::ChainstateActive().CoinsTip());
248248
}
249249

250250
// Test CHECKLOCKTIMEVERIFY
@@ -267,7 +267,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
267267
vchSig.push_back((unsigned char)SIGHASH_ALL);
268268
invalid_with_cltv_tx.vin[0].scriptSig = CScript() << vchSig << 101;
269269

270-
ValidateCheckInputsForAllFlags(CTransaction(invalid_with_cltv_tx), SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY, true);
270+
ValidateCheckInputsForAllFlags(CTransaction(invalid_with_cltv_tx), SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY, true, ::ChainstateActive().CoinsTip());
271271

272272
// Make it valid, and check again
273273
invalid_with_cltv_tx.vin[0].scriptSig = CScript() << vchSig << 100;
@@ -295,7 +295,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
295295
vchSig.push_back((unsigned char)SIGHASH_ALL);
296296
invalid_with_csv_tx.vin[0].scriptSig = CScript() << vchSig << 101;
297297

298-
ValidateCheckInputsForAllFlags(CTransaction(invalid_with_csv_tx), SCRIPT_VERIFY_CHECKSEQUENCEVERIFY, true);
298+
ValidateCheckInputsForAllFlags(CTransaction(invalid_with_csv_tx), SCRIPT_VERIFY_CHECKSEQUENCEVERIFY, true, ::ChainstateActive().CoinsTip());
299299

300300
// Make it valid, and check again
301301
invalid_with_csv_tx.vin[0].scriptSig = CScript() << vchSig << 100;
@@ -324,11 +324,11 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
324324
UpdateInput(valid_with_witness_tx.vin[0], sigdata);
325325

326326
// This should be valid under all script flags.
327-
ValidateCheckInputsForAllFlags(CTransaction(valid_with_witness_tx), 0, true);
327+
ValidateCheckInputsForAllFlags(CTransaction(valid_with_witness_tx), 0, true, ::ChainstateActive().CoinsTip());
328328

329329
// Remove the witness, and check that it is now invalid.
330330
valid_with_witness_tx.vin[0].scriptWitness.SetNull();
331-
ValidateCheckInputsForAllFlags(CTransaction(valid_with_witness_tx), SCRIPT_VERIFY_WITNESS, true);
331+
ValidateCheckInputsForAllFlags(CTransaction(valid_with_witness_tx), SCRIPT_VERIFY_WITNESS, true, ::ChainstateActive().CoinsTip());
332332
}
333333

334334
{
@@ -353,7 +353,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
353353
}
354354

355355
// This should be valid under all script flags
356-
ValidateCheckInputsForAllFlags(CTransaction(tx), 0, true);
356+
ValidateCheckInputsForAllFlags(CTransaction(tx), 0, true, ::ChainstateActive().CoinsTip());
357357

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

0 commit comments

Comments
 (0)