Deterministic block generation for tests (#5654)

* Deterministic block generation for tests
This commit is contained in:
Lion - dapplion
2024-04-26 22:25:45 +09:00
committed by GitHub
parent 13f94ef0f3
commit a1141ea1ef
2 changed files with 7 additions and 6 deletions

View File

@@ -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()
}
}

View File

@@ -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")
}
}