Last active
November 23, 2018 07:27
Star
You must be signed in to star a gist
Tests Xaya Core with very large batch RPC requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Test for https://github.com/xaya/xaya/issues/72. | |
# Should be run from within Xaya's test/functional directory. | |
from test_framework.util import str_to_b64str | |
import http.client | |
import json | |
import urllib.parse | |
url = urllib.parse.urlparse("http://xaya:password@localhost:8396") | |
authpair = url.username + ':' + url.password | |
headers = {"Authorization": "Basic " + str_to_b64str(authpair)} | |
conn = http.client.HTTPConnection(url.hostname, url.port) | |
conn.connect() | |
def send_request(request, wantResult): | |
conn.request('POST', '/', json.dumps(request), headers) | |
resp = conn.getresponse() | |
if not wantResult: | |
print("Status code: %d" % resp.status) | |
out = resp.read() | |
if wantResult: | |
return json.loads(out.decode('ascii')) | |
return None | |
print("Preparing requests...") | |
requests = [] | |
nextBlk = 0 | |
for i in range(5): | |
print("Request number %d..." % (i + 1)) | |
req = [] | |
for j in range(70000): | |
blkhash = send_request({ | |
"method": "getblockhash", | |
"params": [nextBlk], | |
}, True)['result'] | |
req.append({ | |
"method": "getblock", | |
"params": { | |
"blockhash": blkhash, | |
"verbosity": 2, | |
}, | |
"id": nextBlk, | |
}) | |
nextBlk += 1 | |
requests.append(req) | |
for req in requests: | |
print("Sending request now...") | |
send_request(req, False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment