forked from raphjaph/ord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.rs
112 lines (100 loc) · 2.33 KB
/
info.rs
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
use {super::*, ord::subcommand::index::info::TransactionsOutput};
#[test]
fn json_with_satoshi_index() {
let core = mockcore::spawn();
CommandBuilder::new("--index-sats index info")
.core(&core)
.stdout_regex(
r#"\{
"blocks_indexed": 1,
"branch_pages": \d+,
"fragmented_bytes": \d+,
"index_file_size": \d+,
"index_path": ".*\.redb",
"leaf_pages": \d+,
"metadata_bytes": \d+,
"outputs_traversed": 1,
"page_size": \d+,
"sat_ranges": 1,
"stored_bytes": \d+,
"tables": .*,
"total_bytes": \d+,
"transactions": \[
\{
"starting_block_count": 0,
"starting_timestamp": \d+
\}
\],
"tree_height": \d+,
"utxos_indexed": 2
\}
"#,
)
.run_and_extract_stdout();
}
#[test]
fn json_without_satoshi_index() {
let core = mockcore::spawn();
CommandBuilder::new("index info")
.core(&core)
.stdout_regex(
r#"\{
"blocks_indexed": 1,
"branch_pages": \d+,
"fragmented_bytes": \d+,
"index_file_size": \d+,
"index_path": ".*\.redb",
"leaf_pages": \d+,
"metadata_bytes": \d+,
"outputs_traversed": 0,
"page_size": \d+,
"sat_ranges": 0,
"stored_bytes": \d+,
"tables": .*,
"total_bytes": \d+,
"transactions": \[
\{
"starting_block_count": 0,
"starting_timestamp": \d+
\}
\],
"tree_height": \d+,
"utxos_indexed": 0
\}
"#,
)
.run_and_extract_stdout();
}
#[test]
fn transactions() {
let core = mockcore::spawn();
let tempdir = TempDir::new().unwrap();
let index_path = tempdir.path().join("index.redb");
assert!(CommandBuilder::new(format!(
"--index {} index info --transactions",
index_path.display()
))
.core(&core)
.run_and_deserialize_output::<Vec<TransactionsOutput>>()
.is_empty());
core.mine_blocks(10);
let output = CommandBuilder::new(format!(
"--index {} index info --transactions",
index_path.display()
))
.core(&core)
.run_and_deserialize_output::<Vec<TransactionsOutput>>();
assert_eq!(output[0].start, 0);
assert_eq!(output[0].end, 1);
assert_eq!(output[0].count, 1);
core.mine_blocks(10);
let output = CommandBuilder::new(format!(
"--index {} index info --transactions",
index_path.display()
))
.core(&core)
.run_and_deserialize_output::<Vec<TransactionsOutput>>();
assert_eq!(output[1].start, 1);
assert_eq!(output[1].end, 11);
assert_eq!(output[1].count, 10);
}