Changeset View
Changeset View
Standalone View
Standalone View
src/test/txvalidationcache_tests.cpp
Show First 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | |||||
// script flags used contain DISCOURAGE_UPGRADABLE_NOPS but don't contain | // script flags used contain DISCOURAGE_UPGRADABLE_NOPS but don't contain | ||||
// CHECKLOCKTIMEVERIFY (or CHECKSEQUENCEVERIFY), but the script does contain | // CHECKLOCKTIMEVERIFY (or CHECKSEQUENCEVERIFY), but the script does contain | ||||
// OP_CHECKLOCKTIMEVERIFY (or OP_CHECKSEQUENCEVERIFY), then script execution | // OP_CHECKLOCKTIMEVERIFY (or OP_CHECKSEQUENCEVERIFY), then script execution | ||||
// should fail. | // should fail. | ||||
// Capture this interaction with the upgraded_nop argument: set it when | // Capture this interaction with the upgraded_nop argument: set it when | ||||
// evaluating any script flag that is implemented as an upgraded NOP code. | // evaluating any script flag that is implemented as an upgraded NOP code. | ||||
static void ValidateCheckInputsForAllFlags(const CTransaction &tx, | static void ValidateCheckInputsForAllFlags(const CTransaction &tx, | ||||
uint32_t failing_flags, | uint32_t failing_flags, | ||||
bool add_to_cache, | bool add_to_cache, bool upgraded_nop) | ||||
bool upgraded_nop) { | EXCLUSIVE_LOCKS_REQUIRED(cs_main) { | ||||
PrecomputedTransactionData txdata(tx); | PrecomputedTransactionData txdata(tx); | ||||
// If we add many more flags, this loop can get too expensive, but we can | // If we add many more flags, this loop can get too expensive, but we can | ||||
// rewrite in the future to randomly pick a set of flags to evaluate. | // rewrite in the future to randomly pick a set of flags to evaluate. | ||||
for (uint32_t test_flags = 0; test_flags < (1U << 17); test_flags += 1) { | for (uint32_t test_flags = 0; test_flags < (1U << 17); test_flags += 1) { | ||||
CValidationState state; | CValidationState state; | ||||
// Make sure the mandatory flags are enabled. | // Make sure the mandatory flags are enabled. | ||||
test_flags |= MANDATORY_SCRIPT_VERIFY_FLAGS; | test_flags |= MANDATORY_SCRIPT_VERIFY_FLAGS; | ||||
▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | // spend_tx is invalid according to DISCOURAGE_UPGRADABLE_NOPS | ||||
tx, SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS, false, false); | tx, SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS, false, false); | ||||
} | } | ||||
// And if we produce a block with this tx, it should be valid, even though | // And if we produce a block with this tx, it should be valid, even though | ||||
// there's no cache entry. | // there's no cache entry. | ||||
CBlock block; | CBlock block; | ||||
block = CreateAndProcessBlock({spend_tx}, p2pk_scriptPubKey); | block = CreateAndProcessBlock({spend_tx}, p2pk_scriptPubKey); | ||||
LOCK(cs_main); | |||||
BOOST_CHECK(chainActive.Tip()->GetBlockHash() == block.GetHash()); | BOOST_CHECK(chainActive.Tip()->GetBlockHash() == block.GetHash()); | ||||
BOOST_CHECK(pcoinsTip->GetBestBlock() == block.GetHash()); | BOOST_CHECK(pcoinsTip->GetBestBlock() == block.GetHash()); | ||||
LOCK(cs_main); | |||||
// Test P2SH: construct a transaction that is valid without P2SH, and then | // Test P2SH: construct a transaction that is valid without P2SH, and then | ||||
// test validity with P2SH. | // test validity with P2SH. | ||||
{ | { | ||||
CMutableTransaction invalid_under_p2sh_tx; | CMutableTransaction invalid_under_p2sh_tx; | ||||
invalid_under_p2sh_tx.nVersion = 1; | invalid_under_p2sh_tx.nVersion = 1; | ||||
invalid_under_p2sh_tx.vin.resize(1); | invalid_under_p2sh_tx.vin.resize(1); | ||||
invalid_under_p2sh_tx.vin[0].prevout = COutPoint(spend_tx.GetId(), 0); | invalid_under_p2sh_tx.vin[0].prevout = COutPoint(spend_tx.GetId(), 0); | ||||
invalid_under_p2sh_tx.vout.resize(1); | invalid_under_p2sh_tx.vout.resize(1); | ||||
▲ Show 20 Lines • Show All 150 Lines • Show Last 20 Lines |