parazyd 4 лет назад
Родитель
Сommit
7fbd70096f
4 измененных файлов с 176 добавлено и 404 удалено
  1. 8 5
      src/crypto/note.rs
  2. 1 1
      src/crypto/schnorr.rs
  3. 112 134
      src/wallet/cashierdb.rs
  4. 55 264
      src/wallet/walletdb.rs

+ 8 - 5
src/crypto/note.rs

@@ -118,7 +118,11 @@ impl EncryptedNote {
 
 
 #[test]
 #[test]
 fn test_note_encdec() {
 fn test_note_encdec() {
-    use crate::types::*;
+    use crate::{
+        crypto::keypair::Keypair,
+        types::{DrkCoinBlind, DrkSerial, DrkTokenId, DrkValueBlind},
+    };
+    use pasta_curves::arithmetic::Field;
 
 
     let note = Note {
     let note = Note {
         serial: DrkSerial::random(&mut OsRng),
         serial: DrkSerial::random(&mut OsRng),
@@ -128,11 +132,10 @@ fn test_note_encdec() {
         value_blind: DrkValueBlind::random(&mut OsRng),
         value_blind: DrkValueBlind::random(&mut OsRng),
     };
     };
 
 
-    let secret = DrkSecretKey::random(&mut OsRng);
-    let public = derive_public_key(secret);
+    let keypair = Keypair::random(&mut OsRng);
 
 
-    let encrypted_note = note.encrypt(&public).unwrap();
-    let note2 = encrypted_note.decrypt(&secret).unwrap();
+    let encrypted_note = note.encrypt(&keypair.public).unwrap();
+    let note2 = encrypted_note.decrypt(&keypair.secret).unwrap();
     assert_eq!(note.value, note2.value);
     assert_eq!(note.value, note2.value);
     assert_eq!(note.token_id, note2.token_id);
     assert_eq!(note.token_id, note2.token_id);
 }
 }

+ 1 - 1
src/crypto/schnorr.rs

@@ -68,7 +68,7 @@ mod tests {
 
 
     #[test]
     #[test]
     fn test_schnorr() {
     fn test_schnorr() {
-        let secret = SecretKey::random();
+        let secret = SecretKey::random(&mut OsRng);
         let message = b"Foo bar";
         let message = b"Foo bar";
         let signature = secret.sign(&message[..]);
         let signature = secret.sign(&message[..]);
         let public = PublicKey::from_secret(secret);
         let public = PublicKey::from_secret(secret);

+ 112 - 134
src/wallet/cashierdb.rs

@@ -380,164 +380,142 @@ impl CashierDb {
 
 
         Ok(())
         Ok(())
     }
     }
-}
 
 
-#[cfg(test)]
-mod tests {
+    pub async fn get_deposit_token_keys_by_network(
+        &self,
+        network: &NetworkName,
+    ) -> Result<Vec<DepositToken>> {
+        debug!("Checking for existing dkey");
+        let network = self.get_value_serialized(network)?;
+        let confirm = self.get_value_serialized(&false)?;
 
 
-    use super::*;
-    use crate::{crypto::types::derive_publickey, serial::serialize, util::join_config_path};
+        let mut conn = self.conn.acquire().await?;
+        let rows = sqlx::query(
+            "SELECT d_key_public, token_key_secret, token_key_public, token_id, mint_address
+             FROM deposit_keypairs
+             WHERE network = ?1
+             AND confirm = ?2;",
+        )
+        .bind(network)
+        .bind(confirm)
+        .fetch_all(&mut conn)
+        .await?;
 
 
-    use ff::Field;
-    use rand::rngs::OsRng;
+        let mut keys = vec![];
 
 
-    pub fn init_db(path: &Path, password: String) -> Result<()> {
-        if !password.trim().is_empty() {
-            let contents = include_str!("../../sql/cashier.sql");
-            let conn = Connection::open(path)?;
-            debug!(target: "CASHIERDB", "OPENED CONNECTION AT PATH {:?}", path);
-            conn.pragma_update(None, "key", &password)?;
-            conn.execute_batch(contents)?;
-        } else {
-            debug!(target: "CASHIERDB", "Password is empty. You must set a password to use the wallet.");
-            return Err(Error::from(ClientFailed::EmptyPassword))
+        for row in rows {
+            let drk_public_key = self.get_value_deserialized(row.get("d_key_public"))?;
+            let secret_key = row.get("token_key_secret");
+            let public_key = row.get("token_key_public");
+            let token_id = self.get_value_deserialized(row.get("token_id"))?;
+            let mint_address = self.get_value_deserialized(row.get("mint_address"))?;
+            keys.push(DepositToken {
+                drk_public_key,
+                token_key: TokenKey { secret_key, public_key },
+                token_id,
+                mint_address,
+            });
         }
         }
-        Ok(())
-    }
 
 
-    #[test]
-    pub fn test_put_main_keys_and_load_them_with_network_name() -> Result<()> {
-        let walletdb_path = join_config_path(&PathBuf::from("cashier_wallet_test2.db"))?;
-        let password: String = "darkfi".into();
-        let wallet = CashierDb::new(&walletdb_path, password.clone())?;
-        init_db(&walletdb_path, password)?;
-
-        // btc addr testnet
-        let token_addr = serialize(&String::from("mxVFsFW5N4mu1HPkxPttorvocvzeZ7KZyk"));
-        let token_addr_private = serialize(&String::from("2222222222222222222222222222222222"));
-
-        let network = NetworkName::Bitcoin;
-
-        wallet.put_main_keys(
-            &TokenKey { private_key: token_addr_private.clone(), public_key: token_addr.clone() },
-            &network,
-        )?;
-
-        let keys = wallet.get_main_keys(&network)?;
-
-        assert_eq!(keys.len(), 1);
-
-        assert_eq!(keys[0].private_key, token_addr_private);
-        assert_eq!(keys[0].public_key, token_addr);
+        Ok(keys)
+    }
+}
 
 
-        std::fs::remove_file(walletdb_path)?;
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use crate::serial::serialize;
+    use pasta_curves::arithmetic::Field;
+    use rand::rngs::OsRng;
 
 
-        Ok(())
-    }
+    const WPASS: &str = "darkfi";
 
 
-    #[test]
-    pub fn test_put_deposit_keys_and_load_them() -> Result<()> {
-        let walletdb_path = join_config_path(&PathBuf::from("cashier_wallet_test3.db"))?;
-        let password: String = "darkfi".into();
-        let wallet = CashierDb::new(&walletdb_path, password.clone())?;
-        init_db(&walletdb_path, password)?;
+    #[async_std::test]
+    async fn test_cashierdb() -> Result<()> {
+        let wallet = CashierDb::new("sqlite::memory:", WPASS.to_string()).await?;
 
 
-        // btc addr testnet
-        let token_addr = serialize(&String::from("mxVFsFW5N4mu1HPkxPttorvocvzeZ7KZyk"));
-        let token_addr_private = serialize(&String::from("2222222222222222222222222222222222"));
+        // init_db()
+        wallet.init_db().await?;
 
 
-        let network = NetworkName::Bitcoin;
+        // BTC testnet address
+        let token_addr_secret = serialize(&String::from("2222222222222222222222222222222222"));
+        let token_addr_public = serialize(&String::from("mxVFsFW5N4mu1HPkxPttorvocvzeZ7KZyk"));
 
 
-        let secret2 = DrkSecretKey::random(&mut OsRng);
-        let public2 = derive_publickey(secret2);
+        let keypair = Keypair::random(&mut OsRng);
         let token_id = DrkTokenId::random(&mut OsRng);
         let token_id = DrkTokenId::random(&mut OsRng);
 
 
-        wallet.put_deposit_keys(
-            &public2,
-            &token_addr_private,
-            &token_addr,
-            &network,
-            &token_id,
-            String::new(),
-        )?;
-
-        let keys = wallet.get_deposit_token_keys_by_dkey_public(&public2, &network)?;
+        let network = NetworkName::Bitcoin;
 
 
+        // put_main_keys()
+        wallet
+            .put_main_keys(
+                &TokenKey {
+                    secret_key: token_addr_secret.clone(),
+                    public_key: token_addr_public.clone(),
+                },
+                &network,
+            )
+            .await?;
+
+        // get_main_keys()
+        let keys = wallet.get_main_keys(&network).await?;
         assert_eq!(keys.len(), 1);
         assert_eq!(keys.len(), 1);
-
-        assert_eq!(keys[0].private_key, token_addr_private);
-        assert_eq!(keys[0].public_key, token_addr);
-
-        let resumed_keys = wallet.get_deposit_token_keys_by_network(&network)?;
-
-        assert_eq!(resumed_keys[0].drk_public_key, public2);
-        assert_eq!(resumed_keys[0].token_key.private_key, token_addr_private);
-        assert_eq!(resumed_keys[0].token_key.public_key, token_addr);
+        assert_eq!(keys[0].secret_key, token_addr_secret);
+        assert_eq!(keys[0].public_key, token_addr_public);
+
+        // put_deposit_keys()
+        wallet
+            .put_deposit_keys(
+                &keypair.public,
+                &token_addr_secret,
+                &token_addr_public,
+                &network,
+                &token_id,
+                String::new(),
+            )
+            .await?;
+
+        // get_deposit_token_keys_by_dkey_public()
+        let keys = wallet.get_deposit_token_keys_by_dkey_public(&keypair.public, &network).await?;
+        assert_eq!(keys.len(), 1);
+        assert_eq!(keys[0].secret_key, token_addr_secret);
+        assert_eq!(keys[0].public_key, token_addr_public);
+
+        // get_deposit_token_keys_by_network()
+        let resumed_keys = wallet.get_deposit_token_keys_by_network(&network).await?;
+        assert_eq!(resumed_keys[0].drk_public_key, keypair.public);
+        assert_eq!(resumed_keys[0].token_key.secret_key, token_addr_secret);
+        assert_eq!(resumed_keys[0].token_key.public_key, token_addr_public);
         assert_eq!(resumed_keys[0].token_id, token_id);
         assert_eq!(resumed_keys[0].token_id, token_id);
 
 
-        wallet.confirm_deposit_key_record(&public2, &network)?;
-
-        let keys = wallet.get_deposit_token_keys_by_dkey_public(&public2, &network)?;
-
+        // confirm_deposit_key_record()
+        wallet.confirm_deposit_key_record(&keypair.public, &network).await?;
+        let keys = wallet.get_deposit_token_keys_by_dkey_public(&keypair.public, &network).await?;
         assert_eq!(keys.len(), 0);
         assert_eq!(keys.len(), 0);
 
 
-        std::fs::remove_file(walletdb_path)?;
-
-        Ok(())
-    }
-
-    #[test]
-    pub fn test_put_withdraw_keys_and_load_them_with_token_key() -> Result<()> {
-        let walletdb_path = join_config_path(&PathBuf::from("cashier_wallet_test.db"))?;
-        let password: String = "darkfi".into();
-        let wallet = CashierDb::new(&walletdb_path, password.clone())?;
-        init_db(&walletdb_path, password)?;
-
-        let secret2 = DrkSecretKey::random(&mut OsRng);
-        let public2 = derive_publickey(secret2);
-        let token_id = DrkTokenId::random(&mut OsRng);
-
-        // btc addr testnet
-        let token_addr = serialize(&String::from("mxVFsFW5N4mu1HPkxPttorvocvzeZ7KZyk"));
-
-        let network = NetworkName::Bitcoin;
-
-        wallet.put_withdraw_keys(
-            &token_addr,
-            &public2,
-            &secret2,
-            &network,
-            &token_id,
-            String::new(),
-        )?;
-
-        let addr = wallet.get_withdraw_keys_by_token_public_key(&token_addr, &network)?;
-
+        // put_withdraw_keys()
+        wallet
+            .put_withdraw_keys(
+                &token_addr_public,
+                &keypair.public,
+                &keypair.secret,
+                &network,
+                &token_id,
+                String::new(),
+            )
+            .await?;
+
+        // get_withdraw_keys_by_token_public_key()
+        let addr =
+            wallet.get_withdraw_keys_by_token_public_key(&token_addr_public, &network).await?;
         assert!(addr.is_some());
         assert!(addr.is_some());
 
 
-        wallet.confirm_withdraw_key_record(&token_addr, &network)?;
-
-        let addr = wallet.get_withdraw_keys_by_token_public_key(&token_addr, &network)?;
-
+        // confirm_withdraw_key_record()
+        wallet.confirm_withdraw_key_record(&token_addr_public, &network).await?;
+        let addr =
+            wallet.get_withdraw_keys_by_token_public_key(&token_addr_public, &network).await?;
         assert!(addr.is_none());
         assert!(addr.is_none());
 
 
-        wallet.put_withdraw_keys(
-            &token_addr,
-            &public2,
-            &secret2,
-            &network,
-            &token_id,
-            String::new(),
-        )?;
-
-        let addr = wallet.get_withdraw_keys_by_token_public_key(&token_addr, &network)?;
-
-        assert!(addr.is_some());
-
-        wallet.remove_withdraw_and_deposit_keys()?;
-
-        std::fs::remove_file(walletdb_path)?;
-
         Ok(())
         Ok(())
     }
     }
 }
 }

+ 55 - 264
src/wallet/walletdb.rs

@@ -296,288 +296,79 @@ impl WalletDb {
 
 
 #[cfg(test)]
 #[cfg(test)]
 mod tests {
 mod tests {
-    // TODO: Clean up, there's a lot of duplicated code here.
     use super::*;
     use super::*;
-    use crate::{
-        crypto::{
-            coin::Coin,
-            types::{derive_public_key, CoinBlind, NullifierSerial, ValueCommitBlind},
-            OwnCoin,
-        },
-        util::join_config_path,
-    };
-    use ff::PrimeField;
-
-    pub fn init_db(path: &Path, password: String) -> Result<()> {
-        if !password.trim().is_empty() {
-            let contents = include_str!("../../sql/schema.sql");
-            let conn = Connection::open(path)?;
-            debug!(target: "WALLETDB", "OPENED CONNECTION AT PATH {:?}", path);
-            conn.pragma_update(None, "key", &password)?;
-            conn.execute_batch(contents)?;
-        } else {
-            debug!(
-                target: "WALLETDB", "Password is empty. You must set a password to use the wallet."
-            );
-            return Err(Error::from(ClientFailed::EmptyPassword))
-        }
-        Ok(())
-    }
-
-    #[test]
-    pub fn test_get_token_id() -> Result<()> {
-        let walletdb_path = join_config_path(&PathBuf::from("test_wallet.db"))?;
-        let password: String = "darkfi".into();
-        let wallet = WalletDb::new(&walletdb_path, password.clone())?;
-        init_db(&walletdb_path, password)?;
-
-        let secret = DrkSecretKey::random(&mut OsRng);
-        let public = secret.derive_public_key();
+    use crate::types::{DrkCoinBlind, DrkSerial, DrkValueBlind};
+    use pasta_curves::{arithmetic::Field, pallas};
+    use rand::rngs::OsRng;
 
 
-        wallet.put_keypair(&public, &secret)?;
-
-        let token_id = DrkTokenId::random(&mut OsRng);
+    const WPASS: &str = "darkfi";
 
 
+    fn dummy_coin(s: &SecretKey, v: u64, t: &DrkTokenId) -> OwnCoin {
+        let serial = DrkSerial::random(&mut OsRng);
         let note = Note {
         let note = Note {
-            serial: NullifierSerial::random(&mut OsRng),
-            value: 110,
-            token_id,
-            coin_blind: CoinBlind::random(&mut OsRng),
-            valcom_blind: ValueCommitBlind::random(&mut OsRng),
+            serial,
+            value: v,
+            token_id: t.clone(),
+            coin_blind: DrkCoinBlind::random(&mut OsRng),
+            value_blind: DrkValueBlind::random(&mut OsRng),
         };
         };
 
 
-        let coin = Coin::new(bls12_381::Scalar::random(&mut OsRng).to_repr());
-
-        let mut tree = crate::crypto::merkle::CommitmentTree::empty();
-        tree.append(MerkleNode::from_coin(&coin))?;
-
-        let witness = IncrementalWitness::from_tree(&tree);
-
-        let nullifier = Nullifier::new(coin.repr);
-
-        let own_coin = OwnCoin { coin, note, secret, witness, nullifier };
-
-        wallet.put_own_coins(own_coin.clone())?;
-        wallet.put_own_coins(own_coin.clone())?;
-        wallet.put_own_coins(own_coin.clone())?;
-        wallet.put_own_coins(own_coin)?;
-
-        let id = wallet.get_token_id()?;
-
-        assert_eq!(id.len(), 1);
-
-        for i in id {
-            assert_eq!(i, token_id);
-            assert!(wallet.token_id_exists(&i)?);
-        }
-
-        std::fs::remove_file(walletdb_path)?;
-
-        Ok(())
+        let coin = Coin(pallas::Base::random(&mut OsRng));
+        let nullifier = Nullifier::new(s.clone(), serial);
+        OwnCoin { coin, note, secret: s.clone(), nullifier }
     }
     }
 
 
-    #[test]
-    pub fn test_get_balances() -> Result<()> {
-        let walletdb_path = join_config_path(&PathBuf::from("test2_wallet.db"))?;
-        let password: String = "darkfi".into();
-        let wallet = WalletDb::new(&walletdb_path, password.clone())?;
-        init_db(&walletdb_path, password)?;
+    #[async_std::test]
+    async fn test_walletdb() -> Result<()> {
+        let wallet = WalletDb::new("sqlite::memory:", WPASS.to_string()).await?;
+        let keypair = Keypair::random(&mut OsRng);
 
 
-        let secret = DrkSecretKey::random(&mut OsRng);
-        let public = secret.derive_public_key();
+        // init_db()
+        wallet.init_db().await?;
 
 
-        wallet.put_keypair(&public, &secret)?;
+        // put_keypair()
+        wallet.put_keypair(&keypair.public, &keypair.secret).await?;
 
 
         let token_id = DrkTokenId::random(&mut OsRng);
         let token_id = DrkTokenId::random(&mut OsRng);
 
 
-        let note = Note {
-            serial: NullifierSerial::random(&mut OsRng),
-            value: 110,
-            token_id,
-            coin_blind: CoinBlind::random(&mut OsRng),
-            valcom_blind: ValueCommitBlind::random(&mut OsRng),
-        };
-
-        let coin = Coin::new(bls12_381::Scalar::random(&mut OsRng).to_repr());
-
-        let mut tree = crate::crypto::merkle::CommitmentTree::empty();
-        tree.append(MerkleNode::from_coin(&coin))?;
-
-        let witness = IncrementalWitness::from_tree(&tree);
-
-        let nullifier = Nullifier::new(coin.repr);
-
-        let own_coin = OwnCoin { coin, note, secret, witness, nullifier };
-
-        wallet.put_own_coins(own_coin.clone())?;
-        wallet.put_own_coins(own_coin.clone())?;
-        wallet.put_own_coins(own_coin.clone())?;
-        wallet.put_own_coins(own_coin)?;
-
-        let balances = wallet.get_balances()?;
-
-        assert_eq!(balances.list.len(), 1);
-        assert_eq!(balances.list[0].value, 110);
-        assert_eq!(balances.list[0].token_id, token_id);
-
-        std::fs::remove_file(walletdb_path)?;
-
-        Ok(())
-    }
-
-    #[test]
-    pub fn test_save_and_load_keypair() -> Result<()> {
-        let walletdb_path = join_config_path(&PathBuf::from("test3_wallet.db"))?;
-        let password: String = "darkfi".into();
-        let wallet = WalletDb::new(&walletdb_path, password.clone())?;
-        init_db(&walletdb_path, password)?;
-
-        let secret = DrkSecretKey::random(&mut OsRng);
-        let public = secret.derive_public_key();
-
-        wallet.put_keypair(&public, &secret)?;
-
-        let keypair = wallet.get_keypairs()?[0].clone();
-
-        assert_eq!(public, keypair.public);
-        assert_eq!(secret, keypair.private);
-
-        std::fs::remove_file(walletdb_path)?;
-
-        Ok(())
-    }
-
-    #[test]
-    pub fn test_put_and_get_own_coins() -> Result<()> {
-        let walletdb_path = join_config_path(&PathBuf::from("test4_wallet.db"))?;
-        let password: String = "darkfi".into();
-        let wallet = WalletDb::new(&walletdb_path, password.clone())?;
-        init_db(&walletdb_path, password)?;
+        let c0 = dummy_coin(&keypair.secret, 69, &token_id);
+        let c1 = dummy_coin(&keypair.secret, 420, &token_id);
+        let c2 = dummy_coin(&keypair.secret, 42, &token_id);
+        let c3 = dummy_coin(&keypair.secret, 11, &token_id);
 
 
-        let secret = DrkSecretKey::random(&mut OsRng);
-        let public = secret.derive_public_key();
+        // put_own_coins()
+        wallet.put_own_coins(c0).await?;
+        wallet.put_own_coins(c1).await?;
+        wallet.put_own_coins(c2).await?;
+        wallet.put_own_coins(c3).await?;
 
 
-        wallet.put_keypair(&public, &secret)?;
+        // get_token_id()
+        let id = wallet.get_token_id().await?;
+        assert_eq!(id.len(), 4);
 
 
-        let note = Note {
-            serial: NullifierSerial::random(&mut OsRng),
-            value: 110,
-            token_id: DrkTokenId::random(&mut OsRng),
-            coin_blind: CoinBlind::random(&mut OsRng),
-            valcom_blind: ValueCommitBlind::random(&mut OsRng),
-        };
-
-        let coin = Coin::new(bls12_381::Scalar::random(&mut OsRng).to_repr());
-
-        let mut tree = crate::crypto::merkle::CommitmentTree::empty();
-        tree.append(MerkleNode::from_coin(&coin))?;
-
-        let witness = IncrementalWitness::from_tree(&tree);
-
-        let coin_ser = crate::serial::serialize(&coin.repr);
-
-        assert_eq!(coin, crate::serial::deserialize(&coin_ser)?);
-
-        let nullifier = Nullifier::new(coin.repr);
-
-        let own_coin = OwnCoin {
-            coin,
-            note: note.clone(),
-            secret,
-            witness: witness.clone(),
-            nullifier: nullifier.clone(),
-        };
-
-        wallet.put_own_coins(own_coin)?;
-
-        let own_coin = wallet.get_own_coins()?[0].clone();
-
-        assert_eq!(&own_coin.note.valcom_blind, &note.valcom_blind);
-        assert_eq!(&own_coin.note.coin_blind, &note.coin_blind);
-        assert_eq!(own_coin.secret, secret);
-        assert_eq!(own_coin.witness.root(), witness.root());
-        assert_eq!(own_coin.witness.path(), witness.path());
-        assert_eq!(own_coin.nullifier, nullifier);
-
-        wallet.confirm_spend_coin(&own_coin.coin)?;
-
-        let own_coins = wallet.get_own_coins()?;
-
-        assert_eq!(own_coins.len(), 0);
-
-        wallet.put_own_coins(own_coin)?;
-
-        let own_coins = wallet.get_own_coins()?;
-
-        assert_eq!(own_coins.len(), 1);
-
-        wallet.remove_own_coins()?;
-
-        std::fs::remove_file(walletdb_path)?;
-
-        Ok(())
-    }
-
-    #[test]
-    pub fn test_get_witnesses_and_update_them() -> Result<()> {
-        let walletdb_path = join_config_path(&PathBuf::from("test5_wallet.db"))?;
-        let password: String = "darkfi".into();
-        let wallet = WalletDb::new(&walletdb_path, password.clone())?;
-        init_db(&walletdb_path, password)?;
-
-        let secret = DrkSecretKey::random(&mut OsRng);
-        let public = secret.derive_public_key();
-
-        wallet.put_keypair(&public, &secret)?;
-
-        let mut tree = crate::crypto::merkle::CommitmentTree::empty();
-
-        let note = Note {
-            serial: NullifierSerial::random(&mut OsRng),
-            value: 110,
-            token_id: DrkTokenId::random(&mut OsRng),
-            coin_blind: CoinBlind::random(&mut OsRng),
-            valcom_blind: ValueCommitBlind::random(&mut OsRng),
-        };
-
-        let coin = Coin::new(bls12_381::Scalar::random(&mut OsRng).to_repr());
-
-        let node = MerkleNode::from_coin(&coin);
-        tree.append(node)?;
-        tree.append(node)?;
-        tree.append(node)?;
-        tree.append(node)?;
-
-        let witness = IncrementalWitness::from_tree(&tree);
-
-        // for testing
-        let nullifier = Nullifier::new(coin.repr);
-
-        let own_coin = OwnCoin { coin, note, secret, witness, nullifier };
-
-        wallet.put_own_coins(own_coin.clone())?;
-        wallet.put_own_coins(own_coin.clone())?;
-        wallet.put_own_coins(own_coin.clone())?;
-        wallet.put_own_coins(own_coin)?;
-
-        let coin2 = Coin::new(bls12_381::Scalar::random(&mut OsRng).to_repr());
-
-        let node2 = MerkleNode::from_coin(&coin2);
-        tree.append(node2)?;
-
-        let mut updated_witnesses = wallet.get_witnesses()?;
-
-        updated_witnesses.iter_mut().for_each(|(_, witness)| {
-            witness.append(node2).expect("Append to witness");
-        });
-
-        wallet.update_witnesses(updated_witnesses)?;
-
-        for (_, witness) in wallet.get_witnesses()?.iter() {
-            assert_eq!(tree.root(), witness.root());
+        for i in id {
+            assert_eq!(i, token_id);
+            assert!(wallet.token_id_exists(i).await?);
         }
         }
 
 
-        std::fs::remove_file(walletdb_path)?;
+        // get_balances()
+        let balances = wallet.get_balances().await?;
+        assert_eq!(balances.list.len(), 4);
+        assert_eq!(balances.list[1].value, 420);
+        assert_eq!(balances.list[2].value, 42);
+        assert_eq!(balances.list[3].token_id, token_id);
+
+        // get_keypairs()
+        let keypair_r = wallet.get_keypairs().await?[0].clone();
+        assert_eq!(keypair, keypair_r);
+
+        // get_own_coins()
+        let own_coins = wallet.get_own_coins().await?;
+        assert_eq!(own_coins.len(), 4);
+        assert_eq!(own_coins[0], c0);
+        assert_eq!(own_coins[1], c1);
+        assert_eq!(own_coins[2], c2);
+        assert_eq!(own_coins[3], c3);
 
 
         Ok(())
         Ok(())
     }
     }