MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / BOOST_AUTO_TEST_CASE

Function BOOST_AUTO_TEST_CASE

src/test/finalization_tests.cpp:16–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14BOOST_FIXTURE_TEST_SUITE(finalization_tests, TestChain100Setup)
15
16BOOST_AUTO_TEST_CASE(minfinalizationage) {
17 CScript p2pk_scriptPubKey =
18 CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;
19 CBlock block;
20
21 {
22 LOCK(cs_main);
23 // We should have no finalized block because the 100 blocks generated by
24 // the test setup are too close to "now";
25 BOOST_CHECK_MESSAGE(GetFinalizedBlock() == nullptr,
26 "No block finalized (tip at height "
27 << chainActive.Tip()->nHeight << ")");
28 }
29
30 // Create minfinalizationdepth blocks. Auto-finalization will not occur because
31 // the delay is not expired
32 int64_t mockedTime = GetTime();
33 for (uint32_t i = 0; i < DEFAULT_MAX_REORG_DEPTH; i++) {
34 block = CreateAndProcessBlock({}, p2pk_scriptPubKey);
35 LOCK(cs_main);
36 // These blocks are too recent.
37 BOOST_CHECK_MESSAGE(GetFinalizedBlock() == nullptr,
38 "No block finalized (tip at height "
39 << chainActive.Tip()->nHeight << ")");
40 }
41
42 // Make the finalization time to expire
43 mockedTime += DEFAULT_MIN_FINALIZATION_DELAY + 1;
44 SetMockTime(mockedTime);
45
46 // Next minfinalizationdepth blocks should cause auto-finalization
47 CBlockIndex *blockToFinalize = chainActive.Tip()->GetAncestor(
48 chainActive.Tip()->nHeight - DEFAULT_MAX_REORG_DEPTH);
49
50 for (uint32_t i = 0; i < DEFAULT_MAX_REORG_DEPTH; i++) {
51 blockToFinalize = chainActive.Next(blockToFinalize);
52 block = CreateAndProcessBlock({}, p2pk_scriptPubKey);
53 LOCK(cs_main);
54 BOOST_CHECK_MESSAGE(GetFinalizedBlock() == blockToFinalize,
55 "Block finalized at height "
56 << blockToFinalize->nHeight
57 << " (tip at height "
58 << chainActive.Tip()->nHeight << ")");
59 }
60
61 // Next blocks won't cause auto-finalization because the delay is not
62 // expired
63 for (uint32_t i = 0; i < DEFAULT_MAX_REORG_DEPTH; i++) {
64 block = CreateAndProcessBlock({}, p2pk_scriptPubKey);
65 LOCK(cs_main);
66 // These blocks are finalized.
67 BOOST_CHECK_MESSAGE(GetFinalizedBlock() == blockToFinalize,
68 "Finalized block remains unchanged at height "
69 << blockToFinalize->nHeight
70 << " (tip at height "
71 << chainActive.Tip()->nHeight << ")");
72 }
73

Callers

nothing calls this directly

Calls 9

ToByteVectorFunction · 0.85
GetFinalizedBlockFunction · 0.85
GetTimeFunction · 0.85
SetMockTimeFunction · 0.85
GetAncestorMethod · 0.80
CScriptClass · 0.70
GetPubKeyMethod · 0.45
TipMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected