test(miniscript): Check for depth rather than script size

CI failure due to default ~Node() implementation has been confirmed on Windows native, MacOS native, 32-bit ARM, ASan+LSan+UBSan+integer, i686, TSan, MSan. (Not on Alpine as that runs without CI_LIMIT_STACK_SIZE).

Co-authored-by: Antoine Poinsot <darosior@protonmail.com>
Co-authored-by: Lőrinc <pap.lorinc@gmail.com>
This commit is contained in:
Hodlinator
2026-02-05 12:02:15 +01:00
parent 5af5e87646
commit 39e3295c71

View File

@@ -734,18 +734,33 @@ BOOST_AUTO_TEST_CASE(node_stress_stack)
using miniscript::Fragment;
using NodeU32 = miniscript::Node<uint32_t>;
const auto compute_depth{[] (const NodeU32& node) -> size_t {
size_t depth{0};
for (const auto* n{&node}; !n->Subs().empty(); n = &n->Subs().front()) {
++depth;
}
return depth;
}};
constexpr auto ctx{miniscript::MiniscriptContext::TAPSCRIPT};
NodeU32 root{NoDupCheck{}, ctx, Fragment::JUST_1};
for (uint32_t i{0}; i < 200'000; ++i) {
// Some CI jobs run with CI_LIMIT_STACK_SIZE which reduces the stack size
// via ulimit to 512 kbytes. When tested with ~Node()=default (stack-unsafe)
// implementations the test has been shown to fail for the below depth.
// The test may pass locally despite stack-unsafe implementations unless the
// stack is reduced in a similar way or the depth is temporarily increased.
constexpr size_t depth{200'000};
for (size_t i{0}; i < depth; ++i) {
root = NodeU32{NoDupCheck{}, ctx, Fragment::WRAP_N, Vector(std::move(root))};
}
BOOST_CHECK(root.IsValid());
BOOST_CHECK_EQUAL(root.ScriptSize(), 200'001);
BOOST_CHECK_EQUAL(compute_depth(root), depth);
auto clone{root.Clone()};
BOOST_CHECK_EQUAL(clone.ScriptSize(), root.ScriptSize());
BOOST_CHECK_EQUAL(compute_depth(clone), depth);
clone = std::move(root);
BOOST_CHECK_EQUAL(compute_depth(clone), depth);
}
BOOST_AUTO_TEST_SUITE_END()