forked from ordinals/ord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.rs
118 lines (90 loc) · 3.12 KB
/
index.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
113
114
115
116
117
118
use {super::*, crate::command_builder::ToArgs, ord::subcommand::Empty};
#[test]
fn run_is_an_alias_for_update() {
let rpc_server = test_bitcoincore_rpc::spawn();
rpc_server.mine_blocks(1);
let tempdir = TempDir::new().unwrap();
let index_path = tempdir.path().join("foo.redb");
CommandBuilder::new(format!("--index {} index run", index_path.display()))
.rpc_server(&rpc_server)
.run_and_deserialize_output::<Empty>();
assert!(index_path.is_file())
}
#[test]
fn custom_index_path() {
let rpc_server = test_bitcoincore_rpc::spawn();
rpc_server.mine_blocks(1);
let tempdir = TempDir::new().unwrap();
let index_path = tempdir.path().join("foo.redb");
CommandBuilder::new(format!("--index {} index update", index_path.display()))
.rpc_server(&rpc_server)
.run_and_deserialize_output::<Empty>();
assert!(index_path.is_file())
}
#[test]
fn re_opening_database_does_not_trigger_schema_check() {
let rpc_server = test_bitcoincore_rpc::spawn();
rpc_server.mine_blocks(1);
let tempdir = TempDir::new().unwrap();
let index_path = tempdir.path().join("foo.redb");
CommandBuilder::new(format!("--index {} index update", index_path.display()))
.rpc_server(&rpc_server)
.run_and_deserialize_output::<Empty>();
assert!(index_path.is_file());
CommandBuilder::new(format!("--index {} index update", index_path.display()))
.rpc_server(&rpc_server)
.run_and_deserialize_output::<Empty>();
}
#[test]
fn index_runs_with_rpc_user_and_pass_as_env_vars() {
let rpc_server = test_bitcoincore_rpc::spawn();
rpc_server.mine_blocks(1);
let tempdir = TempDir::new().unwrap();
let ord = Command::new(executable_path("ord"))
.args(
format!(
"--rpc-url {} --bitcoin-data-dir {} --data-dir {} index update",
rpc_server.url(),
tempdir.path().display(),
tempdir.path().display()
)
.to_args(),
)
.env("ORD_BITCOIN_RPC_PASS", "bar")
.env("ORD_BITCOIN_RPC_USER", "foo")
.env("ORD_INTEGRATION_TEST", "1")
.current_dir(&tempdir)
.spawn()
.unwrap();
rpc_server.mine_blocks(1);
assert_eq!(ord.wait_with_output().unwrap().status.code(), Some(0));
}
#[test]
fn export_inscription_number_to_id_tsv() {
let rpc_server = test_bitcoincore_rpc::spawn();
let temp_dir = TempDir::new().unwrap();
create_wallet(&rpc_server);
inscribe(&rpc_server);
inscribe(&rpc_server);
let (inscription, _) = inscribe(&rpc_server);
rpc_server.mine_blocks(1);
let tsv = CommandBuilder::new("index export --tsv foo.tsv")
.rpc_server(&rpc_server)
.temp_dir(temp_dir)
.stdout_regex(r"\{\}\n")
.run_and_extract_file("foo.tsv");
let entries: std::collections::BTreeMap<i64, ord::Object> = tsv
.lines()
.filter(|line| !line.is_empty() && !line.starts_with('#'))
.map(|line| {
let value = line.split('\t').collect::<Vec<&str>>();
let inscription_number = i64::from_str(value[0]).unwrap();
let inscription_id = ord::Object::from_str(value[1]).unwrap();
(inscription_number, inscription_id)
})
.collect();
assert_eq!(
entries.get(&2).unwrap(),
&ord::Object::InscriptionId(inscription),
);
}