mirror of
https://github.com/fluencelabs/trust-graph-test
synced 2025-04-24 23:02:32 +00:00
tests work!
This commit is contained in:
parent
256cf96436
commit
e8c109df99
@ -237,6 +237,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::misc::current_time;
|
use crate::misc::current_time;
|
||||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||||
|
use crate::key_pair::KeyPair;
|
||||||
|
|
||||||
pub fn one_second() -> Duration {
|
pub fn one_second() -> Duration {
|
||||||
Duration::from_secs(1)
|
Duration::from_secs(1)
|
||||||
@ -260,7 +261,7 @@ mod tests {
|
|||||||
|
|
||||||
let new_cert = Certificate::issue(
|
let new_cert = Certificate::issue(
|
||||||
&second_kp,
|
&second_kp,
|
||||||
third_kp.key_pair.public(),
|
third_kp.key_pair.public,
|
||||||
&cert,
|
&cert,
|
||||||
cur_time.checked_add(one_second()).unwrap(),
|
cur_time.checked_add(one_second()).unwrap(),
|
||||||
cur_time,
|
cur_time,
|
||||||
@ -287,7 +288,7 @@ mod tests {
|
|||||||
|
|
||||||
let new_cert = Certificate::issue(
|
let new_cert = Certificate::issue(
|
||||||
&second_kp,
|
&second_kp,
|
||||||
third_kp.key_pair.public(),
|
third_kp.key_pair.public,
|
||||||
&cert,
|
&cert,
|
||||||
cur_time.checked_add(one_second()).unwrap(),
|
cur_time.checked_add(one_second()).unwrap(),
|
||||||
cur_time,
|
cur_time,
|
||||||
@ -347,7 +348,7 @@ mod tests {
|
|||||||
|
|
||||||
let new_cert = Certificate::issue(
|
let new_cert = Certificate::issue(
|
||||||
&second_kp,
|
&second_kp,
|
||||||
third_kp.key_pair.public(),
|
third_kp.key_pair.public,
|
||||||
&cert,
|
&cert,
|
||||||
cur_time.checked_add(one_year()).unwrap(),
|
cur_time.checked_add(one_year()).unwrap(),
|
||||||
cur_time,
|
cur_time,
|
||||||
@ -358,18 +359,18 @@ mod tests {
|
|||||||
|
|
||||||
println!(
|
println!(
|
||||||
"root_kp:\n\tprivate: {}\n\tpublic: {}",
|
"root_kp:\n\tprivate: {}\n\tpublic: {}",
|
||||||
bs58::encode(root_kp.key_pair.secret()).into_string(),
|
bs58::encode(root_kp.clone().key_pair.secret).into_string(),
|
||||||
bs58::encode(&root_kp.key_pair.public().encode().to_vec()).into_string()
|
bs58::encode(&root_kp.key_pair.public.to_bytes().to_vec()).into_string()
|
||||||
);
|
);
|
||||||
println!(
|
println!(
|
||||||
"second_kp:\n\tprivate: {}\n\tpublic: {}",
|
"second_kp:\n\tprivate: {}\n\tpublic: {}",
|
||||||
bs58::encode(second_kp.key_pair.secret()).into_string(),
|
bs58::encode(second_kp.clone().key_pair.secret).into_string(),
|
||||||
bs58::encode(&second_kp.key_pair.public().encode().to_vec()).into_string()
|
bs58::encode(&second_kp.key_pair.public.to_bytes().to_vec()).into_string()
|
||||||
);
|
);
|
||||||
println!(
|
println!(
|
||||||
"third_kp:\n\tprivate: {}\n\tpublic: {}",
|
"third_kp:\n\tprivate: {}\n\tpublic: {}",
|
||||||
bs58::encode(third_kp.key_pair.secret()).into_string(),
|
bs58::encode(third_kp.clone().key_pair.secret).into_string(),
|
||||||
bs58::encode(&third_kp.key_pair.public().encode().to_vec()).into_string()
|
bs58::encode(&third_kp.key_pair.public.to_bytes().to_vec()).into_string()
|
||||||
);
|
);
|
||||||
println!("cert is\n{}", new_cert.to_string());
|
println!("cert is\n{}", new_cert.to_string());
|
||||||
|
|
||||||
@ -390,7 +391,7 @@ mod tests {
|
|||||||
|
|
||||||
let new_cert = Certificate::issue(
|
let new_cert = Certificate::issue(
|
||||||
&second_kp,
|
&second_kp,
|
||||||
third_kp.key_pair.public(),
|
third_kp.key_pair.public,
|
||||||
&cert,
|
&cert,
|
||||||
cur_time.checked_sub(one_second()).unwrap(),
|
cur_time.checked_sub(one_second()).unwrap(),
|
||||||
cur_time.checked_sub(one_minute()).unwrap(),
|
cur_time.checked_sub(one_minute()).unwrap(),
|
||||||
@ -412,7 +413,7 @@ mod tests {
|
|||||||
|
|
||||||
let new_cert = Certificate::issue(
|
let new_cert = Certificate::issue(
|
||||||
&second_kp,
|
&second_kp,
|
||||||
third_kp.key_pair.public(),
|
third_kp.key_pair.public,
|
||||||
&cert,
|
&cert,
|
||||||
cur_time.checked_add(one_second()).unwrap(),
|
cur_time.checked_add(one_second()).unwrap(),
|
||||||
cur_time,
|
cur_time,
|
||||||
@ -421,7 +422,7 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
let new_cert = Certificate::issue(
|
let new_cert = Certificate::issue(
|
||||||
&third_kp,
|
&third_kp,
|
||||||
fourth_kp.key_pair.public(),
|
fourth_kp.key_pair.public,
|
||||||
&new_cert,
|
&new_cert,
|
||||||
cur_time.checked_add(one_second()).unwrap(),
|
cur_time.checked_add(one_second()).unwrap(),
|
||||||
cur_time,
|
cur_time,
|
||||||
@ -450,7 +451,7 @@ mod tests {
|
|||||||
|
|
||||||
let new_cert = Certificate::issue(
|
let new_cert = Certificate::issue(
|
||||||
&second_kp,
|
&second_kp,
|
||||||
third_kp.key_pair.public(),
|
third_kp.key_pair.public,
|
||||||
&cert,
|
&cert,
|
||||||
cur_time.checked_add(one_second()).unwrap(),
|
cur_time.checked_add(one_second()).unwrap(),
|
||||||
cur_time,
|
cur_time,
|
||||||
@ -459,7 +460,7 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
let new_cert = Certificate::issue(
|
let new_cert = Certificate::issue(
|
||||||
&second_kp,
|
&second_kp,
|
||||||
fourth_kp.key_pair.public(),
|
fourth_kp.key_pair.public,
|
||||||
&new_cert,
|
&new_cert,
|
||||||
cur_time.checked_add(one_second()).unwrap(),
|
cur_time.checked_add(one_second()).unwrap(),
|
||||||
cur_time,
|
cur_time,
|
||||||
@ -484,7 +485,7 @@ mod tests {
|
|||||||
let bad_kp = KeyPair::generate();
|
let bad_kp = KeyPair::generate();
|
||||||
let new_cert_bad = Certificate::issue(
|
let new_cert_bad = Certificate::issue(
|
||||||
&bad_kp,
|
&bad_kp,
|
||||||
bad_kp.key_pair.public(),
|
bad_kp.key_pair.public,
|
||||||
&cert,
|
&cert,
|
||||||
cur_time.checked_add(one_second()).unwrap(),
|
cur_time.checked_add(one_second()).unwrap(),
|
||||||
cur_time,
|
cur_time,
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
use crate::ed25519::{Keypair as Libp2pKeyPair};
|
use crate::ed25519::{Keypair as Libp2pKeyPair};
|
||||||
use ed25519_dalek::SignatureError;
|
use ed25519_dalek::SignatureError;
|
||||||
use ed25519_dalek::{PublicKey, Signer};
|
use ed25519_dalek::{PublicKey, Signer, SecretKey};
|
||||||
|
|
||||||
use core::fmt::{Debug};
|
use core::fmt::{Debug};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
@ -134,3 +134,14 @@ impl<'de> serde::Deserialize<'de> for KeyPair {
|
|||||||
deserializer.deserialize_str(KeyPairVisitor)
|
deserializer.deserialize_str(KeyPairVisitor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Clone for KeyPair {
|
||||||
|
fn clone(&self) -> KeyPair {
|
||||||
|
let mut sk_bytes = self.key_pair.secret.to_bytes();
|
||||||
|
let secret = SecretKey::from_bytes(&mut sk_bytes)
|
||||||
|
.expect("ed25519::SecretKey::from_bytes(to_bytes(k)) != k");
|
||||||
|
let public = PublicKey::from_bytes(&self.key_pair.public.to_bytes())
|
||||||
|
.expect("ed25519::PublicKey::from_bytes(to_bytes(k)) != k");
|
||||||
|
KeyPair { key_pair: ed25519_dalek::Keypair { secret, public } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -371,7 +371,7 @@ mod tests {
|
|||||||
|
|
||||||
let st = Box::new(InMemoryStorage::new());
|
let st = Box::new(InMemoryStorage::new());
|
||||||
let mut graph = TrustGraph::new(st);
|
let mut graph = TrustGraph::new(st);
|
||||||
graph.add_root_weight(root.key_pair.public().into(), 0);
|
graph.add_root_weight(root.key_pair.public.into(), 0);
|
||||||
|
|
||||||
let addition = graph.add(cert, current_time());
|
let addition = graph.add(cert, current_time());
|
||||||
assert_eq!(addition.is_ok(), true);
|
assert_eq!(addition.is_ok(), true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user