Skip to content

Commit

Permalink
Do not update index for info command (ordinals#4128)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphjaph authored Dec 12, 2024
1 parent 909a4c5 commit ee0281b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 27 deletions.
4 changes: 1 addition & 3 deletions src/subcommand/index/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions tests/command_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub(crate) struct Spawn {

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

let stdout = str::from_utf8(&output.stdout).unwrap();
Expand All @@ -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]
Expand Down Expand Up @@ -263,7 +263,7 @@ impl CommandBuilder {
}

#[track_caller]
fn run(self) -> (TempDir, String) {
pub(crate) fn run(self) -> (Arc<TempDir>, String) {
self.spawn().run()
}

Expand Down
56 changes: 35 additions & 21 deletions tests/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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#"\{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -72,39 +82,43 @@ 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::<Vec<TransactionsOutput>>();

assert!(CommandBuilder::new(format!(
"--index {} index info --transactions",
index_path.display()
))
.core(&core)
.run_and_deserialize_output::<Vec<TransactionsOutput>>()
.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::<Vec<TransactionsOutput>>();
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::<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>>();
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::<Vec<TransactionsOutput>>();

assert_eq!(output[1].start, 1);
assert_eq!(output[1].end, 11);
Expand Down

0 comments on commit ee0281b

Please sign in to comment.