From aebd9c28f5cb062de4d6be52ebda51416a9a2c42 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Tue, 21 Nov 2023 19:20:22 +0100 Subject: [PATCH] Added Merkle tree params tests --- tests/src/merkle_tests.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/src/merkle_tests.cpp b/tests/src/merkle_tests.cpp index 609a7ae..420325c 100644 --- a/tests/src/merkle_tests.cpp +++ b/tests/src/merkle_tests.cpp @@ -18,6 +18,7 @@ #include "common.h" #include "keccak.h" #include "merkle.h" +#include "pool_block.h" #include "gtest/gtest.h" namespace p2pool { @@ -249,7 +250,7 @@ TEST(merkle, aux_nonce) uint32_t nonce; ASSERT_TRUE(find_aux_nonce(aux_id, nonce)); - ASSERT_EQ(nonce, 0); + ASSERT_EQ(nonce, 0U); uint8_t data[] = "aux0"; @@ -273,4 +274,24 @@ TEST(merkle, aux_nonce) ASSERT_FALSE(find_aux_nonce(aux_id, nonce)); } +TEST(merkle, params) +{ + ASSERT_EQ(PoolBlock::encode_merkle_tree_data(1, 0), 0U); + ASSERT_EQ(PoolBlock::encode_merkle_tree_data(1, 0xFFFFFFFFU), 0xFFFFFFFF0ULL); + ASSERT_EQ(PoolBlock::encode_merkle_tree_data(127, 0), 0x3F6U); + ASSERT_EQ(PoolBlock::encode_merkle_tree_data(127, 0xFFFFFFFFU), 0x3FFFFFFFFF6ULL); + + for (uint32_t n_aux_chains = 1; n_aux_chains < 128; ++n_aux_chains) { + for (uint32_t nonce = 1; nonce; nonce <<= 1) { + PoolBlock b; + b.m_merkleTreeData = PoolBlock::encode_merkle_tree_data(n_aux_chains, nonce); + + uint32_t n1, nonce1; + b.decode_merkle_tree_data(n1, nonce1); + ASSERT_EQ(n1, n_aux_chains); + ASSERT_EQ(nonce1, nonce); + } + } +} + }