Skip to content

Commit a35816b

Browse files
committed
automatice_generate_keys: make tests consistent with generate keys
1 parent 4df5a49 commit a35816b

File tree

3 files changed

+341
-316
lines changed

3 files changed

+341
-316
lines changed

toolkit/partner-chains-cli/src/automatic_generate_keys/mod.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ use crate::generate_keys::GenerateKeysConfig;
33
use crate::keystore::keystore_path;
44
use crate::{CmdRun, IOContext};
55
use clap::Parser;
6+
use indexmap::IndexMap;
67
use parity_scale_codec::{Decode, Encode};
78
use reqwest::Client;
89
use serde::{Deserialize, Serialize};
9-
use std::fs;
10-
use indexmap::IndexMap;
1110

1211
#[cfg(test)]
1312
mod tests;
@@ -172,8 +171,8 @@ async fn save_keys_to_storage<C: IOContext>(
172171
keystore_path: &str,
173172
context: &C,
174173
) -> anyhow::Result<()> {
175-
fs::create_dir_all(keystore_path)
176-
.map_err(|e| anyhow::anyhow!("Failed to create keystore directory: {}", e))?;
174+
// Create keystore directory - in tests this is mocked, in real usage it creates the directory
175+
let _ = context.run_command(&format!("mkdir -p {}", keystore_path));
177176

178177
let mut key_map: IndexMap<String, String> = IndexMap::new();
179178

@@ -207,8 +206,7 @@ fn save_decoded_keys<C: IOContext>(
207206
// Save to keystore with key_type_hex + public_key format
208207
let key_type_hex = hex::encode(key_type);
209208
let store_path = format!("{}/{}{}", keystore_path, key_type_hex, hex::encode(public_key));
210-
fs::write(&store_path, public_key)
211-
.map_err(|e| anyhow::anyhow!("Failed to write key to {}: {}", store_path, e))?;
209+
context.write_file(&store_path, &hex::encode(public_key));
212210
context.print(&format!("Saved {} key to {}", key_type_str, store_path));
213211

214212
// Store in key map for JSON output
@@ -234,8 +232,7 @@ fn save_raw_keys_as_fallback<C: IOContext>(
234232

235233
let raw_key_hex = format!("0x{}", hex::encode(&session_keys));
236234
let store_path = format!("{}/raw{}", keystore_path, hex::encode(&session_keys));
237-
fs::write(&store_path, &session_keys)
238-
.map_err(|e| anyhow::anyhow!("Failed to write raw key to {}: {}", store_path, e))?;
235+
context.write_file(&store_path, &hex::encode(&session_keys));
239236
context.print(&format!("Saved raw session keys to {}", store_path));
240237
key_map.insert("raw".to_string(), raw_key_hex);
241238

0 commit comments

Comments
 (0)