@@ -178,11 +178,18 @@ pub fn run(args: Args) -> Result<()> {
178
178
// a - b
179
179
// }
180
180
181
- pub fn wait ( ) {
181
+ pub fn wait ( sleep : & str ) {
182
182
use std:: process:: Command ;
183
- let mut child = Command :: new ( "sleep" ) . arg ( "5" ) . spawn ( ) . unwrap ( ) ;
184
- let _result = child. wait ( ) . unwrap ( ) ;
185
- let _result = child. wait ( ) . unwrap ( ) ;
183
+ let sleep_cmd = Command :: new ( "sleep" ) . arg ( sleep) . output ( ) . expect ( "wait:sleep failed" ) ;
184
+ let result = String :: from_utf8 ( sleep_cmd. stdout )
185
+ . map_err ( |non_utf8| String :: from_utf8_lossy ( non_utf8. as_bytes ( ) ) . into_owned ( ) )
186
+ . unwrap ( ) ;
187
+ println ! ( "\n wait:sleep:{:?}:{}" , sleep, result) ;
188
+ // if result.unwrap().len() <= 0 {
189
+ // true
190
+ // } else {
191
+ // false
192
+ // }
186
193
}
187
194
188
195
#[ cfg( test) ]
@@ -194,81 +201,82 @@ mod tests {
194
201
/// https://mempool.space/docs/api/rest
195
202
/// cargo test -- --nocapture
196
203
#[ test]
197
- fn test_difficulty_adjustment ( ) {
204
+ fn test_difficulty_adjustment ( ) {
198
205
// GET /api/v1/difficulty-adjustment
199
206
let binding = format ! ( "v1/difficulty-adjustment" ) . clone ( ) ;
200
207
let difficulty_adjustment: & str = blocking ( & binding) . expect ( "REASON" ) ;
201
208
let difficulty_adjustment = generic_sys_call ( "difficulty_adjustment" , "extraneous_arg" ) ;
202
- wait ( ) ;
209
+ wait ( "1" ) ;
203
210
}
204
211
#[ test]
205
- fn test_price ( ) {
212
+ fn test_price ( ) {
206
213
// GET /api/v1/prices
207
214
let binding = format ! ( "v1/prices" ) . clone ( ) ;
208
215
let prices: & str = blocking ( & binding) . expect ( "REASON" ) ;
209
216
let prices = generic_sys_call ( "prices" , "extraneous_arg" ) ;
210
- wait ( ) ;
217
+ wait ( "1" ) ;
211
218
}
212
219
#[ test]
213
220
fn test_historical_price ( ) {
214
221
// GET /api/v1/historical-price?currency=EUR×tamp=1500000000
215
222
let historical_price_json = historical_price ( & "EUR" , & "1500000000" ) ;
216
223
print ! ( "\n {{\" prices\" :[{{\" time\" :1499904000,\" EUR\" :1964,\" USD\" :2254.9}}],\" exchangeRates\" :{{\" USDEUR\" :0.92,\" USDGBP\" :0.78,\" USDCAD\" :1.38,\" USDCHF\" :0.87,\" USDAUD\" :1.53,\" USDJPY\" :146.62}}}}\n " ) ;
217
224
let historical_prices = generic_sys_call ( "historical_price" , "USD" ) ;
218
- wait ( ) ;
225
+ wait ( "1" ) ;
219
226
}
220
227
221
-
222
228
/// Addresses
223
229
#[ test]
224
- fn test_address ( ) {
230
+ fn test_address ( ) {
225
231
// GET /api/address/:address
226
232
let binding = format ! ( "address/1wiz18xYmhRX6xStj2b9t1rwWX4GKUgpv" ) . clone ( ) ;
227
- let prices: & str = blocking ( & binding) . expect ( "REASON" ) ;
228
- wait ( ) ;
233
+ let prices: & str = blocking ( & binding) . expect ( "test_address failed" ) ;
234
+ let prices = generic_sys_call ( "address" , "1wiz18xYmhRX6xStj2b9t1rwWX4GKUgpv" ) ;
235
+ wait ( "1" ) ;
229
236
}
230
237
#[ test]
231
- fn test_address_txs ( ) {
238
+ fn test_address_txs ( ) {
232
239
// GET /api/address/:address/txs
233
240
let binding = format ! ( "address/1wiz18xYmhRX6xStj2b9t1rwWX4GKUgpv/txs" ) . clone ( ) ;
234
241
let prices: & str = blocking ( & binding) . expect ( "REASON" ) ;
235
- wait ( ) ;
242
+ let prices = generic_sys_call ( "address_txs" , "1wiz18xYmhRX6xStj2b9t1rwWX4GKUgpv" ) ;
243
+ wait ( "1" ) ;
236
244
}
237
245
#[ test]
238
- fn test_address_txs_chain ( ) {
246
+ fn test_address_txs_chain ( ) {
239
247
// GET /api/address/:address/txs/chain
240
248
let binding = format ! ( "address/1wiz18xYmhRX6xStj2b9t1rwWX4GKUgpv/txs/chain" ) . clone ( ) ;
241
249
let prices: & str = blocking ( & binding) . expect ( "REASON" ) ;
242
- wait ( ) ;
250
+ wait ( "1" ) ;
243
251
}
244
252
#[ test]
245
- fn test_address_txs_mempool ( ) {
253
+ fn test_address_txs_mempool ( ) {
246
254
// GET /api/address/:address/txs/mempool
247
255
let binding = format ! ( "address/1wiz18xYmhRX6xStj2b9t1rwWX4GKUgpv/txs/mempool" ) . clone ( ) ;
248
256
let prices: & str = blocking ( & binding) . expect ( "REASON" ) ;
249
- wait ( ) ;
257
+ wait ( "1" ) ;
250
258
}
251
259
#[ test]
252
- fn test_address_txs_utxo ( ) {
260
+ fn test_address_txs_utxo ( ) {
253
261
// GET /api/address/:address/utxo
254
262
let binding = format ! ( "address/1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY/utxo" ) . clone ( ) ;
255
263
let prices: & str = blocking ( & binding) . expect ( "REASON" ) ;
256
- wait ( ) ;
264
+ wait ( "1" ) ;
257
265
}
258
266
#[ test]
259
- fn test_validate_address ( ) {
267
+ fn test_validate_address ( ) {
260
268
// GET /api/v1/validate-address/:address
261
269
let binding = format ! ( "v1/validate-address/1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY" ) . clone ( ) ;
262
270
let prices: & str = blocking ( & binding) . expect ( "REASON" ) ;
263
- wait ( ) ;
271
+ wait ( "1" ) ;
264
272
}
265
273
266
274
/// Blocks
267
275
#[ test]
268
276
fn test_blockheight ( ) {
269
277
let blockheight = blockheight:: blockheight ( ) ;
270
278
assert_ne ! ( 0 as f64 , blockheight. unwrap( ) ) ;
271
- wait ( ) ;
279
+ wait ( "1" ) ;
272
280
}
273
281
/// Mining
274
282
/// Fees
@@ -278,19 +286,18 @@ mod tests {
278
286
/// Accelerator (Public)
279
287
/// Accelerator (Authenticated)
280
288
281
-
282
289
#[ test]
283
290
fn test_add ( ) {
284
291
// assert_eq!(add(1, 2), 3);
285
- wait ( ) ;
292
+ wait ( "1" ) ;
286
293
}
287
294
288
295
#[ test]
289
296
fn test_bad_add ( ) {
290
297
// This assert would fire and test will fail.
291
298
// Please note, that private functions can be tested too!
292
299
// assert_ne!(bad_add(1, 2), 3);
293
- wait ( ) ;
300
+ wait ( "1" ) ;
294
301
}
295
302
296
303
use std:: panic:: { catch_unwind, AssertUnwindSafe } ;
@@ -301,6 +308,6 @@ mod tests {
301
308
} ) ) ;
302
309
303
310
assert_ne ! ( "foo panic message" , * msg. unwrap_err( ) . downcast_ref:: <& str >( ) . unwrap( ) ) ;
304
- wait ( ) ;
311
+ wait ( "1" ) ;
305
312
}
306
313
}
0 commit comments