mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-12 06:10:37 +02:00
rpc: disallow undefined verbosity in getorphantxs
This commit is contained in:
parent
25dacae9c7
commit
ac68fcca70
@ -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…
x
Reference in New Issue
Block a user