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 = {
CTxIn{m_coinbase_txns[0]->GetHash(), 0}};
53 spends[i].vout = {
CTxOut{11*
CENT, scriptPubKey}};
56 std::vector<unsigned char> vchSig;
60 spends[i].vin[0].scriptSig << vchSig;
66 block = CreateAndProcessBlock(spends, scriptPubKey);
74 block = CreateAndProcessBlock(spends, scriptPubKey);
85 block = CreateAndProcessBlock(spends, scriptPubKey);
95 std::vector<CMutableTransaction> oneSpend;
96 oneSpend.push_back(spends[0]);
98 block = CreateAndProcessBlock(oneSpend, scriptPubKey);
143 bool ret =
CheckInputScripts(tx, state, &active_coins_tip, test_flags,
true, add_to_cache, txdata, validation_cache,
nullptr);
146 bool expected_return_value = !(test_flags & failing_flags);
150 if (
ret && add_to_cache) {
152 std::vector<CScriptCheck> scriptchecks;
158 std::vector<CScriptCheck> scriptchecks;
186 spend_tx.
vin = {
CTxIn{m_coinbase_txns[0]->GetHash(), 0}};
197 std::vector<unsigned char> vchSig;
200 vchSig.push_back((
unsigned char) 0);
202 spend_tx.
vin[0].scriptSig << vchSig;
219 std::vector<CScriptCheck> scriptchecks;
234 block = CreateAndProcessBlock({spend_tx}, p2pk_scriptPubKey);
243 invalid_under_p2sh_tx.
version = 1;
245 invalid_under_p2sh_tx.
vout = {
CTxOut{11*
CENT, p2pk_scriptPubKey}};
246 std::vector<unsigned char> vchSig2(p2pk_scriptPubKey.
begin(), p2pk_scriptPubKey.
end());
247 invalid_under_p2sh_tx.
vin[0].scriptSig << vchSig2;
255 invalid_with_cltv_tx.
version = 1;
261 std::vector<unsigned char> vchSig;
265 invalid_with_cltv_tx.
vin[0].scriptSig =
CScript() << vchSig << 101;
270 invalid_with_cltv_tx.
vin[0].scriptSig =
CScript() << vchSig << 100;
279 invalid_with_csv_tx.
version = 2;
284 std::vector<unsigned char> vchSig;
288 invalid_with_csv_tx.
vin[0].scriptSig =
CScript() << vchSig << 101;
293 invalid_with_csv_tx.
vin[0].scriptSig =
CScript() << vchSig << 100;
305 valid_with_witness_tx.
version = 1;
307 valid_with_witness_tx.
vout = {
CTxOut{11*
CENT, p2pk_scriptPubKey}};
318 valid_with_witness_tx.
vin[0].scriptWitness.SetNull();
330 tr_keystore.
keys.emplace(coinbaseKey.GetPubKey().GetID(), coinbaseKey);
331 const std::map<COutPoint, Coin> coins{
332 {tr_tx.
vin[0].prevout,
Coin(spend_tx.
vout[4], 0,
false)}
334 std::map<int, bilingual_str> input_errors;
336 auto& witness_stack = tr_tx.
vin[0].scriptWitness.stack;
337 BOOST_REQUIRE(witness_stack.size() == 1 && witness_stack[0].size() == 64);
340 witness_stack[0][63] ^= 0x01;
342 witness_stack[0][63] ^= 0x01;
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.
An input of a transaction.
An output of a transaction.
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.
static constexpr script_verify_flags from_int(value_type f)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(headers.FindFirst("key"), "value")
uint256 SignatureHash(const CScript &scriptCode, const T &txTo, unsigned int nIn, int32_t nHashType, const CAmount &amount, SigVersion sigversion, const PrecomputedTransactionData *cache, SigHashCache *sighash_cache)
constexpr script_verify_flags::value_type MAX_SCRIPT_VERIFY_FLAGS
@ BASE
Bare scripts and BIP16 P2SH-wrapped redeemscripts.
@ SIGHASH_DEFAULT
Taproot only; implied when sighash byte is missing, and equivalent to SIGHASH_ALL.
@ SCRIPT_VERIFY_STRICTENC
@ SCRIPT_VERIFY_CHECKSEQUENCEVERIFY
@ SCRIPT_VERIFY_CLEANSTACK
@ SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY
@ CONFLICT
Removed for conflict with in-block transaction.
#define BOOST_CHECK(expr)
static CTransactionRef MakeTransactionRef(Tx &&txIn)
void SignTransaction(CMutableTransaction &mtx, const SigningProvider *keystore, const std::map< COutPoint, Coin > &coins, const UniValue &hashType, UniValue &result)
Sign a transaction with the given keystore and previous transactions.
std::vector< unsigned char > ToByteVector(const T &in)
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.
std::map< CKeyID, CKey > keys
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(...)
static void ValidateCheckInputsForAllFlags(const CTransaction &tx, script_verify_flags failing_flags, bool add_to_cache, CCoinsViewCache &active_coins_tip, ValidationCache &validation_cache) EXCLUSIVE_LOCKS_REQUIRED(
BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, Dersig100Setup)
bool CheckInputScripts(const CTransaction &tx, TxValidationState &state, const CCoinsViewCache &inputs, script_verify_flags 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.