mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-21 07:39:08 +01:00
Merge bitcoin/bitcoin#30571: test: [refactor] Use m_rng directly
948238a683test: Remove FastRandomContext global (Ryan Ofsky)fa0fe08ecascripted-diff: [test] Use g_rng/m_rng directly (MarcoFalke)fa54cab473test: refactor: Accept any RandomNumberGenerator in RandMoney (MarcoFalke)68f77dd21etest: refactor: Pass rng parameters to test functions (Ryan Ofsky)fa19af555dtest: refactor: Move g_insecure_rand_ctx.Reseed out of the helper that calls MakeRandDeterministicDANGEROUS (MarcoFalke)3dc527f460test: refactor: Give unit test functions access to test state (Ryan Ofsky)fab023e177test: refactor: Make unsigned promotion explicit (MarcoFalke)fa2cb654ectest: Add m_rng alias for the global random context (MarcoFalke)fae7e3791ctest: Correct the random seed log on a prevector test failure (MarcoFalke) Pull request description: This is mostly a style-cleanup for the tests' random generation: 1) `g_insecure_rand_ctx` in the tests is problematic, because the name is a leftover when the generator was indeed insecure. However, now the generator is *deterministic*, because the seed is either passed in or printed (c.f. RANDOM_CTX_SEED). Stating that deterministic randomness is insecure in the tests seems redundant at best. Fix it by just using `m_rng` for the name. 2) The global random context has many one-line aliases, such as `InsecureRand32`. This is problematic, because the same line of code may use the context directly and through a wrapper at the same time. For example in net_tests (see below). This inconsistency is harmless, but confusing. Fix it by just removing the one-line aliases. ``` src/test/net_tests.cpp: auto msg_data_1 = g_insecure_rand_ctx.randbytes<uint8_t>(InsecureRandRange(100000)); ```` 3) The wrapper for randmoney has the same problem that the same unit test uses the context directly and through a wrapper at the same time. Also, it has a single type of Rng hardcoded. Fix it by accepting any type. ACKs for top commit: hodlinator: ACK948238a683ryanofsky: Code review ACK948238a683. Only changes since last review were changing a comments a little bit. marcofleon: Code review ACK948238a683. Only changes since my last review are the improvements in `prevector_tests`. Tree-SHA512: 69c6b46a42cb743138ee8c87ff26a588dbe083e3efb3dca49b8a133ba5d3b09e8bf01c590ec7e121a7d77cb1fd7dcacd927a9ca139ac65e1f7c6d1ec46f93b57
This commit is contained in:
@@ -312,11 +312,11 @@ BOOST_AUTO_TEST_CASE(bip340_test_vectors)
|
||||
// In iteration i=0 we tweak with empty Merkle tree.
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
uint256 merkle_root;
|
||||
if (i) merkle_root = InsecureRand256();
|
||||
if (i) merkle_root = m_rng.rand256();
|
||||
auto tweaked = pubkey.CreateTapTweak(i ? &merkle_root : nullptr);
|
||||
BOOST_CHECK(tweaked);
|
||||
XOnlyPubKey tweaked_key = tweaked->first;
|
||||
aux256 = InsecureRand256();
|
||||
aux256 = m_rng.rand256();
|
||||
bool ok = key.SignSchnorr(msg256, sig64, &merkle_root, aux256);
|
||||
BOOST_CHECK(ok);
|
||||
BOOST_CHECK(tweaked_key.VerifySchnorr(msg256, sig64));
|
||||
@@ -336,7 +336,7 @@ BOOST_AUTO_TEST_CASE(key_ellswift)
|
||||
CKey key = DecodeSecret(secret);
|
||||
BOOST_CHECK(key.IsValid());
|
||||
|
||||
uint256 ent32 = InsecureRand256();
|
||||
uint256 ent32 = m_rng.rand256();
|
||||
auto ellswift = key.EllSwiftCreate(AsBytes(Span{ent32}));
|
||||
|
||||
CPubKey decoded_pubkey = ellswift.Decode();
|
||||
@@ -366,7 +366,7 @@ BOOST_AUTO_TEST_CASE(key_schnorr_tweak_smoke_test)
|
||||
|
||||
CKey key;
|
||||
key.MakeNewKey(true);
|
||||
uint256 merkle_root = InsecureRand256();
|
||||
uint256 merkle_root = m_rng.rand256();
|
||||
|
||||
// secp256k1 functions
|
||||
secp256k1_keypair keypair;
|
||||
|
||||
Reference in New Issue
Block a user