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

Deterministic block generation for tests #5654

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
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
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")
}
}
Loading