sal-modular/kvstore/tests/native.rs
Sameh Abouelsaad 9dce815daa feat: Add basic project structure and initial crates
- Added basic project structure with workspace and crates:
  `kvstore`, `vault`, `evm_client`, `cli_app`, `web_app`.
- Created initial `Cargo.toml` files for each crate.
- Added placeholder implementations for key components.
- Included initial documentation files (`README.md`, architecture
  docs, repo structure).
- Included initial implementaion for kvstore crate(async API, backend abstraction, separation of concerns, WASM/native support, testability)
- Included native and browser tests for the kvstore crate
2025-05-13 20:24:29 +03:00

34 lines
1.1 KiB
Rust

#![cfg(not(target_arch = "wasm32"))]
use kvstore::{NativeStore, KVStore};
#[tokio::test]
async fn test_native_store_basic() {
let tmp_dir = tempfile::tempdir().unwrap();
let path = tmp_dir.path().join("testdb");
let store = NativeStore::open(path.to_str().unwrap()).unwrap();
// Test set/get
store.set("foo", b"bar").await.unwrap();
let val = store.get("foo").await.unwrap();
assert_eq!(val, Some(b"bar".to_vec()));
// Test exists
assert_eq!(store.contains_key("foo").await.unwrap(), true);
assert_eq!(store.contains_key("bar").await.unwrap(), false);
store.remove("foo").await.unwrap();
assert_eq!(store.get("foo").await.unwrap(), None);
// Test keys
store.set("foo", b"bar").await.unwrap();
store.set("baz", b"qux").await.unwrap();
let keys = store.keys().await.unwrap();
assert_eq!(keys.len(), 2);
assert!(keys.contains(&"foo".to_string()));
assert!(keys.contains(&"baz".to_string()));
// Test clear
store.clear().await.unwrap();
let keys = store.keys().await.unwrap();
assert_eq!(keys.len(), 0);
}