Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not update index for info command #4128

Merged
merged 7 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading