diff --git a/container/src/root/test/benchmark/random.hh b/container/src/root/test/benchmark/random.hh index 9d836bb..05116ec 100644 --- a/container/src/root/test/benchmark/random.hh +++ b/container/src/root/test/benchmark/random.hh @@ -128,6 +128,30 @@ BENCHMARK_F(RandomLibsodium, generate)(::benchmark::State& state) // NOLINT random.generate(); } } + +// +// Bitcoin +// + +#ifdef __DFI_PLUGIN_BITCOIN__ +//! \brief Bitcoin Random fixture w/ real implementation +//! \since docker-finance 1.1.0 +struct RandomBitcoin : public ::benchmark::Fixture, + public tests::RandomBitcoin_Impl +{ + void SetUp(const ::benchmark::State& state) {} + void TearDown(const ::benchmark::State& state) {} +}; + +BENCHMARK_F(RandomBitcoin, generate)(::benchmark::State& state) // NOLINT +{ + for (auto st : state) + { + random.generate(); + } +} +#endif + } // namespace benchmarks } // namespace tests } // namespace dfi diff --git a/container/src/root/test/common/random.hh b/container/src/root/test/common/random.hh index 3b83312..ee7e397 100644 --- a/container/src/root/test/common/random.hh +++ b/container/src/root/test/common/random.hh @@ -90,6 +90,18 @@ struct RandomLibsodium_Impl using Random = ::dfi::crypto::libsodium::Random; Random random; }; + +#ifdef __DFI_PLUGIN_BITCOIN__ +//! \brief Bitcoin random implementation fixture +//! \since docker-finance 1.1.0 +struct RandomBitcoin_Impl +{ + protected: + using Random = ::dfi::crypto::bitcoin::Random; + Random random; +}; +#endif + } // namespace tests } // namespace dfi diff --git a/container/src/root/test/unit/random.hh b/container/src/root/test/unit/random.hh index b74e361..ae5c314 100644 --- a/container/src/root/test/unit/random.hh +++ b/container/src/root/test/unit/random.hh @@ -70,6 +70,11 @@ TEST_F(RandomInterface, generate_uint32_t) ASSERT_EQ(random.generate(), std::numeric_limits::max()); } +TEST_F(RandomInterface, generate_uint64_t) +{ + ASSERT_EQ(random.generate(), std::numeric_limits::max()); +} + TEST_F(RandomInterface, generate_int16_t) { ASSERT_EQ(random.generate(), std::numeric_limits::max()); @@ -96,9 +101,13 @@ struct RandomFixture : public ::testing::Test, protected t_impl auto two = t_impl::random.template generate(); static_assert(std::is_same_v); - // NOTE: t_random limits are implementation-specific - ASSERT_NEAR(0, one, std::numeric_limits::max()); - ASSERT_NEAR(0, two, std::numeric_limits::max()); + // TODO(unassigned): gtest implicit conversion of uint64_t with ASSERT_NEAR + if constexpr (!std::is_same_v) + { + // NOTE: t_random limits are implementation-specific + ASSERT_NEAR(0, one, std::numeric_limits::max()); + ASSERT_NEAR(0, two, std::numeric_limits::max()); + } // Exceedingly rare (tests the obvious, but is not an accurate entropy test) // If fails, re-run tests to confirm @@ -176,6 +185,28 @@ TEST_F(RandomLibsodium, generate_uint32_t) ASSERT_NO_THROW(generate()); } +#ifdef __DFI_PLUGIN_BITCOIN__ +// +// Bitcoin +// + +//! \brief Bitcoin random number fixture +//! \since docker-finance 1.1.0 +struct RandomBitcoin : public RandomFixture +{ +}; + +TEST_F(RandomBitcoin, generate_uint32_t) +{ + ASSERT_NO_THROW(generate()); +} + +TEST_F(RandomBitcoin, generate_uint64_t) +{ + ASSERT_NO_THROW(generate()); +} +#endif + } // namespace unit } // namespace tests } // namespace dfi