Explorar el Código

test case for rusqlite

rachel-rose hace 5 años
padre
commit
7bb955e686
Se han modificado 2 ficheros con 37 adiciones y 10 borrados
  1. 1 1
      src/rpc/adapter.rs
  2. 36 9
      src/wallet/walletdb.rs

+ 1 - 1
src/rpc/adapter.rs

@@ -1,4 +1,4 @@
-use crate::wallet::{WalletDB};
+use crate::wallet::WalletDB;
 use crate::Result;
 use async_std::sync::Arc;
 use log::*;

+ 36 - 9
src/wallet/walletdb.rs

@@ -8,7 +8,7 @@ use async_std::sync::{Arc, Mutex};
 use ff::Field;
 use log::*;
 use rand::rngs::OsRng;
-use rusqlite::{named_params, Connection};
+use rusqlite::{params, named_params, Connection};
 
 use std::path::PathBuf;
 
@@ -123,14 +123,14 @@ impl WalletDB {
 
     pub async fn put_keypair(&self, pubkey: Vec<u8>, privkey: Vec<u8>) -> Result<()> {
         let conn = Connection::open(&self.path)?;
-        conn.execute(
-            "INSERT INTO keys(key_id, key_private, key_public)
-            VALUES (NULL, :privkey, :pubkey)",
-            named_params! {
-            ":privkey": privkey,
-             ":pubkey": pubkey
-            },
-        )?;
+        //conn.execute(
+        //    "INSERT INTO keys(key_id, key_private, key_public)
+        //    VALUES (NULL, :privkey, :pubkey)",
+        //    named_params! {
+        //    ":privkey": privkey,
+        //     ":pubkey": pubkey
+        //    },
+        //)?;
         Ok(())
     }
 
@@ -198,3 +198,30 @@ impl WalletDB {
         Ok(v)
     }
 }
+
+#[cfg(test)]
+mod tests {
+
+use super::*;
+
+#[test] 
+    pub fn test_keypair() -> Result<()> {
+        let path = join_config_path(&PathBuf::from("wallet.db"))?;
+        let conn = Connection::open(path)?;
+        let secret: jubjub::Fr = jubjub::Fr::random(&mut OsRng);
+        let public = zcash_primitives::constants::SPENDING_KEY_GENERATOR * secret;
+        let pubkey = serial::serialize(&public);
+        let privkey = serial::serialize(&secret);
+        let mut stmt = conn.prepare("SELECT * FROM keys")?;
+        stmt.execute(rusqlite::params![1i32])?;
+        //conn.execute(
+        //    "INSERT INTO keys(key_private, key_public)
+        //    VALUES (NULL, :privkey, :pubkey)",
+        //    named_params! {
+        //    ":privkey": privkey,
+        //     ":pubkey": pubkey
+        //    },
+        //)?;
+        Ok(())
+    }
+}