mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
Merge bitcoin/bitcoin#24944: rpc: add getblockfrompeer RPCTypeCheck and invalid input test coverage
2ef5294a5bb68ceb3797d2638567a172cc21699f rpc: add RPCTypeCheck for getblockfrompeer inputs (Jon Atack) 734b9669ff7b2f5e2820993443a6f868f6b0b20a test: add getblockfrompeer coverage of invalid inputs (Jon Atack) Pull request description: The new getblockfrompeer RPC lacks test coverage for invalid arguments, and its error messages are not harmonized with the existing RPCs. Fix all issues. ACKs for top commit: brunoerg: ACK 2ef5294a5bb68ceb3797d2638567a172cc21699f Tree-SHA512: 454782cf6a44fd0e05483bb152153667ef5c8021358385ddcf89724fbbbd35e187362bdff757e00c99319527bc4c0b20c7187f67241d4585d767a29787142f25
This commit is contained in:
parent
de4e7e16b4
commit
9590929900
@ -790,6 +790,11 @@ static RPCHelpMan getblockfrompeer()
|
|||||||
},
|
},
|
||||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
{
|
{
|
||||||
|
RPCTypeCheck(request.params, {
|
||||||
|
UniValue::VSTR, // blockhash
|
||||||
|
UniValue::VNUM, // peer_id
|
||||||
|
});
|
||||||
|
|
||||||
const NodeContext& node = EnsureAnyNodeContext(request.context);
|
const NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||||
ChainstateManager& chainman = EnsureChainman(node);
|
ChainstateManager& chainman = EnsureChainman(node);
|
||||||
PeerManager& peerman = EnsurePeerman(node);
|
PeerManager& peerman = EnsurePeerman(node);
|
||||||
|
@ -49,14 +49,17 @@ class GetBlockFromPeerTest(BitcoinTestFramework):
|
|||||||
assert_equal(len(peers), 1)
|
assert_equal(len(peers), 1)
|
||||||
peer_0_peer_1_id = peers[0]["id"]
|
peer_0_peer_1_id = peers[0]["id"]
|
||||||
|
|
||||||
self.log.info("Arguments must be sensible")
|
self.log.info("Arguments must be valid")
|
||||||
assert_raises_rpc_error(-8, "hash must be of length 64 (not 4, for '1234')", self.nodes[0].getblockfrompeer, "1234", 0)
|
assert_raises_rpc_error(-8, "hash must be of length 64 (not 4, for '1234')", self.nodes[0].getblockfrompeer, "1234", peer_0_peer_1_id)
|
||||||
|
assert_raises_rpc_error(-3, "Expected type string, got number", self.nodes[0].getblockfrompeer, 1234, peer_0_peer_1_id)
|
||||||
|
assert_raises_rpc_error(-3, "Expected type number, got string", self.nodes[0].getblockfrompeer, short_tip, "0")
|
||||||
|
|
||||||
self.log.info("We must already have the header")
|
self.log.info("We must already have the header")
|
||||||
assert_raises_rpc_error(-1, "Block header missing", self.nodes[0].getblockfrompeer, "00" * 32, 0)
|
assert_raises_rpc_error(-1, "Block header missing", self.nodes[0].getblockfrompeer, "00" * 32, 0)
|
||||||
|
|
||||||
self.log.info("Non-existent peer generates error")
|
self.log.info("Non-existent peer generates error")
|
||||||
assert_raises_rpc_error(-1, "Peer does not exist", self.nodes[0].getblockfrompeer, short_tip, peer_0_peer_1_id + 1)
|
for peer_id in [-1, peer_0_peer_1_id + 1]:
|
||||||
|
assert_raises_rpc_error(-1, "Peer does not exist", self.nodes[0].getblockfrompeer, short_tip, peer_id)
|
||||||
|
|
||||||
self.log.info("Successful fetch")
|
self.log.info("Successful fetch")
|
||||||
result = self.nodes[0].getblockfrompeer(short_tip, peer_0_peer_1_id)
|
result = self.nodes[0].getblockfrompeer(short_tip, peer_0_peer_1_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user