Skip to content

Commit

Permalink
Cosmetics (trailing whitespace, comment conventions, etc.)
Browse files Browse the repository at this point in the history
Signed-off-by: Daira Hopwood <[email protected]>
  • Loading branch information
daira committed Jun 22, 2017
1 parent 811b36b commit ff0f305
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 111 deletions.
40 changes: 20 additions & 20 deletions qa/rpc-tests/httpbasics.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,66 +37,66 @@ def run_test(self):
conn = httplib.HTTPConnection(url.hostname, url.port)
conn.connect()
conn.request('POST', '/', '{"method": "getbestblockhash"}', headers)
out1 = conn.getresponse().read();
out1 = conn.getresponse().read()
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)
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(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()

#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"}

conn = httplib.HTTPConnection(url.hostname, url.port)
conn.connect()
conn.request('POST', '/', '{"method": "getbestblockhash"}', headers)
out1 = conn.getresponse().read();
out1 = conn.getresponse().read()
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)
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(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()

#now do the same with "Connection: close"
# now do the same with "Connection: close"
headers = {"Authorization": "Basic " + base64.b64encode(authpair), "Connection":"close"}

conn = httplib.HTTPConnection(url.hostname, url.port)
conn.connect()
conn.request('POST', '/', '{"method": "getbestblockhash"}', headers)
out1 = conn.getresponse().read();
out1 = conn.getresponse().read()
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)
authpair = urlNode1.username + ':' + urlNode1.password
headers = {"Authorization": "Basic " + base64.b64encode(authpair)}

conn = httplib.HTTPConnection(urlNode1.hostname, urlNode1.port)
conn.connect()
conn.request('POST', '/', '{"method": "getbestblockhash"}', headers)
out1 = conn.getresponse().read();
out1 = conn.getresponse().read()
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)
authpair = urlNode2.username + ':' + urlNode2.password
headers = {"Authorization": "Basic " + base64.b64encode(authpair)}

conn = httplib.HTTPConnection(urlNode2.hostname, urlNode2.port)
conn.connect()
conn.request('POST', '/', '{"method": "getbestblockhash"}', headers)
out1 = conn.getresponse().read();
out1 = conn.getresponse().read()
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__':
HTTPBasicsTest ().main ()
HTTPBasicsTest().main()
8 changes: 3 additions & 5 deletions qa/rpc-tests/invalidateblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@
import time

class InvalidateTest(BitcoinTestFramework):


def setup_chain(self):
print("Initializing test directory "+self.options.tmpdir)
initialize_chain_clean(self.options.tmpdir, 3)

def setup_network(self):
self.nodes = []
self.is_network_split = False
self.is_network_split = False
self.nodes.append(start_node(0, self.options.tmpdir, ["-debug"]))
self.nodes.append(start_node(1, self.options.tmpdir, ["-debug"]))
self.nodes.append(start_node(2, self.options.tmpdir, ["-debug"]))

def run_test(self):
print "Make sure we repopulate setBlockIndexCandidates after InvalidateBlock:"
print "Mine 4 blocks on Node 0"
Expand Down
2 changes: 1 addition & 1 deletion qa/rpc-tests/invalidblockrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# Use the ComparisonTestFramework with 1 node: only use --testbinary.
class InvalidBlockRequestTest(ComparisonTestFramework):

