Make another instance of Gen[ECPrivateKey] be deterministic (#5353)

* Make another instance of Gen[ECPrivateKey] be deterministic

* Revert CommonSettings.scala
This commit is contained in:
Chris Stewart 2024-01-14 12:01:06 -06:00 committed by GitHub
parent 63b1f05b2e
commit deb79c5994
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -127,7 +127,16 @@ sealed abstract class CryptoGenerators {
pass <- bip39Password
} yield BIP39Seed.fromMnemonic(code, pass)
def privateKey: Gen[ECPrivateKey] = Gen.delay(ECPrivateKey())
def privateKey: Gen[ECPrivateKey] = {
//purposefully don't reach for cryptographically strong
//number generation, we want determinism to reproduce failed
//test cases. If we don't generate the private key with scalacheck
//we won't be able to reproduce the test case with a seed
//see: https://github.com/bitcoin-s/bitcoin-s/issues/1339
NumberGenerator.bytevector(32).map { vec =>
ECPrivateKey.fromBytes(vec)
}
}
def fieldElement: Gen[FieldElement] = privateKey.map(_.fieldElement)