diff options
author | Jonas Schnelli <jonas.schnelli@include7.ch> | 2014-11-26 16:26:02 +0100 |
---|---|---|
committer | Jonas Schnelli <jonas.schnelli@include7.ch> | 2014-12-01 12:52:21 +0100 |
commit | 01dc2d83f80d8890ccb197110bbeb328ab68c285 (patch) | |
tree | 3461fd0cd5d8e2b44681ba3042d471e9a2ec1124 /qa/rpc-tests/rest.py | |
parent | 0ddf4416cc8011d788494a0539ccb687cdb03f3d (diff) |
[REST] add REST interface tests in rpc-test section
Diffstat (limited to 'qa/rpc-tests/rest.py')
-rwxr-xr-x | qa/rpc-tests/rest.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/qa/rpc-tests/rest.py b/qa/rpc-tests/rest.py new file mode 100755 index 0000000000..ca09a5c6d8 --- /dev/null +++ b/qa/rpc-tests/rest.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# Copyright (c) 2014 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +# +# Test REST interface +# + +from test_framework import BitcoinTestFramework +from util import * +import json + +try: + import http.client as httplib +except ImportError: + import httplib +try: + import urllib.parse as urlparse +except ImportError: + import urlparse + +def http_get_call(host, port, path, response_object = 0): + conn = httplib.HTTPConnection(host, port) + conn.request('GET', path) + + if response_object: + return conn.getresponse() + + return conn.getresponse().read() + + +class RESTTest (BitcoinTestFramework): + FORMAT_SEPARATOR = "/" + + def run_test(self): + url = urlparse.urlparse(self.nodes[0].url) + bb_hash = self.nodes[0].getbestblockhash() + + # check binary format + response = http_get_call(url.hostname, url.port, '/rest/block/'+bb_hash+self.FORMAT_SEPARATOR+"bin", True) + assert_equal(response.status, 200) + assert_greater_than(int(response.getheader('content-length')), 10) + + # check json format + json_string = http_get_call(url.hostname, url.port, '/rest/block/'+bb_hash+self.FORMAT_SEPARATOR+'json') + json_obj = json.loads(json_string) + assert_equal(json_obj['hash'], bb_hash) + + # do tx test + tx_hash = json_obj['tx'][0]; + json_string = http_get_call(url.hostname, url.port, '/rest/tx/'+tx_hash+self.FORMAT_SEPARATOR+"json") + json_obj = json.loads(json_string) + assert_equal(json_obj['txid'], tx_hash) + + # check hex format response + hex_string = http_get_call(url.hostname, url.port, '/rest/tx/'+tx_hash+self.FORMAT_SEPARATOR+"hex", True) + assert_equal(response.status, 200) + assert_greater_than(int(response.getheader('content-length')), 10) + +if __name__ == '__main__': + RESTTest ().main ()
\ No newline at end of file |