more misc tests
This commit is contained in:
parent
90d2f46cda
commit
7e8702a150
|
@ -570,6 +570,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bincode",
|
"bincode",
|
||||||
"clap",
|
"clap",
|
||||||
|
"ed25519-dalek",
|
||||||
"hex-literal",
|
"hex-literal",
|
||||||
"keyfork-derive-util",
|
"keyfork-derive-util",
|
||||||
"keyfork-frame",
|
"keyfork-frame",
|
||||||
|
|
|
@ -111,3 +111,16 @@ fn ed25519() {
|
||||||
assert_eq!(response.data, private_key);
|
assert_eq!(response.data, private_key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "ed25519")]
|
||||||
|
#[test]
|
||||||
|
#[should_panic]
|
||||||
|
fn panics_at_depth() {
|
||||||
|
use ed25519_dalek::SigningKey;
|
||||||
|
|
||||||
|
let seed = hex!("000102030405060708090a0b0c0d0e0f");
|
||||||
|
let mut xkey = ExtendedPrivateKey::<SigningKey>::new(seed).unwrap();
|
||||||
|
for i in 0..u32::from(u8::MAX) + 1 {
|
||||||
|
xkey = xkey.derive_child(&DerivationIndex::new(i, true).unwrap()).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ keyfork-frame = { version = "0.1.0", path = "../keyfork-frame", default-features
|
||||||
thiserror = "1.0.48"
|
thiserror = "1.0.48"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
ed25519-dalek = "2.0.0"
|
||||||
hex-literal = "0.4.1"
|
hex-literal = "0.4.1"
|
||||||
keyforkd = { path = "../keyforkd", default-features = false }
|
keyforkd = { path = "../keyforkd", default-features = false }
|
||||||
tempdir = "0.3.7"
|
tempdir = "0.3.7"
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use crate::client::Client;
|
use crate::client::Client;
|
||||||
use hex_literal::hex;
|
use hex_literal::hex;
|
||||||
use keyfork_derive_util::{request::*, DerivationPath};
|
use keyfork_derive_util::{request::*, DerivationPath, DerivationIndex, ExtendedPrivateKey};
|
||||||
|
use std::sync::mpsc::channel;
|
||||||
use std::{os::unix::net::UnixStream, str::FromStr};
|
use std::{os::unix::net::UnixStream, str::FromStr};
|
||||||
use tempdir::TempDir;
|
use tempdir::TempDir;
|
||||||
use tokio::runtime::Builder;
|
use tokio::runtime::Builder;
|
||||||
use std::sync::mpsc::channel;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn it_works() {
|
fn it_works() {
|
||||||
|
@ -45,3 +45,47 @@ fn it_works() {
|
||||||
);
|
);
|
||||||
handle.abort();
|
handle.abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn misc_multi_requests() {
|
||||||
|
// Setup
|
||||||
|
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 (tx, rx) = channel();
|
||||||
|
|
||||||
|
let handle = rt.spawn({
|
||||||
|
let socket_path = socket_path.clone();
|
||||||
|
async move {
|
||||||
|
let mut server = keyforkd::UnixServer::bind(&socket_path).unwrap();
|
||||||
|
// Connections can be pending for a few seconds, so signal to the main
|
||||||
|
// test we're ready to start accepting.
|
||||||
|
tx.send(()).unwrap();
|
||||||
|
let service = keyforkd::ServiceBuilder::new()
|
||||||
|
.layer(keyforkd::middleware::BincodeLayer::new())
|
||||||
|
.service(keyforkd::Keyforkd::new(mnemonic));
|
||||||
|
server.run(service).await.unwrap();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
rx.recv().unwrap();
|
||||||
|
let socket = UnixStream::connect(&socket_path).unwrap();
|
||||||
|
let mut client = Client::new(socket);
|
||||||
|
let req = DerivationRequest::new(
|
||||||
|
DerivationAlgorithm::Ed25519,
|
||||||
|
DerivationPath::from_str("m/7366512'/0'").unwrap(),
|
||||||
|
);
|
||||||
|
let response = client.request(&req).unwrap();
|
||||||
|
let key = ExtendedPrivateKey::<ed25519_dalek::SigningKey>::new_from_parts(
|
||||||
|
&response.data,
|
||||||
|
response.depth,
|
||||||
|
response.chain_code,
|
||||||
|
).unwrap();
|
||||||
|
|
||||||
|
for i in 0..255 {
|
||||||
|
key.derive_child(&DerivationIndex::new(i, true).unwrap()).unwrap();
|
||||||
|
}
|
||||||
|
handle.abort();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue