You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/database/mod.rs
+217-2Lines changed: 217 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -217,6 +217,7 @@ pub mod test {
217
217
use std::str::FromStr;
218
218
219
219
use bitcoin::consensus::encode::deserialize;
220
+
use bitcoin::consensus::serialize;
220
221
use bitcoin::hashes::hex::*;
221
222
use bitcoin::*;
222
223
@@ -322,8 +323,24 @@ pub mod test {
322
323
}
323
324
324
325
pubfntest_raw_tx<D:Database>(muttree:D){
325
-
let hex_tx = Vec::<u8>::from_hex("0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000").unwrap();
326
-
let tx:Transaction = deserialize(&hex_tx).unwrap();
326
+
let hex_tx = Vec::<u8>::from_hex("02000000000101f58c18a90d7a76b30c7e47d4e817adfdd79a6a589a615ef36e360f913adce2cd0000000000feffffff0210270000000000001600145c9a1816d38db5cbdd4b067b689dc19eb7d930e2cf70aa2b080000001600140f48b63160043047f4f60f7f8f551f80458f693f024730440220413f42b7bc979945489a38f5221e5527d4b8e3aa63eae2099e01945896ad6c10022024ceec492d685c31d8adb64e935a06933877c5ae0e21f32efe029850914c5bad012102361caae96f0e9f3a453d354bb37a5c3244422fb22819bf0166c0647a38de39f21fca2300").unwrap();
let hex_tx = Vec::<u8>::from_hex("0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000").unwrap();
466
+
let first_tx:Transaction = deserialize(&hex_tx).unwrap();
467
+
468
+
let hex_tx = Vec::<u8>::from_hex("02000000000101f58c18a90d7a76b30c7e47d4e817adfdd79a6a589a615ef36e360f913adce2cd0000000000feffffff0210270000000000001600145c9a1816d38db5cbdd4b067b689dc19eb7d930e2cf70aa2b080000001600140f48b63160043047f4f60f7f8f551f80458f693f024730440220413f42b7bc979945489a38f5221e5527d4b8e3aa63eae2099e01945896ad6c10022024ceec492d685c31d8adb64e935a06933877c5ae0e21f32efe029850914c5bad012102361caae96f0e9f3a453d354bb37a5c3244422fb22819bf0166c0647a38de39f21fca2300").unwrap();
469
+
let second_tx:Transaction = deserialize(&hex_tx).unwrap();
let hex_tx = Vec::<u8>::from_hex("02000000000101f58c18a90d7a76b30c7e47d4e817adfdd79a6a589a615ef36e360f913adce2cd0000000000feffffff0210270000000000001600145c9a1816d38db5cbdd4b067b689dc19eb7d930e2cf70aa2b080000001600140f48b63160043047f4f60f7f8f551f80458f693f024730440220413f42b7bc979945489a38f5221e5527d4b8e3aa63eae2099e01945896ad6c10022024ceec492d685c31d8adb64e935a06933877c5ae0e21f32efe029850914c5bad012102361caae96f0e9f3a453d354bb37a5c3244422fb22819bf0166c0647a38de39f21fca2300").unwrap();
563
+
let tx:Transaction = deserialize(&hex_tx).unwrap();
564
+
565
+
let res = db.del_raw_tx(&tx.txid()).unwrap();
566
+
567
+
assert!(res.is_none());
568
+
569
+
db.set_raw_tx(&tx).unwrap();
570
+
571
+
let res = db.del_raw_tx(&tx.txid()).unwrap();
572
+
573
+
assert_eq!(res.unwrap(), tx);
574
+
575
+
let res = db.get_raw_tx(&tx.txid()).unwrap();
576
+
assert!(res.is_none());
577
+
}
578
+
579
+
pubfntest_del_tx<D:Database>(mutdb:D){
580
+
let hex_tx = Vec::<u8>::from_hex("0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000").unwrap();
581
+
let tx:Transaction = deserialize(&hex_tx).unwrap();
582
+
let txid = tx.txid();
583
+
letmut tx_details = TransactionDetails{
584
+
transaction:Some(tx.clone()),
585
+
txid,
586
+
received:1337,
587
+
sent:420420,
588
+
fee:Some(140),
589
+
confirmation_time:Some(BlockTime{
590
+
timestamp:123456,
591
+
height:1000,
592
+
}),
593
+
};
594
+
595
+
let res = db.del_tx(&tx.txid(),true).unwrap();
596
+
597
+
assert!(res.is_none());
598
+
599
+
db.set_tx(&tx_details).unwrap();
600
+
601
+
let res = db.del_tx(&tx.txid(),false).unwrap();
602
+
tx_details.transaction = None;
603
+
assert_eq!(res.unwrap(), tx_details);
604
+
605
+
let res = db.get_tx(&tx.txid(),true).unwrap();
606
+
assert!(res.is_none());
607
+
608
+
let res = db.get_raw_tx(&tx.txid()).unwrap();
609
+
assert_eq!(res.unwrap(), tx);
610
+
611
+
db.set_tx(&tx_details).unwrap();
612
+
let res = db.del_tx(&tx.txid(),true).unwrap();
613
+
tx_details.transaction = Some(tx.clone());
614
+
assert_eq!(res.unwrap(), tx_details);
615
+
616
+
let res = db.get_tx(&tx.txid(),true).unwrap();
617
+
assert!(res.is_none());
618
+
619
+
let res = db.get_raw_tx(&tx.txid()).unwrap();
620
+
assert!(res.is_none());
621
+
}
622
+
623
+
pubfntest_del_last_index<D:Database>(mutdb:D){
624
+
let keychain = KeychainKind::External;
625
+
626
+
let _res = db.increment_last_index(keychain);
627
+
628
+
let res = db.get_last_index(keychain).unwrap().unwrap();
629
+
630
+
assert_eq!(res,0);
631
+
632
+
let _res = db.increment_last_index(keychain);
633
+
634
+
let res = db.del_last_index(keychain).unwrap().unwrap();
0 commit comments