Cosmetics (trailing whitespace, comment conventions, etc.)

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
Daira Hopwood
2017-06-20 21:23:24 +01:00
parent 811b36ba80
commit ff0f305497
11 changed files with 108 additions and 111 deletions

View File

@@ -37,45 +37,45 @@ class HTTPBasicsTest (BitcoinTestFramework):
conn = httplib.HTTPConnection(url.hostname, url.port) conn = httplib.HTTPConnection(url.hostname, url.port)
conn.connect() conn.connect()
conn.request('POST', '/', '{"method": "getbestblockhash"}', headers) conn.request('POST', '/', '{"method": "getbestblockhash"}', headers)
out1 = conn.getresponse().read(); out1 = conn.getresponse().read()
assert_equal('"error":null' in out1, True) assert_equal('"error":null' in out1, True)
assert_equal(conn.sock!=None, True) #according to http/1.1 connection must still be open! assert_equal(conn.sock!=None, True) # according to http/1.1 connection must still be open!
#send 2nd request without closing connection # send 2nd request without closing connection
conn.request('POST', '/', '{"method": "getchaintips"}', headers) conn.request('POST', '/', '{"method": "getchaintips"}', headers)
out2 = conn.getresponse().read(); out2 = conn.getresponse().read()
assert_equal('"error":null' in out2, True) # must also response with a correct json-rpc message assert_equal('"error":null' in out2, True) # must also response with a correct json-rpc message
assert_equal(conn.sock!=None, True) #according to http/1.1 connection must still be open! assert_equal(conn.sock!=None, True) # according to http/1.1 connection must still be open!
conn.close() conn.close()
#same should be if we add keep-alive because this should be the std. behaviour # same should be if we add keep-alive because this should be the std. behaviour
headers = {"Authorization": "Basic " + base64.b64encode(authpair), "Connection": "keep-alive"} headers = {"Authorization": "Basic " + base64.b64encode(authpair), "Connection": "keep-alive"}
conn = httplib.HTTPConnection(url.hostname, url.port) conn = httplib.HTTPConnection(url.hostname, url.port)
conn.connect() conn.connect()
conn.request('POST', '/', '{"method": "getbestblockhash"}', headers) conn.request('POST', '/', '{"method": "getbestblockhash"}', headers)
out1 = conn.getresponse().read(); out1 = conn.getresponse().read()
assert_equal('"error":null' in out1, True) assert_equal('"error":null' in out1, True)
assert_equal(conn.sock!=None, True) #according to http/1.1 connection must still be open! assert_equal(conn.sock!=None, True) # according to http/1.1 connection must still be open!
#send 2nd request without closing connection # send 2nd request without closing connection
conn.request('POST', '/', '{"method": "getchaintips"}', headers) conn.request('POST', '/', '{"method": "getchaintips"}', headers)
out2 = conn.getresponse().read(); out2 = conn.getresponse().read()
assert_equal('"error":null' in out2, True) # must also response with a correct json-rpc message assert_equal('"error":null' in out2, True) # must also response with a correct json-rpc message
assert_equal(conn.sock!=None, True) #according to http/1.1 connection must still be open! assert_equal(conn.sock!=None, True) # according to http/1.1 connection must still be open!
conn.close() conn.close()
#now do the same with "Connection: close" # now do the same with "Connection: close"
headers = {"Authorization": "Basic " + base64.b64encode(authpair), "Connection":"close"} headers = {"Authorization": "Basic " + base64.b64encode(authpair), "Connection":"close"}
conn = httplib.HTTPConnection(url.hostname, url.port) conn = httplib.HTTPConnection(url.hostname, url.port)
conn.connect() conn.connect()
conn.request('POST', '/', '{"method": "getbestblockhash"}', headers) conn.request('POST', '/', '{"method": "getbestblockhash"}', headers)
out1 = conn.getresponse().read(); out1 = conn.getresponse().read()
assert_equal('"error":null' in out1, True) assert_equal('"error":null' in out1, True)
assert_equal(conn.sock!=None, False) #now the connection must be closed after the response assert_equal(conn.sock!=None, False) # now the connection must be closed after the response
#node1 (2nd node) is running with disabled keep-alive option # node1 (2nd node) is running with disabled keep-alive option
urlNode1 = urlparse.urlparse(self.nodes[1].url) urlNode1 = urlparse.urlparse(self.nodes[1].url)
authpair = urlNode1.username + ':' + urlNode1.password authpair = urlNode1.username + ':' + urlNode1.password
headers = {"Authorization": "Basic " + base64.b64encode(authpair)} headers = {"Authorization": "Basic " + base64.b64encode(authpair)}
@@ -83,10 +83,10 @@ class HTTPBasicsTest (BitcoinTestFramework):
conn = httplib.HTTPConnection(urlNode1.hostname, urlNode1.port) conn = httplib.HTTPConnection(urlNode1.hostname, urlNode1.port)
conn.connect() conn.connect()
conn.request('POST', '/', '{"method": "getbestblockhash"}', headers) conn.request('POST', '/', '{"method": "getbestblockhash"}', headers)
out1 = conn.getresponse().read(); out1 = conn.getresponse().read()
assert_equal('"error":null' in out1, True) assert_equal('"error":null' in out1, True)
#node2 (third node) is running with standard keep-alive parameters which means keep-alive is on # node2 (third node) is running with standard keep-alive parameters which means keep-alive is on
urlNode2 = urlparse.urlparse(self.nodes[2].url) urlNode2 = urlparse.urlparse(self.nodes[2].url)
authpair = urlNode2.username + ':' + urlNode2.password authpair = urlNode2.username + ':' + urlNode2.password
headers = {"Authorization": "Basic " + base64.b64encode(authpair)} headers = {"Authorization": "Basic " + base64.b64encode(authpair)}
@@ -94,9 +94,9 @@ class HTTPBasicsTest (BitcoinTestFramework):
conn = httplib.HTTPConnection(urlNode2.hostname, urlNode2.port) conn = httplib.HTTPConnection(urlNode2.hostname, urlNode2.port)
conn.connect() conn.connect()
conn.request('POST', '/', '{"method": "getbestblockhash"}', headers) conn.request('POST', '/', '{"method": "getbestblockhash"}', headers)
out1 = conn.getresponse().read(); out1 = conn.getresponse().read()
assert_equal('"error":null' in out1, True) assert_equal('"error":null' in out1, True)
assert_equal(conn.sock!=None, True) #connection must be closed because bitcoind should use keep-alive by default assert_equal(conn.sock!=None, True) # connection must be closed because bitcoind should use keep-alive by default
if __name__ == '__main__': if __name__ == '__main__':
HTTPBasicsTest ().main () HTTPBasicsTest().main()

