Skip to content

Commit

Permalink
Simplify testing RNG code
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa committed Dec 12, 2018
1 parent fd3e797 commit 022cf47
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/test/prevector_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ class prevector_tester {

prevector_tester() {
SeedInsecureRand();
rand_seed = insecure_rand_seed;
rand_cache = insecure_rand_ctx;
rand_seed = InsecureRand256();
rand_cache = FastRandomContext(rand_seed);
}
};

Expand Down
3 changes: 1 addition & 2 deletions src/test/test_bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ void CConnmanTest::ClearNodes()
g_connman->vNodes.clear();
}

uint256 insecure_rand_seed = GetRandHash();
FastRandomContext insecure_rand_ctx(insecure_rand_seed);
FastRandomContext insecure_rand_ctx;

extern bool fPrintToConsole;
extern void noui_connect();
Expand Down
10 changes: 2 additions & 8 deletions src/test/test_bitcoin.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,11 @@ std::ostream& operator<<(typename std::enable_if<std::is_enum<T>::value, std::os
return stream << static_cast<typename std::underlying_type<T>::type>(e);
}

extern uint256 insecure_rand_seed;
extern FastRandomContext insecure_rand_ctx;

static inline void SeedInsecureRand(bool fDeterministic = false)
static inline void SeedInsecureRand(bool deterministic = false)
{
if (fDeterministic) {
insecure_rand_seed = uint256();
} else {
insecure_rand_seed = GetRandHash();
}
insecure_rand_ctx = FastRandomContext(insecure_rand_seed);
insecure_rand_ctx = FastRandomContext(deterministic);
}

static inline uint32_t InsecureRand32() { return insecure_rand_ctx.rand32(); }
Expand Down

0 comments on commit 022cf47

Please sign in to comment.