@@ -223,27 +223,27 @@ pub mod test {
223
223
224
224
use super :: * ;
225
225
226
- pub fn test_script_pubkey < D : Database > ( mut tree : D ) {
226
+ pub fn test_script_pubkey < D : Database > ( mut db : D ) {
227
227
let script = Script :: from (
228
228
Vec :: < u8 > :: from_hex ( "76a91402306a7c23f3e8010de41e9e591348bb83f11daa88ac" ) . unwrap ( ) ,
229
229
) ;
230
230
let path = 42 ;
231
231
let keychain = KeychainKind :: External ;
232
232
233
- tree . set_script_pubkey ( & script, keychain, path) . unwrap ( ) ;
233
+ db . set_script_pubkey ( & script, keychain, path) . unwrap ( ) ;
234
234
235
235
assert_eq ! (
236
- tree . get_script_pubkey_from_path( keychain, path) . unwrap( ) ,
236
+ db . get_script_pubkey_from_path( keychain, path) . unwrap( ) ,
237
237
Some ( script. clone( ) )
238
238
) ;
239
239
assert_eq ! (
240
- tree . get_path_from_script_pubkey( & script) . unwrap( ) ,
240
+ db . get_path_from_script_pubkey( & script) . unwrap( ) ,
241
241
Some ( ( keychain, path) )
242
242
) ;
243
243
}
244
244
245
- pub fn test_batch_script_pubkey < D : BatchDatabase > ( mut tree : D ) {
246
- let mut batch = tree . begin_batch ( ) ;
245
+ pub fn test_batch_script_pubkey < D : BatchDatabase > ( mut db : D ) {
246
+ let mut batch = db . begin_batch ( ) ;
247
247
248
248
let script = Script :: from (
249
249
Vec :: < u8 > :: from_hex ( "76a91402306a7c23f3e8010de41e9e591348bb83f11daa88ac" ) . unwrap ( ) ,
@@ -254,50 +254,50 @@ pub mod test {
254
254
batch. set_script_pubkey ( & script, keychain, path) . unwrap ( ) ;
255
255
256
256
assert_eq ! (
257
- tree . get_script_pubkey_from_path( keychain, path) . unwrap( ) ,
257
+ db . get_script_pubkey_from_path( keychain, path) . unwrap( ) ,
258
258
None
259
259
) ;
260
- assert_eq ! ( tree . get_path_from_script_pubkey( & script) . unwrap( ) , None ) ;
260
+ assert_eq ! ( db . get_path_from_script_pubkey( & script) . unwrap( ) , None ) ;
261
261
262
- tree . commit_batch ( batch) . unwrap ( ) ;
262
+ db . commit_batch ( batch) . unwrap ( ) ;
263
263
264
264
assert_eq ! (
265
- tree . get_script_pubkey_from_path( keychain, path) . unwrap( ) ,
265
+ db . get_script_pubkey_from_path( keychain, path) . unwrap( ) ,
266
266
Some ( script. clone( ) )
267
267
) ;
268
268
assert_eq ! (
269
- tree . get_path_from_script_pubkey( & script) . unwrap( ) ,
269
+ db . get_path_from_script_pubkey( & script) . unwrap( ) ,
270
270
Some ( ( keychain, path) )
271
271
) ;
272
272
}
273
273
274
- pub fn test_iter_script_pubkey < D : Database > ( mut tree : D ) {
274
+ pub fn test_iter_script_pubkey < D : Database > ( mut db : D ) {
275
275
let script = Script :: from (
276
276
Vec :: < u8 > :: from_hex ( "76a91402306a7c23f3e8010de41e9e591348bb83f11daa88ac" ) . unwrap ( ) ,
277
277
) ;
278
278
let path = 42 ;
279
279
let keychain = KeychainKind :: External ;
280
280
281
- tree . set_script_pubkey ( & script, keychain, path) . unwrap ( ) ;
281
+ db . set_script_pubkey ( & script, keychain, path) . unwrap ( ) ;
282
282
283
- assert_eq ! ( tree . iter_script_pubkeys( None ) . unwrap( ) . len( ) , 1 ) ;
283
+ assert_eq ! ( db . iter_script_pubkeys( None ) . unwrap( ) . len( ) , 1 ) ;
284
284
}
285
285
286
- pub fn test_del_script_pubkey < D : Database > ( mut tree : D ) {
286
+ pub fn test_del_script_pubkey < D : Database > ( mut db : D ) {
287
287
let script = Script :: from (
288
288
Vec :: < u8 > :: from_hex ( "76a91402306a7c23f3e8010de41e9e591348bb83f11daa88ac" ) . unwrap ( ) ,
289
289
) ;
290
290
let path = 42 ;
291
291
let keychain = KeychainKind :: External ;
292
292
293
- tree . set_script_pubkey ( & script, keychain, path) . unwrap ( ) ;
294
- assert_eq ! ( tree . iter_script_pubkeys( None ) . unwrap( ) . len( ) , 1 ) ;
293
+ db . set_script_pubkey ( & script, keychain, path) . unwrap ( ) ;
294
+ assert_eq ! ( db . iter_script_pubkeys( None ) . unwrap( ) . len( ) , 1 ) ;
295
295
296
- tree . del_script_pubkey_from_path ( keychain, path) . unwrap ( ) ;
297
- assert_eq ! ( tree . iter_script_pubkeys( None ) . unwrap( ) . len( ) , 0 ) ;
296
+ db . del_script_pubkey_from_path ( keychain, path) . unwrap ( ) ;
297
+ assert_eq ! ( db . iter_script_pubkeys( None ) . unwrap( ) . len( ) , 0 ) ;
298
298
}
299
299
300
- pub fn test_utxo < D : Database > ( mut tree : D ) {
300
+ pub fn test_utxo < D : Database > ( mut db : D ) {
301
301
let outpoint = OutPoint :: from_str (
302
302
"5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456:0" ,
303
303
)
@@ -316,21 +316,21 @@ pub mod test {
316
316
is_spent : true ,
317
317
} ;
318
318
319
- tree . set_utxo ( & utxo) . unwrap ( ) ;
320
- tree . set_utxo ( & utxo) . unwrap ( ) ;
321
- assert_eq ! ( tree . iter_utxos( ) . unwrap( ) . len( ) , 1 ) ;
322
- assert_eq ! ( tree . get_utxo( & outpoint) . unwrap( ) , Some ( utxo) ) ;
319
+ db . set_utxo ( & utxo) . unwrap ( ) ;
320
+ db . set_utxo ( & utxo) . unwrap ( ) ;
321
+ assert_eq ! ( db . iter_utxos( ) . unwrap( ) . len( ) , 1 ) ;
322
+ assert_eq ! ( db . get_utxo( & outpoint) . unwrap( ) , Some ( utxo) ) ;
323
323
}
324
324
325
- pub fn test_raw_tx < D : Database > ( mut tree : D ) {
325
+ pub fn test_raw_tx < D : Database > ( mut db : D ) {
326
326
let hex_tx = Vec :: < u8 > :: from_hex ( "02000000000101f58c18a90d7a76b30c7e47d4e817adfdd79a6a589a615ef36e360f913adce2cd0000000000feffffff0210270000000000001600145c9a1816d38db5cbdd4b067b689dc19eb7d930e2cf70aa2b080000001600140f48b63160043047f4f60f7f8f551f80458f693f024730440220413f42b7bc979945489a38f5221e5527d4b8e3aa63eae2099e01945896ad6c10022024ceec492d685c31d8adb64e935a06933877c5ae0e21f32efe029850914c5bad012102361caae96f0e9f3a453d354bb37a5c3244422fb22819bf0166c0647a38de39f21fca2300" ) . unwrap ( ) ;
327
327
let mut tx: Transaction = deserialize ( & hex_tx) . unwrap ( ) ;
328
328
329
- tree . set_raw_tx ( & tx) . unwrap ( ) ;
329
+ db . set_raw_tx ( & tx) . unwrap ( ) ;
330
330
331
331
let txid = tx. txid ( ) ;
332
332
333
- assert_eq ! ( tree . get_raw_tx( & txid) . unwrap( ) , Some ( tx. clone( ) ) ) ;
333
+ assert_eq ! ( db . get_raw_tx( & txid) . unwrap( ) , Some ( tx. clone( ) ) ) ;
334
334
335
335
// mutate transaction's witnesses
336
336
for tx_in in tx. input . iter_mut ( ) {
@@ -342,14 +342,14 @@ pub mod test {
342
342
// verify that mutation was successful
343
343
assert_ne ! ( hex_tx, updated_hex_tx) ;
344
344
345
- tree . set_raw_tx ( & tx) . unwrap ( ) ;
345
+ db . set_raw_tx ( & tx) . unwrap ( ) ;
346
346
347
347
let txid = tx. txid ( ) ;
348
348
349
- assert_eq ! ( tree . get_raw_tx( & txid) . unwrap( ) , Some ( tx) ) ;
349
+ assert_eq ! ( db . get_raw_tx( & txid) . unwrap( ) , Some ( tx) ) ;
350
350
}
351
351
352
- pub fn test_tx < D : Database > ( mut tree : D ) {
352
+ pub fn test_tx < D : Database > ( mut db : D ) {
353
353
let hex_tx = Vec :: < u8 > :: from_hex ( "0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000" ) . unwrap ( ) ;
354
354
let tx: Transaction = deserialize ( & hex_tx) . unwrap ( ) ;
355
355
let txid = tx. txid ( ) ;
@@ -365,28 +365,28 @@ pub mod test {
365
365
} ) ,
366
366
} ;
367
367
368
- tree . set_tx ( & tx_details) . unwrap ( ) ;
368
+ db . set_tx ( & tx_details) . unwrap ( ) ;
369
369
370
370
// get with raw tx too
371
371
assert_eq ! (
372
- tree . get_tx( & tx_details. txid, true ) . unwrap( ) ,
372
+ db . get_tx( & tx_details. txid, true ) . unwrap( ) ,
373
373
Some ( tx_details. clone( ) )
374
374
) ;
375
375
// get only raw_tx
376
376
assert_eq ! (
377
- tree . get_raw_tx( & tx_details. txid) . unwrap( ) ,
377
+ db . get_raw_tx( & tx_details. txid) . unwrap( ) ,
378
378
tx_details. transaction
379
379
) ;
380
380
381
381
// now get without raw_tx
382
382
tx_details. transaction = None ;
383
383
assert_eq ! (
384
- tree . get_tx( & tx_details. txid, false ) . unwrap( ) ,
384
+ db . get_tx( & tx_details. txid, false ) . unwrap( ) ,
385
385
Some ( tx_details)
386
386
) ;
387
387
}
388
388
389
- pub fn test_list_transaction < D : Database > ( mut tree : D ) {
389
+ pub fn test_list_transaction < D : Database > ( mut db : D ) {
390
390
let hex_tx = Vec :: < u8 > :: from_hex ( "0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000" ) . unwrap ( ) ;
391
391
let tx: Transaction = deserialize ( & hex_tx) . unwrap ( ) ;
392
392
let txid = tx. txid ( ) ;
@@ -402,60 +402,57 @@ pub mod test {
402
402
} ) ,
403
403
} ;
404
404
405
- tree . set_tx ( & tx_details) . unwrap ( ) ;
405
+ db . set_tx ( & tx_details) . unwrap ( ) ;
406
406
407
407
// get raw tx
408
- assert_eq ! ( tree . iter_txs( true ) . unwrap( ) , vec![ tx_details. clone( ) ] ) ;
408
+ assert_eq ! ( db . iter_txs( true ) . unwrap( ) , vec![ tx_details. clone( ) ] ) ;
409
409
410
410
// now get without raw tx
411
411
tx_details. transaction = None ;
412
412
413
413
// get not raw tx
414
- assert_eq ! ( tree . iter_txs( false ) . unwrap( ) , vec![ tx_details. clone( ) ] ) ;
414
+ assert_eq ! ( db . iter_txs( false ) . unwrap( ) , vec![ tx_details. clone( ) ] ) ;
415
415
}
416
416
417
- pub fn test_last_index < D : Database > ( mut tree : D ) {
418
- tree . set_last_index ( KeychainKind :: External , 1337 ) . unwrap ( ) ;
417
+ pub fn test_last_index < D : Database > ( mut db : D ) {
418
+ db . set_last_index ( KeychainKind :: External , 1337 ) . unwrap ( ) ;
419
419
420
420
assert_eq ! (
421
- tree . get_last_index( KeychainKind :: External ) . unwrap( ) ,
421
+ db . get_last_index( KeychainKind :: External ) . unwrap( ) ,
422
422
Some ( 1337 )
423
423
) ;
424
- assert_eq ! ( tree . get_last_index( KeychainKind :: Internal ) . unwrap( ) , None ) ;
424
+ assert_eq ! ( db . get_last_index( KeychainKind :: Internal ) . unwrap( ) , None ) ;
425
425
426
- let res = tree . increment_last_index ( KeychainKind :: External ) . unwrap ( ) ;
426
+ let res = db . increment_last_index ( KeychainKind :: External ) . unwrap ( ) ;
427
427
assert_eq ! ( res, 1338 ) ;
428
- let res = tree . increment_last_index ( KeychainKind :: Internal ) . unwrap ( ) ;
428
+ let res = db . increment_last_index ( KeychainKind :: Internal ) . unwrap ( ) ;
429
429
assert_eq ! ( res, 0 ) ;
430
430
431
431
assert_eq ! (
432
- tree . get_last_index( KeychainKind :: External ) . unwrap( ) ,
432
+ db . get_last_index( KeychainKind :: External ) . unwrap( ) ,
433
433
Some ( 1338 )
434
434
) ;
435
- assert_eq ! (
436
- tree. get_last_index( KeychainKind :: Internal ) . unwrap( ) ,
437
- Some ( 0 )
438
- ) ;
435
+ assert_eq ! ( db. get_last_index( KeychainKind :: Internal ) . unwrap( ) , Some ( 0 ) ) ;
439
436
}
440
437
441
- pub fn test_sync_time < D : Database > ( mut tree : D ) {
442
- assert ! ( tree . get_sync_time( ) . unwrap( ) . is_none( ) ) ;
438
+ pub fn test_sync_time < D : Database > ( mut db : D ) {
439
+ assert ! ( db . get_sync_time( ) . unwrap( ) . is_none( ) ) ;
443
440
444
- tree . set_sync_time ( SyncTime {
441
+ db . set_sync_time ( SyncTime {
445
442
block_time : BlockTime {
446
443
height : 100 ,
447
444
timestamp : 1000 ,
448
445
} ,
449
446
} )
450
447
. unwrap ( ) ;
451
448
452
- let extracted = tree . get_sync_time ( ) . unwrap ( ) ;
449
+ let extracted = db . get_sync_time ( ) . unwrap ( ) ;
453
450
assert ! ( extracted. is_some( ) ) ;
454
451
assert_eq ! ( extracted. as_ref( ) . unwrap( ) . block_time. height, 100 ) ;
455
452
assert_eq ! ( extracted. as_ref( ) . unwrap( ) . block_time. timestamp, 1000 ) ;
456
453
457
- tree . del_sync_time ( ) . unwrap ( ) ;
458
- assert ! ( tree . get_sync_time( ) . unwrap( ) . is_none( ) ) ;
454
+ db . del_sync_time ( ) . unwrap ( ) ;
455
+ assert ! ( db . get_sync_time( ) . unwrap( ) . is_none( ) ) ;
459
456
}
460
457
461
458
pub fn test_iter_raw_txs < D : Database > ( mut db : D ) {
0 commit comments