I've reworked this test to use the MiniWallet.
If you want you can take the diff and squash. It requires a rebase on current master, though.
However, for some reason one line in the test fails and I fail to see why. I can take another look there, unless someone beats me to it.
Also, there are some whitespace fixes. You can check them with git diff --ignore-all-space.
diff --git a/src/rpc/mempool.cpp b/src/rpc/mempool.cpp
index fe25dc9edc..2d07b8bd2e 100644
--- a/src/rpc/mempool.cpp
+++ b/src/rpc/mempool.cpp
@@ -590,83 +590,83 @@ static RPCHelpMan getmempoolentry()
static RPCHelpMan getmempooltxspendingprevout()
{
return RPCHelpMan{"getmempooltxspendingprevout",
- "Scans the mempool to find transactions spending any of the given outputs",
+ "Scans the mempool to find transactions spending any of the given outputs",
+ {
+ {"outputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "The transaction outputs that we want to check, and within each, the txid (string) vout (numeric).",
{
- {"outputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "The transaction outputs that we want to check, and within each, the txid (string) vout (numeric).",
+ {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "",
{
- {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "",
- {
- {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"},
- {"vout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The output number"},
- },
- },
+ {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"},
+ {"vout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The output number"},
},
},
},
- RPCResult{
- RPCResult::Type::ARR, "", "",
- {
- {RPCResult::Type::OBJ, "", "",
- {
- {RPCResult::Type::STR_HEX, "txid", "the transaction id of the spent output"},
- {RPCResult::Type::NUM, "vout", "the vout value of the spent output"},
- {RPCResult::Type::STR_HEX, "spendingtxid", /*optional=*/true, "the transaction id of the mempool transaction spending this output (omitted if unspent)"},
- }},
- }
- },
- RPCExamples{
- HelpExampleCli("getmempooltxspendingprevout", "\"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":3}]\"")
- + HelpExampleRpc("getmempooltxspendingprevout", "\"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":3}]\"")
- },
+ },
+ },
+ RPCResult{
+ RPCResult::Type::ARR, "", "",
+ {
+ {RPCResult::Type::OBJ, "", "",
+ {
+ {RPCResult::Type::STR_HEX, "txid", "the transaction id of the spent output"},
+ {RPCResult::Type::NUM, "vout", "the vout value of the spent output"},
+ {RPCResult::Type::STR_HEX, "spendingtxid", /*optional=*/true, "the transaction id of the mempool transaction spending this output (omitted if unspent)"},
+ }},
+ }
+ },
+ RPCExamples{
+ HelpExampleCli("getmempooltxspendingprevout", "\"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":3}]\"")
+ + HelpExampleRpc("getmempooltxspendingprevout", "\"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":3}]\"")
+ },
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
-{
- RPCTypeCheckArgument(request.params[0], UniValue::VARR);
- const UniValue& output_params = request.params[0];
- if (output_params.empty()) {
- throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, outputs are missing");
- }
+ {
+ RPCTypeCheckArgument(request.params[0], UniValue::VARR);
+ const UniValue& output_params = request.params[0];
+ if (output_params.empty()) {
+ throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, outputs are missing");
+ }
- std::vector<COutPoint> outputs;
- outputs.reserve(output_params.size());
+ std::vector<COutPoint> outputs;
+ outputs.reserve(output_params.size());
- for (unsigned int idx = 0; idx < output_params.size(); idx++) {
- const UniValue& o = output_params[idx].get_obj();
+ for (unsigned int idx = 0; idx < output_params.size(); idx++) {
+ const UniValue& o = output_params[idx].get_obj();
- RPCTypeCheckObj(o,
- {
- {"txid", UniValueType(UniValue::VSTR)},
- {"vout", UniValueType(UniValue::VNUM)},
- });
+ RPCTypeCheckObj(o,
+ {
+ {"txid", UniValueType(UniValue::VSTR)},
+ {"vout", UniValueType(UniValue::VNUM)},
+ });
+
+ const uint256 txid(ParseHashO(o, "txid"));
+ const int nOutput = find_value(o, "vout").get_int();
+ if (nOutput < 0) {
+ throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative");
+ }
- const uint256 txid(ParseHashO(o, "txid"));
- const int nOutput = find_value(o, "vout").get_int();
- if (nOutput < 0) {
- throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative");
- }
+ outputs.emplace_back(txid, nOutput);
+ }
- outputs.emplace_back(txid, nOutput);
- }
+ const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
+ LOCK(mempool.cs);
- const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
- LOCK(mempool.cs);
-
- UniValue result{UniValue::VARR};
+ UniValue result{UniValue::VARR};
- for (const COutPoint& output : outputs) {
- UniValue o(UniValue::VOBJ);
- o.pushKV("txid", output.hash.ToString());
- o.pushKV("vout", (uint64_t)output.n);
+ for (const COutPoint& output : outputs) {
+ UniValue o(UniValue::VOBJ);
+ o.pushKV("txid", output.hash.ToString());
+ o.pushKV("vout", (uint64_t)output.n);
- const CTransaction* spendingTx = mempool.GetConflictTx(output);
- if (spendingTx != nullptr) {
- o.pushKV("spendingtxid", spendingTx->GetHash().ToString());
- }
+ const CTransaction* spendingTx = mempool.GetConflictTx(output);
+ if (spendingTx != nullptr) {
+ o.pushKV("spendingtxid", spendingTx->GetHash().ToString());
+ }
- result.push_back(o);
- }
+ result.push_back(o);
+ }
- return result;
-},
+ return result;
+ },
};
}
diff --git a/test/functional/rpc_mempool_info.py b/test/functional/rpc_mempool_info.py
index ef5b9535d4..da4314444d 100755
--- a/test/functional/rpc_mempool_info.py
+++ b/test/functional/rpc_mempool_info.py
@@ -13,19 +13,17 @@ from test_framework.util import (
assert_raises_rpc_error,
chain_transaction,
)
+from test_framework.wallet import MiniWallet
+
class RPCMempoolInfoTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
- self.setup_clean_chain = True
-
- def skip_test_if_missing_module(self):
- self.skip_if_no_wallet()
def run_test(self):
- # Mine some blocks and have them mature.
- self.generate(self.nodes[0], COINBASE_MATURITY + 1)
- confirmed_utxo = self.nodes[0].listunspent(1)[0]
+ self.wallet = MiniWallet(self.nodes[0])
+ self.wallet.rescan_utxos()
+ confirmed_utxo = self.wallet.get_utxo()
# Create a tree of unconfirmed transactions in the mempool:
# txA
@@ -41,15 +39,21 @@ class RPCMempoolInfoTest(BitcoinTestFramework):
# \ /
# \ /
# txH
- fee = Decimal("0.0001")
- (txidA, txA_amount) = chain_transaction(self.nodes[0], [confirmed_utxo['txid']], [0], confirmed_utxo['amount'], fee, 2)
- (txidB, txB_amount) = chain_transaction(self.nodes[0], [txidA], [0], txA_amount, fee, 2)
- (txidC, txC_amount) = chain_transaction(self.nodes[0], [txidA], [1], txA_amount, fee, 2)
- txidD, _ = chain_transaction(self.nodes[0], [txidB], [0], txB_amount, fee, 1)
- (txidE, txE_amount) = chain_transaction(self.nodes[0], [txidB], [1], txB_amount, fee, 3)
- (txidF, txF_amount) = chain_transaction(self.nodes[0], [txidC], [0], txC_amount, fee, 2)
- txidG, _ = chain_transaction(self.nodes[0], [txidC], [1], txC_amount, fee, 1)
- txidH, _ = chain_transaction(self.nodes[0], [txidE, txidF], [0, 1], txE_amount + txF_amount, fee, 1)
+
+ def create_tx(**kwargs):
+ return self.wallet.send_self_transfer_multi(
+ from_node=self.nodes[0],
+ **kwargs,
+ )
+
+ txA = create_tx(utxos_to_spend=[confirmed_utxo], num_outputs=2)
+ txB, txC = [create_tx(utxos_to_spend=[u], num_outputs=2) for u in txA["new_utxos"]]
+ txD, txE = [create_tx(utxos_to_spend=[u]) for u in txB["new_utxos"]]
+ txF, txG = [create_tx(utxos_to_spend=[u]) for u in txC["new_utxos"]]
+ txH = create_tx(utxos_to_spend=txE["new_utxos"] + txF["new_utxos"])
+ txidA, txidB, txidC, txidD, txidE, txidF, txidG, txidH = [
+ tx["txid"] for tx in [txA, txB, txC, txD, txE, txF, txG, txH]
+ ]
mempool = self.nodes[0].getrawmempool()
assert_equal(len(mempool), 8)