-
Notifications
You must be signed in to change notification settings - Fork 296
/
remote_vault_public_seed_randomness_generator_delegation.rs
49 lines (43 loc) · 1.87 KB
/
remote_vault_public_seed_randomness_generator_delegation.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use ic_crypto_temp_crypto_vault::RemoteVaultEnvironment;
use ic_crypto_test_utils_local_csp_vault::MockLocalCspVault;
use proptest::proptest;
use proptest::result::maybe_err;
use std::sync::Arc;
use ic_crypto_internal_csp::vault::api::PublicRandomSeedGeneratorError;
use ic_crypto_internal_csp_proptest_utils::{arb_public_random_seed_generator_error, arb_seed};
use ic_crypto_internal_seed::Seed;
mod common;
use common::proptest_config_for_delegation;
proptest! {
#![proptest_config(proptest_config_for_delegation())]
#[test]
fn should_delegate_for_new_public_seed(
expected_result in maybe_err(arb_seed(), arb_public_random_seed_generator_error())
) {
let mut local_vault = MockLocalCspVault::new();
local_vault
.expect_new_public_seed()
.times(1)
.return_const(expected_result.clone());
let env = RemoteVaultEnvironment::start_server_with_local_csp_vault(Arc::new(local_vault));
let remote_vault = env.new_vault_client();
let result = remote_vault.new_public_seed();
assert_equals_comparing_seeds_indirectly(result, expected_result);
}
}
fn assert_equals_comparing_seeds_indirectly(
actual: Result<Seed, PublicRandomSeedGeneratorError>,
expected: Result<Seed, PublicRandomSeedGeneratorError>,
) {
match (actual, expected) {
(Ok(actual_seed), Ok(expected_seed)) => {
// Seed voluntarily does not implement Eq, PartialEq to avoid extracting the value
// We compare 2 Seeds indirectly by instantiating 2 RNGs and checking we get the same result.
let actual_rng = actual_seed.into_rng();
let expected_rng = expected_seed.into_rng();
assert_eq!(actual_rng, expected_rng);
}
(Err(actual_err), Err(expected_err)) => assert_eq!(actual_err, expected_err),
_ => panic!("unexpected result"),
}
}