View File

@@ -14,8 +14,6 @@ from test_framework.util import initialize_chain_clean, start_node, \
import time import time
class InvalidateTest(BitcoinTestFramework): class InvalidateTest(BitcoinTestFramework):
def setup_chain(self): def setup_chain(self):
print("Initializing test directory "+self.options.tmpdir) print("Initializing test directory "+self.options.tmpdir)
initialize_chain_clean(self.options.tmpdir, 3) initialize_chain_clean(self.options.tmpdir, 3)

View File

@@ -117,9 +117,9 @@ class RawTransactionsTest(BitcoinTestFramework):
self.nodes[0].generate(1) self.nodes[0].generate(1)
self.sync_all() self.sync_all()
#THIS IS A INCOMPLETE FEATURE # THIS IS A INCOMPLETE FEATURE
#NODE2 HAS TWO OF THREE KEY AND THE FUNDS SHOULD BE SPENDABLE AND COUNT AT BALANCE CALCULATION # NODE2 HAS TWO OF THREE KEY AND THE FUNDS SHOULD BE SPENDABLE AND COUNT AT BALANCE CALCULATION
assert_equal(self.nodes[2].getbalance(), bal) #for now, assume the funds of a 2of3 multisig tx are not marked as spendable assert_equal(self.nodes[2].getbalance(), bal) # for now, assume the funds of a 2of3 multisig tx are not marked as spendable
txDetails = self.nodes[0].gettransaction(txId, True) txDetails = self.nodes[0].gettransaction(txId, True)
rawTx = self.nodes[0].decoderawtransaction(txDetails['hex']) rawTx = self.nodes[0].decoderawtransaction(txDetails['hex'])
@@ -134,10 +134,10 @@ class RawTransactionsTest(BitcoinTestFramework):
outputs = { self.nodes[0].getnewaddress() : 2.199 } outputs = { self.nodes[0].getnewaddress() : 2.199 }
rawTx = self.nodes[2].createrawtransaction(inputs, outputs) rawTx = self.nodes[2].createrawtransaction(inputs, outputs)
rawTxPartialSigned = self.nodes[1].signrawtransaction(rawTx, inputs) rawTxPartialSigned = self.nodes[1].signrawtransaction(rawTx, inputs)
assert_equal(rawTxPartialSigned['complete'], False) #node1 only has one key, can't comp. sign the tx assert_equal(rawTxPartialSigned['complete'], False) # node1 only has one key, can't comp. sign the tx
rawTxSigned = self.nodes[2].signrawtransaction(rawTx, inputs) rawTxSigned = self.nodes[2].signrawtransaction(rawTx, inputs)
assert_equal(rawTxSigned['complete'], True) #node2 can sign the tx compl., own two of three keys assert_equal(rawTxSigned['complete'], True) # node2 can sign the tx compl., own two of three keys
self.nodes[2].sendrawtransaction(rawTxSigned['hex']) self.nodes[2].sendrawtransaction(rawTxSigned['hex'])
rawTx = self.nodes[0].decoderawtransaction(rawTxSigned['hex']) rawTx = self.nodes[0].decoderawtransaction(rawTxSigned['hex'])
self.sync_all() self.sync_all()