''' Can either run this test as 1 node with expected answers, or two and compare them.
''' Can either run this test as 1 node with expected answers, or two and compare them.
Change the "outcome" variable from each TestInstance object to only do the comparison. '''
def __init__(self):
self.num_nodes = 1
Expand Down
4 changes: 2 additions & 2 deletions qa/rpc-tests/maxblocksinflight.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def run(self):
current_invs = []
if len(current_invs) > 0:
self.connection.send_message(msg_inv(current_invs))

# Wait and see how many blocks were requested
time.sleep(2)

Expand All @@ -80,7 +80,7 @@ def run(self):
self.disconnectOkay = True
self.connection.disconnect_node()


class MaxBlocksInFlightTest(BitcoinTestFramework):
def add_options(self, parser):
parser.add_option("--testbinary", dest="testbinary",
Expand Down
12 changes: 6 additions & 6 deletions qa/rpc-tests/rawtransactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ def run_test(self):
self.nodes[0].generate(1)
self.sync_all()

#THIS IS A INCOMPLETE FEATURE
#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
# THIS IS A INCOMPLETE FEATURE
# 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

txDetails = self.nodes[0].gettransaction(txId, True)
rawTx = self.nodes[0].decoderawtransaction(txDetails['hex'])
Expand All @@ -134,10 +134,10 @@ def run_test(self):
outputs = { self.nodes[0].getnewaddress() : 2.199 }
rawTx = self.nodes[2].createrawtransaction(inputs, outputs)
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)
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'])
rawTx = self.nodes[0].decoderawtransaction(rawTxSigned['hex'])
self.sync_all()
Expand Down
40 changes: 20 additions & 20 deletions qa/rpc-tests/receivedby.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

def get_sub_array_from_array(object_array, to_match):
'''
Finds and returns a sub array from an array of arrays.
to_match should be a unique idetifier of a sub array
Finds and returns a sub array from an array of arrays.
to_match should be a unique idetifier of a sub array
'''
for item in object_array:
all_match = True
Expand All @@ -25,12 +25,12 @@ def get_sub_array_from_array(object_array, to_match):
return []

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
to match against, and another dictionary with expected key/value
pairs.
If the should_not_find flag is true, to_match should not be found in object_array
"""
'''
Pass in array of JSON objects, a dictionary with key/value pairs
to match against, and another dictionary with expected key/value
pairs.
If the should_not_find flag is true, to_match should not be found in object_array
'''
if should_not_find == True:
expected = { }
num_matched = 0
Expand Down Expand Up @@ -61,59 +61,59 @@ def run_test(self):
txid = self.nodes[0].sendtoaddress(addr, 0.1)
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(),
{"address":addr},
{ },
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.sync_all()
check_array_result(self.nodes[1].listreceivedbyaddress(),
{"address":addr},
{"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),
{"address":addr},
{"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)

#Empty Tx
# Empty Tx
addr = self.nodes[1].getnewaddress()
check_array_result(self.nodes[1].listreceivedbyaddress(0,True),
{"address":addr},
{"address":addr, "account":"", "amount":0, "confirmations":0, "txids":[]})

'''
getreceivedbyaddress Test
getreceivedbyaddress Test
'''
# Send from node 0 to 1
addr = self.nodes[1].getnewaddress()
txid = self.nodes[0].sendtoaddress(addr, 0.1)
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)
if balance != Decimal("0.0"):
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)
if balance != Decimal("0.1"):
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.sync_all()
balance = self.nodes[1].getreceivedbyaddress(addr)
if balance != Decimal("0.1"):
raise AssertionError("Wrong balance returned by getreceivedbyaddress, %0.2f"%(balance))

'''
listreceivedbyaccount + getreceivedbyaccount Test
listreceivedbyaccount + getreceivedbyaccount Test
'''
#set pre-state
# set pre-state
addrArr = self.nodes[1].getnewaddress()
account = self.nodes[1].getaccount(addrArr)
received_by_account_json = get_sub_array_from_array(self.nodes[1].listreceivedbyaccount(),{"account":account})
Expand Down Expand Up @@ -146,7 +146,7 @@ def run_test(self):
if balance != balance_by_account + Decimal("0.1"):
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")
received_by_account_json = get_sub_array_from_array(self.nodes[1].listreceivedbyaccount(0,True),{"account":"mynewaccount"})
if len(received_by_account_json) == 0:
Expand Down
Loading

0 comments on commit ff0f305

Please sign in to comment.