11 #include <txmempool.h>
15 #include <boost/test/unit_test.hpp>
45 std::vector<CMutableTransaction> spends;
47 for (
int i = 0; i < 2; i++)
49 spends[i].nVersion = 1;
50 spends[i].vin.resize(1);
51 spends[i].vin[0].prevout.hash = m_coinbase_txns[0]->GetHash();
52 spends[i].vin[0].prevout.n = 0;
53 spends[i].vout.resize(1);
54 spends[i].vout[0].nValue = 11*
CENT;
55 spends[i].vout[0].scriptPubKey = scriptPubKey;
58 std::vector<unsigned char> vchSig;
62 spends[i].vin[0].scriptSig << vchSig;
68 block = CreateAndProcessBlock(spends, scriptPubKey);
76 block = CreateAndProcessBlock(spends, scriptPubKey);
87 block = CreateAndProcessBlock(spends, scriptPubKey);
97 std::vector<CMutableTransaction> oneSpend;
98 oneSpend.push_back(spends[0]);
100 block = CreateAndProcessBlock(oneSpend, scriptPubKey);
143 bool ret =
CheckInputScripts(tx, state, &active_coins_tip, test_flags,
true, add_to_cache, txdata,
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;
185 spend_tx.
vin.resize(1);
186 spend_tx.
vin[0].prevout.hash = m_coinbase_txns[0]->GetHash();
187 spend_tx.
vin[0].prevout.n = 0;
188 spend_tx.
vout.resize(4);
190 spend_tx.
vout[0].scriptPubKey = p2sh_scriptPubKey;
192 spend_tx.
vout[1].scriptPubKey = p2wpkh_scriptPubKey;
200 std::vector<unsigned char> vchSig;
203 vchSig.push_back((
unsigned char) 0);
205 spend_tx.
vin[0].scriptSig << vchSig;
222 std::vector<CScriptCheck> scriptchecks;
237 block = CreateAndProcessBlock({spend_tx}, p2pk_scriptPubKey);
247 invalid_under_p2sh_tx.
vin.resize(1);
248 invalid_under_p2sh_tx.
vin[0].prevout.hash = spend_tx.
GetHash();
249 invalid_under_p2sh_tx.
vin[0].prevout.n = 0;
250 invalid_under_p2sh_tx.
vout.resize(1);
251 invalid_under_p2sh_tx.
vout[0].nValue = 11*
CENT;
252 invalid_under_p2sh_tx.
vout[0].scriptPubKey = p2pk_scriptPubKey;
253 std::vector<unsigned char> vchSig2(p2pk_scriptPubKey.
begin(), p2pk_scriptPubKey.
end());
254 invalid_under_p2sh_tx.
vin[0].scriptSig << vchSig2;
264 invalid_with_cltv_tx.
vin.resize(1);
265 invalid_with_cltv_tx.
vin[0].prevout.hash = spend_tx.
GetHash();
266 invalid_with_cltv_tx.
vin[0].prevout.n = 2;
267 invalid_with_cltv_tx.
vin[0].nSequence = 0;
268 invalid_with_cltv_tx.
vout.resize(1);
269 invalid_with_cltv_tx.
vout[0].nValue = 11*
CENT;
270 invalid_with_cltv_tx.
vout[0].scriptPubKey = p2pk_scriptPubKey;
273 std::vector<unsigned char> vchSig;
277 invalid_with_cltv_tx.
vin[0].scriptSig =
CScript() << vchSig << 101;
282 invalid_with_cltv_tx.
vin[0].scriptSig =
CScript() << vchSig << 100;
292 invalid_with_csv_tx.
vin.resize(1);
293 invalid_with_csv_tx.
vin[0].prevout.hash = spend_tx.
GetHash();
294 invalid_with_csv_tx.
vin[0].prevout.n = 3;
295 invalid_with_csv_tx.
vin[0].nSequence = 100;
296 invalid_with_csv_tx.
vout.resize(1);
297 invalid_with_csv_tx.
vout[0].nValue = 11*
CENT;
298 invalid_with_csv_tx.
vout[0].scriptPubKey = p2pk_scriptPubKey;
301 std::vector<unsigned char> vchSig;
305 invalid_with_csv_tx.
vin[0].scriptSig =
CScript() << vchSig << 101;
310 invalid_with_csv_tx.
vin[0].scriptSig =
CScript() << vchSig << 100;
323 valid_with_witness_tx.
vin.resize(1);
324 valid_with_witness_tx.
vin[0].prevout.hash = spend_tx.
GetHash();
325 valid_with_witness_tx.
vin[0].prevout.n = 1;
326 valid_with_witness_tx.
vout.resize(1);
327 valid_with_witness_tx.
vout[0].nValue = 11*
CENT;
328 valid_with_witness_tx.
vout[0].scriptPubKey = p2pk_scriptPubKey;
339 valid_with_witness_tx.
vin[0].scriptWitness.SetNull();
350 tx.
vin[0].prevout.n = 0;
352 tx.
vin[1].prevout.n = 1;
355 tx.
vout[0].scriptPubKey = p2pk_scriptPubKey;
358 for (
int i = 0; i < 2; ++i) {
370 tx.
vin[1].scriptWitness.SetNull();
377 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.
uint64_t randrange(uint64_t range) noexcept
Generate a random integer in the range [0..range).
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.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
BOOST_AUTO_TEST_SUITE(cuckoocache_tests)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
uint256 SignatureHash(const CScript &scriptCode, const T &txTo, unsigned int nIn, int 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(...)
bool CheckInputScripts(const CTransaction &tx, TxValidationState &state, const CCoinsViewCache &inputs, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData &txdata, std::vector< CScriptCheck > *pvChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Check whether all of this transaction's input scripts succeed.
BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, Dersig100Setup)
static void ValidateCheckInputsForAllFlags(const CTransaction &tx, uint32_t failing_flags, bool add_to_cache, CCoinsViewCache &active_coins_tip) EXCLUSIVE_LOCKS_REQUIRED(