Skip to content

Commit 3fd4490

Browse files
jnewberyromanz
authored andcommitted
[tests] improve logging and documentation in interface_rest.py
1 parent abf190e commit 3fd4490

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

test/functional/interface_rest.py

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def setup_network(self, split=False):
5555

5656
def run_test(self):
5757
url = urllib.parse.urlparse(self.nodes[0].url)
58-
self.log.info("Mining blocks...")
58+
59+
self.log.info("Mine blocks and send Bitcoin to node 1")
5960

6061
self.nodes[0].generate(1)
6162
self.sync_all()
@@ -70,9 +71,10 @@ def run_test(self):
7071
self.sync_all()
7172
bb_hash = self.nodes[0].getbestblockhash()
7273

73-
assert_equal(self.nodes[1].getbalance(), Decimal("0.1")) # balance now should be 0.1 on node 1
74+
assert_equal(self.nodes[1].getbalance(), Decimal("0.1"))
75+
76+
self.log.info("Load the transaction using the /tx URI")
7477

75-
# load the latest 0.1 tx over the REST API
7678
json_string = http_get_call(url.hostname, url.port, '/rest/tx/' + txid + self.FORMAT_SEPARATOR + "json")
7779
json_obj = json.loads(json_string)
7880
vintx = json_obj['vin'][0]['txid'] # get the vin to later check for utxo (should be spent by then)
@@ -82,9 +84,8 @@ def run_test(self):
8284
if vout['value'] == 0.1:
8385
n = vout['n']
8486

85-
#######################################
86-
# GETUTXOS: query an unspent outpoint #
87-
#######################################
87+
self.log.info("Query an unspent TXO using the /getutxos URI")
88+
8889
json_request = '/' + txid + '-' + str(n)
8990
json_string = http_get_call(url.hostname, url.port, '/rest/getutxos' + json_request + self.FORMAT_SEPARATOR + 'json')
9091
json_obj = json.loads(json_string)
@@ -96,9 +97,8 @@ def run_test(self):
9697
assert_equal(len(json_obj['utxos']), 1)
9798
assert_equal(json_obj['utxos'][0]['value'], 0.1)
9899

99-
#################################################
100-
# GETUTXOS: now query an already spent outpoint #
101-
#################################################
100+
self.log.info("Query a spent TXO using the /getutxos URI")
101+
102102
json_request = '/' + vintx + '-0'
103103
json_string = http_get_call(url.hostname, url.port, '/rest/getutxos' + json_request + self.FORMAT_SEPARATOR + 'json')
104104
json_obj = json.loads(json_string)
@@ -112,16 +112,16 @@ def run_test(self):
112112
# Check bitmap
113113
assert_equal(json_obj['bitmap'], "0")
114114

115-
##################################################
116-
# GETUTXOS: now check both with the same request #
117-
##################################################
115+
self.log.info("Query two TXOs using the /getutxos URI")
116+
118117
json_request = '/' + txid + '-' + str(n) + '/' + vintx + '-0'
119118
json_string = http_get_call(url.hostname, url.port, '/rest/getutxos' + json_request + self.FORMAT_SEPARATOR + 'json')
120119
json_obj = json.loads(json_string)
121120
assert_equal(len(json_obj['utxos']), 1)
122121
assert_equal(json_obj['bitmap'], "10")
123122

124-
# Test binary response
123+
self.log.info("Query the TXOs using the /getutxos URI with a binary response")
124+
125125
bb_hash = self.nodes[0].getbestblockhash()
126126

127127
bin_request = b'\x01\x02'
@@ -140,9 +140,10 @@ def run_test(self):
140140
assert_equal(bb_hash, response_hash) # check if getutxo's chaintip during calculation was fine
141141
assert_equal(chain_height, 102) # chain height must be 102
142142

143-
############################
144-
# GETUTXOS: mempool checks #
145-
############################
143+
self.log.info("Test the /getutxos URI with and without /checkmempool")
144+
# Create a transaction, check that it's found with /checkmempool, but
145+
# not found without. Then confirm the transaction and check that it's
146+
# found with or without /checkmempool.
146147

147148
# do a tx and don't sync
148149
txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1)
@@ -160,35 +161,35 @@ def run_test(self):
160161
json_request = '/' + spending
161162
json_string = http_get_call(url.hostname, url.port, '/rest/getutxos' + json_request + self.FORMAT_SEPARATOR + 'json')
162163
json_obj = json.loads(json_string)
163-
assert_equal(len(json_obj['utxos']), 0) # there should be no outpoint because it has just added to the mempool
164+
assert_equal(len(json_obj['utxos']), 0)
164165

