Skip to content

Commit ee0281b

Browse files
authored
Do not update index for info command (ordinals#4128)
1 parent 909a4c5 commit ee0281b

File tree

3 files changed

+39
-27
lines changed

3 files changed

+39
-27
lines changed

src/subcommand/index/info.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub(crate) struct Info {
66
transactions: bool,
77
}
88

9-
#[derive(Serialize, Deserialize)]
9+
#[derive(Serialize, Deserialize, Debug)]
1010
pub struct TransactionsOutput {
1111
pub start: u32,
1212
pub end: u32,
@@ -18,8 +18,6 @@ impl Info {
1818
pub(crate) fn run(self, settings: Settings) -> SubcommandResult {
1919
let index = Index::open(&settings)?;
2020

21-
index.update()?;
22-
2321
let info = index.info()?;
2422

2523
if self.transactions {

tests/command_builder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub(crate) struct Spawn {
3838

3939
impl Spawn {
4040
#[track_caller]
41-
fn run(self) -> (TempDir, String) {
41+
fn run(self) -> (Arc<TempDir>, String) {
4242
let output = self.child.wait_with_output().unwrap();
4343

4444
let stdout = str::from_utf8(&output.stdout).unwrap();
@@ -53,7 +53,7 @@ impl Spawn {
5353
self.expected_stderr.assert_match(stderr);
5454
self.expected_stdout.assert_match(stdout);
5555

56-
(Arc::try_unwrap(self.tempdir).unwrap(), stdout.into())
56+
(self.tempdir, stdout.into())
5757
}
5858

5959
#[track_caller]
@@ -263,7 +263,7 @@ impl CommandBuilder {
263263
}
264264

265265
#[track_caller]
266-
fn run(self) -> (TempDir, String) {
266+
pub(crate) fn run(self) -> (Arc<TempDir>, String) {
267267
self.spawn().run()
268268
}
269269

tests/info.rs

+35-21
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ use {super::*, ord::subcommand::index::info::TransactionsOutput};
33
#[test]
44
fn json_with_satoshi_index() {
55
let core = mockcore::spawn();
6+
7+
let (tempdir, _) = CommandBuilder::new("--index-sats index update")
8+
.core(&core)
9+
.run();
10+
611
CommandBuilder::new("--index-sats index info")
12+
.temp_dir(tempdir)
713
.core(&core)
814
.stdout_regex(
915
r#"\{
@@ -37,8 +43,12 @@ fn json_with_satoshi_index() {
3743
#[test]
3844
fn json_without_satoshi_index() {
3945
let core = mockcore::spawn();
46+
47+
let (tempdir, _) = CommandBuilder::new("index update").core(&core).run();
48+
4049
CommandBuilder::new("index info")
4150
.core(&core)
51+
.temp_dir(tempdir)
4252
.stdout_regex(
4353
r#"\{
4454
"blocks_indexed": 1,
@@ -72,39 +82,43 @@ fn json_without_satoshi_index() {
7282
fn transactions() {
7383
let core = mockcore::spawn();
7484

75-
let tempdir = TempDir::new().unwrap();
85+
let (tempdir, _) = CommandBuilder::new("index update").core(&core).run();
7686

77-
let index_path = tempdir.path().join("index.redb");
87+
let output = CommandBuilder::new("index info --transactions")
88+
.temp_dir(tempdir.clone())
89+
.core(&core)
90+
.run_and_deserialize_output::<Vec<TransactionsOutput>>();
7891

79-
assert!(CommandBuilder::new(format!(
80-
"--index {} index info --transactions",
81-
index_path.display()
82-
))
83-
.core(&core)
84-
.run_and_deserialize_output::<Vec<TransactionsOutput>>()
85-
.is_empty());
92+
assert!(output.is_empty());
8693

8794
core.mine_blocks(10);
8895

89-
let output = CommandBuilder::new(format!(
90-
"--index {} index info --transactions",
91-
index_path.display()
92-
))
93-
.core(&core)
94-
.run_and_deserialize_output::<Vec<TransactionsOutput>>();
96+
CommandBuilder::new("index update")
97+
.temp_dir(tempdir.clone())
98+
.core(&core)
99+
.run();
100+
101+
let output = CommandBuilder::new("index info --transactions")
102+
.temp_dir(tempdir.clone())
103+
.core(&core)
104+
.stdout_regex(".*")
105+
.run_and_deserialize_output::<Vec<TransactionsOutput>>();
95106

96107
assert_eq!(output[0].start, 0);
97108
assert_eq!(output[0].end, 1);
98109
assert_eq!(output[0].count, 1);
99110

100111
core.mine_blocks(10);
101112

102-
let output = CommandBuilder::new(format!(
103-
"--index {} index info --transactions",
104-
index_path.display()
105-
))
106-
.core(&core)
107-
.run_and_deserialize_output::<Vec<TransactionsOutput>>();
113+
CommandBuilder::new("index update")
114+
.temp_dir(tempdir.clone())
115+
.core(&core)
116+
.run();
117+
118+
let output = CommandBuilder::new("index info --transactions")
119+
.temp_dir(tempdir.clone())
120+
.core(&core)
121+
.run_and_deserialize_output::<Vec<TransactionsOutput>>();
108122

109123
assert_eq!(output[1].start, 1);
110124
assert_eq!(output[1].end, 11);

0 commit comments

Comments
 (0)