| 115 | // Capture this interaction with the upgraded_nop argument: set it when evaluating |
| 116 | // any script flag that is implemented as an upgraded NOP code. |
| 117 | static void ValidateCheckInputsForAllFlags(const CTransaction &tx, uint32_t failing_flags, bool add_to_cache, CCoinsViewCache& active_coins_tip) EXCLUSIVE_LOCKS_REQUIRED(cs_main) |
| 118 | { |
| 119 | PrecomputedTransactionData txdata; |
| 120 | |
| 121 | FastRandomContext insecure_rand(true); |
| 122 | |
| 123 | for (int count = 0; count < 10000; ++count) { |
| 124 | TxValidationState state; |
| 125 | |
| 126 | // Randomly selects flag combinations |
| 127 | // |
| 128 | // ELEMENTS |
| 129 | // Upstream bitcoin uses SCRIPT_VERIFY_END_MARKER, but this will break the bitcoin tests, because |
| 130 | // of some extra elements flags that have been added. |
| 131 | // SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_PUBKEYTYPE is the highest non-elements flag. |
| 132 | // FIXME: Adjust this test to work with the extra elements flags. |
| 133 | uint32_t test_flags = (uint32_t) insecure_rand.randrange((SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_PUBKEYTYPE - 1) << 1); |
| 134 | |
| 135 | // Filter out incompatible flag choices |
| 136 | if ((test_flags & SCRIPT_VERIFY_CLEANSTACK)) { |
| 137 | // CLEANSTACK requires P2SH and WITNESS, see VerifyScript() in |
| 138 | // script/interpreter.cpp |
| 139 | test_flags |= SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS; |
| 140 | } |
| 141 | if ((test_flags & SCRIPT_VERIFY_WITNESS)) { |
| 142 | // WITNESS requires P2SH |
| 143 | test_flags |= SCRIPT_VERIFY_P2SH; |
| 144 | } |
| 145 | bool ret = CheckInputScripts(tx, state, &active_coins_tip, test_flags, true, add_to_cache, txdata, nullptr); |
| 146 | // CheckInputScripts should succeed iff test_flags doesn't intersect with |
| 147 | // failing_flags |
| 148 | bool expected_return_value = !(test_flags & failing_flags); |
| 149 | BOOST_CHECK_EQUAL(ret, expected_return_value); |
| 150 | |
| 151 | // Test the caching |
| 152 | if (ret && add_to_cache) { |
| 153 | // Check that we get a cache hit if the tx was valid |
| 154 | std::vector<CCheck*> scriptchecks; |
| 155 | BOOST_CHECK(CheckInputScripts(tx, state, &active_coins_tip, test_flags, true, add_to_cache, txdata, &scriptchecks)); |
| 156 | BOOST_CHECK(scriptchecks.empty()); |
| 157 | for (auto check : scriptchecks) delete check; |
| 158 | } else { |
| 159 | // Check that we get script executions to check, if the transaction |
| 160 | // was invalid, or we didn't add to cache. |
| 161 | std::vector<CCheck*> scriptchecks; |
| 162 | BOOST_CHECK(CheckInputScripts(tx, state, &active_coins_tip, test_flags, true, add_to_cache, txdata, &scriptchecks)); |
| 163 | BOOST_CHECK_EQUAL(scriptchecks.size(), tx.vin.size()); |
| 164 | for (auto check : scriptchecks) delete check; |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | BOOST_FIXTURE_TEST_CASE(checkinputs_test, Dersig100Setup) |
| 170 | { |
no test coverage detected