Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/qa test #599

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/storage/src/key_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,50 @@ mod tests {
use super::*;
use ethers::prelude::{LocalWallet, Signer};
use std::ops::Deref;
use std::fs;
use tempdir::TempDir;

#[test]
fn test_has_key_existing() {
let tmp_dir_path = TempDir::new("tmp_dir").expect("create temp dir");
let real_path = tmp_dir_path.path().to_str().unwrap().to_string();
let keystore = KeyStore::new(KeyStoreConfig { key_root_path: real_path.clone() });
let key = "test_key";
let value = b"value";
keystore.write_key(key, value).unwrap();
assert_eq!(keystore.has_key(key), true);
}

#[test]
fn test_has_key_non_existing() {
let tmp_dir_path = TempDir::new("tmp_dir").expect("create temp dir");
let real_path = tmp_dir_path.path().to_str().unwrap().to_string();
let keystore = KeyStore::new(KeyStoreConfig { key_root_path: real_path.clone() });
let key = "test_key";
assert_eq!(keystore.has_key(key), false);
}

#[test]
fn test_has_key_invalid_input() {
let tmp_dir_path = TempDir::new("tmp_dir").expect("create temp dir");
let real_path = tmp_dir_path.path().to_str().unwrap().to_string();
let keystore = KeyStore::new(KeyStoreConfig { key_root_path: real_path.clone() });
let empty_key = "";
assert_eq!(keystore.has_key(empty_key), false);
}

#[test]
fn test_has_key_file_error() {
let tmp_dir_path = TempDir::new("tmp_dir").expect("create temp dir");
let real_path = tmp_dir_path.path().to_str().unwrap().to_string();
let keystore = KeyStore::new(KeyStoreConfig { key_root_path: real_path.clone() });
let mut invalid_file = std::fs::File::create(format!("{}/INVALID", real_path)).unwrap();
invalid_file.write_all(b"invalid content").unwrap(); // create an invalid file
let invalid_key = "INVALID";
assert_eq!(keystore.has_key(invalid_key), false);
}


#[test]
fn evm_account_key_store_smoke_test() {
let tmp_dir_path = TempDir::new("key store").expect("create temp dir");
Expand Down