Skip to content

Commit

Permalink
Deterministic block generation for tests (#5654)
Browse files Browse the repository at this point in the history
* Deterministic block generation for tests
  • Loading branch information
dapplion authored Apr 26, 2024
1 parent 13f94ef commit a1141ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 2 additions & 0 deletions consensus/types/src/test_utils/test_random/secret_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use super::*;

impl TestRandom for SecretKey {
fn random_for_test(_rng: &mut impl RngCore) -> Self {
// TODO: Not deterministic generation. Using `SecretKey::deserialize` results in
// `BlstError(BLST_BAD_ENCODING)`, need to debug with blst source on what encoding expects.
SecretKey::random()
}
}
11 changes: 5 additions & 6 deletions consensus/types/src/test_utils/test_random/signature.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use super::*;

impl TestRandom for Signature {
fn random_for_test(rng: &mut impl RngCore) -> Self {
let secret_key = SecretKey::random_for_test(rng);
let mut message = vec![0; 32];
rng.fill_bytes(&mut message);

secret_key.sign(Hash256::from_slice(&message))
fn random_for_test(_rng: &mut impl RngCore) -> Self {
// TODO: `SecretKey::random_for_test` does not return a deterministic signature. Since this
// signature will not pass verification we could just return the generator point or the
// generator point multiplied by a random scalar if we want disctint signatures.
Signature::infinity().expect("infinity signature is valid")
}
}

0 comments on commit a1141ea

Please sign in to comment.