aboutsummaryrefslogtreecommitdiff
path: root/qa/rpc-tests/rest.py
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2015-09-04 11:48:54 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2015-09-04 13:06:32 +0200
commit9aa90994ee85e549ddbe23a6f03e33d0edcd57b2 (patch)
tree1f5eb525df417378a8677084a5a01731bca76960 /qa/rpc-tests/rest.py
parent4b437b227c596f23ab8983559552b8c4910d2b17 (diff)
parentd52802551752140cf41f0d9a225a43e84404d3e9 (diff)
downloadbitcoin-9aa90994ee85e549ddbe23a6f03e33d0edcd57b2.tar.xz
Merge pull request #5677
d528025 Revert "rpc-tests: re-enable rpc-tests for Windows" (Wladimir J. van der Laan) 1e700c9 doc: update deps in build-unix.md after libevent (Wladimir J. van der Laan) 26c9b83 Move windows socket init to utility function (Wladimir J. van der Laan) 4be0b08 libevent: Windows reuseaddr workaround in depends (Cory Fields) 3a174cd Fix race condition between starting HTTP server thread and setting EventBase() (Wladimir J. van der Laan) 6d2bc22 Document options for new HTTP/RPC server in --help (Wladimir J. van der Laan) be33f3f Implement RPCTimerHandler for Qt RPC console (Wladimir J. van der Laan) 57d85d9 doc: mention SSL support dropped for RPC in release notes (Wladimir J. van der Laan) 40b556d evhttpd implementation (Wladimir J. van der Laan) ee2a42b tests: GET requests cannot have request body, use POST in rest.py (Wladimir J. van der Laan) 6e996d3 tests: fix qt payment test (Cory Fields) 3140ef9 build: build-system changes for libevent (Wladimir J. van der Laan) a9af234 libevent: add depends (Cory Fields) 6a21dd5 Remove rpc_boostasiotocnetaddr test (Wladimir J. van der Laan) 8f9301c qa: Remove -rpckeepalive tests from httpbasics (Wladimir J. van der Laan) 51fcfc0 doc: remove documentation for rpcssl (Wladimir J. van der Laan)
Diffstat (limited to 'qa/rpc-tests/rest.py')
-rwxr-xr-xqa/rpc-tests/rest.py42
1 files changed, 26 insertions, 16 deletions
diff --git a/qa/rpc-tests/rest.py b/qa/rpc-tests/rest.py
index 3a035f996c..e084ad55ab 100755
--- a/qa/rpc-tests/rest.py
+++ b/qa/rpc-tests/rest.py
@@ -32,10 +32,20 @@ def deser_uint256(f):
r += t << (i * 32)
return r
-#allows simple http get calls with a request body
-def http_get_call(host, port, path, requestdata = '', response_object = 0):
+#allows simple http get calls
+def http_get_call(host, port, path, response_object = 0):
conn = httplib.HTTPConnection(host, port)
- conn.request('GET', path, requestdata)
+ conn.request('GET', path)
+
+ if response_object:
+ return conn.getresponse()
+
+ return conn.getresponse().read()
+
+#allows simple http post calls with a request body
+def http_post_call(host, port, path, requestdata = '', response_object = 0):
+ conn = httplib.HTTPConnection(host, port)
+ conn.request('POST', path, requestdata)
if response_object:
return conn.getresponse()
@@ -137,7 +147,7 @@ class RESTTest (BitcoinTestFramework):
binaryRequest += binascii.unhexlify(vintx);
binaryRequest += pack("i", 0);
- bin_response = http_get_call(url.hostname, url.port, '/rest/getutxos'+self.FORMAT_SEPARATOR+'bin', binaryRequest)
+ bin_response = http_post_call(url.hostname, url.port, '/rest/getutxos'+self.FORMAT_SEPARATOR+'bin', binaryRequest)
output = StringIO.StringIO()
output.write(bin_response)
output.seek(0)
@@ -175,14 +185,14 @@ class RESTTest (BitcoinTestFramework):
#do some invalid requests
json_request = '{"checkmempool'
- response = http_get_call(url.hostname, url.port, '/rest/getutxos'+self.FORMAT_SEPARATOR+'json', json_request, True)
+ response = http_post_call(url.hostname, url.port, '/rest/getutxos'+self.FORMAT_SEPARATOR+'json', json_request, True)
assert_equal(response.status, 500) #must be a 500 because we send a invalid json request
json_request = '{"checkmempool'
- response = http_get_call(url.hostname, url.port, '/rest/getutxos'+self.FORMAT_SEPARATOR+'bin', json_request, True)
+ response = http_post_call(url.hostname, url.port, '/rest/getutxos'+self.FORMAT_SEPARATOR+'bin', json_request, True)
assert_equal(response.status, 500) #must be a 500 because we send a invalid bin request
- response = http_get_call(url.hostname, url.port, '/rest/getutxos/checkmempool'+self.FORMAT_SEPARATOR+'bin', '', True)
+ response = http_post_call(url.hostname, url.port, '/rest/getutxos/checkmempool'+self.FORMAT_SEPARATOR+'bin', '', True)
assert_equal(response.status, 500) #must be a 500 because we send a invalid bin request
#test limits
@@ -190,14 +200,14 @@ class RESTTest (BitcoinTestFramework):
for x in range(0, 20):
json_request += txid+'-'+str(n)+'/'
json_request = json_request.rstrip("/")
- response = http_get_call(url.hostname, url.port, '/rest/getutxos'+json_request+self.FORMAT_SEPARATOR+'json', '', True)
+ response = http_post_call(url.hostname, url.port, '/rest/getutxos'+json_request+self.FORMAT_SEPARATOR+'json', '', True)
assert_equal(response.status, 500) #must be a 500 because we exceeding the limits
json_request = '/checkmempool/'
for x in range(0, 15):
json_request += txid+'-'+str(n)+'/'
json_request = json_request.rstrip("/");
- response = http_get_call(url.hostname, url.port, '/rest/getutxos'+json_request+self.FORMAT_SEPARATOR+'json', '', True)
+ response = http_post_call(url.hostname, url.port, '/rest/getutxos'+json_request+self.FORMAT_SEPARATOR+'json', '', True)
assert_equal(response.status, 200) #must be a 500 because we exceeding the limits
self.nodes[0].generate(1) #generate block to not affect upcoming tests
@@ -208,27 +218,27 @@ class RESTTest (BitcoinTestFramework):
################
# check binary format
- response = http_get_call(url.hostname, url.port, '/rest/block/'+bb_hash+self.FORMAT_SEPARATOR+"bin", "", True)
+ 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')), 80)
response_str = response.read()
# compare with block header
- response_header = http_get_call(url.hostname, url.port, '/rest/headers/1/'+bb_hash+self.FORMAT_SEPARATOR+"bin", "", True)
+ response_header = http_get_call(url.hostname, url.port, '/rest/headers/1/'+bb_hash+self.FORMAT_SEPARATOR+"bin", True)
assert_equal(response_header.status, 200)
assert_equal(int(response_header.getheader('content-length')), 80)
response_header_str = response_header.read()
assert_equal(response_str[0:80], response_header_str)
# check block hex format
- response_hex = http_get_call(url.hostname, url.port, '/rest/block/'+bb_hash+self.FORMAT_SEPARATOR+"hex", "", True)
+ response_hex = http_get_call(url.hostname, url.port, '/rest/block/'+bb_hash+self.FORMAT_SEPARATOR+"hex", True)
assert_equal(response_hex.status, 200)
assert_greater_than(int(response_hex.getheader('content-length')), 160)
response_hex_str = response_hex.read()
assert_equal(response_str.encode("hex")[0:160], response_hex_str[0:160])
# compare with hex block header
- response_header_hex = http_get_call(url.hostname, url.port, '/rest/headers/1/'+bb_hash+self.FORMAT_SEPARATOR+"hex", "", True)
+ response_header_hex = http_get_call(url.hostname, url.port, '/rest/headers/1/'+bb_hash+self.FORMAT_SEPARATOR+"hex", True)
assert_equal(response_header_hex.status, 200)
assert_greater_than(int(response_header_hex.getheader('content-length')), 160)
response_header_hex_str = response_header_hex.read()
@@ -241,7 +251,7 @@ class RESTTest (BitcoinTestFramework):
assert_equal(block_json_obj['hash'], bb_hash)
# compare with json block header
- response_header_json = http_get_call(url.hostname, url.port, '/rest/headers/1/'+bb_hash+self.FORMAT_SEPARATOR+"json", "", True)
+ response_header_json = http_get_call(url.hostname, url.port, '/rest/headers/1/'+bb_hash+self.FORMAT_SEPARATOR+"json", True)
assert_equal(response_header_json.status, 200)
response_header_json_str = response_header_json.read()
json_obj = json.loads(response_header_json_str, parse_float=decimal.Decimal)
@@ -265,7 +275,7 @@ class RESTTest (BitcoinTestFramework):
#see if we can get 5 headers in one response
self.nodes[1].generate(5)
self.sync_all()
- response_header_json = http_get_call(url.hostname, url.port, '/rest/headers/5/'+bb_hash+self.FORMAT_SEPARATOR+"json", "", True)
+ response_header_json = http_get_call(url.hostname, url.port, '/rest/headers/5/'+bb_hash+self.FORMAT_SEPARATOR+"json", True)
assert_equal(response_header_json.status, 200)
response_header_json_str = response_header_json.read()
json_obj = json.loads(response_header_json_str)
@@ -278,7 +288,7 @@ class RESTTest (BitcoinTestFramework):
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)
+ hex_string = http_get_call(url.hostname, url.port, '/rest/tx/'+tx_hash+self.FORMAT_SEPARATOR+"hex", True)
assert_equal(hex_string.status, 200)
assert_greater_than(int(response.getheader('content-length')), 10)