Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing get_last_timestamps_shamir test for CertificateOps #9010

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 91 additions & 2 deletions libparsec/crates/client/tests/unit/certif/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,96 @@ async fn get_realm_bootstrap_state(env: &TestbedEnv) {
}

#[parsec_test(testbed = "minimal")]
#[ignore]
async fn get_last_timestamps_shamir(env: &TestbedEnv) {
// TODO: Shamir not implemented yet !
env.customize(|builder| {
builder.new_user("bob");
builder.new_shamir_recovery(
"alice",
1,
[("bob".parse().unwrap(), 1.try_into().unwrap())],
"alice@dev1",
);
})
.await;

let alice = env.local_device("alice@dev1");
let store = certificates_store_factory(env, &alice).await;

// Retrieve Alice's shamir recovery brief certificate
let (certif, signed) = env
.template
.certificates()
.find_map(|event| match &event.certificate {
AnyArcCertificate::ShamirRecoveryBrief(certif) => {
if certif.user_id == alice.user_id {
Some((certif.clone(), event.signed.clone()))
} else {
None
}
}
_ => None,
})
.unwrap();

macro_rules! store_get_last_timestamps {
($store:ident) => {
$store.for_read(|store| async move { store.get_last_timestamps().await })
};
}

let got = store_get_last_timestamps!(store).await.unwrap().unwrap();
assert_eq!(
got,
PerTopicLastTimestamps {
common: None,
sequester: None,
realm: HashMap::default(),
shamir_recovery: None,
}
);

store
.for_write({
let certif = certif.clone();
|store| async move {
store
.add_next_shamir_recovery_certificate(
ShamirRecoveryTopicArcCertificate::ShamirRecoveryBrief(certif),
&signed,
)
.await
}
})
.await
.unwrap()
.unwrap();

// Check the timestamps has changed

let got = store_get_last_timestamps!(store).await.unwrap().unwrap();
assert_eq!(
got,
PerTopicLastTimestamps {
common: None,
sequester: None,
realm: HashMap::default(),
shamir_recovery: Some(certif.timestamp),
}
);

store.stop().await.unwrap();

// Ensure we don't rely on a cache but on data in persistent database

let store = certificates_store_factory(env, &alice).await;
let got = store_get_last_timestamps!(store).await.unwrap().unwrap();
assert_eq!(
got,
PerTopicLastTimestamps {
common: None,
sequester: None,
realm: HashMap::default(),
shamir_recovery: Some(certif.timestamp),
}
);
}
Loading