CI: added more tests
This commit is contained in:
@@ -26,6 +26,12 @@ namespace p2pool {
|
||||
void merkle_hash(const std::vector<hash>& hashes, root_hash& root)
|
||||
{
|
||||
const size_t count = hashes.size();
|
||||
|
||||
if (count == 0) {
|
||||
root.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
const uint8_t* h = hashes[0].h;
|
||||
|
||||
if (count == 1) {
|
||||
@@ -62,10 +68,15 @@ void merkle_hash(const std::vector<hash>& hashes, root_hash& root)
|
||||
void merkle_hash_full_tree(const std::vector<hash>& hashes, std::vector<std::vector<hash>>& tree)
|
||||
{
|
||||
const size_t count = hashes.size();
|
||||
const uint8_t* h = hashes[0].h;
|
||||
|
||||
tree.clear();
|
||||
|
||||
if (count == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const uint8_t* h = hashes[0].h;
|
||||
|
||||
if (count == 1) {
|
||||
tree.push_back(hashes);
|
||||
}
|
||||
|
||||
@@ -175,6 +175,8 @@ template<> FORCEINLINE bool out_of_range<uint64_t>(uint64_t) { return false; }
|
||||
template<typename T>
|
||||
const uint8_t* readVarint(const uint8_t* data, const uint8_t* data_end, T& b)
|
||||
{
|
||||
static_assert(std::is_unsigned_v<T>, "readVarint works only with unsigned types");
|
||||
|
||||
uint64_t result = 0;
|
||||
int k = 0;
|
||||
|
||||
|
||||
@@ -236,6 +236,7 @@ TEST(block_template, submit_sidechain_block)
|
||||
|
||||
ASSERT_EQ(sidechain.difficulty(), 219467);
|
||||
ASSERT_EQ(sidechain.blocksById().size(), 4487);
|
||||
ASSERT_TRUE(sidechain.precalcFinished());
|
||||
|
||||
const PoolBlock* tip = sidechain.chainTip();
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ using namespace p2pool;
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
set_main_thread();
|
||||
p2pool_usage();
|
||||
|
||||
PoolBlock::s_precalculatedSharesLock = new ReadWriteLock();
|
||||
|
||||
|
||||
@@ -168,6 +168,17 @@ TEST(merkle, tree)
|
||||
}
|
||||
};
|
||||
|
||||
// 0 leaves
|
||||
uint32_t path_monero;
|
||||
ASSERT_FALSE(tree_path(0, 0, &path_monero));
|
||||
|
||||
merkle_hash(std::vector<hash>(), root);
|
||||
ASSERT_TRUE(root.empty());
|
||||
|
||||
std::vector<std::vector<hash>> tree;
|
||||
merkle_hash_full_tree(std::vector<hash>(), tree);
|
||||
ASSERT_TRUE(tree.empty());
|
||||
|
||||
// 1 leaf
|
||||
merkle_hash(hashes, root);
|
||||
ASSERT_EQ(root, input[0]);
|
||||
|
||||
@@ -80,6 +80,16 @@ TEST(util, varint)
|
||||
// Invalid value 2
|
||||
uint8_t buf2[1] = { 0x80 };
|
||||
ASSERT_EQ(readVarint(buf2, buf2 + 1, check), nullptr);
|
||||
|
||||
// Invalid value 3
|
||||
uint8_t buf3[16];
|
||||
memset(buf3, 128, sizeof(buf3));
|
||||
ASSERT_EQ(readVarint(buf3, buf3 + sizeof(buf3), check), nullptr);
|
||||
|
||||
// Invalid value 4
|
||||
uint32_t check2;
|
||||
uint8_t buf4[] = {255, 255, 255, 255, 127};
|
||||
ASSERT_EQ(readVarint(buf4, buf4 + sizeof(buf4), check2), nullptr);
|
||||
}
|
||||
|
||||
TEST(util, bsr)
|
||||
|
||||
Reference in New Issue
Block a user