12 #include <txmempool.h> 16 #include <boost/test/unit_test.hpp> 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);
191 spend_tx.vout[0].nValue = 11*
CENT;
192 spend_tx.vout[0].scriptPubKey = p2sh_scriptPubKey;
193 spend_tx.vout[1].nValue = 11*
CENT;
194 spend_tx.vout[1].scriptPubKey = p2wpkh_scriptPubKey;
195 spend_tx.vout[2].nValue = 11*
CENT;
197 spend_tx.vout[3].nValue = 11*
CENT;
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();
351 tx.
vin[0].prevout.hash = spend_tx.GetHash();
352 tx.
vin[0].prevout.n = 0;
353 tx.
vin[1].prevout.hash = spend_tx.GetHash();
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;
Convenience class for initializing and passing the script execution cache and signature cache...
virtual bool AddCScript(const CScript &redeemScript)
Removed for conflict with in-block transaction.
Bare scripts and BIP16 P2SH-wrapped redeemscripts.
const ResultType m_result_type
Result type.
A signature creator for transactions.
std::unique_ptr< CTxMemPool > mempool
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.
BOOST_AUTO_TEST_SUITE_END()
static void ValidateCheckInputsForAllFlags(const CTransaction &tx, uint32_t failing_flags, bool add_to_cache, CCoinsViewCache &active_coins_tip, ValidationCache &validation_cache) EXCLUSIVE_LOCKS_REQUIRED(
Fillable signing provider that keeps keys in an address->secret map.
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
std::vector< CTxOut > vout
Validation result for a transaction evaluated by MemPoolAccept (single or package).
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::vector< unsigned char > ToByteVector(const T &in)
#define EXCLUSIVE_LOCKS_REQUIRED(...)
#define BOOST_CHECK_EQUAL(v1, v2)
Serialized script, used inside transaction inputs and outputs.
void UpdateInput(CTxIn &input, const SignatureData &data)
uint256 SignatureHash(const CScript &scriptCode, const T &txTo, unsigned int nIn, int nHashType, const CAmount &amount, SigVersion sigversion, const PrecomputedTransactionData *cache)
I randrange(I range) noexcept
Generate a random integer in the range [0..range), with range > 0.
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
BOOST_AUTO_TEST_SUITE(cuckoocache_tests)
Test Suite for CuckooCache.
A mutable version of CTransaction.
static constexpr CAmount CENT
The basic transaction that is broadcasted on the network and contained in blocks. ...
CCoinsView that adds a memory cache for transactions to another CCoinsView.
BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, Dersig100Setup)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
std::unique_ptr< ChainstateManager > chainman
virtual bool AddKey(const CKey &key)
#define BOOST_CHECK(expr)