From d33f30e582fc90ea618842cd818862bf3adf7de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Mon, 13 Feb 2023 09:53:15 +0100 Subject: [PATCH] Simplifiy tests --- src/tests.rs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/tests.rs b/src/tests.rs index 084441886f2..889b7091000 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,6 +1,7 @@ #![cfg(test)] use chacha20::ChaCha20; +use crate::pipe::TrussedInterchange; use crate::types::*; use crate::*; use entropy::shannon_entropy; @@ -147,6 +148,21 @@ macro_rules! create_memory { }}; } +fn test_client( + platform: P, + pipe: &TrussedInterchange<1>, + seed: [u8; 32], +) -> ClientImplementation<'_, Service<'_, P, 1>> { + let test_client_id = "TEST"; + let mut trussed: crate::Service = 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 { @@ -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); }; }