Added Merkle tree params tests

This commit is contained in:
SChernykh 2023-11-21 19:20:22 +01:00
parent 13087dd45e
commit aebd9c28f5

View file

@ -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);
}
}
}
}