1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
crate::ix!();
//-------------------------------------------[.cpp/bitcoin/src/test/blockchain_tests.cpp]
/**
| Equality between doubles is imprecise.
| Comparison should be done with a small
| threshold of tolerance, rather than
| exact equality.
|
*/
pub fn double_equals(
a: f64,
b: f64,
epsilon: f64) -> bool {
todo!();
/*
return std::abs(a - b) < epsilon;
*/
}
pub fn create_block_index_with_nbits(nbits: u32) -> Arc<Mutex<BlockIndex>> {
todo!();
/*
CBlockIndex* block_index = new CBlockIndex();
block_index->nHeight = 46367;
block_index->nTime = 1269211443;
block_index->nBits = nbits;
return block_index;
*/
}
pub fn reject_difficulty_mismatch(
difficulty: f64,
expected_difficulty: f64) {
todo!();
/*
BOOST_CHECK_MESSAGE(
DoubleEquals(difficulty, expected_difficulty, 0.00001),
"Difficulty was " + ToString(difficulty)
+ " but was expected to be " + ToString(expected_difficulty));
*/
}
/**
| Given a BlockIndex with the provided
| nbits, verify that the expected difficulty
| results.
|
*/
pub fn test_difficulty(
nbits: u32,
expected_difficulty: f64) {
todo!();
/*
CBlockIndex* block_index = CreateBlockIndexWithNbits(nbits);
double difficulty = GetDifficulty(block_index);
delete block_index;
RejectDifficultyMismatch(difficulty, expected_difficulty);
*/
}
#[cfg(test)]
#[BasicTestingSetup]
pub mod blockchain_tests {
#[test] fn get_difficulty_for_very_low_target() {
todo!();
/*
TestDifficulty(0x1f111111, 0.000001);
*/
}
#[test] fn get_difficulty_for_low_target() {
todo!();
/*
TestDifficulty(0x1ef88f6f, 0.000016);
*/
}
#[test] fn get_difficulty_for_mid_target() {
todo!();
/*
TestDifficulty(0x1df88f6f, 0.004023);
*/
}
#[test] fn get_difficulty_for_high_target() {
todo!();
/*
TestDifficulty(0x1cf88f6f, 1.029916);
*/
}
#[test] fn get_difficulty_for_very_high_target() {
todo!();
/*
TestDifficulty(0x12345678, 5913134931067755359633408.0);
*/
}
}