Merge remote-tracking branch 'github/pr/724'

This commit is contained in:
William Casarin
2025-02-10 16:52:56 -08:00
3 changed files with 23 additions and 8 deletions

View File

@@ -47,11 +47,14 @@ impl FileKeyStorage {
}
fn get_selected_pubkey(&self) -> Result<Option<Pubkey>> {
let pubkey_str = self
match self
.selected_key_directory
.get_file(SELECTED_PUBKEY_FILE_NAME.to_owned())?;
Ok(serde_json::from_str(&pubkey_str)?)
.get_file(SELECTED_PUBKEY_FILE_NAME.to_owned())
{
Ok(pubkey_str) => Ok(Some(serde_json::from_str(&pubkey_str)?)),
Err(crate::Error::Io(_)) => Ok(None),
Err(e) => Err(e),
}
}
fn select_pubkey(&self, pubkey: Option<Pubkey>) -> Result<()> {
@@ -164,4 +167,15 @@ mod tests {
assert!(resp.is_ok());
}
#[test]
fn test_get_selected_key_when_no_file() {
let storage = FileKeyStorage::mock().unwrap();
// Should return Ok(None) when no key has been selected
match storage.get_selected_key() {
KeyStorageResponse::ReceivedResult(Ok(None)) => (), // This is what we expect
other => panic!("Expected Ok(None), got {:?}", other),
}
}
}

View File

@@ -105,9 +105,9 @@ impl Directory {
.ok_or_else(|| Error::Generic("Could not turn path to string".to_owned()))?;
Ok(fs::read_to_string(filepath_str)?)
} else {
Err(Error::Generic(format!(
"Requested file was not found: {}",
file_name
Err(Error::Io(io::Error::new(
io::ErrorKind::NotFound,
format!("Requested file was not found: {}", file_name),
)))
}
}

View File

@@ -36,8 +36,9 @@ impl Default for DecksCache {
}
impl DecksCache {
pub fn new(account_to_decks: HashMap<Pubkey, Decks>) -> Self {
pub fn new(mut account_to_decks: HashMap<Pubkey, Decks>) -> Self {
let fallback_pubkey = FALLBACK_PUBKEY();
account_to_decks.entry(fallback_pubkey).or_default();
Self {
account_to_decks,