View File

@@ -25,12 +25,12 @@ def get_sub_array_from_array(object_array, to_match):
return [] return []
def check_array_result(object_array, to_match, expected, should_not_find = False): def check_array_result(object_array, to_match, expected, should_not_find = False):
""" '''
Pass in array of JSON objects, a dictionary with key/value pairs Pass in array of JSON objects, a dictionary with key/value pairs
to match against, and another dictionary with expected key/value to match against, and another dictionary with expected key/value
pairs. pairs.
If the should_not_find flag is true, to_match should not be found in object_array If the should_not_find flag is true, to_match should not be found in object_array
""" '''
if should_not_find == True: if should_not_find == True:
expected = { } expected = { }
num_matched = 0 num_matched = 0
@@ -61,25 +61,25 @@ class ReceivedByTest(BitcoinTestFramework):
txid = self.nodes[0].sendtoaddress(addr, 0.1) txid = self.nodes[0].sendtoaddress(addr, 0.1)
self.sync_all() self.sync_all()
#Check not listed in listreceivedbyaddress because has 0 confirmations # Check not listed in listreceivedbyaddress because has 0 confirmations
check_array_result(self.nodes[1].listreceivedbyaddress(), check_array_result(self.nodes[1].listreceivedbyaddress(),
{"address":addr}, {"address":addr},
{ }, { },
True) True)
#Bury Tx under 10 block so it will be returned by listreceivedbyaddress # Bury Tx under 10 block so it will be returned by listreceivedbyaddress
self.nodes[1].generate(10) self.nodes[1].generate(10)
self.sync_all() self.sync_all()
check_array_result(self.nodes[1].listreceivedbyaddress(), check_array_result(self.nodes[1].listreceivedbyaddress(),
{"address":addr}, {"address":addr},
{"address":addr, "account":"", "amount":Decimal("0.1"), "confirmations":10, "txids":[txid,]}) {"address":addr, "account":"", "amount":Decimal("0.1"), "confirmations":10, "txids":[txid,]})
#With min confidence < 10 # With min confidence < 10
check_array_result(self.nodes[1].listreceivedbyaddress(5), check_array_result(self.nodes[1].listreceivedbyaddress(5),
{"address":addr}, {"address":addr},
{"address":addr, "account":"", "amount":Decimal("0.1"), "confirmations":10, "txids":[txid,]}) {"address":addr, "account":"", "amount":Decimal("0.1"), "confirmations":10, "txids":[txid,]})
#With min confidence > 10, should not find Tx # With min confidence > 10, should not find Tx
check_array_result(self.nodes[1].listreceivedbyaddress(11),{"address":addr},{ },True) check_array_result(self.nodes[1].listreceivedbyaddress(11),{"address":addr},{ },True)
#Empty Tx # Empty Tx
addr = self.nodes[1].getnewaddress() addr = self.nodes[1].getnewaddress()
check_array_result(self.nodes[1].listreceivedbyaddress(0,True), check_array_result(self.nodes[1].listreceivedbyaddress(0,True),
{"address":addr}, {"address":addr},
@@ -93,17 +93,17 @@ class ReceivedByTest(BitcoinTestFramework):
txid = self.nodes[0].sendtoaddress(addr, 0.1) txid = self.nodes[0].sendtoaddress(addr, 0.1)
self.sync_all() self.sync_all()
#Check balance is 0 because of 0 confirmations # Check balance is 0 because of 0 confirmations
balance = self.nodes[1].getreceivedbyaddress(addr) balance = self.nodes[1].getreceivedbyaddress(addr)
if balance != Decimal("0.0"): if balance != Decimal("0.0"):
raise AssertionError("Wrong balance returned by getreceivedbyaddress, %0.2f"%(balance)) raise AssertionError("Wrong balance returned by getreceivedbyaddress, %0.2f"%(balance))
#Check balance is 0.1 # Check balance is 0.1
balance = self.nodes[1].getreceivedbyaddress(addr,0) balance = self.nodes[1].getreceivedbyaddress(addr,0)
if balance != Decimal("0.1"): if balance != Decimal("0.1"):
raise AssertionError("Wrong balance returned by getreceivedbyaddress, %0.2f"%(balance)) raise AssertionError("Wrong balance returned by getreceivedbyaddress, %0.2f"%(balance))
#Bury Tx under 10 block so it will be returned by the default getreceivedbyaddress # Bury Tx under 10 block so it will be returned by the default getreceivedbyaddress
self.nodes[1].generate(10) self.nodes[1].generate(10)
self.sync_all() self.sync_all()
balance = self.nodes[1].getreceivedbyaddress(addr) balance = self.nodes[1].getreceivedbyaddress(addr)
@@ -113,7 +113,7 @@ class ReceivedByTest(BitcoinTestFramework):
''' '''
listreceivedbyaccount + getreceivedbyaccount Test listreceivedbyaccount + getreceivedbyaccount Test
''' '''
#set pre-state # set pre-state
addrArr = self.nodes[1].getnewaddress() addrArr = self.nodes[1].getnewaddress()
account = self.nodes[1].getaccount(addrArr) account = self.nodes[1].getaccount(addrArr)
received_by_account_json = get_sub_array_from_array(self.nodes[1].listreceivedbyaccount(),{"account":account}) received_by_account_json = get_sub_array_from_array(self.nodes[1].listreceivedbyaccount(),{"account":account})
@@ -146,7 +146,7 @@ class ReceivedByTest(BitcoinTestFramework):
if balance != balance_by_account + Decimal("0.1"): if balance != balance_by_account + Decimal("0.1"):
raise AssertionError("Wrong balance returned by getreceivedbyaccount, %0.2f"%(balance)) raise AssertionError("Wrong balance returned by getreceivedbyaccount, %0.2f"%(balance))
#Create a new account named "mynewaccount" that has a 0 balance # Create a new account named "mynewaccount" that has a 0 balance
self.nodes[1].getaccountaddress("mynewaccount") self.nodes[1].getaccountaddress("mynewaccount")
received_by_account_json = get_sub_array_from_array(self.nodes[1].listreceivedbyaccount(0,True),{"account":"mynewaccount"}) received_by_account_json = get_sub_array_from_array(self.nodes[1].listreceivedbyaccount(0,True),{"account":"mynewaccount"})
if len(received_by_account_json) == 0: if len(received_by_account_json) == 0:

View File

@@ -7,7 +7,6 @@
# Test REST interface # Test REST interface
# #
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_greater_than, \ from test_framework.util import assert_equal, assert_greater_than, \
initialize_chain_clean, start_nodes, connect_nodes_bi initialize_chain_clean, start_nodes, connect_nodes_bi
@@ -34,7 +33,7 @@ def deser_uint256(f):
r += t << (i * 32) r += t << (i * 32)
return r return r
#allows simple http get calls # allows simple http get calls
def http_get_call(host, port, path, response_object = 0): def http_get_call(host, port, path, response_object = 0):
conn = httplib.HTTPConnection(host, port) conn = httplib.HTTPConnection(host, port)
conn.request('GET', path) conn.request('GET', path)
@@ -44,7 +43,7 @@ def http_get_call(host, port, path, response_object = 0):
return conn.getresponse().read() return conn.getresponse().read()
#allows simple http post calls with a request body # allows simple http post calls with a request body
def http_post_call(host, port, path, requestdata = '', response_object = 0): def http_post_call(host, port, path, requestdata = '', response_object = 0):
conn = httplib.HTTPConnection(host, port) conn = httplib.HTTPConnection(host, port)
conn.request('POST', path, requestdata) conn.request('POST', path, requestdata)
@@ -86,7 +85,7 @@ class RESTTest (BitcoinTestFramework):
self.sync_all() self.sync_all()
bb_hash = self.nodes[0].getbestblockhash() bb_hash = self.nodes[0].getbestblockhash()
assert_equal(self.nodes[1].getbalance(), Decimal("0.1")) #balance now should be 0.1 on node 1 assert_equal(self.nodes[1].getbalance(), Decimal("0.1")) # balance now should be 0.1 on node 1
# load the latest 0.1 tx over the REST API # load the latest 0.1 tx over the REST API
json_string = http_get_call(url.hostname, url.port, '/rest/tx/'+txid+self.FORMAT_SEPARATOR+"json") json_string = http_get_call(url.hostname, url.port, '/rest/tx/'+txid+self.FORMAT_SEPARATOR+"json")
@@ -121,13 +120,13 @@ class RESTTest (BitcoinTestFramework):
json_string = http_get_call(url.hostname, url.port, '/rest/getutxos'+json_request+self.FORMAT_SEPARATOR+'json') json_string = http_get_call(url.hostname, url.port, '/rest/getutxos'+json_request+self.FORMAT_SEPARATOR+'json')
json_obj = json.loads(json_string) json_obj = json.loads(json_string)
#check chainTip response # check chainTip response
assert_equal(json_obj['chaintipHash'], bb_hash) assert_equal(json_obj['chaintipHash'], bb_hash)
#make sure there is no utox in the response because this oupoint has been spent # make sure there is no utox in the response because this oupoint has been spent
assert_equal(len(json_obj['utxos']), 0) assert_equal(len(json_obj['utxos']), 0)
#check bitmap # check bitmap
assert_equal(json_obj['bitmap'], "0") assert_equal(json_obj['bitmap'], "0")
@@ -140,7 +139,7 @@ class RESTTest (BitcoinTestFramework):
assert_equal(len(json_obj['utxos']), 1) assert_equal(len(json_obj['utxos']), 1)
assert_equal(json_obj['bitmap'], "10") assert_equal(json_obj['bitmap'], "10")
#test binary response # test binary response
bb_hash = self.nodes[0].getbestblockhash() bb_hash = self.nodes[0].getbestblockhash()
binaryRequest = b'\x01\x02' binaryRequest = b'\x01\x02'
@@ -156,8 +155,8 @@ class RESTTest (BitcoinTestFramework):
chainHeight = struct.unpack("i", output.read(4))[0] chainHeight = struct.unpack("i", output.read(4))[0]
hashFromBinResponse = hex(deser_uint256(output))[2:].zfill(65).rstrip("L") hashFromBinResponse = hex(deser_uint256(output))[2:].zfill(65).rstrip("L")
assert_equal(bb_hash, hashFromBinResponse) #check if getutxo's chaintip during calculation was fine assert_equal(bb_hash, hashFromBinResponse) # check if getutxo's chaintip during calculation was fine
assert_equal(chainHeight, 102) #chain height must be 102 assert_equal(chainHeight, 102) # chain height must be 102
############################ ############################
@@ -178,41 +177,41 @@ class RESTTest (BitcoinTestFramework):
json_request = '/'+txid+'-'+str(n) json_request = '/'+txid+'-'+str(n)
json_string = http_get_call(url.hostname, url.port, '/rest/getutxos'+json_request+self.FORMAT_SEPARATOR+'json') json_string = http_get_call(url.hostname, url.port, '/rest/getutxos'+json_request+self.FORMAT_SEPARATOR+'json')
json_obj = json.loads(json_string) json_obj = json.loads(json_string)
assert_equal(len(json_obj['utxos']), 0) #there should be a outpoint because it has just added to the mempool assert_equal(len(json_obj['utxos']), 0) # there should be a outpoint because it has just added to the mempool
json_request = '/checkmempool/'+txid+'-'+str(n) json_request = '/checkmempool/'+txid+'-'+str(n)
json_string = http_get_call(url.hostname, url.port, '/rest/getutxos'+json_request+self.FORMAT_SEPARATOR+'json') json_string = http_get_call(url.hostname, url.port, '/rest/getutxos'+json_request+self.FORMAT_SEPARATOR+'json')
json_obj = json.loads(json_string) json_obj = json.loads(json_string)
assert_equal(len(json_obj['utxos']), 1) #there should be a outpoint because it has just added to the mempool assert_equal(len(json_obj['utxos']), 1) # there should be a outpoint because it has just added to the mempool
#do some invalid requests # do some invalid requests
json_request = '{"checkmempool' json_request = '{"checkmempool'
response = http_post_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 assert_equal(response.status, 500) # must be a 500 because we send a invalid json request
json_request = '{"checkmempool' json_request = '{"checkmempool'
response = http_post_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 assert_equal(response.status, 500) # must be a 500 because we send a invalid bin request
response = http_post_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 assert_equal(response.status, 500) # must be a 500 because we send a invalid bin request
#test limits # test limits
json_request = '/checkmempool/' json_request = '/checkmempool/'
for x in range(0, 20): for x in range(0, 20):
json_request += txid+'-'+str(n)+'/' json_request += txid+'-'+str(n)+'/'
json_request = json_request.rstrip("/") json_request = json_request.rstrip("/")
response = http_post_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 assert_equal(response.status, 500) # must be a 500 because we exceeding the limits
json_request = '/checkmempool/' json_request = '/checkmempool/'
for x in range(0, 15): for x in range(0, 15):
json_request += txid+'-'+str(n)+'/' json_request += txid+'-'+str(n)+'/'
json_request = json_request.rstrip("/"); json_request = json_request.rstrip("/");
response = http_post_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 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 self.nodes[0].generate(1) # generate block to not affect upcoming tests
self.sync_all() self.sync_all()
################ ################
@@ -266,10 +265,10 @@ class RESTTest (BitcoinTestFramework):
assert_equal(response_header_json.status, 200) assert_equal(response_header_json.status, 200)
response_header_json_str = response_header_json.read() response_header_json_str = response_header_json.read()
json_obj = json.loads(response_header_json_str, parse_float=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(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 assert_equal(json_obj[0]['hash'], bb_hash) # request/response hash should be the same
#compare with normal RPC block response # compare with normal RPC block response
rpc_block_json = self.nodes[0].getblock(bb_hash) rpc_block_json = self.nodes[0].getblock(bb_hash)
assert_equal(json_obj[0]['hash'], rpc_block_json['hash']) assert_equal(json_obj[0]['hash'], rpc_block_json['hash'])
assert_equal(json_obj[0]['confirmations'], rpc_block_json['confirmations']) assert_equal(json_obj[0]['confirmations'], rpc_block_json['confirmations'])
@@ -283,14 +282,14 @@ class RESTTest (BitcoinTestFramework):
assert_equal(json_obj[0]['chainwork'], rpc_block_json['chainwork']) assert_equal(json_obj[0]['chainwork'], rpc_block_json['chainwork'])
assert_equal(json_obj[0]['previousblockhash'], rpc_block_json['previousblockhash']) assert_equal(json_obj[0]['previousblockhash'], rpc_block_json['previousblockhash'])
#see if we can get 5 headers in one response # see if we can get 5 headers in one response
self.nodes[1].generate(5) self.nodes[1].generate(5)
self.sync_all() 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) assert_equal(response_header_json.status, 200)
response_header_json_str = response_header_json.read() response_header_json_str = response_header_json.read()
json_obj = json.loads(response_header_json_str) json_obj = json.loads(response_header_json_str)
assert_equal(len(json_obj), 5) #now we should have 5 header objects assert_equal(len(json_obj), 5) # now we should have 5 header objects
# do tx test # do tx test
tx_hash = block_json_obj['tx'][0]['txid']; tx_hash = block_json_obj['tx'][0]['txid'];
@@ -330,20 +329,20 @@ class RESTTest (BitcoinTestFramework):
newblockhash = self.nodes[1].generate(1) newblockhash = self.nodes[1].generate(1)
self.sync_all() self.sync_all()
#check if the 3 tx show up in the new block # check if the 3 tx show up in the new block
json_string = http_get_call(url.hostname, url.port, '/rest/block/'+newblockhash[0]+self.FORMAT_SEPARATOR+'json') json_string = http_get_call(url.hostname, url.port, '/rest/block/'+newblockhash[0]+self.FORMAT_SEPARATOR+'json')
json_obj = json.loads(json_string) json_obj = json.loads(json_string)
for tx in json_obj['tx']: for tx in json_obj['tx']:
if not 'coinbase' in tx['vin'][0]: #exclude coinbase if not 'coinbase' in tx['vin'][0]: # exclude coinbase
assert_equal(tx['txid'] in txs, True) assert_equal(tx['txid'] in txs, True)
#check the same but without tx details # check the same but without tx details
json_string = http_get_call(url.hostname, url.port, '/rest/block/notxdetails/'+newblockhash[0]+self.FORMAT_SEPARATOR+'json') json_string = http_get_call(url.hostname, url.port, '/rest/block/notxdetails/'+newblockhash[0]+self.FORMAT_SEPARATOR+'json')
json_obj = json.loads(json_string) json_obj = json.loads(json_string)
for tx in txs: for tx in txs:
assert_equal(tx in json_obj['tx'], True) assert_equal(tx in json_obj['tx'], True)
#test rest bestblock # test rest bestblock
bb_hash = self.nodes[0].getbestblockhash() bb_hash = self.nodes[0].getbestblockhash()
json_string = http_get_call(url.hostname, url.port, '/rest/chaininfo.json') json_string = http_get_call(url.hostname, url.port, '/rest/chaininfo.json')
@@ -351,4 +350,4 @@ class RESTTest (BitcoinTestFramework):
assert_equal(json_obj['bestblockhash'], bb_hash) assert_equal(json_obj['bestblockhash'], bb_hash)
if __name__ == '__main__': if __name__ == '__main__':
RESTTest ().main () RESTTest().main()

View File

@@ -5,7 +5,7 @@
# Test for -rpcbind, as well as -rpcallowip and -rpcconnect # Test for -rpcbind, as well as -rpcallowip and -rpcconnect
# Add python-bitcoinrpc to module search path: # Dependency: python-bitcoinrpc
from test_framework.util import assert_equal, check_json_precision, \ from test_framework.util import assert_equal, check_json_precision, \
initialize_chain, start_nodes, stop_nodes, wait_bitcoinds, \ initialize_chain, start_nodes, stop_nodes, wait_bitcoinds, \

View File

@@ -42,29 +42,29 @@ class ZapWalletTXesTest (BitcoinTestFramework):
txid3 = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 5) txid3 = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 5)
tx0 = self.nodes[0].gettransaction(txid0) tx0 = self.nodes[0].gettransaction(txid0)
assert_equal(tx0['txid'], txid0) #tx0 must be available (confirmed) assert_equal(tx0['txid'], txid0) # tx0 must be available (confirmed)
tx1 = self.nodes[0].gettransaction(txid1) tx1 = self.nodes[0].gettransaction(txid1)
assert_equal(tx1['txid'], txid1) #tx1 must be available (confirmed) assert_equal(tx1['txid'], txid1) # tx1 must be available (confirmed)
tx2 = self.nodes[0].gettransaction(txid2) tx2 = self.nodes[0].gettransaction(txid2)
assert_equal(tx2['txid'], txid2) #tx2 must be available (unconfirmed) assert_equal(tx2['txid'], txid2) # tx2 must be available (unconfirmed)
tx3 = self.nodes[0].gettransaction(txid3) tx3 = self.nodes[0].gettransaction(txid3)
assert_equal(tx3['txid'], txid3) #tx3 must be available (unconfirmed) assert_equal(tx3['txid'], txid3) # tx3 must be available (unconfirmed)
#restart bitcoind # restart zcashd
self.nodes[0].stop() self.nodes[0].stop()
bitcoind_processes[0].wait() bitcoind_processes[0].wait()
self.nodes[0] = start_node(0,self.options.tmpdir) self.nodes[0] = start_node(0,self.options.tmpdir)
tx3 = self.nodes[0].gettransaction(txid3) tx3 = self.nodes[0].gettransaction(txid3)
assert_equal(tx3['txid'], txid3) #tx must be available (unconfirmed) assert_equal(tx3['txid'], txid3) # tx must be available (unconfirmed)
self.nodes[0].stop() self.nodes[0].stop()
bitcoind_processes[0].wait() bitcoind_processes[0].wait()
#restart bitcoind with zapwallettxes # restart zcashd with zapwallettxes
self.nodes[0] = start_node(0,self.options.tmpdir, ["-zapwallettxes=1"]) self.nodes[0] = start_node(0,self.options.tmpdir, ["-zapwallettxes=1"])
aException = False aException = False
@@ -74,11 +74,11 @@ class ZapWalletTXesTest (BitcoinTestFramework):
print e print e
aException = True aException = True
assert_equal(aException, True) #there must be a expection because the unconfirmed wallettx0 must be gone by now assert_equal(aException, True) # there must be a expection because the unconfirmed wallettx0 must be gone by now
tx0 = self.nodes[0].gettransaction(txid0) tx0 = self.nodes[0].gettransaction(txid0)
assert_equal(tx0['txid'], txid0) #tx0 (confirmed) must still be available because it was confirmed assert_equal(tx0['txid'], txid0) # tx0 (confirmed) must still be available because it was confirmed
if __name__ == '__main__': if __name__ == '__main__':
ZapWalletTXesTest ().main () ZapWalletTXesTest().main()

View File

@@ -13,7 +13,7 @@ from test_framework.util import assert_equal, bytes_to_hex_str, start_nodes
import zmq import zmq
import struct import struct
class ZMQTest (BitcoinTestFramework): class ZMQTest(BitcoinTestFramework):
port = 28332 port = 28332
@@ -44,7 +44,7 @@ class ZMQTest (BitcoinTestFramework):
nseq = msg[2] nseq = msg[2]
[nseq] # hush pyflakes [nseq] # hush pyflakes
msgSequence = struct.unpack('<I', msg[-1])[-1] msgSequence = struct.unpack('<I', msg[-1])[-1]
assert_equal(msgSequence, 0) #must be sequence 0 on hashtx assert_equal(msgSequence, 0) # must be sequence 0 on hashtx
msg = self.zmqSubSocket.recv_multipart() msg = self.zmqSubSocket.recv_multipart()
topic = msg[0] topic = msg[0]