165166
json_request = '/checkmempool/' + spending
166167
json_string = http_get_call(url.hostname, url.port, '/rest/getutxos' + json_request + self.FORMAT_SEPARATOR + 'json')
167168
json_obj = json.loads(json_string)
168-
assert_equal(len(json_obj['utxos']), 1) # there should be an outpoint because it has just added to the mempool
169+
assert_equal(len(json_obj['utxos']), 1)
169170

170171
json_request = '/' + spent
171172
json_string = http_get_call(url.hostname, url.port, '/rest/getutxos' + json_request + self.FORMAT_SEPARATOR + 'json')
172173
json_obj = json.loads(json_string)
173-
assert_equal(len(json_obj['utxos']), 1) # there should be an outpoint because its spending tx is not confirmed
174+
assert_equal(len(json_obj['utxos']), 1)
174175

175176
json_request = '/checkmempool/' + spent
176177
json_string = http_get_call(url.hostname, url.port, '/rest/getutxos' + json_request + self.FORMAT_SEPARATOR + 'json')
177178
json_obj = json.loads(json_string)
178-
assert_equal(len(json_obj['utxos']), 0) # there should be no outpoint because it has just spent (by mempool tx)
179+
assert_equal(len(json_obj['utxos']), 0)
179180

180181
self.nodes[0].generate(1)
181182
self.sync_all()
182183

183184
json_request = '/' + spending
184185
json_string = http_get_call(url.hostname, url.port, '/rest/getutxos' + json_request + self.FORMAT_SEPARATOR + 'json')
185186
json_obj = json.loads(json_string)
186-
assert_equal(len(json_obj['utxos']), 1) # there should be an outpoint because it was mined
187+
assert_equal(len(json_obj['utxos']), 1)
187188

188189
json_request = '/checkmempool/' + spending
189190
json_string = http_get_call(url.hostname, url.port, '/rest/getutxos' + json_request + self.FORMAT_SEPARATOR + 'json')
190191
json_obj = json.loads(json_string)
191-
assert_equal(len(json_obj['utxos']), 1) # there should be an outpoint because it was mined
192+
assert_equal(len(json_obj['utxos']), 1)
192193

193194
# Do some invalid requests
194195
json_request = '{"checkmempool'
@@ -220,9 +221,7 @@ def run_test(self):
220221
self.nodes[0].generate(1) # generate block to not affect upcoming tests
221222
self.sync_all()
222223

223-
################
224-
# /rest/block/ #
225-
################
224+
self.log.info("Test the /block and /headers URIs")
226225

227226
# Check binary format
228227
response = http_get_call(url.hostname, url.port, '/rest/block/' + bb_hash + self.FORMAT_SEPARATOR + "bin", True)
@@ -279,7 +278,8 @@ def run_test(self):
279278
json_obj = json.loads(response_header_json_str)
280279
assert_equal(len(json_obj), 5) # now we should have 5 header objects
281280

282-
# Do tx test
281+
self.log.info("Test the /tx URI")
282+
283283
tx_hash = block_json_obj['tx'][0]['txid']
284284
json_string = http_get_call(url.hostname, url.port, '/rest/tx/' + tx_hash + self.FORMAT_SEPARATOR + "json")
285285
json_obj = json.loads(json_string)
@@ -290,8 +290,9 @@ def run_test(self):
290290
assert_equal(hex_string.status, 200)
291291
assert_greater_than(int(response.getheader('content-length')), 10)
292292

293-
# Check block tx details
294-
# Let's make 3 tx and mine them on node 1
293+
self.log.info("Test tx inclusion in the /mempool and /block URIs")
294+
295+
# Make 3 tx and mine them on node 1
295296
txs = []
296297
txs.append(self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11))
297298
txs.append(self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11))
@@ -330,7 +331,8 @@ def run_test(self):
330331
for tx in txs:
331332
assert_equal(tx in json_obj['tx'], True)
332333

333-
# Test rest bestblock
334+
self.log.info("Test the /chaininfo URI")
335+
334336
bb_hash = self.nodes[0].getbestblockhash()
335337

336338
json_string = http_get_call(url.hostname, url.port, '/rest/chaininfo.json')

0 commit comments

Comments
 (0)