shohu / c0ban

c0ban source tree
MIT License
0 stars 0 forks source link

Pass for test segwit.py #21

Closed shohu closed 6 years ago

shohu commented 6 years ago
# test/functional/segwit.py
2018-03-22 05:32:55.776000 TestFramework (INFO): Initializing test directory /tmp/test602p9826
2018-03-22 05:32:56.807000 TestFramework (INFO): Verify sigops are counted in GBT with pre-BIP141 rules before the fork
2018-03-22 05:32:58.168000 TestFramework (INFO): Verify default node can't accept any witness format txs before fork
2018-03-22 05:32:58.171000 TestFramework (ERROR): Assertion failed
Traceback (most recent call last):
  File "/c0ban/test/functional/test_framework/util.py", line 112, in try_rpc
    fun(*args, **kwds)
  File "test/functional/segwit.py", line 64, in send_to_witness
    return node.sendrawtransaction(tx_to_witness)
  File "/c0ban/test/functional/test_framework/coverage.py", line 46, in __call__
    return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs)
  File "/c0ban/test/functional/test_framework/authproxy.py", line 154, in __call__
    raise JSONRPCException(response['error'])
test_framework.authproxy.JSONRPCException: 256: absurdly-high-fee (-26)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/c0ban/test/functional/test_framework/test_framework.py", line 120, in main
    self.run_test()
  File "test/functional/segwit.py", line 165, in run_test
    self.fail_accept(self.nodes[0], "mandatory-script-verify-flag", wit_ids[NODE_0][WIT_V0][0], False)
  File "test/functional/segwit.py", line 103, in fail_accept
    assert_raises_rpc_error(-26, error_msg, send_to_witness, 1, node, getutxo(txid), self.pubkey[0], False, Decimal("49.998"), sign, redeem_script)
  File "/c0ban/test/functional/test_framework/util.py", line 104, in assert_raises_rpc_error
    assert try_rpc(code, message, fun, *args, **kwds), "No exception raised"
  File "/c0ban/test/functional/test_framework/util.py", line 118, in try_rpc
    raise AssertionError("Expected substring not found:" + e.error['message'])
AssertionError: Expected substring not found:256: absurdly-high-fee
2018-03-22 05:32:58.201000 TestFramework (INFO): Stopping nodes
2018-03-22 05:33:00.389000 TestFramework (WARNING): Not cleaning up dir /tmp/test602p9826
2018-03-22 05:33:00.390000 TestFramework (ERROR): Test failed. Test logging available at /tmp/test602p9826/test_framework.log
shohu commented 6 years ago
/**
 * Check whether all inputs of this transaction are valid (no double spends, scripts & sigs, amounts)
 * This does not modify the UTXO set.
 *
 * If pvChecks is not nullptr, script checks are pushed onto it instead of being performed inline. Any
 * script checks which are not necessary (eg due to script execution cache hits) are, obviously,
 * not pushed onto pvChecks/run.
 *
 * Setting cacheSigStore/cacheFullScriptStore to false will remove elements from the corresponding cache
 * which are matched. This is useful for checking blocks where we will likely never need the cache
 * entry again.
 *
 * Non-static (and re-declared) in src/test/txvalidationcache_tests.cpp
 */
bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsViewCache &inputs, bool fScriptChecks, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks)
{
 :
 :
            for (unsigned int i = 0; i < tx.vin.size(); i++) {
                const COutPoint &prevout = tx.vin[i].prevout;
                const Coin& coin = inputs.AccessCoin(prevout);
                assert(!coin.IsSpent());

                // We very carefully only pass in things to CScriptCheck which
                // are clearly committed to by tx' witness hash. This provides
                // a sanity check that our caching is not introducing consensus
                // failures through additional data in, eg, the coins being
                // spent being checked as a part of CScriptCheck.
                const CScript& scriptPubKey = coin.out.scriptPubKey;
                const CAmount amount = coin.out.nValue;

                // Verify signature
                CScriptCheck check(scriptPubKey, amount, tx, i, flags, cacheSigStore, &txdata);
                if (pvChecks) {
                    pvChecks->push_back(CScriptCheck());
                    check.swap(pvChecks->back());
                } else if (!check()) {
                    if (flags & STANDARD_NOT_MANDATORY_VERIFY_FLAGS) {
                        // Check whether the failure was caused by a
                        // non-mandatory script verification check, such as
                        // non-standard DER encodings or non-null dummy
                        // arguments; if so, don't trigger DoS protection to
                        // avoid splitting the network between upgraded and
                        // non-upgraded nodes.
                        CScriptCheck check2(scriptPubKey, amount, tx, i,
                                flags & ~STANDARD_NOT_MANDATORY_VERIFY_FLAGS, cacheSigStore, &txdata);
                        if (check2())
                            return state.Invalid(false, REJECT_NONSTANDARD, strprintf("non-mandatory-script-verify-flag (%s)", ScriptErrorString(check.GetScriptError())));
                    }
                    // Failures of other flags indicate a transaction that is
                    // invalid in new blocks, e.g. an invalid P2SH. We DoS ban
                    // such nodes as they are not following the protocol. That
                    // said during an upgrade careful thought should be taken
                    // as to the correct behavior - we may want to continue
                    // peering with non-upgraded nodes even after soft-fork
                    // super-majority signaling has occurred.
                    return state.DoS(100,false, REJECT_INVALID, strprintf("mandatory-script-verify-flag-failed (%s)", ScriptErrorString(check.GetScriptError())));
                }
            }
shohu commented 6 years ago

đź‘Ť

# test/functional/segwit.py
2018-03-22 05:44:56.455000 TestFramework (INFO): Initializing test directory /tmp/testd4pb60ap
2018-03-22 05:44:57.509000 TestFramework (INFO): Verify sigops are counted in GBT with pre-BIP141 rules before the fork
2018-03-22 05:44:58.891000 TestFramework (INFO): Verify default node can't accept any witness format txs before fork
2018-03-22 05:44:58.914000 TestFramework (INFO): Verify witness txs are skipped for mining before the fork
2018-03-22 05:44:59.097000 TestFramework (INFO): Verify unsigned bare witness txs in versionbits-setting blocks are valid before the fork
2018-03-22 05:44:59.135000 TestFramework (INFO): Verify unsigned p2sh witness txs without a redeem script are invalid
2018-03-22 05:44:59.139000 TestFramework (INFO): Verify unsigned p2sh witness txs with a redeem script in versionbits-settings blocks are valid before the fork
2018-03-22 05:44:59.169000 TestFramework (INFO): Verify previous witness txs skipped for mining can now be mined
2018-03-22 05:44:59.188000 TestFramework (INFO): Verify block and transaction serialization rpcs return differing serializations depending on rpc serialization flag
2018-03-22 05:44:59.243000 TestFramework (INFO): Verify witness txs without witness data are invalid after the fork
2018-03-22 05:44:59.292000 TestFramework (INFO): Verify default node can now use witness txs
2018-03-22 05:44:59.368000 TestFramework (INFO): Verify sigops are counted in GBT with BIP141 rules after the fork
2018-03-22 05:44:59.407000 TestFramework (INFO): Non-segwit miners are able to use GBT response after activation.
2018-03-22 05:44:59.493000 TestFramework (INFO): Verify behaviour of importaddress, addwitnessaddress and listunspent
2018-03-22 05:45:02.233000 TestFramework (INFO): Stopping nodes
2018-03-22 05:45:04.372000 TestFramework (INFO): Cleaning up
2018-03-22 05:45:04.377000 TestFramework (INFO): Tests successful