Skip to content

Instantly share code, notes, and snippets.

@domob1812
Last active November 23, 2018 07:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save domob1812/b3a681e15178aab469436f435bdeb2ff to your computer and use it in GitHub Desktop.
Tests Xaya Core with very large batch RPC requests
#!/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