Skip to content

Commit

Permalink
Added Merkle tree params tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SChernykh committed Nov 21, 2023
1 parent 13087dd commit aebd9c2
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tests/src/merkle_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "common.h"
#include "keccak.h"
#include "merkle.h"
#include "pool_block.h"
#include "gtest/gtest.h"

namespace p2pool {
Expand Down Expand Up @@ -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";

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

}

0 comments on commit aebd9c2

Please sign in to comment.