@@ -55,7 +55,8 @@ def setup_network(self, split=False):
55
55
56
56
def run_test (self ):
57
57
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" )
59
60
60
61
self .nodes [0 ].generate (1 )
61
62
self .sync_all ()
@@ -70,9 +71,10 @@ def run_test(self):
70
71
self .sync_all ()
71
72
bb_hash = self .nodes [0 ].getbestblockhash ()
72
73
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" )
74
77
75
- # load the latest 0.1 tx over the REST API
76
78
json_string = http_get_call (url .hostname , url .port , '/rest/tx/' + txid + self .FORMAT_SEPARATOR + "json" )
77
79
json_obj = json .loads (json_string )
78
80
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):
82
84
if vout ['value' ] == 0.1 :
83
85
n = vout ['n' ]
84
86
85
- #######################################
86
- # GETUTXOS: query an unspent outpoint #
87
- #######################################
87
+ self .log .info ("Query an unspent TXO using the /getutxos URI" )
88
+
88
89
json_request = '/' + txid + '-' + str (n )
89
90
json_string = http_get_call (url .hostname , url .port , '/rest/getutxos' + json_request + self .FORMAT_SEPARATOR + 'json' )
90
91
json_obj = json .loads (json_string )
@@ -96,9 +97,8 @@ def run_test(self):
96
97
assert_equal (len (json_obj ['utxos' ]), 1 )
97
98
assert_equal (json_obj ['utxos' ][0 ]['value' ], 0.1 )
98
99
99
- #################################################
100
- # GETUTXOS: now query an already spent outpoint #
101
- #################################################
100
+ self .log .info ("Query a spent TXO using the /getutxos URI" )
101
+
102
102
json_request = '/' + vintx + '-0'
103
103
json_string = http_get_call (url .hostname , url .port , '/rest/getutxos' + json_request + self .FORMAT_SEPARATOR + 'json' )
104
104
json_obj = json .loads (json_string )
@@ -112,16 +112,16 @@ def run_test(self):
112
112
# Check bitmap
113
113
assert_equal (json_obj ['bitmap' ], "0" )
114
114
115
- ##################################################
116
- # GETUTXOS: now check both with the same request #
117
- ##################################################
115
+ self .log .info ("Query two TXOs using the /getutxos URI" )
116
+
118
117
json_request = '/' + txid + '-' + str (n ) + '/' + vintx + '-0'
119
118
json_string = http_get_call (url .hostname , url .port , '/rest/getutxos' + json_request + self .FORMAT_SEPARATOR + 'json' )
120
119
json_obj = json .loads (json_string )
121
120
assert_equal (len (json_obj ['utxos' ]), 1 )
122
121
assert_equal (json_obj ['bitmap' ], "10" )
123
122
124
- # Test binary response
123
+ self .log .info ("Query the TXOs using the /getutxos URI with a binary response" )
124
+
125
125
bb_hash = self .nodes [0 ].getbestblockhash ()
126
126
127
127
bin_request = b'\x01 \x02 '
@@ -140,9 +140,10 @@ def run_test(self):
140
140
assert_equal (bb_hash , response_hash ) # check if getutxo's chaintip during calculation was fine
141
141
assert_equal (chain_height , 102 ) # chain height must be 102
142
142
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.
146
147
147
148
# do a tx and don't sync
148
149
txid = self .nodes [0 ].sendtoaddress (self .nodes [1 ].getnewaddress (), 0.1 )
@@ -160,35 +161,35 @@ def run_test(self):
160
161
json_request = '/' + spending
161
162
json_string = http_get_call (url .hostname , url .port , '/rest/getutxos' + json_request + self .FORMAT_SEPARATOR + 'json' )
162
163
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 )
164
165
165
166
json_request = '/checkmempool/' + spending
166
167
json_string = http_get_call (url .hostname , url .port , '/rest/getutxos' + json_request + self .FORMAT_SEPARATOR + 'json' )
167
168
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 )
169
170
170
171
json_request = '/' + spent
171
172
json_string = http_get_call (url .hostname , url .port , '/rest/getutxos' + json_request + self .FORMAT_SEPARATOR + 'json' )
172
173
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 )
174
175
175
176
json_request = '/checkmempool/' + spent
176
177
json_string = http_get_call (url .hostname , url .port , '/rest/getutxos' + json_request + self .FORMAT_SEPARATOR + 'json' )
177
178
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 )
179
180
180
181
self .nodes [0 ].generate (1 )
181
182
self .sync_all ()
182
183
183
184
json_request = '/' + spending
184
185
json_string = http_get_call (url .hostname , url .port , '/rest/getutxos' + json_request + self .FORMAT_SEPARATOR + 'json' )
185
186
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 )
187
188
188
189
json_request = '/checkmempool/' + spending
189
190
json_string = http_get_call (url .hostname , url .port , '/rest/getutxos' + json_request + self .FORMAT_SEPARATOR + 'json' )
190
191
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 )
192
193
193
194
# Do some invalid requests
194
195
json_request = '{"checkmempool'
@@ -220,9 +221,7 @@ def run_test(self):
220
221
self .nodes [0 ].generate (1 ) # generate block to not affect upcoming tests
221
222
self .sync_all ()
222
223
223
- ################
224
- # /rest/block/ #
225
- ################
224
+ self .log .info ("Test the /block and /headers URIs" )
226
225
227
226
# Check binary format
228
227
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):
279
278
json_obj = json .loads (response_header_json_str )
280
279
assert_equal (len (json_obj ), 5 ) # now we should have 5 header objects
281
280
282
- # Do tx test
281
+ self .log .info ("Test the /tx URI" )
282
+
283
283
tx_hash = block_json_obj ['tx' ][0 ]['txid' ]
284
284
json_string = http_get_call (url .hostname , url .port , '/rest/tx/' + tx_hash + self .FORMAT_SEPARATOR + "json" )
285
285
json_obj = json .loads (json_string )
@@ -290,8 +290,9 @@ def run_test(self):
290
290
assert_equal (hex_string .status , 200 )
291
291
assert_greater_than (int (response .getheader ('content-length' )), 10 )
292
292
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
295
296
txs = []
296
297
txs .append (self .nodes [0 ].sendtoaddress (self .nodes [2 ].getnewaddress (), 11 ))
297
298
txs .append (self .nodes [0 ].sendtoaddress (self .nodes [2 ].getnewaddress (), 11 ))
@@ -330,7 +331,8 @@ def run_test(self):
330
331
for tx in txs :
331
332
assert_equal (tx in json_obj ['tx' ], True )
332
333
333
- # Test rest bestblock
334
+ self .log .info ("Test the /chaininfo URI" )
335
+
334
336
bb_hash = self .nodes [0 ].getbestblockhash ()
335
337
336
338
json_string = http_get_call (url .hostname , url .port , '/rest/chaininfo.json' )
0 commit comments