|
|
@ -9,12 +9,14 @@ |
|
|
|
|
|
|
|
|
|
|
|
from test_framework.test_framework import BitcoinTestFramework |
|
|
|
from test_framework.util import * |
|
|
|
from struct import * |
|
|
|
from test_framework.util import assert_equal, assert_greater_than, \ |
|
|
|
initialize_chain_clean, start_nodes, connect_nodes_bi |
|
|
|
|
|
|
|
import struct |
|
|
|
import binascii |
|
|
|
import json |
|
|
|
import StringIO |
|
|
|
import decimal |
|
|
|
from decimal import Decimal |
|
|
|
|
|
|
|
try: |
|
|
|
import http.client as httplib |
|
|
@ -28,7 +30,7 @@ except ImportError: |
|
|
|
def deser_uint256(f): |
|
|
|
r = 0 |
|
|
|
for i in range(8): |
|
|
|
t = unpack(b"<I", f.read(4))[0] |
|
|
|
t = struct.unpack(b"<I", f.read(4))[0] |
|
|
|
r += t << (i * 32) |
|
|
|
return r |
|
|
|
|
|
|
@ -143,15 +145,15 @@ class RESTTest (BitcoinTestFramework): |
|
|
|
|
|
|
|
binaryRequest = b'\x01\x02' |
|
|
|
binaryRequest += binascii.unhexlify(txid) |
|
|
|
binaryRequest += pack("i", n); |
|
|
|
binaryRequest += struct.pack("i", n); |
|
|
|
binaryRequest += binascii.unhexlify(vintx); |
|
|
|
binaryRequest += pack("i", 0); |
|
|
|
binaryRequest += struct.pack("i", 0); |
|
|
|
|
|
|
|
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) |
|
|
|
chainHeight = unpack("i", output.read(4))[0] |
|
|
|
chainHeight = struct.unpack("i", output.read(4))[0] |
|
|
|
hashFromBinResponse = hex(deser_uint256(output))[2:].zfill(65).rstrip("L") |
|
|
|
|
|
|
|
assert_equal(bb_hash, hashFromBinResponse) #check if getutxo's chaintip during calculation was fine |
|
|
@ -263,7 +265,7 @@ class RESTTest (BitcoinTestFramework): |
|
|
|
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) |
|
|
|
json_obj = json.loads(response_header_json_str, parse_float=Decimal) |
|
|
|
assert_equal(len(json_obj), 1) #ensure that there is one header in the json response |
|
|
|
assert_equal(json_obj[0]['hash'], bb_hash) #request/response hash should be the same |
|
|
|
|
|
|
|