diff --git a/src/subcommand/index/info.rs b/src/subcommand/index/info.rs index 11143e8e36..5f51b2ebeb 100644 --- a/src/subcommand/index/info.rs +++ b/src/subcommand/index/info.rs @@ -6,7 +6,7 @@ pub(crate) struct Info { transactions: bool, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Debug)] pub struct TransactionsOutput { pub start: u32, pub end: u32, @@ -18,8 +18,6 @@ impl Info { pub(crate) fn run(self, settings: Settings) -> SubcommandResult { let index = Index::open(&settings)?; - index.update()?; - let info = index.info()?; if self.transactions { diff --git a/tests/command_builder.rs b/tests/command_builder.rs index 574b797476..ba9f57157a 100644 --- a/tests/command_builder.rs +++ b/tests/command_builder.rs @@ -38,7 +38,7 @@ pub(crate) struct Spawn { impl Spawn { #[track_caller] - fn run(self) -> (TempDir, String) { + fn run(self) -> (Arc, String) { let output = self.child.wait_with_output().unwrap(); let stdout = str::from_utf8(&output.stdout).unwrap(); @@ -53,7 +53,7 @@ impl Spawn { self.expected_stderr.assert_match(stderr); self.expected_stdout.assert_match(stdout); - (Arc::try_unwrap(self.tempdir).unwrap(), stdout.into()) + (self.tempdir, stdout.into()) } #[track_caller] @@ -263,7 +263,7 @@ impl CommandBuilder { } #[track_caller] - fn run(self) -> (TempDir, String) { + pub(crate) fn run(self) -> (Arc, String) { self.spawn().run() } diff --git a/tests/info.rs b/tests/info.rs index 7c294f9933..4a6eb910d1 100644 --- a/tests/info.rs +++ b/tests/info.rs @@ -3,7 +3,13 @@ use {super::*, ord::subcommand::index::info::TransactionsOutput}; #[test] fn json_with_satoshi_index() { let core = mockcore::spawn(); + + let (tempdir, _) = CommandBuilder::new("--index-sats index update") + .core(&core) + .run(); + CommandBuilder::new("--index-sats index info") + .temp_dir(tempdir) .core(&core) .stdout_regex( r#"\{ @@ -37,8 +43,12 @@ fn json_with_satoshi_index() { #[test] fn json_without_satoshi_index() { let core = mockcore::spawn(); + + let (tempdir, _) = CommandBuilder::new("index update").core(&core).run(); + CommandBuilder::new("index info") .core(&core) + .temp_dir(tempdir) .stdout_regex( r#"\{ "blocks_indexed": 1, @@ -72,26 +82,27 @@ fn json_without_satoshi_index() { fn transactions() { let core = mockcore::spawn(); - let tempdir = TempDir::new().unwrap(); + let (tempdir, _) = CommandBuilder::new("index update").core(&core).run(); - let index_path = tempdir.path().join("index.redb"); + let output = CommandBuilder::new("index info --transactions") + .temp_dir(tempdir.clone()) + .core(&core) + .run_and_deserialize_output::>(); - assert!(CommandBuilder::new(format!( - "--index {} index info --transactions", - index_path.display() - )) - .core(&core) - .run_and_deserialize_output::>() - .is_empty()); + assert!(output.is_empty()); core.mine_blocks(10); - let output = CommandBuilder::new(format!( - "--index {} index info --transactions", - index_path.display() - )) - .core(&core) - .run_and_deserialize_output::>(); + CommandBuilder::new("index update") + .temp_dir(tempdir.clone()) + .core(&core) + .run(); + + let output = CommandBuilder::new("index info --transactions") + .temp_dir(tempdir.clone()) + .core(&core) + .stdout_regex(".*") + .run_and_deserialize_output::>(); assert_eq!(output[0].start, 0); assert_eq!(output[0].end, 1); @@ -99,12 +110,15 @@ fn transactions() { core.mine_blocks(10); - let output = CommandBuilder::new(format!( - "--index {} index info --transactions", - index_path.display() - )) - .core(&core) - .run_and_deserialize_output::>(); + CommandBuilder::new("index update") + .temp_dir(tempdir.clone()) + .core(&core) + .run(); + + let output = CommandBuilder::new("index info --transactions") + .temp_dir(tempdir.clone()) + .core(&core) + .run_and_deserialize_output::>(); assert_eq!(output[1].start, 1); assert_eq!(output[1].end, 11);