Page MenuHomePhabricator

Move SetMTP into test utils
ClosedPublic

Authored by sdulfari on Jan 30 2023, 21:35.

Details

Reviewers
PiRK
Group Reviewers
Restricted Project
Commits
rABCd0962fc829e6: Move SetMTP into test utils
Summary

SetMTP is useful for testing any function that takes a block index and does its own activation checks.

It is possible to set MTP in unit tests with a naive implementation like:

for (auto &block : blocks) {
    block.nTime = target_mtp;
}

This works but has the possibly unintended effect of not testing activation boundaries reliably. We should encourage the use of SetMTP over the naive implementation. The first step to doing so is moving it into test utils.

Test Plan
ninja check

Event Timeline

LGTM.

Optional suggestion: len and 12 could be replaced by a single constant. Maybe CBlockIndex::nMedianTimeSpan + 1 could be used somehow, unless it is important that it be a size_t.

This revision is now accepted and ready to land.Jan 31 2023, 20:02
This revision was automatically updated to reflect the committed changes.