Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
fix: resolving failing AE tests
Browse files Browse the repository at this point in the history
As threshold_crypto::SecretKeySet only has the `secret_key` function
for internal test purpose. Meanwhile the SAP requires a `set` to be
generated. Hence the setup of the AE tests become tricky.
  • Loading branch information
maqi authored and Yoga07 committed May 20, 2021
1 parent 6b6788b commit fcdf30a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
33 changes: 21 additions & 12 deletions src/routing/core/anti_entropy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ mod tests {
agreement::test_utils::proven,
crypto,
section::{
test_utils::{gen_addr, gen_section_authority_provider},
test_utils::{
create_section_authority_provider, gen_addr, gen_section_authority_provider,
},
SectionChain,
},
Error, XorName, ELDER_SIZE, MIN_ADULT_AGE,
Expand All @@ -152,7 +154,7 @@ mod tests {
fn everything_up_to_date() -> Result<()> {
let env = Env::new(1)?;

let proof_chain = SectionChain::new(env.their_sk.public_key());
let proof_chain = SectionChain::new(env.their_pk);
let msg = env.create_message(&env.their_prefix, proof_chain)?;
let dest_info = DestInfo {
dest: XorName::random(),
Expand All @@ -177,13 +179,18 @@ mod tests {
fn new_src_key_from_other_section() -> Result<()> {
let env = Env::new(1)?;

let their_old_pk = env.their_sk.public_key();
let root_key =
bls::PublicKey::from_bytes(env.their_sk.public_keys().public_key_share(0).to_bytes())
.unwrap();
let their_new_pk = bls::SecretKey::random().public_key();
let mut proof_chain = SectionChain::new(their_old_pk);
let mut proof_chain = SectionChain::new(root_key);
proof_chain.insert(
&their_old_pk,
&root_key,
their_new_pk,
env.their_sk.sign(&bincode::serialize(&their_new_pk)?),
env.their_sk
.secret_key_share(0)
.sign(&bincode::serialize(&their_new_pk)?)
.0,
)?;

let msg = env.create_message(&env.their_prefix, proof_chain)?;
Expand All @@ -207,7 +214,7 @@ mod tests {
message.variant(),
Variant::SectionKnowledgeQuery { last_known_key, .. } => {
assert!(last_known_key.is_some());
assert_eq!(last_known_key.ok_or(Error::InvalidMessage)?, their_old_pk);
assert_eq!(last_known_key.ok_or(Error::InvalidMessage)?, env.their_pk);
}
);
});
Expand Down Expand Up @@ -254,7 +261,7 @@ mod tests {
fn outdated_dst_key_from_other_section() -> Result<()> {
let env = Env::new(2)?;

let proof_chain = SectionChain::new(env.their_sk.public_key());
let proof_chain = SectionChain::new(env.their_pk);
let msg = env.create_message(&env.their_prefix, proof_chain)?;
let dest_info = DestInfo {
dest: XorName::random(),
Expand Down Expand Up @@ -313,7 +320,8 @@ mod tests {
network: Network,
our_sk: bls::SecretKey,
their_prefix: Prefix,
their_sk: bls::SecretKey,
their_sk: bls::SecretKeySet,
their_pk: bls::PublicKey,
}

impl Env {
Expand All @@ -331,11 +339,11 @@ mod tests {
let section = Section::new(*chain.root_key(), chain, section_auth0)
.context("failed to create section")?;

let (section_auth1, _) = gen_section_authority_provider(prefix1, ELDER_SIZE);
let (section_auth1, _, their_sk) =
create_section_authority_provider(prefix1, ELDER_SIZE);
let their_pk = their_sk.public_keys().public_key();
let section_auth1 = proven(&our_sk, section_auth1)?;

let their_sk = bls::SecretKey::random();

let mut network = Network::new();
assert!(network.update_section(section_auth1, None, section.chain()));

Expand All @@ -346,6 +354,7 @@ mod tests {
our_sk,
their_prefix: prefix1,
their_sk,
their_pk,
})
}

Expand Down
11 changes: 10 additions & 1 deletion src/section/section_authority_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,15 @@ pub(crate) mod test_utils {
prefix: Prefix,
count: usize,
) -> (SectionAuthorityProvider, Vec<Node>) {
let (section_auth, nodes, _) = create_section_authority_provider(prefix, count);
(section_auth, nodes)
}

// Create a random `SectionAuthorityProvider` for testing purposes.
pub(crate) fn create_section_authority_provider(
prefix: Prefix,
count: usize,
) -> (SectionAuthorityProvider, Vec<Node>, bls::SecretKeySet) {
let nodes = gen_sorted_nodes(&prefix, count, false);
let elders = nodes
.iter()
Expand All @@ -265,6 +274,6 @@ pub(crate) mod test_utils {
secret_key_set.public_keys(),
);

(section_auth, nodes)
(section_auth, nodes, secret_key_set)
}
}

0 comments on commit fcdf30a

Please sign in to comment.