Skip to content

Commit f3e2832

Browse files
committed
Fully derive root_electrumx_cp8 for merkle tests.
1 parent 2462526 commit f3e2832

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

test/query/merkle.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,23 @@ BOOST_FIXTURE_TEST_SUITE(query_merkle_tests, test::directory_setup_fixture)
2525
// nop event handler.
2626
const auto events_handler = [](auto, auto) {};
2727

28-
// Merkle root of test blocks [0..1]
29-
constexpr auto root01 = system::base16_hash("abdc2227d02d114b77be15085c1257709252a7a103f9ac0ab3c85d67e12bc0b8");
28+
constexpr auto root01 = system::sha256::double_hash(test::block0_hash, test::block1_hash);
29+
constexpr auto root23 = system::sha256::double_hash(test::block2_hash, test::block3_hash);
30+
constexpr auto root03 = system::sha256::double_hash(root01, root23);
31+
constexpr auto root45 = system::sha256::double_hash(test::block4_hash, test::block5_hash);
32+
constexpr auto root67 = system::sha256::double_hash(test::block6_hash, test::block7_hash);
33+
constexpr auto root47 = system::sha256::double_hash(root45, root67);
34+
constexpr auto root07 = system::sha256::double_hash(root03, root47);
3035

31-
// Merkle root of test blocks [2..4]
32-
constexpr auto root02 = system::base16_hash("f2a2a2907abb326726a2d6500fe494f63772a941b414236c302e920bc1aa9caf");
36+
constexpr auto root82 = system::sha256::double_hash(test::block8_hash, test::block8_hash);
37+
constexpr auto root84 = system::sha256::double_hash(root82, root82);
38+
constexpr auto root88 = system::sha256::double_hash(root84, root84);
3339

34-
// Merkle root of test blocks [0..4]
35-
constexpr auto root04 = system::sha256::double_hash(root01, root02);
40+
constexpr auto root08 = system::sha256::double_hash(root07, root88);
41+
42+
// electrumx.readthedocs.io/en/latest/protocol-methods.html#cp-height-example
43+
constexpr auto root_electrumx_cp8 = system::base16_hash("e347b1c43fd9b5415bf0d92708db8284b78daf4d0e24f9c3405f45feb85e25db");
44+
static_assert(root08 == root_electrumx_cp8);
3645

3746
class merkle_accessor
3847
: public test::query_accessor
@@ -144,7 +153,7 @@ BOOST_AUTO_TEST_CASE(query_merkle__create_interval__depth_1__expected)
144153
BOOST_REQUIRE(!query.create_interval(header2, 2).has_value());
145154
BOOST_REQUIRE( query.create_interval(header3, 3).has_value());
146155
BOOST_REQUIRE_EQUAL(query.create_interval(header1, 1).value(), root01);
147-
BOOST_REQUIRE_EQUAL(query.create_interval(header3, 3).value(), root02);
156+
BOOST_REQUIRE_EQUAL(query.create_interval(header3, 3).value(), root23);
148157
}
149158

150159
BOOST_AUTO_TEST_CASE(query_merkle__create_interval__depth_2__expected)
@@ -163,7 +172,7 @@ BOOST_AUTO_TEST_CASE(query_merkle__create_interval__depth_2__expected)
163172
const auto header3 = query.to_header(test::block3.hash());
164173
BOOST_REQUIRE(!header3.is_terminal());
165174
BOOST_REQUIRE(query.create_interval(header3, 3).has_value());
166-
BOOST_REQUIRE_EQUAL(query.create_interval(header3, 3).value(), root04);
175+
BOOST_REQUIRE_EQUAL(query.create_interval(header3, 3).value(), root03);
167176
}
168177

169178
// get_confirmed_interval

0 commit comments

Comments
 (0)