Allow manually configured zero work multipliers for testing
This commit is contained in:
parent
41ce5bb46e
commit
83f8a931fd
4 changed files with 11 additions and 19 deletions
|
|
@ -10,11 +10,8 @@
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
TEST (difficultyDeathTest, multipliers)
|
TEST (difficulty, multipliers)
|
||||||
{
|
{
|
||||||
// For ASSERT_DEATH_IF_SUPPORTED
|
|
||||||
testing::FLAGS_gtest_death_test_style = "threadsafe";
|
|
||||||
|
|
||||||
{
|
{
|
||||||
uint64_t base = 0xff00000000000000;
|
uint64_t base = 0xff00000000000000;
|
||||||
uint64_t difficulty = 0xfff27e7a57c285cd;
|
uint64_t difficulty = 0xfff27e7a57c285cd;
|
||||||
|
|
@ -51,19 +48,14 @@ TEST (difficultyDeathTest, multipliers)
|
||||||
ASSERT_EQ (difficulty, nano::difficulty::from_multiplier (expected_multiplier, base));
|
ASSERT_EQ (difficulty, nano::difficulty::from_multiplier (expected_multiplier, base));
|
||||||
}
|
}
|
||||||
|
|
||||||
// The death checks don't fail on a release config, so guard against them
|
|
||||||
#ifndef NDEBUG
|
|
||||||
// Causes valgrind to be noisy
|
|
||||||
if (!nano::running_within_valgrind ())
|
|
||||||
{
|
{
|
||||||
uint64_t base = 0xffffffc000000000;
|
uint64_t base = 0xffffffc000000000;
|
||||||
uint64_t difficulty_nil = 0;
|
uint64_t difficulty_nil = 0;
|
||||||
double multiplier_nil = 0.;
|
double multiplier_nil = 0.;
|
||||||
|
|
||||||
ASSERT_DEATH_IF_SUPPORTED (nano::difficulty::to_multiplier (difficulty_nil, base), "");
|
ASSERT_EQ (0., nano::difficulty::to_multiplier (difficulty_nil, base));
|
||||||
ASSERT_DEATH_IF_SUPPORTED (nano::difficulty::from_multiplier (multiplier_nil, base), "");
|
ASSERT_EQ (0, nano::difficulty::from_multiplier (multiplier_nil, base));
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST (difficulty, overflow)
|
TEST (difficulty, overflow)
|
||||||
|
|
|
||||||
|
|
@ -129,11 +129,6 @@ TEST (unchecked, simple)
|
||||||
TEST (unchecked, multiple)
|
TEST (unchecked, multiple)
|
||||||
{
|
{
|
||||||
nano::test::system system{};
|
nano::test::system system{};
|
||||||
if (nano::rocksdb_config::using_rocksdb_in_tests ())
|
|
||||||
{
|
|
||||||
// Don't test this in rocksdb mode
|
|
||||||
GTEST_SKIP ();
|
|
||||||
}
|
|
||||||
nano::unchecked_map unchecked{ max_unchecked_blocks, system.stats, false };
|
nano::unchecked_map unchecked{ max_unchecked_blocks, system.stats, false };
|
||||||
nano::block_builder builder;
|
nano::block_builder builder;
|
||||||
auto block = builder
|
auto block = builder
|
||||||
|
|
|
||||||
|
|
@ -168,7 +168,6 @@ double nano::work_thresholds::denormalized_multiplier (double const multiplier_a
|
||||||
if (threshold_a == epoch_1 || threshold_a == epoch_2_receive)
|
if (threshold_a == epoch_1 || threshold_a == epoch_2_receive)
|
||||||
{
|
{
|
||||||
auto ratio (nano::difficulty::to_multiplier (epoch_2, threshold_a));
|
auto ratio (nano::difficulty::to_multiplier (epoch_2, threshold_a));
|
||||||
debug_assert (ratio >= 1);
|
|
||||||
multiplier = multiplier * ratio + 1.0 - ratio;
|
multiplier = multiplier * ratio + 1.0 - ratio;
|
||||||
debug_assert (multiplier >= 1);
|
debug_assert (multiplier >= 1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -805,7 +805,10 @@ std::ostream & nano::operator<< (std::ostream & os, const nano::account & val)
|
||||||
|
|
||||||
uint64_t nano::difficulty::from_multiplier (double const multiplier_a, uint64_t const base_difficulty_a)
|
uint64_t nano::difficulty::from_multiplier (double const multiplier_a, uint64_t const base_difficulty_a)
|
||||||
{
|
{
|
||||||
debug_assert (multiplier_a > 0.);
|
if (multiplier_a <= 0.)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
nano::uint128_t reverse_difficulty ((-base_difficulty_a) / multiplier_a);
|
nano::uint128_t reverse_difficulty ((-base_difficulty_a) / multiplier_a);
|
||||||
if (reverse_difficulty > std::numeric_limits<std::uint64_t>::max ())
|
if (reverse_difficulty > std::numeric_limits<std::uint64_t>::max ())
|
||||||
{
|
{
|
||||||
|
|
@ -823,7 +826,10 @@ uint64_t nano::difficulty::from_multiplier (double const multiplier_a, uint64_t
|
||||||
|
|
||||||
double nano::difficulty::to_multiplier (uint64_t const difficulty_a, uint64_t const base_difficulty_a)
|
double nano::difficulty::to_multiplier (uint64_t const difficulty_a, uint64_t const base_difficulty_a)
|
||||||
{
|
{
|
||||||
debug_assert (difficulty_a > 0);
|
if (difficulty_a == 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return static_cast<double> (-base_difficulty_a) / (-difficulty_a);
|
return static_cast<double> (-base_difficulty_a) / (-difficulty_a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue