MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / TestDepGraphSerialization

Function TestDepGraphSerialization

src/test/cluster_linearize_tests.cpp:27–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25
26template<typename SetType>
27void TestDepGraphSerialization(const std::vector<std::pair<FeeFrac, SetType>>& cluster, const std::string& hexenc)
28{
29 // Construct DepGraph from cluster argument.
30 DepGraph<SetType> depgraph;
31 SetType holes;
32 for (DepGraphIndex i = 0; i < cluster.size(); ++i) {
33 depgraph.AddTransaction(cluster[i].first);
34 if (cluster[i] == HOLE) holes.Set(i);
35 }
36 for (DepGraphIndex i = 0; i < cluster.size(); ++i) {
37 depgraph.AddDependencies(cluster[i].second, i);
38 }
39 depgraph.RemoveTransactions(holes);
40 SanityCheck(depgraph);
41
42 // There may be multiple serializations of the same graph, but DepGraphFormatter's serializer
43 // only produces one of those. Verify that hexenc matches that canonical serialization.
44 std::vector<unsigned char> encoding;
45 VectorWriter writer(encoding, 0);
46 writer << Using<DepGraphFormatter>(depgraph);
47 BOOST_CHECK_EQUAL(HexStr(encoding), hexenc);
48
49 // Test that deserializing that encoding yields depgraph. This is effectively already implied
50 // by the round-trip test above (if depgraph is acyclic), but verify it explicitly again here.
51 SpanReader reader(encoding);
52 DepGraph<SetType> depgraph_read;
53 reader >> Using<DepGraphFormatter>(depgraph_read);
54 BOOST_CHECK(depgraph == depgraph_read);
55}
56
57void TestOptimalLinearization(std::span<const uint8_t> enc, std::initializer_list<DepGraphIndex> optimal_linearization)
58{

Callers

nothing calls this directly

Calls 7

SanityCheckFunction · 0.85
RemoveTransactionsMethod · 0.80
HexStrFunction · 0.50
sizeMethod · 0.45
AddTransactionMethod · 0.45
SetMethod · 0.45
AddDependenciesMethod · 0.45

Tested by

no test coverage detected