mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
rpc: disallow undefined verbosity in getorphantxs
This commit is contained in:
parent
25dacae9c7
commit
ac68fcca70
2 changed files with 12 additions and 8 deletions
|
@ -891,7 +891,7 @@ static RPCHelpMan getorphantxs()
|
||||||
|
|
||||||
UniValue ret(UniValue::VARR);
|
UniValue ret(UniValue::VARR);
|
||||||
|
|
||||||
if (verbosity <= 0) {
|
if (verbosity == 0) {
|
||||||
for (auto const& orphan : orphanage) {
|
for (auto const& orphan : orphanage) {
|
||||||
ret.push_back(orphan.tx->GetHash().ToString());
|
ret.push_back(orphan.tx->GetHash().ToString());
|
||||||
}
|
}
|
||||||
|
@ -899,13 +899,14 @@ static RPCHelpMan getorphantxs()
|
||||||
for (auto const& orphan : orphanage) {
|
for (auto const& orphan : orphanage) {
|
||||||
ret.push_back(OrphanToJSON(orphan));
|
ret.push_back(OrphanToJSON(orphan));
|
||||||
}
|
}
|
||||||
} else {
|
} else if (verbosity == 2) {
|
||||||
// >= 2
|
|
||||||
for (auto const& orphan : orphanage) {
|
for (auto const& orphan : orphanage) {
|
||||||
UniValue o{OrphanToJSON(orphan)};
|
UniValue o{OrphanToJSON(orphan)};
|
||||||
o.pushKV("hex", EncodeHexTx(*orphan.tx));
|
o.pushKV("hex", EncodeHexTx(*orphan.tx));
|
||||||
ret.push_back(o);
|
ret.push_back(o);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid verbosity value " + ToString(verbosity));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -7,7 +7,10 @@
|
||||||
from test_framework.mempool_util import tx_in_orphanage
|
from test_framework.mempool_util import tx_in_orphanage
|
||||||
from test_framework.messages import msg_tx
|
from test_framework.messages import msg_tx
|
||||||
from test_framework.p2p import P2PInterface
|
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.test_framework import BitcoinTestFramework
|
||||||
from test_framework.wallet import MiniWallet
|
from test_framework.wallet import MiniWallet
|
||||||
|
|
||||||
|
@ -37,13 +40,13 @@ class GetOrphanTxsTest(BitcoinTestFramework):
|
||||||
self.log.info("Check that neither parent is in the mempool")
|
self.log.info("Check that neither parent is in the mempool")
|
||||||
assert_equal(node.getmempoolinfo()["size"], 0)
|
assert_equal(node.getmempoolinfo()["size"], 0)
|
||||||
|
|
||||||
self.log.info("Check that both children are in the orphanage")
|
|
||||||
|
|
||||||
orphanage = node.getorphantxs(verbosity=0)
|
orphanage = node.getorphantxs(verbosity=0)
|
||||||
self.log.info("Check the size of the orphanage")
|
self.log.info("Check the size of the orphanage")
|
||||||
assert_equal(len(orphanage), 2)
|
assert_equal(len(orphanage), 2)
|
||||||
self.log.info("Check that negative verbosity is treated as 0")
|
self.log.info("Check that undefined verbosity is disallowed")
|
||||||
assert_equal(orphanage, node.getorphantxs(verbosity=-1))
|
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_1["tx"])
|
||||||
assert tx_in_orphanage(node, tx_child_2["tx"])
|
assert tx_in_orphanage(node, tx_child_2["tx"])
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue