11 #include <txmempool.h>
14 #include <boost/test/unit_test.hpp>
44 std::vector<CMutableTransaction> spends;
46 for (
int i = 0; i < 2; i++)
48 spends[i].nVersion = 1;
49 spends[i].vin.resize(1);
50 spends[i].vin[0].prevout.hash = m_coinbase_txns[0]->GetHash();
51 spends[i].vin[0].prevout.n = 0;
52 spends[i].vout.resize(1);
53 spends[i].vout[0].nValue = 11*
CENT;
54 spends[i].vout[0].scriptPubKey = scriptPubKey;
57 std::vector<unsigned char> vchSig;
61 spends[i].vin[0].scriptSig << vchSig;
67 block = CreateAndProcessBlock(spends, scriptPubKey);
75 block = CreateAndProcessBlock(spends, scriptPubKey);
86 block = CreateAndProcessBlock(spends, scriptPubKey);
96 std::vector<CMutableTransaction> oneSpend;
97 oneSpend.push_back(spends[0]);
99 block = CreateAndProcessBlock(oneSpend, scriptPubKey);
142 bool ret =
CheckInputScripts(tx, state, &active_coins_tip, test_flags,
true, add_to_cache, txdata,
nullptr);
145 bool expected_return_value = !(test_flags & failing_flags);
149 if (
ret && add_to_cache) {
151 std::vector<CScriptCheck> scriptchecks;
157 std::vector<CScriptCheck> scriptchecks;
184 spend_tx.
vin.resize(1);
185 spend_tx.
vin[0].prevout.hash = m_coinbase_txns[0]->GetHash();
186 spend_tx.
vin[0].prevout.n = 0;
187 spend_tx.
vout.resize(4);
189 spend_tx.
vout[0].scriptPubKey = p2sh_scriptPubKey;
191 spend_tx.
vout[1].scriptPubKey = p2wpkh_scriptPubKey;
199 std::vector<unsigned char> vchSig;
202 vchSig.push_back((
unsigned char) 0);
204 spend_tx.
vin[0].scriptSig << vchSig;
221 std::vector<CScriptCheck> scriptchecks;
236 block = CreateAndProcessBlock({spend_tx}, p2pk_scriptPubKey);
246 invalid_under_p2sh_tx.
vin.resize(1);
247 invalid_under_p2sh_tx.
vin[0].prevout.hash = spend_tx.
GetHash();
248 invalid_under_p2sh_tx.
vin[0].prevout.n = 0;
249 invalid_under_p2sh_tx.
vout.resize(1);
250 invalid_under_p2sh_tx.
vout[0].nValue = 11*
CENT;
251 invalid_under_p2sh_tx.
vout[0].scriptPubKey = p2pk_scriptPubKey;
252 std::vector<unsigned char> vchSig2(p2pk_scriptPubKey.
begin(), p2pk_scriptPubKey.
end());
253 invalid_under_p2sh_tx.
vin[0].scriptSig << vchSig2;
263 invalid_with_cltv_tx.
vin.resize(1);
264 invalid_with_cltv_tx.
vin[0].prevout.hash = spend_tx.
GetHash();
265 invalid_with_cltv_tx.
vin[0].prevout.n = 2;
266 invalid_with_cltv_tx.
vin[0].nSequence = 0;
267 invalid_with_cltv_tx.
vout.resize(1);
268 invalid_with_cltv_tx.
vout[0].nValue = 11*
CENT;
269 invalid_with_cltv_tx.
vout[0].scriptPubKey = p2pk_scriptPubKey;
272 std::vector<unsigned char> vchSig;
276 invalid_with_cltv_tx.
vin[0].scriptSig =
CScript() << vchSig << 101;
281 invalid_with_cltv_tx.
vin[0].scriptSig =
CScript() << vchSig << 100;
291 invalid_with_csv_tx.
vin.resize(1);
292 invalid_with_csv_tx.
vin[0].prevout.hash = spend_tx.
GetHash();
293 invalid_with_csv_tx.
vin[0].prevout.n = 3;
294 invalid_with_csv_tx.
vin[0].nSequence = 100;
295 invalid_with_csv_tx.
vout.resize(1);
296 invalid_with_csv_tx.
vout[0].nValue = 11*
CENT;
297 invalid_with_csv_tx.
vout[0].scriptPubKey = p2pk_scriptPubKey;
300 std::vector<unsigned char> vchSig;
304 invalid_with_csv_tx.
vin[0].scriptSig =
CScript() << vchSig << 101;
309 invalid_with_csv_tx.
vin[0].scriptSig =
CScript() << vchSig << 100;
322 valid_with_witness_tx.
vin.resize(1);
323 valid_with_witness_tx.
vin[0].prevout.hash = spend_tx.
GetHash();
324 valid_with_witness_tx.
vin[0].prevout.n = 1;
325 valid_with_witness_tx.
vout.resize(1);
326 valid_with_witness_tx.
vout[0].nValue = 11*
CENT;
327 valid_with_witness_tx.
vout[0].scriptPubKey = p2pk_scriptPubKey;
338 valid_with_witness_tx.
vin[0].scriptWitness.SetNull();
349 tx.
vin[0].prevout.n = 0;
351 tx.
vin[1].prevout.n = 1;
354 tx.
vout[0].scriptPubKey = p2pk_scriptPubKey;
357 for (
int i = 0; i < 2; ++i) {
369 tx.
vin[1].scriptWitness.SetNull();
376 std::vector<CScriptCheck> scriptchecks;
CBaseChainParams defines the base parameters (shared between bitcoin-cli and bitcoind) of a given ins...
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
#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)
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
A mutable version of CTransaction.
uint256 GetHash() const
Compute the hash of this CMutableTransaction.
std::vector< CTxOut > vout
Validation result for a single transaction mempool acceptance.
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(...)
@ CONFLICT
Removed for conflict with in-block transaction.
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(