Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
justprosh committed Jan 20, 2022
1 parent a491cf1 commit a21733b
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions service/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ mod service_tests {
cp
}

fn set_root_peer_id(trust_graph: &mut ServiceInterface, peer_id: PeerId, weight_factor: u32) {
let result = trust_graph.set_root(peer_id.to_base58(), weight_factor);
fn set_root_peer_id(trust_graph: &mut ServiceInterface, peer_id: PeerId, max_chain_len: u32) {
let result = trust_graph.set_root(peer_id.to_base58(), max_chain_len);
assert!(result.success, "{}", result.error);
}

Expand All @@ -97,9 +97,9 @@ mod service_tests {
issuer_kp: &KeyPair,
issued_at_sec: u64,
expires_at_sec: u64,
weight_factor: u32,
max_chain_len: u32,
) -> Trust {
let result = trust_graph.set_root(issuer_kp.get_peer_id().to_base58(), weight_factor);
let result = trust_graph.set_root(issuer_kp.get_peer_id().to_base58(), max_chain_len);
assert!(result.success, "{}", result.error);
add_trust(
trust_graph,
Expand Down Expand Up @@ -408,7 +408,7 @@ mod service_tests {
&root_kp,
cur_time,
root_expired_time - 1,
4,
10,
);

let trust_kp = KeyPair::generate_ed25519();
Expand Down Expand Up @@ -447,7 +447,7 @@ mod service_tests {

let peerA_kp = KeyPair::generate_ed25519();
let mut cur_time = 100u64;
add_root_with_trust(&mut trust_graph, &peerA_kp, cur_time, cur_time + 9999, 4u32);
add_root_with_trust(&mut trust_graph, &peerA_kp, cur_time, cur_time + 9999, 10);

let peerB_kp = KeyPair::generate_ed25519();
add_trust(
Expand Down Expand Up @@ -490,7 +490,7 @@ mod service_tests {
let mut cur_time = current_time();

let root_peer_id = key_pairs[0].get_peer_id();
set_root_peer_id(&mut trust_graph, root_peer_id, 2);
set_root_peer_id(&mut trust_graph, root_peer_id, 10);
add_trusts(&mut trust_graph, &trusts, cur_time);

let target_peer_id = key_pairs[4].get_peer_id();
Expand Down Expand Up @@ -536,7 +536,7 @@ mod service_tests {
let cur_time = current_time();

let root_peer_id = key_pairs[0].get_peer_id();
set_root_peer_id(&mut trust_graph, root_peer_id, 2);
set_root_peer_id(&mut trust_graph, root_peer_id, 10);
add_trusts(&mut trust_graph, &trusts, cur_time);

let issued_by = key_pairs.last().unwrap().get_peer_id();
Expand Down Expand Up @@ -577,7 +577,7 @@ mod service_tests {
let cur_time = current_time();

let root1_peer_id = key_pairs[0].get_peer_id();
set_root_peer_id(&mut trust_graph, root1_peer_id, 2);
set_root_peer_id(&mut trust_graph, root1_peer_id, 10);
add_trusts(&mut trust_graph, &trusts, cur_time);

let issued_by = key_pairs.last().unwrap().get_peer_id();
Expand Down Expand Up @@ -620,7 +620,7 @@ mod service_tests {

let cur_time = current_time();
let root_peer_id = key_pairs[0].get_peer_id();
set_root_peer_id(&mut trust_graph, root_peer_id, 1);
set_root_peer_id(&mut trust_graph, root_peer_id, 10);

for auth in trusts.iter() {
add_trust_checked(&mut trust_graph, auth.trust.clone(), auth.issuer, cur_time);
Expand Down Expand Up @@ -649,9 +649,9 @@ mod service_tests {
let far_future = cur_time + 9999;

// add first and last trusts as roots
set_root_peer_id(&mut trust_graph, kps[0].get_peer_id(), 0);
set_root_peer_id(&mut trust_graph, kps[0].get_peer_id(), 10);
add_trusts(&mut trust_graph, &trusts, cur_time);
add_root_with_trust(&mut trust_graph, &kps[5], cur_time, far_future, 0);
add_root_with_trust(&mut trust_graph, &kps[5], cur_time, far_future, 10);

let certs = get_all_certs(&mut trust_graph, kps[5].get_peer_id(), cur_time);
// first with self-signed last trust, second - without
Expand All @@ -667,7 +667,7 @@ mod service_tests {

let root_kp = KeyPair::generate_ed25519();
let cur_time = 100u64;
add_root_with_trust(&mut trust_graph, &root_kp, cur_time, cur_time + 999, 4u32);
add_root_with_trust(&mut trust_graph, &root_kp, cur_time, cur_time + 999, 10);

let trust_kp = KeyPair::generate_ed25519();
add_trust(
Expand Down Expand Up @@ -712,7 +712,7 @@ mod service_tests {

let root_kp = KeyPair::generate_ed25519();
let mut cur_time = 100u64;
add_root_with_trust(&mut trust_graph, &root_kp, cur_time, cur_time + 999, 4u32);
add_root_with_trust(&mut trust_graph, &root_kp, cur_time, cur_time + 999, 10);

let trust_kp = KeyPair::generate_ed25519();
let expires_at_sec = cur_time + 10;
Expand Down Expand Up @@ -752,10 +752,10 @@ mod service_tests {
let root2_kp = KeyPair::generate_ed25519();
let cur_time = 100;
let far_future = cur_time + 99999;
// root with bigger weight (smaller weight factor)
add_root_with_trust(&mut trust_graph, &root1_kp, cur_time, far_future, 0u32);
// root with bigger weight (bigger max_chain_len)
add_root_with_trust(&mut trust_graph, &root1_kp, cur_time, far_future, 10);
// opposite
add_root_with_trust(&mut trust_graph, &root2_kp, cur_time, far_future, 5u32);
add_root_with_trust(&mut trust_graph, &root2_kp, cur_time, far_future, 5);

// issue trust from root2 to any other peer_id
let issued_by_root2_peer_id = KeyPair::generate_ed25519().get_peer_id();
Expand Down Expand Up @@ -832,7 +832,7 @@ mod service_tests {

let cur_time = current_time();
let root_peer_id = key_pairs[0].get_peer_id();
set_root_peer_id(&mut trust_graph, root_peer_id, 1);
set_root_peer_id(&mut trust_graph, root_peer_id, 10);

for auth in trusts.iter() {
add_trust_checked(&mut trust_graph, auth.trust.clone(), auth.issuer, cur_time);
Expand Down Expand Up @@ -862,7 +862,7 @@ mod service_tests {

let cur_time = current_time();
let root_peer_id = key_pairs[0].get_peer_id();
set_root_peer_id(&mut trust_graph, root_peer_id, 1);
set_root_peer_id(&mut trust_graph, root_peer_id, 10);

for auth in trusts.iter() {
add_trust_checked(&mut trust_graph, auth.trust.clone(), auth.issuer, cur_time);
Expand Down

0 comments on commit a21733b

Please sign in to comment.