txgraph: Add internal sanity check function (tests)

To make testing more powerful, expose a function to perform an internal sanity
check on the state of a TxGraph. This is especially important as TxGraphImpl
contains many redundantly represented pieces of information:

* graph contains clusters, which refer to entries, but the entries refer back
* graph maintains pointers to Ref objects, which point back to the graph.

This lets us make sure they are always in sync.
This commit is contained in:
Pieter Wuille
2024-11-14 22:45:46 -05:00
parent 05abf336f9
commit ee57e93099
3 changed files with 134 additions and 0 deletions

View File

@@ -363,6 +363,11 @@ FUZZ_TARGET(txgraph)
}
}
}
// After running all modifications, perform an internal sanity check (before invoking
// inspectors that may modify the internal state).
real->SanityCheck();
// Compare simple properties of the graph with the simulation.
assert(real->GetTransactionCount() == sim.GetTransactionCount());
@@ -411,6 +416,9 @@ FUZZ_TARGET(txgraph)
}
}
// Sanity check again (because invoking inspectors may modify internal unobservable state).
real->SanityCheck();
// Remove all remaining transactions, because Refs cannot be destroyed otherwise (this will be
// addressed in a follow-up commit).
for (auto i : sim.graph.Positions()) {