16#include <boost/test/unit_test.hpp>
29BOOST_AUTO_TEST_SUITE(txvalidationcache_tests)
47 std::vector<CMutableTransaction> spends;
49 for (
int i = 0; i < 2; i++)
51 spends[i].version = 1;
52 spends[i].vin.resize(1);
53 spends[i].vin[0].prevout.hash = m_coinbase_txns[0]->GetHash();
54 spends[i].vin[0].prevout.n = 0;
55 spends[i].vout.resize(1);
56 spends[i].vout[0].nValue = 11*
CENT;
57 spends[i].vout[0].scriptPubKey = scriptPubKey;
60 std::vector<unsigned char> vchSig;
64 spends[i].vin[0].scriptSig << vchSig;
70 block = CreateAndProcessBlock(spends, scriptPubKey);
78 block = CreateAndProcessBlock(spends, scriptPubKey);
89 block = CreateAndProcessBlock(spends, scriptPubKey);
99 std::vector<CMutableTransaction> oneSpend;
100 oneSpend.push_back(spends[0]);
102 block = CreateAndProcessBlock(oneSpend, scriptPubKey);
145 bool ret =
CheckInputScripts(tx, state, &active_coins_tip, test_flags,
true, add_to_cache, txdata, validation_cache,
nullptr);
148 bool expected_return_value = !(test_flags & failing_flags);
152 if (
ret && add_to_cache) {
154 std::vector<CScriptCheck> scriptchecks;
160 std::vector<CScriptCheck> scriptchecks;
187 spend_tx.
vin.resize(1);
188 spend_tx.
vin[0].prevout.hash = m_coinbase_txns[0]->GetHash();
189 spend_tx.
vin[0].prevout.n = 0;
190 spend_tx.
vout.resize(4);
192 spend_tx.
vout[0].scriptPubKey = p2sh_scriptPubKey;
194 spend_tx.
vout[1].scriptPubKey = p2wpkh_scriptPubKey;
202 std::vector<unsigned char> vchSig;
205 vchSig.push_back((
unsigned char) 0);
207 spend_tx.
vin[0].scriptSig << vchSig;
224 std::vector<CScriptCheck> scriptchecks;
239 block = CreateAndProcessBlock({spend_tx}, p2pk_scriptPubKey);
248 invalid_under_p2sh_tx.
version = 1;
249 invalid_under_p2sh_tx.
vin.resize(1);
250 invalid_under_p2sh_tx.
vin[0].prevout.hash = spend_tx.
GetHash();
251 invalid_under_p2sh_tx.
vin[0].prevout.n = 0;
252 invalid_under_p2sh_tx.
vout.resize(1);
253 invalid_under_p2sh_tx.
vout[0].nValue = 11*
CENT;
254 invalid_under_p2sh_tx.
vout[0].scriptPubKey = p2pk_scriptPubKey;
255 std::vector<unsigned char> vchSig2(p2pk_scriptPubKey.
begin(), p2pk_scriptPubKey.
end());
256 invalid_under_p2sh_tx.
vin[0].scriptSig << vchSig2;
264 invalid_with_cltv_tx.
version = 1;
266 invalid_with_cltv_tx.
vin.resize(1);
267 invalid_with_cltv_tx.
vin[0].prevout.hash = spend_tx.
GetHash();
268 invalid_with_cltv_tx.
vin[0].prevout.n = 2;
269 invalid_with_cltv_tx.
vin[0].nSequence = 0;
270 invalid_with_cltv_tx.
vout.resize(1);
271 invalid_with_cltv_tx.
vout[0].nValue = 11*
CENT;
272 invalid_with_cltv_tx.
vout[0].scriptPubKey = p2pk_scriptPubKey;
275 std::vector<unsigned char> vchSig;
279 invalid_with_cltv_tx.
vin[0].scriptSig =
CScript() << vchSig << 101;
284 invalid_with_cltv_tx.
vin[0].scriptSig =
CScript() << vchSig << 100;
293 invalid_with_csv_tx.
version = 2;
294 invalid_with_csv_tx.
vin.resize(1);
295 invalid_with_csv_tx.
vin[0].prevout.hash = spend_tx.
GetHash();
296 invalid_with_csv_tx.
vin[0].prevout.n = 3;
297 invalid_with_csv_tx.
vin[0].nSequence = 100;
298 invalid_with_csv_tx.
vout.resize(1);
299 invalid_with_csv_tx.
vout[0].nValue = 11*
CENT;
300 invalid_with_csv_tx.
vout[0].scriptPubKey = p2pk_scriptPubKey;
303 std::vector<unsigned char> vchSig;
307 invalid_with_csv_tx.
vin[0].scriptSig =
CScript() << vchSig << 101;
312 invalid_with_csv_tx.
vin[0].scriptSig =
CScript() << vchSig << 100;
324 valid_with_witness_tx.
version = 1;
325 valid_with_witness_tx.
vin.resize(1);
326 valid_with_witness_tx.
vin[0].prevout.hash = spend_tx.
GetHash();
327 valid_with_witness_tx.
vin[0].prevout.n = 1;
328 valid_with_witness_tx.
vout.resize(1);
329 valid_with_witness_tx.
vout[0].nValue = 11*
CENT;
330 valid_with_witness_tx.
vout[0].scriptPubKey = p2pk_scriptPubKey;
341 valid_with_witness_tx.
vin[0].scriptWitness.SetNull();
352 tx.
vin[0].prevout.n = 0;
354 tx.
vin[1].prevout.n = 1;
357 tx.
vout[0].scriptPubKey = p2pk_scriptPubKey;
360 for (
int i = 0; i < 2; ++i) {
372 tx.
vin[1].scriptWitness.SetNull();
379 std::vector<CScriptCheck> scriptchecks;
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Serialized script, used inside transaction inputs and outputs.
The basic transaction that is broadcasted on the network and contained in blocks.
Fillable signing provider that keeps keys in an address->secret map.
virtual bool AddCScript(const CScript &redeemScript)
virtual bool AddKey(const CKey &key)
A signature creator for transactions.
I randrange(I range) noexcept
Generate a random integer in the range [0..range), with range > 0.
Convenience class for initializing and passing the script execution cache and signature cache.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
BOOST_AUTO_TEST_SUITE_END()
uint256 SignatureHash(const CScript &scriptCode, const T &txTo, unsigned int nIn, int32_t nHashType, const CAmount &amount, SigVersion sigversion, const PrecomputedTransactionData *cache)
@ BASE
Bare scripts and BIP16 P2SH-wrapped redeemscripts.
@ SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY
@ SCRIPT_VERIFY_STRICTENC
@ SCRIPT_VERIFY_END_MARKER
@ SCRIPT_VERIFY_CLEANSTACK
@ SCRIPT_VERIFY_CHECKSEQUENCEVERIFY
@ CONFLICT
Removed for conflict with in-block transaction.
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::vector< unsigned char > ToByteVector(const T &in)
static constexpr CAmount CENT
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
void UpdateInput(CTxIn &input, const SignatureData &data)
A mutable version of CTransaction.
std::vector< CTxOut > vout
Txid GetHash() const
Compute the hash of this CMutableTransaction.
Validation result for a transaction evaluated by MemPoolAccept (single or package).
const ResultType m_result_type
Result type.
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
std::unique_ptr< CTxMemPool > mempool
std::unique_ptr< ChainstateManager > chainman
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
#define EXCLUSIVE_LOCKS_REQUIRED(...)
BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, Dersig100Setup)
bool CheckInputScripts(const CTransaction &tx, TxValidationState &state, const CCoinsViewCache &inputs, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData &txdata, ValidationCache &validation_cache, std::vector< CScriptCheck > *pvChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Check whether all of this transaction's input scripts succeed.
static void ValidateCheckInputsForAllFlags(const CTransaction &tx, uint32_t failing_flags, bool add_to_cache, CCoinsViewCache &active_coins_tip, ValidationCache &validation_cache) EXCLUSIVE_LOCKS_REQUIRED(