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
This commit is contained in:
33
kvstore/tests/native.rs
Normal file
33
kvstore/tests/native.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
#![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);
|
||||
}
|
46
kvstore/tests/web.rs
Normal file
46
kvstore/tests/web.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
#![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);
|
||||
}
|
Reference in New Issue
Block a user