|
| 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() |
0 commit comments