sal-modular/kvstore/tests/web.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

47 lines
1.5 KiB
Rust

#![cfg(target_arch = "wasm32")]
//! WASM/browser tests for kvstore using wasm-bindgen-test
use kvstore::{WasmStore, KVStore};
use wasm_bindgen_test::*;
wasm_bindgen_test_configure!(run_in_browser);
#[wasm_bindgen_test]
async fn test_set_and_get() {
let store = WasmStore::open("test-db").await.expect("open");
store.set("foo", b"bar").await.expect("set");
let val = store.get("foo").await.expect("get");
assert_eq!(val, Some(b"bar".to_vec()));
}
#[wasm_bindgen_test]
async fn test_delete_and_exists() {
let store = WasmStore::open("test-db").await.expect("open");
store.set("foo", b"bar").await.expect("set");
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);
}
#[wasm_bindgen_test]
async fn test_keys() {
let store = WasmStore::open("test-db").await.expect("open");
store.set("foo", b"bar").await.expect("set");
store.set("baz", b"qux").await.expect("set");
let keys = store.keys().await.unwrap();
assert_eq!(keys.len(), 2);
assert!(keys.contains(&"foo".to_string()));
assert!(keys.contains(&"baz".to_string()));
}
#[wasm_bindgen_test]
async fn test_clear() {
let store = WasmStore::open("test-db").await.expect("open");
store.set("foo", b"bar").await.expect("set");
store.set("baz", b"qux").await.expect("set");
store.clear().await.unwrap();
let keys = store.keys().await.unwrap();
assert_eq!(keys.len(), 0);
}