@@ -57,7 +57,7 @@ def test_rest_request(self, uri, http_method='GET', req_type=ReqType.JSON, body=
57
57
rest_uri += '.hex'
58
58
59
59
conn = http .client .HTTPConnection (self .url .hostname , self .url .port )
60
- self .log .debug ('%s %s %s' , http_method , rest_uri , body )
60
+ self .log .debug (f' { http_method } { rest_uri } { body } ' )
61
61
if http_method == 'GET' :
62
62
conn .request ('GET' , rest_uri )
63
63
elif http_method == 'POST' :
@@ -92,11 +92,11 @@ def run_test(self):
92
92
93
93
self .log .info ("Test the /tx URI" )
94
94
95
- json_obj = self .test_rest_request ("/tx/{}" . format ( txid ) )
95
+ json_obj = self .test_rest_request (f "/tx/{ txid } " )
96
96
assert_equal (json_obj ['txid' ], txid )
97
97
98
98
# Check hex format response
99
- hex_response = self .test_rest_request ("/tx/{}" . format ( txid ) , req_type = ReqType .HEX , ret_type = RetType .OBJ )
99
+ hex_response = self .test_rest_request (f "/tx/{ txid } " , req_type = ReqType .HEX , ret_type = RetType .OBJ )
100
100
assert_greater_than_or_equal (int (hex_response .getheader ('content-length' )),
101
101
json_obj ['size' ]* 2 )
102
102
@@ -114,7 +114,7 @@ def run_test(self):
114
114
assert_equal (self .nodes [1 ].getbalance (), Decimal ("0.1" ))
115
115
116
116
# Check chainTip response
117
- json_obj = self .test_rest_request ("/getutxos/{}-{}" . format ( * spending ) )
117
+ json_obj = self .test_rest_request (f "/getutxos/{ spending [ 0 ] } -{ spending [ 1 ] } " )
118
118
assert_equal (json_obj ['chaintipHash' ], bb_hash )
119
119
120
120
# Make sure there is one utxo
@@ -123,7 +123,7 @@ def run_test(self):
123
123
124
124
self .log .info ("Query a spent TXO using the /getutxos URI" )
125
125
126
- json_obj = self .test_rest_request ("/getutxos/{}-{}" . format ( * spent ) )
126
+ json_obj = self .test_rest_request (f "/getutxos/{ spent [ 0 ] } -{ spent [ 1 ] } " )
127
127
128
128
# Check chainTip response
129
129
assert_equal (json_obj ['chaintipHash' ], bb_hash )
@@ -136,7 +136,7 @@ def run_test(self):
136
136
137
137
self .log .info ("Query two TXOs using the /getutxos URI" )
138
138
139
- json_obj = self .test_rest_request ("/getutxos/{}-{}/{}-{}" . format ( * ( spending + spent )) )
139
+ json_obj = self .test_rest_request (f "/getutxos/{ spending [ 0 ] } -{ spending [ 1 ] } /{ spent [ 0 ] } -{ spent [ 1 ] } " )
140
140
141
141
assert_equal (len (json_obj ['utxos' ]), 1 )
142
142
assert_equal (json_obj ['bitmap' ], "10" )
@@ -163,32 +163,32 @@ def run_test(self):
163
163
164
164
# do a tx and don't sync
165
165
txid = self .nodes [0 ].sendtoaddress (self .nodes [1 ].getnewaddress (), 0.1 )
166
- json_obj = self .test_rest_request ("/tx/{}" . format ( txid ) )
166
+ json_obj = self .test_rest_request (f "/tx/{ txid } " )
167
167
# get the spent output to later check for utxo (should be spent by then)
168
168
spent = (json_obj ['vin' ][0 ]['txid' ], json_obj ['vin' ][0 ]['vout' ])
169
169
# get n of 0.1 outpoint
170
170
n , = filter_output_indices_by_value (json_obj ['vout' ], Decimal ('0.1' ))
171
171
spending = (txid , n )
172
172
173
- json_obj = self .test_rest_request ("/getutxos/{}-{}" . format ( * spending ) )
173
+ json_obj = self .test_rest_request (f "/getutxos/{ spending [ 0 ] } -{ spending [ 1 ] } " )
174
174
assert_equal (len (json_obj ['utxos' ]), 0 )
175
175
176
- json_obj = self .test_rest_request ("/getutxos/checkmempool/{}-{}" . format ( * spending ) )
176
+ json_obj = self .test_rest_request (f "/getutxos/checkmempool/{ spending [ 0 ] } -{ spending [ 1 ] } " )
177
177
assert_equal (len (json_obj ['utxos' ]), 1 )
178
178
179
- json_obj = self .test_rest_request ("/getutxos/{}-{}" . format ( * spent ) )
179
+ json_obj = self .test_rest_request (f "/getutxos/{ spent [ 0 ] } -{ spent [ 1 ] } " )
180
180
assert_equal (len (json_obj ['utxos' ]), 1 )
181
181
182
- json_obj = self .test_rest_request ("/getutxos/checkmempool/{}-{}" . format ( * spent ) )
182
+ json_obj = self .test_rest_request (f "/getutxos/checkmempool/{ spent [ 0 ] } -{ spent [ 1 ] } " )
183
183
assert_equal (len (json_obj ['utxos' ]), 0 )
184
184
185
185
self .nodes [0 ].generate (1 )
186
186
self .sync_all ()
187
187
188
- json_obj = self .test_rest_request ("/getutxos/{}-{}" . format ( * spending ) )
188
+ json_obj = self .test_rest_request (f "/getutxos/{ spending [ 0 ] } -{ spending [ 1 ] } " )
189
189
assert_equal (len (json_obj ['utxos' ]), 1 )
190
190
191
- json_obj = self .test_rest_request ("/getutxos/checkmempool/{}-{}" . format ( * spending ) )
191
+ json_obj = self .test_rest_request (f "/getutxos/checkmempool/{ spending [ 0 ] } -{ spending [ 1 ] } " )
192
192
assert_equal (len (json_obj ['utxos' ]), 1 )
193
193
194
194
# Do some invalid requests
@@ -197,11 +197,11 @@ def run_test(self):
197
197
self .test_rest_request ("/getutxos/checkmempool" , http_method = 'POST' , req_type = ReqType .JSON , status = 400 , ret_type = RetType .OBJ )
198
198
199
199
# Test limits
200
- long_uri = '/' .join (["{ }-{}" . format ( txid , n_ ) for n_ in range (20 )])
201
- self .test_rest_request ("/getutxos/checkmempool/{}" . format ( long_uri ) , http_method = 'POST' , status = 400 , ret_type = RetType .OBJ )
200
+ long_uri = '/' .join ([f" { txid } -{ n_ } " for n_ in range (20 )])
201
+ self .test_rest_request (f "/getutxos/checkmempool/{ long_uri } " , http_method = 'POST' , status = 400 , ret_type = RetType .OBJ )
202
202
203
- long_uri = '/' .join (['{ }-{}' . format ( txid , n_ ) for n_ in range (15 )])
204
- self .test_rest_request ("/getutxos/checkmempool/{}" . format ( long_uri ) , http_method = 'POST' , status = 200 )
203
+ long_uri = '/' .join ([f' { txid } -{ n_ } ' for n_ in range (15 )])
204
+ self .test_rest_request (f "/getutxos/checkmempool/{ long_uri } " , http_method = 'POST' , status = 200 )
205
205
206
206
self .nodes [0 ].generate (1 ) # generate block to not affect upcoming tests
207
207
self .sync_all ()
@@ -215,42 +215,42 @@ def run_test(self):
215
215
216
216
# Check result if block is not in the active chain
217
217
self .nodes [0 ].invalidateblock (bb_hash )
218
- assert_equal (self .test_rest_request ('/headers/1/{}' . format ( bb_hash ) ), [])
219
- self .test_rest_request ('/block/{}' . format ( bb_hash ) )
218
+ assert_equal (self .test_rest_request (f '/headers/1/{ bb_hash } ' ), [])
219
+ self .test_rest_request (f '/block/{ bb_hash } ' )
220
220
self .nodes [0 ].reconsiderblock (bb_hash )
221
221
222
222
# Check binary format
223
- response = self .test_rest_request ("/block/{}" . format ( bb_hash ) , req_type = ReqType .BIN , ret_type = RetType .OBJ )
223
+ response = self .test_rest_request (f "/block/{ bb_hash } " , req_type = ReqType .BIN , ret_type = RetType .OBJ )
224
224
assert_greater_than (int (response .getheader ('content-length' )), BLOCK_HEADER_SIZE )
225
225
response_bytes = response .read ()
226
226
227
227
# Compare with block header
228
- response_header = self .test_rest_request ("/headers/1/{}" . format ( bb_hash ) , req_type = ReqType .BIN , ret_type = RetType .OBJ )
228
+ response_header = self .test_rest_request (f "/headers/1/{ bb_hash } " , req_type = ReqType .BIN , ret_type = RetType .OBJ )
229
229
assert_equal (int (response_header .getheader ('content-length' )), BLOCK_HEADER_SIZE )
230
230
response_header_bytes = response_header .read ()
231
231
assert_equal (response_bytes [:BLOCK_HEADER_SIZE ], response_header_bytes )
232
232
233
233
# Check block hex format
234
- response_hex = self .test_rest_request ("/block/{}" . format ( bb_hash ) , req_type = ReqType .HEX , ret_type = RetType .OBJ )
234
+ response_hex = self .test_rest_request (f "/block/{ bb_hash } " , req_type = ReqType .HEX , ret_type = RetType .OBJ )
235
235
assert_greater_than (int (response_hex .getheader ('content-length' )), BLOCK_HEADER_SIZE * 2 )
236
236
response_hex_bytes = response_hex .read ().strip (b'\n ' )
237
237
assert_equal (response_bytes .hex ().encode (), response_hex_bytes )
238
238
239
239
# Compare with hex block header
240
- response_header_hex = self .test_rest_request ("/headers/1/{}" . format ( bb_hash ) , req_type = ReqType .HEX , ret_type = RetType .OBJ )
240
+ response_header_hex = self .test_rest_request (f "/headers/1/{ bb_hash } " , req_type = ReqType .HEX , ret_type = RetType .OBJ )
241
241
assert_greater_than (int (response_header_hex .getheader ('content-length' )), BLOCK_HEADER_SIZE * 2 )
242
242
response_header_hex_bytes = response_header_hex .read (BLOCK_HEADER_SIZE * 2 )
243
243
assert_equal (response_bytes [:BLOCK_HEADER_SIZE ].hex ().encode (), response_header_hex_bytes )
244
244
245
245
# Check json format
246
- block_json_obj = self .test_rest_request ("/block/{}" . format ( bb_hash ) )
246
+ block_json_obj = self .test_rest_request (f "/block/{ bb_hash } " )
247
247
assert_equal (block_json_obj ['hash' ], bb_hash )
248
- assert_equal (self .test_rest_request ("/blockhashbyheight/{}" . format ( block_json_obj ['height' ]) )['blockhash' ], bb_hash )
248
+ assert_equal (self .test_rest_request (f "/blockhashbyheight/{ block_json_obj ['height' ]} " )['blockhash' ], bb_hash )
249
249
250
250
# Check hex/bin format
251
- resp_hex = self .test_rest_request ("/blockhashbyheight/{}" . format ( block_json_obj ['height' ]) , req_type = ReqType .HEX , ret_type = RetType .OBJ )
251
+ resp_hex = self .test_rest_request (f "/blockhashbyheight/{ block_json_obj ['height' ]} " , req_type = ReqType .HEX , ret_type = RetType .OBJ )
252
252
assert_equal (resp_hex .read ().decode ('utf-8' ).rstrip (), bb_hash )
253
- resp_bytes = self .test_rest_request ("/blockhashbyheight/{}" . format ( block_json_obj ['height' ]) , req_type = ReqType .BIN , ret_type = RetType .BYTES )
253
+ resp_bytes = self .test_rest_request (f "/blockhashbyheight/{ block_json_obj ['height' ]} " , req_type = ReqType .BIN , ret_type = RetType .BYTES )
254
254
blockhash = resp_bytes [::- 1 ].hex ()
255
255
assert_equal (blockhash , bb_hash )
256
256
@@ -264,7 +264,7 @@ def run_test(self):
264
264
self .test_rest_request ("/blockhashbyheight/" , ret_type = RetType .OBJ , status = 400 )
265
265
266
266
# Compare with json block header
267
- json_obj = self .test_rest_request ("/headers/1/{}" . format ( bb_hash ) )
267
+ json_obj = self .test_rest_request (f "/headers/1/{ bb_hash } " )
268
268
assert_equal (len (json_obj ), 1 ) # ensure that there is one header in the json response
269
269
assert_equal (json_obj [0 ]['hash' ], bb_hash ) # request/response hash should be the same
270
270
@@ -276,7 +276,7 @@ def run_test(self):
276
276
# See if we can get 5 headers in one response
277
277
self .nodes [1 ].generate (5 )
278
278
self .sync_all ()
279
- json_obj = self .test_rest_request ("/headers/5/{}" . format ( bb_hash ) )
279
+ json_obj = self .test_rest_request (f "/headers/5/{ bb_hash } " )
280
280
assert_equal (len (json_obj ), 5 ) # now we should have 5 header objects
281
281
282
282
self .log .info ("Test tx inclusion in the /mempool and /block URIs" )
@@ -306,13 +306,13 @@ def run_test(self):
306
306
self .sync_all ()
307
307
308
308
# Check if the 3 tx show up in the new block
309
- json_obj = self .test_rest_request ("/block/{}" . format ( newblockhash [0 ]) )
309
+ json_obj = self .test_rest_request (f "/block/{ newblockhash [0 ]} " )
310
310
non_coinbase_txs = {tx ['txid' ] for tx in json_obj ['tx' ]
311
311
if 'coinbase' not in tx ['vin' ][0 ]}
312
312
assert_equal (non_coinbase_txs , set (txs ))
313
313
314
314
# Check the same but without tx details
315
- json_obj = self .test_rest_request ("/block/notxdetails/{}" . format ( newblockhash [0 ]) )
315
+ json_obj = self .test_rest_request (f "/block/notxdetails/{ newblockhash [0 ]} " )
316
316
for tx in txs :
317
317
assert tx in json_obj ['tx' ]
318
318
0 commit comments