Skip to content

Commit

Permalink
improve another_of code
Browse files Browse the repository at this point in the history
  • Loading branch information
oblique committed Sep 29, 2023
1 parent 1f75899 commit f92cb72
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions types/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,15 @@ impl ExtendedHeaderGenerator {
///
/// This method does not change the state of `ExtendedHeaderGenerator`.
pub fn another_of(&self, header: &ExtendedHeader) -> ExtendedHeader {
generate_another_of(header, &self.key)
let mut header = header.to_owned();

header.header.consensus_hash = Hash::Sha256(rand::random());
header.commit.block_id.part_set_header =
parts::Header::new(1, Hash::Sha256(rand::random())).expect("invalid PartSetHeader");

rehash_and_sign(&mut header, &self.key);

header
}

/// Skips an amount of headers.
Expand Down Expand Up @@ -329,13 +337,8 @@ fn generate_next(current: &ExtendedHeader, signing_key: &SigningKey) -> Extended
header
}

fn generate_another_of(header: &ExtendedHeader, signing_key: &SigningKey) -> ExtendedHeader {
let mut header = header.to_owned();

header.header.consensus_hash = Hash::Sha256(rand::random());
header.commit.block_id.part_set_header =
parts::Header::new(1, Hash::Sha256(rand::random())).expect("invalid PartSetHeader");

fn rehash_and_sign(header: &mut ExtendedHeader, signing_key: &SigningKey) {
header.header.data_hash = header.dah.hash();
header.commit.block_id.hash = header.header.hash();

let vote_sign = header
Expand All @@ -350,8 +353,6 @@ fn generate_another_of(header: &ExtendedHeader, signing_key: &SigningKey) -> Ext
{
*signature = Some(Signature::new(sig).unwrap().unwrap());
}

header
}

#[cfg(test)]
Expand Down

0 comments on commit f92cb72

Please sign in to comment.