Skip to content

Commit 3dda4c5

Browse files
author
MarcoFalke
committed
Merge #14777: tests: Add regtest for JSON-RPC batch calls
3d2c7d6 Add regtest for JSON-RPC batch calls. (Daniel Kraft) Pull request description: This adds a new regtest file `interface_rpc.py`, containing a test for batch JSON-RPC requests. Those were previously not tested at all. Tests for basic requests are not really necessary, as those are used anyway in lots of other regtests. The existing `interface_http.py` file is more about the underlying HTTP connection, so adding a new interface file for the JSON-RPC specific things makes sense. Tree-SHA512: 7c7576004c8474e23c98f4bf25fb655328ba6bb73ea06744ebee1c0ffbb26bc132e621ae52955d51dab0803b322f8d711667626a777ac9b26003339c2484502f
2 parents 2a97f19 + 3d2c7d6 commit 3dda4c5

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

test/functional/interface_rpc.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2018 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
"""Tests some generic aspects of the RPC interface."""
6+
7+
from test_framework.test_framework import BitcoinTestFramework
8+
from test_framework.util import assert_equal
9+
10+
class RPCInterfaceTest(BitcoinTestFramework):
11+
def set_test_params(self):
12+
self.num_nodes = 1
13+
self.setup_clean_chain = True
14+
15+
def test_batch_request(self):
16+
self.log.info("Testing basic JSON-RPC batch request...")
17+
18+
results = self.nodes[0].batch([
19+
# A basic request that will work fine.
20+
{"method": "getblockcount", "id": 1},
21+
# Request that will fail. The whole batch request should still
22+
# work fine.
23+
{"method": "invalidmethod", "id": 2},
24+
# Another call that should succeed.
25+
{"method": "getbestblockhash", "id": 3},
26+
])
27+
28+
result_by_id = {}
29+
for res in results:
30+
result_by_id[res["id"]] = res
31+
32+
assert_equal(result_by_id[1]['error'], None)
33+
assert_equal(result_by_id[1]['result'], 0)
34+
35+
assert_equal(result_by_id[2]['error']['code'], -32601)
36+
assert_equal(result_by_id[2]['result'], None)
37+
38+
assert_equal(result_by_id[3]['error'], None)
39+
assert result_by_id[3]['result'] is not None
40+
41+
def run_test(self):
42+
self.test_batch_request()
43+
44+
45+
if __name__ == '__main__':
46+
RPCInterfaceTest().main()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
'wallet_disableprivatekeys.py',
121121
'wallet_disableprivatekeys.py --usecli',
122122
'interface_http.py',
123+
'interface_rpc.py',
123124
'rpc_psbt.py',
124125
'rpc_users.py',
125126
'feature_proxy.py',

0 commit comments

Comments
 (0)