2
2
3
3
#include " stdlib.h"
4
4
5
- #include " rpc/blockchain.cpp "
5
+ #include " rpc/blockchain.h "
6
6
#include " test/test_bitcoin.h"
7
7
8
8
/* Equality between doubles is imprecise. Comparison should be done
@@ -22,14 +22,6 @@ static CBlockIndex* CreateBlockIndexWithNbits(uint32_t nbits)
22
22
return block_index;
23
23
}
24
24
25
- static CChain CreateChainWithNbits (uint32_t nbits)
26
- {
27
- CBlockIndex* block_index = CreateBlockIndexWithNbits (nbits);
28
- CChain chain;
29
- chain.SetTip (block_index);
30
- return chain;
31
- }
32
-
33
25
static void RejectDifficultyMismatch (double difficulty, double expected_difficulty) {
34
26
BOOST_CHECK_MESSAGE (
35
27
DoubleEquals (difficulty, expected_difficulty, 0.00001 ),
@@ -43,12 +35,7 @@ static void RejectDifficultyMismatch(double difficulty, double expected_difficul
43
35
static void TestDifficulty (uint32_t nbits, double expected_difficulty)
44
36
{
45
37
CBlockIndex* block_index = CreateBlockIndexWithNbits (nbits);
46
- /* Since we are passing in block index explicitly,
47
- * there is no need to set up anything within the chain itself.
48
- */
49
- CChain chain;
50
-
51
- double difficulty = GetDifficulty (chain, block_index);
38
+ double difficulty = GetDifficulty (block_index);
52
39
delete block_index;
53
40
54
41
RejectDifficultyMismatch (difficulty, expected_difficulty);
@@ -84,43 +71,8 @@ BOOST_AUTO_TEST_CASE(get_difficulty_for_very_high_target)
84
71
// Verify that difficulty is 1.0 for an empty chain.
85
72
BOOST_AUTO_TEST_CASE (get_difficulty_for_null_tip)
86
73
{
87
- CChain chain;
88
- double difficulty = GetDifficulty (chain, nullptr );
74
+ double difficulty = GetDifficulty (nullptr );
89
75
RejectDifficultyMismatch (difficulty, 1.0 );
90
76
}
91
77
92
- /* Verify that if difficulty is based upon the block index
93
- * in the chain, if no block index is explicitly specified.
94
- */
95
- BOOST_AUTO_TEST_CASE (get_difficulty_for_null_block_index)
96
- {
97
- CChain chain = CreateChainWithNbits (0x1df88f6f );
98
-
99
- double difficulty = GetDifficulty (chain, nullptr );
100
- delete chain.Tip ();
101
-
102
- double expected_difficulty = 0.004023 ;
103
-
104
- RejectDifficultyMismatch (difficulty, expected_difficulty);
105
- }
106
-
107
- /* Verify that difficulty is based upon the explicitly specified
108
- * block index rather than being taken from the provided chain,
109
- * when both are present.
110
- */
111
- BOOST_AUTO_TEST_CASE (get_difficulty_for_block_index_overrides_tip)
112
- {
113
- CChain chain = CreateChainWithNbits (0x1df88f6f );
114
- /* This block index's nbits should be used
115
- * instead of the chain's when calculating difficulty.
116
- */
117
- CBlockIndex* override_block_index = CreateBlockIndexWithNbits (0x12345678 );
118
-
119
- double difficulty = GetDifficulty (chain, override_block_index);
120
- delete chain.Tip ();
121
- delete override_block_index;
122
-
123
- RejectDifficultyMismatch (difficulty, 5913134931067755359633408.0 );
124
- }
125
-
126
78
BOOST_AUTO_TEST_SUITE_END ()
0 commit comments