|
|
|
@ -27,12 +27,7 @@ struct MMRWithLeafset {
|
|
|
|
|
|
|
|
|
|
static mmr::Leaf DeterministicLeaf(const uint64_t i)
|
|
|
|
|
{
|
|
|
|
|
std::vector<uint8_t> serialized{
|
|
|
|
|
uint8_t(i >> 24),
|
|
|
|
|
uint8_t(i >> 16),
|
|
|
|
|
uint8_t(i >> 8),
|
|
|
|
|
uint8_t(i)};
|
|
|
|
|
return mmr::Leaf::Create(mmr::LeafIndex::At(i), serialized);
|
|
|
|
|
return mmr::Leaf::Create(mmr::LeafIndex::At(i), Hasher().Append(i).hash().vec());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static MMRWithLeafset BuildDetermininisticMMR(const uint64_t num_leaves)
|
|
|
|
@ -62,10 +57,10 @@ BOOST_AUTO_TEST_CASE(AssembleSegment)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
std::vector<mw::Hash> expected_leaves{
|
|
|
|
|
DeterministicLeaf(0).GetHash(),
|
|
|
|
|
DeterministicLeaf(1).GetHash(),
|
|
|
|
|
DeterministicLeaf(2).GetHash(),
|
|
|
|
|
DeterministicLeaf(3).GetHash()
|
|
|
|
|
Hasher().Append<uint64_t>(0).hash(),
|
|
|
|
|
Hasher().Append<uint64_t>(1).hash(),
|
|
|
|
|
Hasher().Append<uint64_t>(2).hash(),
|
|
|
|
|
Hasher().Append<uint64_t>(3).hash(),
|
|
|
|
|
};
|
|
|
|
|
BOOST_REQUIRE_EQUAL_COLLECTIONS(segment.leaves.begin(), segment.leaves.end(), expected_leaves.begin(), expected_leaves.end());
|
|
|
|
|
|
|
|
|
@ -78,8 +73,12 @@ BOOST_AUTO_TEST_CASE(AssembleSegment)
|
|
|
|
|
BOOST_REQUIRE_EQUAL(expected_lower_peak, segment.lower_peak);
|
|
|
|
|
|
|
|
|
|
// Verify PMMR root can be fully recomputed
|
|
|
|
|
mw::Hash n2 = MMRUtil::CalcParentHash(mmr::Index::At(2), segment.leaves[0], segment.leaves[1]);
|
|
|
|
|
mw::Hash n5 = MMRUtil::CalcParentHash(mmr::Index::At(5), segment.leaves[2], segment.leaves[3]);
|
|
|
|
|
mw::Hash n0 = mmr::Leaf::CalcHash(mmr::LeafIndex::At(0), segment.leaves[0].vec());
|
|
|
|
|
mw::Hash n1 = mmr::Leaf::CalcHash(mmr::LeafIndex::At(1), segment.leaves[1].vec());
|
|
|
|
|
mw::Hash n2 = MMRUtil::CalcParentHash(mmr::Index::At(2), n0, n1);
|
|
|
|
|
mw::Hash n3 = mmr::Leaf::CalcHash(mmr::LeafIndex::At(2), segment.leaves[2].vec());
|
|
|
|
|
mw::Hash n4 = mmr::Leaf::CalcHash(mmr::LeafIndex::At(3), segment.leaves[3].vec());
|
|
|
|
|
mw::Hash n5 = MMRUtil::CalcParentHash(mmr::Index::At(5), n3, n4);
|
|
|
|
|
mw::Hash n6 = MMRUtil::CalcParentHash(mmr::Index::At(6), n2, n5);
|
|
|
|
|
mw::Hash n14 = MMRUtil::CalcParentHash(mmr::Index::At(14), n6, segment.hashes[0]);
|
|
|
|
|
mw::Hash root = MMRUtil::CalcParentHash(Index::At(26), n14, *segment.lower_peak);
|
|
|
|
|