Skip to content

Commit

Permalink
Fix non-deterministic coverage of test DoS_mapOrphans
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuzzbawls committed Apr 14, 2021
1 parent 79e7fd3 commit 22a7121
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion contrib/devtools/test_deterministic_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ GCOV_EXECUTABLE="gcov"

# Disable tests known to cause non-deterministic behaviour and document the source or point of non-determinism.
NON_DETERMINISTIC_TESTS=(
"DoS_tests/DoS_mapOrphans" # RandomOrphan()
"dummy_tests" # We currently don't have any unit tests that have determinism issues
)

TEST_BITCOIN_BINARY="src/test/test_pivx"
Expand Down
20 changes: 19 additions & 1 deletion src/test/DoS_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

#include "test/test_pivx.h"

#include "arith_uint256.h"
#include "keystore.h"
#include "net_processing.h"
#include "net.h"
#include "pubkey.h"
#include "pow.h"
#include "script/sign.h"
#include "serialize.h"
Expand Down Expand Up @@ -139,10 +141,26 @@ CTransactionRef RandomOrphan()
return it->second.tx;
}

static void MakeNewKeyWithFastRandomContext(CKey& key)
{
std::vector<unsigned char> keydata;
keydata = insecure_rand_ctx.randbytes(32);
key.Set(keydata.data(), keydata.data() + keydata.size(), /*fCompressedIn*/ true);
assert(key.IsValid());
}

BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
{
// This test had non-deterministic coverage due to
// randomly selected seeds.
// This seed is chosen so that all branches of the function
// ecdsa_signature_parse_der_lax are executed during this test.
// Specifically branches that run only when an ECDSA
// signature's R and S values have leading zeros.
insecure_rand_ctx = FastRandomContext(ArithToUint256(arith_uint256(33)));

CKey key;
key.MakeNewKey(true);
MakeNewKeyWithFastRandomContext(key);
CBasicKeyStore keystore;
keystore.AddKey(key);

Expand Down

0 comments on commit 22a7121

Please sign in to comment.