shohu / c0ban

c0ban source tree
MIT License
0 stars 0 forks source link

Pass signlogic for mempool_limit.py #57

Closed shohu closed 6 years ago

shohu commented 6 years ago
# test/functional/mempool_limit.py
2018-07-11 05:26:04.717000 TestFramework (INFO): Initializing test directory /tmp/testye0yoo8k
2018-07-11 05:26:05.442000 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/mempool_limit.py", line 38, in run_test
    txids[i] = create_lots_of_big_transactions(self.nodes[0], txouts, utxos[30*i:30*i+30], 30, (i+1)*base_fee)
  File "/c0ban/test/functional/test_framework/util.py", line 553, in create_lots_of_big_transactions
    signresult = node.signrawtransaction(newtx, None, None, "NONE")
  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: Signature must use SIGHASH_FORKID (-8)
2018-07-11 05:26:05.457000 TestFramework (INFO): Stopping nodes
2018-07-11 05:26:07.736000 TestFramework (WARNING): Not cleaning up dir /tmp/testye0yoo8k
2018-07-11 05:26:07.737000 TestFramework (ERROR): Test failed. Test logging available at /tmp/testye0yoo8k/test_framework.log
shohu commented 6 years ago
    def run_test(self):
        txouts = gen_return_txouts()
        relayfee = self.nodes[0].getnetworkinfo()['relayfee']

        txids = []
        utxos = create_confirmed_utxos(relayfee, self.nodes[0], 91)

        #create a mempool tx that will be evicted
        us0 = utxos.pop()
        inputs = [{ "txid" : us0["txid"], "vout" : us0["vout"]}]
        outputs = {self.nodes[0].getnewaddress() : 0.0001}
        tx = self.nodes[0].createrawtransaction(inputs, outputs)
        self.nodes[0].settxfee(relayfee) # specifically fund this tx with low fee
        txF = self.nodes[0].fundrawtransaction(tx)
        self.nodes[0].settxfee(0) # return to automatic fee selection
        txFS = self.nodes[0].signrawtransaction(txF['hex'])
        txid = self.nodes[0].sendrawtransaction(txFS['hex'])

        relayfee = self.nodes[0].getnetworkinfo()['relayfee']
        base_fee = relayfee*100
        for i in range (3):
            txids.append([])
            txids[i] = create_lots_of_big_transactions(self.nodes[0], txouts, utxos[30*i:30*i+30], 30, (i+1)*base_fee)
# Create a spend of each passed-in utxo, splicing in "txouts" to each raw
# transaction to make it large.  See gen_return_txouts() above.
def create_lots_of_big_transactions(node, txouts, utxos, num, fee):
    addr = node.getnewaddress()
    txids = []
    for _ in range(num):
        t = utxos.pop()
        inputs = [{"txid": t["txid"], "vout": t["vout"]}]
        outputs = {}
        change = t['amount'] - fee
        outputs[addr] = satoshi_round(change)
        rawtx = node.createrawtransaction(inputs, outputs)
        newtx = rawtx[0:92]
        newtx = newtx + txouts
        newtx = newtx + rawtx[94:]
        signresult = node.signrawtransaction(newtx, None, None, "NONE")
        txid = node.sendrawtransaction(signresult["hex"], True)
        txids.append(txid)
    return txids
UniValue signrawtransaction(const JSONRPCRequest& request)
{
 :
 :
    SigHashType sigHashType = SigHashType().withForkId();
    if (request.params.size() > 3 && !request.params[3].isNull()) {
        static std::map<std::string, int> mapSigHashValues = {
            {std::string("ALL"), int(SIGHASH_ALL)},
            {std::string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY)},
            {std::string("ALL|FORKID"), int(SIGHASH_ALL|SIGHASH_FORKID)},
            {std::string("ALL|FORKID|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_FORKID|SIGHASH_ANYONECANPAY)},
            {std::string("NONE"), int(SIGHASH_NONE)},
            {std::string("NONE|ANYONECANPAY"), int(SIGHASH_NONE|SIGHASH_ANYONECANPAY)},
            {std::string("NONE|FORKID"), int(SIGHASH_NONE|SIGHASH_FORKID)},
            {std::string("NONE|FORKID|ANYONECANPAY"), int(SIGHASH_NONE|SIGHASH_FORKID|SIGHASH_ANYONECANPAY)},
            {std::string("SINGLE"), int(SIGHASH_SINGLE)},
            {std::string("SINGLE|ANYONECANPAY"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY)},
            {std::string("SINGLE|FORKID"), int(SIGHASH_SINGLE|SIGHASH_FORKID)},
            {std::string("SINGLE|FORKID|ANYONECANPAY"), int(SIGHASH_SINGLE|SIGHASH_FORKID|SIGHASH_ANYONECANPAY)},
        };
        std::string strHashType = request.params[3].get_str();
        // if (mapSigHashValues.count(strHashType))
        //     nHashType = mapSigHashValues[strHashType];
        // else
        //     throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid sighash param");
        if (!mapSigHashValues.count(strHashType)) {
            throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid sighash param");
        }

        sigHashType = SigHashType(mapSigHashValues[strHashType]);
        if (!sigHashType.hasForkId()) {
            throw JSONRPCError(RPC_INVALID_PARAMETER,
                               "Signature must use SIGHASH_FORKID");
        }
    }
 :
shohu commented 6 years ago

I changed following source 2018-07-12 13 31 44

I got pass 👍

# test/functional/mempool_limit.py
2018-07-12 04:30:21.101000 TestFramework (INFO): Initializing test directory /tmp/testhpn02qf6
2018-07-12 04:30:24.660000 TestFramework (INFO): Stopping nodes
2018-07-12 04:30:26.841000 TestFramework (INFO): Cleaning up
2018-07-12 04:30:26.846000 TestFramework (INFO): Tests successful