Simplify tx validation tests
This commit is contained in:
parent
2dd6f80680
commit
01013f5d2f
1 changed files with 8 additions and 14 deletions
|
@ -101,7 +101,7 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup)
|
||||||
// should fail.
|
// should fail.
|
||||||
// Capture this interaction with the upgraded_nop argument: set it when evaluating
|
// Capture this interaction with the upgraded_nop argument: set it when evaluating
|
||||||
// any script flag that is implemented as an upgraded NOP code.
|
// any script flag that is implemented as an upgraded NOP code.
|
||||||
void ValidateCheckInputsForAllFlags(CMutableTransaction &tx, uint32_t failing_flags, bool add_to_cache, bool upgraded_nop)
|
void ValidateCheckInputsForAllFlags(CMutableTransaction &tx, uint32_t failing_flags, bool add_to_cache)
|
||||||
{
|
{
|
||||||
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
|
||||||
|
@ -122,12 +122,6 @@ void ValidateCheckInputsForAllFlags(CMutableTransaction &tx, uint32_t failing_fl
|
||||||
// CheckInputs should succeed iff test_flags doesn't intersect with
|
// CheckInputs should succeed iff test_flags doesn't intersect with
|
||||||
// failing_flags
|
// failing_flags
|
||||||
bool expected_return_value = !(test_flags & failing_flags);
|
bool expected_return_value = !(test_flags & failing_flags);
|
||||||
if (expected_return_value && upgraded_nop) {
|
|
||||||
// If the script flag being tested corresponds to an upgraded NOP,
|
|
||||||
// then script execution should fail if DISCOURAGE_UPGRADABLE_NOPS
|
|
||||||
// is set.
|
|
||||||
expected_return_value = !(test_flags & SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS);
|
|
||||||
}
|
|
||||||
BOOST_CHECK_EQUAL(ret, expected_return_value);
|
BOOST_CHECK_EQUAL(ret, expected_return_value);
|
||||||
|
|
||||||
// Test the caching
|
// Test the caching
|
||||||
|
@ -213,7 +207,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
|
||||||
// not present. Don't add these checks to the cache, so that we can
|
// not present. Don't add these checks to the cache, so that we can
|
||||||
// test later that block validation works fine in the absence of cached
|
// test later that block validation works fine in the absence of cached
|
||||||
// successes.
|
// successes.
|
||||||
ValidateCheckInputsForAllFlags(spend_tx, SCRIPT_VERIFY_DERSIG | SCRIPT_VERIFY_LOW_S | SCRIPT_VERIFY_STRICTENC, false, false);
|
ValidateCheckInputsForAllFlags(spend_tx, SCRIPT_VERIFY_DERSIG | SCRIPT_VERIFY_LOW_S | SCRIPT_VERIFY_STRICTENC, false);
|
||||||
|
|
||||||
// And if we produce a block with this tx, it should be valid (DERSIG not
|
// And if we produce a block with this tx, it should be valid (DERSIG not
|
||||||
// enabled yet), even though there's no cache entry.
|
// enabled yet), even though there's no cache entry.
|
||||||
|
@ -238,7 +232,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
|
||||||
std::vector<unsigned char> vchSig2(p2pk_scriptPubKey.begin(), p2pk_scriptPubKey.end());
|
std::vector<unsigned char> vchSig2(p2pk_scriptPubKey.begin(), p2pk_scriptPubKey.end());
|
||||||
invalid_under_p2sh_tx.vin[0].scriptSig << vchSig2;
|
invalid_under_p2sh_tx.vin[0].scriptSig << vchSig2;
|
||||||
|
|
||||||
ValidateCheckInputsForAllFlags(invalid_under_p2sh_tx, SCRIPT_VERIFY_P2SH, true, false);
|
ValidateCheckInputsForAllFlags(invalid_under_p2sh_tx, SCRIPT_VERIFY_P2SH, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test CHECKLOCKTIMEVERIFY
|
// Test CHECKLOCKTIMEVERIFY
|
||||||
|
@ -261,7 +255,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
|
||||||
vchSig.push_back((unsigned char)SIGHASH_ALL);
|
vchSig.push_back((unsigned char)SIGHASH_ALL);
|
||||||
invalid_with_cltv_tx.vin[0].scriptSig = CScript() << vchSig << 101;
|
invalid_with_cltv_tx.vin[0].scriptSig = CScript() << vchSig << 101;
|
||||||
|
|
||||||
ValidateCheckInputsForAllFlags(invalid_with_cltv_tx, SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY, true, true);
|
ValidateCheckInputsForAllFlags(invalid_with_cltv_tx, SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY, true);
|
||||||
|
|
||||||
// Make it valid, and check again
|
// Make it valid, and check again
|
||||||
invalid_with_cltv_tx.vin[0].scriptSig = CScript() << vchSig << 100;
|
invalid_with_cltv_tx.vin[0].scriptSig = CScript() << vchSig << 100;
|
||||||
|
@ -289,7 +283,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
|
||||||
vchSig.push_back((unsigned char)SIGHASH_ALL);
|
vchSig.push_back((unsigned char)SIGHASH_ALL);
|
||||||
invalid_with_csv_tx.vin[0].scriptSig = CScript() << vchSig << 101;
|
invalid_with_csv_tx.vin[0].scriptSig = CScript() << vchSig << 101;
|
||||||
|
|
||||||
ValidateCheckInputsForAllFlags(invalid_with_csv_tx, SCRIPT_VERIFY_CHECKSEQUENCEVERIFY, true, true);
|
ValidateCheckInputsForAllFlags(invalid_with_csv_tx, SCRIPT_VERIFY_CHECKSEQUENCEVERIFY, true);
|
||||||
|
|
||||||
// Make it valid, and check again
|
// Make it valid, and check again
|
||||||
invalid_with_csv_tx.vin[0].scriptSig = CScript() << vchSig << 100;
|
invalid_with_csv_tx.vin[0].scriptSig = CScript() << vchSig << 100;
|
||||||
|
@ -318,11 +312,11 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
|
||||||
UpdateTransaction(valid_with_witness_tx, 0, sigdata);
|
UpdateTransaction(valid_with_witness_tx, 0, sigdata);
|
||||||
|
|
||||||
// This should be valid under all script flags.
|
// This should be valid under all script flags.
|
||||||
ValidateCheckInputsForAllFlags(valid_with_witness_tx, 0, true, false);
|
ValidateCheckInputsForAllFlags(valid_with_witness_tx, 0, true);
|
||||||
|
|
||||||
// Remove the witness, and check that it is now invalid.
|
// Remove the witness, and check that it is now invalid.
|
||||||
valid_with_witness_tx.vin[0].scriptWitness.SetNull();
|
valid_with_witness_tx.vin[0].scriptWitness.SetNull();
|
||||||
ValidateCheckInputsForAllFlags(valid_with_witness_tx, SCRIPT_VERIFY_WITNESS, true, false);
|
ValidateCheckInputsForAllFlags(valid_with_witness_tx, SCRIPT_VERIFY_WITNESS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -347,7 +341,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This should be valid under all script flags
|
// This should be valid under all script flags
|
||||||
ValidateCheckInputsForAllFlags(tx, 0, true, false);
|
ValidateCheckInputsForAllFlags(tx, 0, true);
|
||||||
|
|
||||||
// Check that if the second input is invalid, but the first input is
|
// Check that if the second input is invalid, but the first input is
|
||||||
// valid, the transaction is not cached.
|
// valid, the transaction is not cached.
|
||||||
|
|
Loading…
Reference in a new issue