shohu / c0ban

c0ban source tree
MIT License
0 stars 0 forks source link

Pass signlogic for bumpfee.py #61

Closed shohu closed 6 years ago

shohu commented 6 years ago
# test/functional/bumpfee.py
2018-07-11 05:56:27.341000 TestFramework (INFO): Initializing test directory /tmp/testul_6tzvu
2018-07-11 05:56:30.968000 TestFramework (INFO): Mining blocks...
2018-07-11 05:56:32.364000 TestFramework (INFO): Running tests
2018-07-11 05:56:34.489000 TestFramework (ERROR): JSONRPC error
Traceback (most recent call last):
  File "/c0ban/test/functional/test_framework/test_framework.py", line 120, in main
    self.run_test()
  File "test/functional/bumpfee.py", line 67, in run_test
    test_notmine_bumpfee_fails(rbf_node, peer_node, dest_address)
  File "test/functional/bumpfee.py", line 155, in test_notmine_bumpfee_fails
    rbfid = rbf_node.sendrawtransaction(signedtx["hex"])
  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: 16: mandatory-script-verify-flag-failed (Operation not valid with the current stack size) (-26)
2018-07-11 05:56:34.500000 TestFramework (INFO): Stopping nodes
2018-07-11 05:56:36.615000 TestFramework (WARNING): Not cleaning up dir /tmp/testul_6tzvu
2018-07-11 05:56:36.615000 TestFramework (ERROR): Test failed. Test logging available at /tmp/testul_6tzvu/test_framework.log
shohu commented 6 years ago
def test_notmine_bumpfee_fails(rbf_node, peer_node, dest_address):
    # cannot bump fee unless the tx has only inputs that we own.
    # here, the rbftx has a peer_node coin and then adds a rbf_node input
    # Note that this test depends upon the RPC code checking input ownership prior to change outputs
    # (since it can't use fundrawtransaction, it lacks a proper change output)
    utxos = [node.listunspent()[-1] for node in (rbf_node, peer_node)]
    inputs = [{
        "txid": utxo["txid"],
        "vout": utxo["vout"],
        "address": utxo["address"],
        "sequence": BIP125_SEQUENCE_NUMBER
    } for utxo in utxos]
    output_val = sum(utxo["amount"] for utxo in utxos) - Decimal("0.001")
    rawtx = rbf_node.createrawtransaction(inputs, {dest_address: output_val})
    signedtx = rbf_node.signrawtransaction(rawtx)
    signedtx = peer_node.signrawtransaction(signedtx["hex"])
    rbfid = rbf_node.sendrawtransaction(signedtx["hex"])
    assert_raises_rpc_error(-4, "Transaction contains inputs that don't belong to this wallet",
                          rbf_node.bumpfee, rbfid)
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)
{
 :
 :
                // 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

I passed this test 👍 Maybe this test was affected by https://github.com/shohu/c0ban/commit/dfad1fe863baae4e570580e5ae3e78cfeaadd602

test/functional/bumpfee.py
2018-07-13 04:46:01.392000 TestFramework (INFO): Initializing test directory /tmp/testi7dq9c9a
2018-07-13 04:46:05.008000 TestFramework (INFO): Mining blocks...
2018-07-13 04:46:06.423000 TestFramework (INFO): Running tests
2018-07-13 04:46:09.907000 TestFramework (INFO): Success
2018-07-13 04:46:09.907000 TestFramework (INFO): Stopping nodes
2018-07-13 04:46:12.103000 TestFramework (INFO): Cleaning up
2018-07-13 04:46:12.106000 TestFramework (INFO): Tests successful