Explorar o código

cleaned up tests

lunar-mining %!s(int64=4) %!d(string=hai) anos
pai
achega
b98754eb8d
Modificáronse 1 ficheiros con 17 adicións e 73 borrados
  1. 17 73
      src/wallet/walletdb.rs

+ 17 - 73
src/wallet/walletdb.rs

@@ -320,11 +320,8 @@ impl WalletDb {
 
         let mut token_table = Vec::new();
         for coin_id in rows {
-            println!("FOUND A THING: {:?}", coin_id);
             token_table.push(coin_id?);
         }
-        println!("TOKEN TABLE: {:?}", token_table);
-
         Ok(token_table)
     }
 
@@ -342,10 +339,8 @@ impl WalletDb {
 
         let mut token_id = Vec::new();
         for coin_id in rows {
-            println!("FOUND A THING: {:?}", coin_id);
             token_id.push(coin_id?);
         }
-        println!("TOKEN ID: {:?}", token_id);
 
         Ok(token_id)
     }
@@ -374,16 +369,10 @@ mod tests {
         let wallet = WalletDb::new(&walletdb_path, password.clone())?;
         init_db(&walletdb_path, password)?;
 
-        //test_coin_exist()?;
-        test_put_and_get_own_coins()?;
-
-        //test_coin_exist()?;
-        test_put_and_get_own_coins()?;
-
-        //test_coin_exist()?;
+        test_coin_exist()?;
         test_put_and_get_own_coins()?;
 
-        //test_coin_exist()?;
+        test_coin_exist()?;
         test_put_and_get_own_coins()?;
 
         let table_vec = wallet.get_token_table()?;
@@ -391,66 +380,21 @@ mod tests {
         Ok(())
     }
 
-    //    fn test_coin_exist() -> Result<()> {
-    //        let path = join_config_path(&PathBuf::from("test_wallet.db"))?;
-    //        let password: String = "darkfi".into();
-    //        let contents = include_str!("../../sql/schema.sql");
-    //        let conn = Connection::open(&path)?;
-    //        conn.pragma_update(None, "key", &password)?;
-    //        conn.execute_batch(&contents)?;
-    //
-    //        let mut stmt = conn.prepare("SELECT * FROM coins WHERE key_id > :id")?;
-    //        let boolean = stmt.exists(&[(":id", &"0")])?;
-    //
-    //        let coin = jubjub::Fr::random(&mut OsRng);
-    //        let coin = serial::serialize(&coin);
-    //        let serial = jubjub::Fr::random(&mut OsRng);
-    //        let serial = serial::serialize(&serial);
-    //        let value = 110;
-    //        let asset_id = jubjub::Fr::random(&mut OsRng);
-    //        let asset_id = serial::serialize(&asset_id);
-    //        let coin_blind = jubjub::Fr::random(&mut OsRng);
-    //        let coin_blind = serial::serialize(&coin_blind);
-    //        let valcom_blind = jubjub::Fr::random(&mut OsRng);
-    //        let valcom_blind = serial::serialize(&valcom_blind);
-    //        let witness = jubjub::Fr::random(&mut OsRng);
-    //        let witness = serial::serialize(&witness);
-    //
-    //        // return key_id from key_private
-    //        let mut get_id =
-    //            conn.prepare("SELECT key_id FROM keys WHERE key_private = :key_private")?;
-    //
-    //        let rows = get_id.query_map::<u64, _, _>(&[(":key_private", &secret)], |row| row.get(0))?;
-    //
-    //        let mut key_id = Vec::new();
-    //        for id in rows {
-    //            key_id.push(id?)
-    //        }
-    //
-    //        conn.execute(
-    //            "INSERT INTO coins
-    //            (coin, serial, value, asset_id, coin_blind, valcom_blind, witness, key_id)
-    //            VALUES
-    //            (:coin, :serial, :value, :asset_id, :coin_blind, :valcom_blind, :witness, key_id);",
-    //            named_params! {
-    //                ":coin": coin,
-    //                ":serial": serial,
-    //                ":value": value,
-    //                ":asset_id": asset_id,
-    //                ":coin_blind": coin_blind,
-    //                ":valcom_blind": valcom_blind,
-    //                ":witness": witness,
-    //                ":key_id": key_id.pop().expect("Get key_id"),
-    //            },
-    //        )?;
-    //
-    //        let mut stmt = conn.prepare("SELECT * FROM coins WHERE key_id > :id")?;
-    //        let boolean = stmt.exists(&[(":id", &"0")])?;
-    //
-    //        println!("Coin test. Result is the following: {}", boolean);
-    //
-    //        Ok(())
-    //    }
+    fn test_coin_exist() -> Result<()> {
+        let path = join_config_path(&PathBuf::from("test_wallet.db"))?;
+        let password: String = "darkfi".into();
+        let contents = include_str!("../../sql/schema.sql");
+        let conn = Connection::open(&path)?;
+        conn.pragma_update(None, "key", &password)?;
+        conn.execute_batch(&contents)?;
+        let mut stmt = conn.prepare("SELECT * FROM coins WHERE coin_id > :id")?;
+        let boolean = stmt.exists(&[(":id", &"0")])?;
+
+        println!("Test coin exists. Result is the following: {}", boolean);
+
+        std::fs::remove_file(path)?;
+        Ok(())
+    }
 
     #[test]
     pub fn test_token_id() -> Result<()> {