From 3f902b0569d68a8a7125f22606e95c11daec4c30 Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Fri, 25 Jan 2019 15:02:21 -0500 Subject: [PATCH] Add ComputeFastMerkleRoot unit test example generated by elements-0.14.1 --- src/test/merkle_tests.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/test/merkle_tests.cpp b/src/test/merkle_tests.cpp index 5e55ad6622..8046449f9c 100644 --- a/src/test/merkle_tests.cpp +++ b/src/test/merkle_tests.cpp @@ -249,4 +249,25 @@ BOOST_AUTO_TEST_CASE(merkle_test) } } +// ELEMENTS +// Test fast merkle root calculations used in witness merkle tree calculation, +// and asset issuance derivation +BOOST_AUTO_TEST_CASE(fast_merkle_test) +{ + + // generated using elements-0.14.1 implementation: + std::vector test_leaves = { uint256S("b66b041650db0f297b53f8d93c0e8706925bf3323f8c59c14a6fac37bfdcd06f"), uint256S("99cb2fa68b2294ae133550a9f765fc755d71baa7b24389fed67d1ef3e5cb0255"), uint256S("257e1b2fa49dd15724c67bac4df7911d44f6689860aa9f65a881ae0a2f40a303"), uint256S("b67b0b9f093fa83d5e44b707ab962502b7ac58630e556951136196e65483bb80") }; + + std::vector test_roots = { uint256S("0000000000000000000000000000000000000000000000000000000000000000"), uint256S("b66b041650db0f297b53f8d93c0e8706925bf3323f8c59c14a6fac37bfdcd06f"), uint256S("f752938da0cb71c051aabdd5a86658e8d0b7ac00e1c2074202d8d2a79d8a6cf6"), uint256S("245d364a28e9ad20d522c4a25ffc6a7369ab182f884e1c7dcd01aa3d32896bd3"), uint256S("317d6498574b6ca75ee0368ec3faec75e096e245bdd5f36e8726fa693f775dfc") }; + + std::vector leaves; + + for (unsigned int i = 0; i < 4; i++) { + uint256 root = ComputeFastMerkleRoot(leaves); + BOOST_CHECK(root == test_roots[i]); + leaves.push_back(test_leaves[i]); + } + BOOST_CHECK(ComputeFastMerkleRoot(leaves) == test_roots.back()); +} + BOOST_AUTO_TEST_SUITE_END()