Getting ready to create Bitcoin keys

This commit is contained in:
Dave Hrycyszyn
2024-06-18 16:00:02 +01:00
parent a244207f77
commit 4cf6513959
6 changed files with 133 additions and 12 deletions

View File

@@ -53,6 +53,24 @@ mod tests {
(SideNodeConfig { name: name.clone() }, name)
}
#[test]
fn creates_bitcoin_keys() {
let (config, name) = side_node_config();
let side_dir = format!("/tmp/side/{name}");
let mut key_file_path = PathBuf::new();
key_file_path.push(side_dir.clone());
key_file_path.push(utils::BFT_CRDT_KEY_FILE);
let _ = init(PathBuf::from_str(&side_dir).unwrap(), config);
assert!(key_file_path.exists());
// check that the pem is readable
let data = fs::read_to_string(key_file_path).expect("couldn't read key file");
let keys = Ed25519KeyPair::decode_base64(&data).expect("couldn't load keypair from file");
assert_eq!(keys.public().as_bytes().len(), 32);
}
#[test]
fn creates_side_node_directory() {
let (config, name) = side_node_config();
@@ -67,13 +85,13 @@ mod tests {
}
#[test]
fn creates_key_file() {
fn creates_bft_crdt_key_file() {
let (config, name) = side_node_config();
let side_dir = format!("/tmp/side/{name}");
let mut key_file_path = PathBuf::new();
key_file_path.push(side_dir.clone());
key_file_path.push(utils::KEY_FILE);
key_file_path.push(utils::BFT_CRDT_KEY_FILE);
let _ = init(PathBuf::from_str(&side_dir).unwrap(), config);
assert!(key_file_path.exists());

View File

@@ -5,7 +5,6 @@ pub(crate) fn input(stdin_sender: std::sync::mpsc::Sender<String>) {
let stdin = std::io::stdin();
let lines = stdin.lock().lines();
for line in lines {
println!("We're in stdin_input");
let line = line.unwrap();
stdin_sender.send(line).unwrap();
}

View File

@@ -3,13 +3,13 @@ use std::path::PathBuf;
use bft_json_crdt::json_crdt::SignedOp;
use serde_json::{json, Value};
pub(crate) const KEY_FILE: &str = "keys.pem";
pub(crate) const BFT_CRDT_KEY_FILE: &str = "keys.pem";
pub(crate) const CONFIG_FILE: &str = "config.toml";
/// Returns the path to the key file and config for this host OS.
pub(crate) fn side_paths(prefix: PathBuf) -> (PathBuf, PathBuf) {
let mut key_path = prefix.clone();
key_path.push(KEY_FILE);
key_path.push(BFT_CRDT_KEY_FILE);
let mut config_path = prefix.clone();
config_path.push(CONFIG_FILE);

View File

@@ -47,9 +47,7 @@ impl ezsockets::ClientExt for WebSocketClient {
let object_sha = utils::shappy(incoming.clone());
println!("deserialized: {}", object_sha);
if string_sha != object_sha {
println!("SHA mismatch: {string_sha} != {object_sha}");
println!("text: {text}");
println!("incoming: {incoming:?}");
panic!("sha mismatch: {string_sha} != {object_sha}, bft-crdt has failed");
}
self.incoming_sender.send(incoming).await?;
Ok(())