diff --git a/src/database/mod.rs b/src/database/mod.rs index 711dea7ef..e3e2b3310 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -223,27 +223,27 @@ pub mod test { use super::*; - pub fn test_script_pubkey(mut tree: D) { + pub fn test_script_pubkey(mut db: D) { let script = Script::from( Vec::::from_hex("76a91402306a7c23f3e8010de41e9e591348bb83f11daa88ac").unwrap(), ); let path = 42; let keychain = KeychainKind::External; - tree.set_script_pubkey(&script, keychain, path).unwrap(); + db.set_script_pubkey(&script, keychain, path).unwrap(); assert_eq!( - tree.get_script_pubkey_from_path(keychain, path).unwrap(), + db.get_script_pubkey_from_path(keychain, path).unwrap(), Some(script.clone()) ); assert_eq!( - tree.get_path_from_script_pubkey(&script).unwrap(), + db.get_path_from_script_pubkey(&script).unwrap(), Some((keychain, path)) ); } - pub fn test_batch_script_pubkey(mut tree: D) { - let mut batch = tree.begin_batch(); + pub fn test_batch_script_pubkey(mut db: D) { + let mut batch = db.begin_batch(); let script = Script::from( Vec::::from_hex("76a91402306a7c23f3e8010de41e9e591348bb83f11daa88ac").unwrap(), @@ -254,50 +254,50 @@ pub mod test { batch.set_script_pubkey(&script, keychain, path).unwrap(); assert_eq!( - tree.get_script_pubkey_from_path(keychain, path).unwrap(), + db.get_script_pubkey_from_path(keychain, path).unwrap(), None ); - assert_eq!(tree.get_path_from_script_pubkey(&script).unwrap(), None); + assert_eq!(db.get_path_from_script_pubkey(&script).unwrap(), None); - tree.commit_batch(batch).unwrap(); + db.commit_batch(batch).unwrap(); assert_eq!( - tree.get_script_pubkey_from_path(keychain, path).unwrap(), + db.get_script_pubkey_from_path(keychain, path).unwrap(), Some(script.clone()) ); assert_eq!( - tree.get_path_from_script_pubkey(&script).unwrap(), + db.get_path_from_script_pubkey(&script).unwrap(), Some((keychain, path)) ); } - pub fn test_iter_script_pubkey(mut tree: D) { + pub fn test_iter_script_pubkey(mut db: D) { let script = Script::from( Vec::::from_hex("76a91402306a7c23f3e8010de41e9e591348bb83f11daa88ac").unwrap(), ); let path = 42; let keychain = KeychainKind::External; - tree.set_script_pubkey(&script, keychain, path).unwrap(); + db.set_script_pubkey(&script, keychain, path).unwrap(); - assert_eq!(tree.iter_script_pubkeys(None).unwrap().len(), 1); + assert_eq!(db.iter_script_pubkeys(None).unwrap().len(), 1); } - pub fn test_del_script_pubkey(mut tree: D) { + pub fn test_del_script_pubkey(mut db: D) { let script = Script::from( Vec::::from_hex("76a91402306a7c23f3e8010de41e9e591348bb83f11daa88ac").unwrap(), ); let path = 42; let keychain = KeychainKind::External; - tree.set_script_pubkey(&script, keychain, path).unwrap(); - assert_eq!(tree.iter_script_pubkeys(None).unwrap().len(), 1); + db.set_script_pubkey(&script, keychain, path).unwrap(); + assert_eq!(db.iter_script_pubkeys(None).unwrap().len(), 1); - tree.del_script_pubkey_from_path(keychain, path).unwrap(); - assert_eq!(tree.iter_script_pubkeys(None).unwrap().len(), 0); + db.del_script_pubkey_from_path(keychain, path).unwrap(); + assert_eq!(db.iter_script_pubkeys(None).unwrap().len(), 0); } - pub fn test_utxo(mut tree: D) { + pub fn test_utxo(mut db: D) { let outpoint = OutPoint::from_str( "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456:0", ) @@ -316,21 +316,21 @@ pub mod test { is_spent: true, }; - tree.set_utxo(&utxo).unwrap(); - tree.set_utxo(&utxo).unwrap(); - assert_eq!(tree.iter_utxos().unwrap().len(), 1); - assert_eq!(tree.get_utxo(&outpoint).unwrap(), Some(utxo)); + db.set_utxo(&utxo).unwrap(); + db.set_utxo(&utxo).unwrap(); + assert_eq!(db.iter_utxos().unwrap().len(), 1); + assert_eq!(db.get_utxo(&outpoint).unwrap(), Some(utxo)); } - pub fn test_raw_tx(mut tree: D) { + pub fn test_raw_tx(mut db: D) { let hex_tx = Vec::::from_hex("02000000000101f58c18a90d7a76b30c7e47d4e817adfdd79a6a589a615ef36e360f913adce2cd0000000000feffffff0210270000000000001600145c9a1816d38db5cbdd4b067b689dc19eb7d930e2cf70aa2b080000001600140f48b63160043047f4f60f7f8f551f80458f693f024730440220413f42b7bc979945489a38f5221e5527d4b8e3aa63eae2099e01945896ad6c10022024ceec492d685c31d8adb64e935a06933877c5ae0e21f32efe029850914c5bad012102361caae96f0e9f3a453d354bb37a5c3244422fb22819bf0166c0647a38de39f21fca2300").unwrap(); let mut tx: Transaction = deserialize(&hex_tx).unwrap(); - tree.set_raw_tx(&tx).unwrap(); + db.set_raw_tx(&tx).unwrap(); let txid = tx.txid(); - assert_eq!(tree.get_raw_tx(&txid).unwrap(), Some(tx.clone())); + assert_eq!(db.get_raw_tx(&txid).unwrap(), Some(tx.clone())); // mutate transaction's witnesses for tx_in in tx.input.iter_mut() { @@ -342,14 +342,14 @@ pub mod test { // verify that mutation was successful assert_ne!(hex_tx, updated_hex_tx); - tree.set_raw_tx(&tx).unwrap(); + db.set_raw_tx(&tx).unwrap(); let txid = tx.txid(); - assert_eq!(tree.get_raw_tx(&txid).unwrap(), Some(tx)); + assert_eq!(db.get_raw_tx(&txid).unwrap(), Some(tx)); } - pub fn test_tx(mut tree: D) { + pub fn test_tx(mut db: D) { let hex_tx = Vec::::from_hex("0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000").unwrap(); let tx: Transaction = deserialize(&hex_tx).unwrap(); let txid = tx.txid(); @@ -365,28 +365,28 @@ pub mod test { }), }; - tree.set_tx(&tx_details).unwrap(); + db.set_tx(&tx_details).unwrap(); // get with raw tx too assert_eq!( - tree.get_tx(&tx_details.txid, true).unwrap(), + db.get_tx(&tx_details.txid, true).unwrap(), Some(tx_details.clone()) ); // get only raw_tx assert_eq!( - tree.get_raw_tx(&tx_details.txid).unwrap(), + db.get_raw_tx(&tx_details.txid).unwrap(), tx_details.transaction ); // now get without raw_tx tx_details.transaction = None; assert_eq!( - tree.get_tx(&tx_details.txid, false).unwrap(), + db.get_tx(&tx_details.txid, false).unwrap(), Some(tx_details) ); } - pub fn test_list_transaction(mut tree: D) { + pub fn test_list_transaction(mut db: D) { let hex_tx = Vec::::from_hex("0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000").unwrap(); let tx: Transaction = deserialize(&hex_tx).unwrap(); let txid = tx.txid(); @@ -402,46 +402,43 @@ pub mod test { }), }; - tree.set_tx(&tx_details).unwrap(); + db.set_tx(&tx_details).unwrap(); // get raw tx - assert_eq!(tree.iter_txs(true).unwrap(), vec![tx_details.clone()]); + assert_eq!(db.iter_txs(true).unwrap(), vec![tx_details.clone()]); // now get without raw tx tx_details.transaction = None; // get not raw tx - assert_eq!(tree.iter_txs(false).unwrap(), vec![tx_details.clone()]); + assert_eq!(db.iter_txs(false).unwrap(), vec![tx_details.clone()]); } - pub fn test_last_index(mut tree: D) { - tree.set_last_index(KeychainKind::External, 1337).unwrap(); + pub fn test_last_index(mut db: D) { + db.set_last_index(KeychainKind::External, 1337).unwrap(); assert_eq!( - tree.get_last_index(KeychainKind::External).unwrap(), + db.get_last_index(KeychainKind::External).unwrap(), Some(1337) ); - assert_eq!(tree.get_last_index(KeychainKind::Internal).unwrap(), None); + assert_eq!(db.get_last_index(KeychainKind::Internal).unwrap(), None); - let res = tree.increment_last_index(KeychainKind::External).unwrap(); + let res = db.increment_last_index(KeychainKind::External).unwrap(); assert_eq!(res, 1338); - let res = tree.increment_last_index(KeychainKind::Internal).unwrap(); + let res = db.increment_last_index(KeychainKind::Internal).unwrap(); assert_eq!(res, 0); assert_eq!( - tree.get_last_index(KeychainKind::External).unwrap(), + db.get_last_index(KeychainKind::External).unwrap(), Some(1338) ); - assert_eq!( - tree.get_last_index(KeychainKind::Internal).unwrap(), - Some(0) - ); + assert_eq!(db.get_last_index(KeychainKind::Internal).unwrap(), Some(0)); } - pub fn test_sync_time(mut tree: D) { - assert!(tree.get_sync_time().unwrap().is_none()); + pub fn test_sync_time(mut db: D) { + assert!(db.get_sync_time().unwrap().is_none()); - tree.set_sync_time(SyncTime { + db.set_sync_time(SyncTime { block_time: BlockTime { height: 100, timestamp: 1000, @@ -449,13 +446,13 @@ pub mod test { }) .unwrap(); - let extracted = tree.get_sync_time().unwrap(); + let extracted = db.get_sync_time().unwrap(); assert!(extracted.is_some()); assert_eq!(extracted.as_ref().unwrap().block_time.height, 100); assert_eq!(extracted.as_ref().unwrap().block_time.timestamp, 1000); - tree.del_sync_time().unwrap(); - assert!(tree.get_sync_time().unwrap().is_none()); + db.del_sync_time().unwrap(); + assert!(db.get_sync_time().unwrap().is_none()); } pub fn test_iter_raw_txs(mut db: D) {