38 lines
1.6 KiB
Rust
38 lines
1.6 KiB
Rust
|
use hex_literal::hex;
|
||
|
use keyfork_derive_util::{request::*, DerivationPath};
|
||
|
use keyfork_frame::*;
|
||
|
use std::{os::unix::net::UnixStream, str::FromStr};
|
||
|
use tempdir::TempDir;
|
||
|
use tokio::runtime::Builder;
|
||
|
|
||
|
#[test]
|
||
|
fn it_works() {
|
||
|
// Test literals taken from keyfork-derive-util.
|
||
|
let entropy = &hex!("000102030405060708090a0b0c0d0e0f")[..];
|
||
|
let mnemonic = keyforkd::Mnemonic::from_entropy(entropy, Default::default()).unwrap();
|
||
|
let rt = Builder::new_multi_thread().enable_io().build().unwrap();
|
||
|
let tempdir = TempDir::new("keyfork-seed").unwrap();
|
||
|
let socket_path = tempdir.path().join("keyforkd.sock");
|
||
|
let handle = rt.spawn({
|
||
|
let socket_path = socket_path.clone();
|
||
|
async move {
|
||
|
keyforkd::start_and_run_server_on(mnemonic, &socket_path)
|
||
|
.await
|
||
|
.unwrap();
|
||
|
}
|
||
|
});
|
||
|
// TODO: send a channel to start_and_run_server_on, or extract logic out of server,
|
||
|
// so we can send a "started" message back to main thread.
|
||
|
std::thread::sleep(std::time::Duration::from_secs(2));
|
||
|
let mut socket = UnixStream::connect(&socket_path).unwrap();
|
||
|
let req = DerivationRequest::new(
|
||
|
DerivationAlgorithm::Ed25519,
|
||
|
DerivationPath::from_str("m/0'/1'/2'/2'/1000000000'").unwrap(),
|
||
|
);
|
||
|
try_encode_to(&bincode::serialize(&req).unwrap(), &mut socket).unwrap();
|
||
|
let response: DerivationResponse =
|
||
|
bincode::deserialize(&try_decode_from(&mut socket).unwrap()).unwrap();
|
||
|
assert_eq!(response.data, hex!("8f94d394a8e8fd6b1bc2f3f49f5c47e385281d5c17e65324b0f62483e37e8793"));
|
||
|
handle.abort();
|
||
|
}
|