Skip to content

Commit

Permalink
Simplifiy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Feb 22, 2023
1 parent dc930cc commit 4944904
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![cfg(test)]
use chacha20::ChaCha20;

use crate::pipe::TrussedInterchange;
use crate::types::*;
use crate::*;
use entropy::shannon_entropy;
Expand Down Expand Up @@ -147,6 +148,21 @@ macro_rules! create_memory {
}};
}

fn test_client<P: Platform>(
platform: P,
pipe: &TrussedInterchange<1>,
seed: [u8; 32],
) -> ClientImplementation<'_, Service<'_, P, 1>> {
let test_client_id = "TEST";
let mut trussed: crate::Service<P, 1> = crate::service::Service::new(platform, pipe);

trussed.set_seed_if_uninitialized(&seed);
crate::client::ClientBuilder::new(test_client_id)
.prepare(&mut trussed)
.expect("Preparing the client should not fail")
.build(trussed)
}

// TODO: what's going on here? Duplicates code in `tests/client/mod.rs`.
// Might make sense as a trussed::fixture submodule activated via feature flag.
macro_rules! setup {
Expand Down Expand Up @@ -177,15 +193,7 @@ macro_rules! setup {
let platform = $platform::new(rng, store, pc_interface);

let pipe = interchange::Interchange::new();
let test_client_id = "TEST";
let mut trussed: crate::Service<$platform, 1> =
crate::service::Service::new(platform, &pipe);

trussed.set_seed_if_uninitialized(&$seed);
let mut $client = crate::client::ClientBuilder::new(test_client_id)
.prepare(&mut trussed)
.expect("Preparing the client should not fail")
.build(&mut trussed);
let mut $client = test_client(platform, &pipe, $seed);
};
}

Expand Down

0 comments on commit 4944904

Please sign in to comment.