From b82d4578735261fa8df010e2a712a200e8933290 Mon Sep 17 00:00:00 2001 From: Sameh Abouel-saad Date: Thu, 29 May 2025 13:41:10 +0300 Subject: [PATCH] Fixed unused imports and variables --- README.md | 8 ++++---- evm_client/src/lib.rs | 4 ++-- evm_client/src/rhai_bindings.rs | 4 ++-- evm_client/src/rhai_sync_helpers.rs | 1 - evm_client/tests/balance.rs | 1 - hero_vault_extension/.gitignore | 1 + kvstore/src/wasm.rs | 11 +++++++++-- vault/src/rhai_bindings.rs | 4 ++-- vault/src/session.rs | 13 ++++++------- vault/tests/keypair_management.rs | 6 ++++-- vault/tests/session_manager.rs | 2 +- 11 files changed, 31 insertions(+), 24 deletions(-) create mode 100644 hero_vault_extension/.gitignore diff --git a/README.md b/README.md index b3e482c..5bce3f4 100644 --- a/README.md +++ b/README.md @@ -134,13 +134,13 @@ For questions, contributions, or more details, see the architecture docs or open ### Native ```sh -cargo check --workspace --features kvstore/native +cargo check --workspace +cargo test --workspace ``` -### WASM (kvstore only) +### WASM ```sh -cd kvstore -wasm-pack test --headless --firefox --features web +make test-browser-all ``` # Rhai Scripting System diff --git a/evm_client/src/lib.rs b/evm_client/src/lib.rs index 264deae..60eb0fd 100644 --- a/evm_client/src/lib.rs +++ b/evm_client/src/lib.rs @@ -68,7 +68,7 @@ impl EvmClient { mut tx: provider::Transaction, signer: &dyn crate::signer::Signer, ) -> Result { - use ethers_core::types::{U256, H256, Bytes, Address}; + use ethers_core::types::{U256, H256}; use std::str::FromStr; use serde_json::json; use crate::provider::{send_rpc, parse_signature_rs_v}; @@ -131,7 +131,7 @@ impl EvmClient { // 3. Sign the RLP-encoded unsigned transaction let sig = signer.sign(&rlp_unsigned).await?; - let (r, s, v) = parse_signature_rs_v(&sig, tx.chain_id.unwrap()).ok_or_else(|| EvmError::Signing("Invalid signature format".to_string()))?; + let (r, s, _v) = parse_signature_rs_v(&sig, tx.chain_id.unwrap()).ok_or_else(|| EvmError::Signing("Invalid signature format".to_string()))?; // 4. RLP encode signed transaction (EIP-155) use rlp::RlpStream; diff --git a/evm_client/src/rhai_bindings.rs b/evm_client/src/rhai_bindings.rs index 7772d3d..2bbf966 100644 --- a/evm_client/src/rhai_bindings.rs +++ b/evm_client/src/rhai_bindings.rs @@ -1,7 +1,7 @@ //! Rhai bindings for EVM Client module //! Provides a single source of truth for scripting integration for EVM actions. -use rhai::{Engine, Map}; +use rhai::Engine; pub use crate::EvmClient; // Ensure EvmClient is public and defined in lib.rs /// Register EVM Client APIs with the Rhai scripting engine. @@ -25,7 +25,7 @@ pub fn register_rhai_api(engine: &mut Engine, evm_client: std::sync::Arc(); engine.register_fn("get_balance", RhaiEvmClient::get_balance); // Register instance for scripts - let rhai_ec = RhaiEvmClient { inner: evm_client.clone() }; + let _rhai_ec = RhaiEvmClient { inner: evm_client.clone() }; // Rhai does not support register_global_constant; pass the client as a parameter or use module scope. } diff --git a/evm_client/src/rhai_sync_helpers.rs b/evm_client/src/rhai_sync_helpers.rs index af4165b..2d49c29 100644 --- a/evm_client/src/rhai_sync_helpers.rs +++ b/evm_client/src/rhai_sync_helpers.rs @@ -2,7 +2,6 @@ //! These use block_on for native, and should be adapted for WASM as needed. use crate::EvmClient; -use rhai::Map; #[cfg(not(target_arch = "wasm32"))] use tokio::runtime::Handle; diff --git a/evm_client/tests/balance.rs b/evm_client/tests/balance.rs index 84115ef..8315448 100644 --- a/evm_client/tests/balance.rs +++ b/evm_client/tests/balance.rs @@ -37,7 +37,6 @@ #[cfg(not(target_arch = "wasm32"))] #[tokio::test] async fn test_get_balance_real_address() { - use ethers_core::types::{Address, U256}; use evm_client::provider::get_balance; // Vitalik's address diff --git a/hero_vault_extension/.gitignore b/hero_vault_extension/.gitignore new file mode 100644 index 0000000..1521c8b --- /dev/null +++ b/hero_vault_extension/.gitignore @@ -0,0 +1 @@ +dist diff --git a/kvstore/src/wasm.rs b/kvstore/src/wasm.rs index 7d9d9df..cc982c5 100644 --- a/kvstore/src/wasm.rs +++ b/kvstore/src/wasm.rs @@ -130,6 +130,7 @@ store.put(&js_value, Some(&JsValue::from_str(key)))?.await #[cfg(not(target_arch = "wasm32"))] pub struct WasmStore; + #[cfg(not(target_arch = "wasm32"))] #[async_trait] impl KVStore for WasmStore { @@ -139,10 +140,16 @@ impl KVStore for WasmStore { async fn set(&self, _key: &str, _value: &[u8]) -> Result<()> { Err(KVError::Other("WasmStore is only available on wasm32 targets".to_string())) } - async fn delete(&self, _key: &str) -> Result<()> { + async fn remove(&self, _key: &str) -> Result<()> { Err(KVError::Other("WasmStore is only available on wasm32 targets".to_string())) } - async fn exists(&self, _key: &str) -> Result { + async fn contains_key(&self, _key: &str) -> Result { + Err(KVError::Other("WasmStore is only available on wasm32 targets".to_string())) + } + async fn keys(&self) -> Result> { + Err(KVError::Other("WasmStore is only available on wasm32 targets".to_string())) + } + async fn clear(&self) -> Result<()> { Err(KVError::Other("WasmStore is only available on wasm32 targets".to_string())) } } diff --git a/vault/src/rhai_bindings.rs b/vault/src/rhai_bindings.rs index e8514fd..d8a81c0 100644 --- a/vault/src/rhai_bindings.rs +++ b/vault/src/rhai_bindings.rs @@ -9,7 +9,7 @@ use crate::session::SessionManager; #[cfg(not(target_arch = "wasm32"))] pub fn register_rhai_api( engine: &mut Engine, - session_manager: std::sync::Arc>>, + _session_manager: std::sync::Arc>>, ) { engine.register_type::>(); engine.register_fn("select_keypair", RhaiSessionManager::::select_keypair); @@ -37,7 +37,7 @@ impl RhaiSessionMan // Use Mutex for interior mutability, &self is sufficient self.inner.lock().unwrap().select_keypair(&key_id).map_err(|e| format!("select_keypair error: {e}")) } - + pub fn select_default_keypair(&self) -> Result<(), String> { self.inner.lock().unwrap().select_default_keypair() .map_err(|e| format!("select_default_keypair error: {e}")) diff --git a/vault/src/session.rs b/vault/src/session.rs index 22b30fa..c54b0c0 100644 --- a/vault/src/session.rs +++ b/vault/src/session.rs @@ -3,7 +3,6 @@ //! All state is local to the SessionManager instance. No global state. use crate::{KVStore, KeyEntry, KeyspaceData, Vault, VaultError}; -use std::collections::HashMap; use zeroize::Zeroize; /// SessionManager: Ergonomic, stateful wrapper over the Vault stateless API. @@ -130,17 +129,17 @@ impl SessionManager { self.current_keyspace() .and_then(|ks| ks.keypairs.first()) } - + /// Selects the default keypair (first keypair) as the current keypair. pub fn select_default_keypair(&mut self) -> Result<(), VaultError> { let default_id = self .default_keypair() .map(|k| k.id.clone()) .ok_or_else(|| VaultError::Crypto("No default keypair found".to_string()))?; - + self.select_keypair(&default_id) } - + /// Returns true if the current keypair is the default keypair (first keypair). pub fn is_default_keypair_selected(&self) -> bool { match (self.current_keypair(), self.default_keypair()) { @@ -312,17 +311,17 @@ impl SessionManager { self.current_keyspace() .and_then(|ks| ks.keypairs.first()) } - + /// Selects the default keypair (first keypair) as the current keypair. pub fn select_default_keypair(&mut self) -> Result<(), VaultError> { let default_id = self .default_keypair() .map(|k| k.id.clone()) .ok_or_else(|| VaultError::Crypto("No default keypair found".to_string()))?; - + self.select_keypair(&default_id) } - + /// Returns true if the current keypair is the default keypair (first keypair). pub fn is_default_keypair_selected(&self) -> bool { match (self.current_keypair(), self.default_keypair()) { diff --git a/vault/tests/keypair_management.rs b/vault/tests/keypair_management.rs index 59eade3..3c75b68 100644 --- a/vault/tests/keypair_management.rs +++ b/vault/tests/keypair_management.rs @@ -26,6 +26,8 @@ async fn test_keypair_management_and_crypto() { vault.create_keyspace(keyspace, password, None).await.unwrap(); debug!("after create_keyspace: keyspace={} password={}", keyspace, hex::encode(password)); + let keys = vault.list_keypairs(keyspace, password).await.unwrap(); + assert_eq!(keys.len(), 1); // should be 1 because we added a default keypair on create_keyspace debug!("before add Ed25519 keypair"); let key_id = vault.add_keypair(keyspace, password, Some(KeyType::Ed25519), Some(KeyMetadata { name: Some("edkey".into()), created_at: None, tags: None })).await; match &key_id { @@ -38,7 +40,7 @@ async fn test_keypair_management_and_crypto() { debug!("before list_keypairs"); let keys = vault.list_keypairs(keyspace, password).await.unwrap(); - assert_eq!(keys.len(), 2); + assert_eq!(keys.len(), 3); debug!("before export Ed25519 keypair"); let (priv_bytes, pub_bytes) = vault.export_keypair(keyspace, password, &key_id).await.unwrap(); @@ -65,5 +67,5 @@ async fn test_keypair_management_and_crypto() { // Remove a keypair vault.remove_keypair(keyspace, password, &key_id).await.unwrap(); let keys = vault.list_keypairs(keyspace, password).await.unwrap(); - assert_eq!(keys.len(), 1); + assert_eq!(keys.len(), 2); } diff --git a/vault/tests/session_manager.rs b/vault/tests/session_manager.rs index e37b524..15ae122 100644 --- a/vault/tests/session_manager.rs +++ b/vault/tests/session_manager.rs @@ -11,7 +11,7 @@ async fn session_manager_end_to_end() { use tempfile::TempDir; let tmp_dir = TempDir::new().expect("create temp dir"); let store = NativeStore::open(tmp_dir.path().to_str().unwrap()).expect("open NativeStore"); - let mut vault = Vault::new(store); + let vault = Vault::new(store); let keyspace = "personal"; let password = b"testpass";