rpc: disallow undefined verbosity in getorphantxs

pull/31043/head
tdb3 1 month ago
parent 25dacae9c7
commit ac68fcca70
No known key found for this signature in database

@ -891,7 +891,7 @@ static RPCHelpMan getorphantxs()
UniValue ret(UniValue::VARR);
if (verbosity <= 0) {
if (verbosity == 0) {
for (auto const& orphan : orphanage) {
ret.push_back(orphan.tx->GetHash().ToString());
}
@ -899,13 +899,14 @@ static RPCHelpMan getorphantxs()
for (auto const& orphan : orphanage) {
ret.push_back(OrphanToJSON(orphan));
}
} else {
// >= 2
} else if (verbosity == 2) {
for (auto const& orphan : orphanage) {
UniValue o{OrphanToJSON(orphan)};
o.pushKV("hex", EncodeHexTx(*orphan.tx));
ret.push_back(o);
}
} else {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid verbosity value " + ToString(verbosity));
}
return ret;

@ -7,7 +7,10 @@
from test_framework.mempool_util import tx_in_orphanage
from test_framework.messages import msg_tx
from test_framework.p2p import P2PInterface
from test_framework.util import assert_equal
from test_framework.util import (
assert_equal,
assert_raises_rpc_error,
)
from test_framework.test_framework import BitcoinTestFramework
from test_framework.wallet import MiniWallet
@ -37,13 +40,13 @@ class GetOrphanTxsTest(BitcoinTestFramework):
self.log.info("Check that neither parent is in the mempool")
assert_equal(node.getmempoolinfo()["size"], 0)
self.log.info("Check that both children are in the orphanage")
orphanage = node.getorphantxs(verbosity=0)
self.log.info("Check the size of the orphanage")
assert_equal(len(orphanage), 2)
self.log.info("Check that negative verbosity is treated as 0")
assert_equal(orphanage, node.getorphantxs(verbosity=-1))
self.log.info("Check that undefined verbosity is disallowed")
assert_raises_rpc_error(-8, "Invalid verbosity value -1", node.getorphantxs, verbosity=-1)
assert_raises_rpc_error(-8, "Invalid verbosity value 3", node.getorphantxs, verbosity=3)
self.log.info("Check that both children are in the orphanage")
assert tx_in_orphanage(node, tx_child_1["tx"])
assert tx_in_orphanage(node, tx_child_2["tx"])

Loading…
Cancel
Save