From 86abf3f6bd20e9aa26de3388b9e99dd300fd1fa8 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Tue, 10 Dec 2024 21:26:54 -0500 Subject: [PATCH 1/6] Do not update index for info command --- src/subcommand/index/info.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/subcommand/index/info.rs b/src/subcommand/index/info.rs index 11143e8e36..595a924b6c 100644 --- a/src/subcommand/index/info.rs +++ b/src/subcommand/index/info.rs @@ -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 { From b55809682d7110be9988953f1e76cb0ae5db1fad Mon Sep 17 00:00:00 2001 From: raphjaph Date: Tue, 10 Dec 2024 21:33:40 -0500 Subject: [PATCH 2/6] Amend --- tests/info.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/info.rs b/tests/info.rs index 7c294f9933..0aa8012d41 100644 --- a/tests/info.rs +++ b/tests/info.rs @@ -3,6 +3,11 @@ use {super::*, ord::subcommand::index::info::TransactionsOutput}; #[test] fn json_with_satoshi_index() { let core = mockcore::spawn(); + + CommandBuilder::new("--index-sats index update") + .core(&core) + .run_and_extract_stdout(); + CommandBuilder::new("--index-sats index info") .core(&core) .stdout_regex( @@ -37,6 +42,11 @@ fn json_with_satoshi_index() { #[test] fn json_without_satoshi_index() { let core = mockcore::spawn(); + + CommandBuilder::new("index update") + .core(&core) + .run_and_extract_stdout(); + CommandBuilder::new("index info") .core(&core) .stdout_regex( @@ -72,6 +82,10 @@ fn json_without_satoshi_index() { fn transactions() { let core = mockcore::spawn(); + CommandBuilder::new("index update") + .core(&core) + .run_and_extract_stdout(); + let tempdir = TempDir::new().unwrap(); let index_path = tempdir.path().join("index.redb"); From 41811946c98e57e36035085241a42d3066370fb9 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Thu, 12 Dec 2024 17:45:56 -0500 Subject: [PATCH 3/6] fix tests --- tests/command_builder.rs | 2 +- tests/info.rs | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/command_builder.rs b/tests/command_builder.rs index 574b797476..fdfb3b9309 100644 --- a/tests/command_builder.rs +++ b/tests/command_builder.rs @@ -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()) + (Arc::try_unwrap(dbg!(self.tempdir)).unwrap(), stdout.into()) } #[track_caller] diff --git a/tests/info.rs b/tests/info.rs index 0aa8012d41..8cdb0b7c57 100644 --- a/tests/info.rs +++ b/tests/info.rs @@ -4,11 +4,15 @@ use {super::*, ord::subcommand::index::info::TransactionsOutput}; fn json_with_satoshi_index() { let core = mockcore::spawn(); + let tempdir = Arc::new(TempDir::new().unwrap()); + CommandBuilder::new("--index-sats index update") + .temp_dir(tempdir.clone()) .core(&core) .run_and_extract_stdout(); CommandBuilder::new("--index-sats index info") + .temp_dir(tempdir.clone()) .core(&core) .stdout_regex( r#"\{ @@ -43,11 +47,15 @@ fn json_with_satoshi_index() { fn json_without_satoshi_index() { let core = mockcore::spawn(); + let tempdir = Arc::new(TempDir::new().unwrap()); + CommandBuilder::new("index update") + .temp_dir(tempdir.clone()) .core(&core) .run_and_extract_stdout(); CommandBuilder::new("index info") + .temp_dir(tempdir.clone()) .core(&core) .stdout_regex( r#"\{ @@ -82,12 +90,13 @@ fn json_without_satoshi_index() { fn transactions() { let core = mockcore::spawn(); + let tempdir = Arc::new(TempDir::new().unwrap()); + CommandBuilder::new("index update") + .temp_dir(tempdir.clone()) .core(&core) .run_and_extract_stdout(); - let tempdir = TempDir::new().unwrap(); - let index_path = tempdir.path().join("index.redb"); assert!(CommandBuilder::new(format!( From 29b8f28e77520365999e57eb2d44c369880a6221 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Thu, 12 Dec 2024 18:33:58 -0500 Subject: [PATCH 4/6] I just wanted to remove one line lmao --- src/subcommand/index/info.rs | 2 +- tests/command_builder.rs | 4 +- tests/info.rs | 71 +++++++++++++++++++++++------------- 3 files changed, 48 insertions(+), 29 deletions(-) diff --git a/src/subcommand/index/info.rs b/src/subcommand/index/info.rs index 595a924b6c..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, diff --git a/tests/command_builder.rs b/tests/command_builder.rs index fdfb3b9309..2524fe46ea 100644 --- a/tests/command_builder.rs +++ b/tests/command_builder.rs @@ -53,7 +53,7 @@ impl Spawn { self.expected_stderr.assert_match(stderr); self.expected_stdout.assert_match(stdout); - (Arc::try_unwrap(dbg!(self.tempdir)).unwrap(), stdout.into()) + (Arc::try_unwrap(self.tempdir).unwrap(), stdout.into()) } #[track_caller] @@ -263,7 +263,7 @@ impl CommandBuilder { } #[track_caller] - fn run(self) -> (TempDir, String) { + pub(crate) fn run(self) -> (TempDir, String) { self.spawn().run() } diff --git a/tests/info.rs b/tests/info.rs index 8cdb0b7c57..00e3c52463 100644 --- a/tests/info.rs +++ b/tests/info.rs @@ -4,15 +4,12 @@ use {super::*, ord::subcommand::index::info::TransactionsOutput}; fn json_with_satoshi_index() { let core = mockcore::spawn(); - let tempdir = Arc::new(TempDir::new().unwrap()); - - CommandBuilder::new("--index-sats index update") - .temp_dir(tempdir.clone()) + let (tempdir, _) = CommandBuilder::new("--index-sats index update") .core(&core) - .run_and_extract_stdout(); + .run(); CommandBuilder::new("--index-sats index info") - .temp_dir(tempdir.clone()) + .temp_dir(Arc::new(tempdir)) .core(&core) .stdout_regex( r#"\{ @@ -47,16 +44,11 @@ fn json_with_satoshi_index() { fn json_without_satoshi_index() { let core = mockcore::spawn(); - let tempdir = Arc::new(TempDir::new().unwrap()); - - CommandBuilder::new("index update") - .temp_dir(tempdir.clone()) - .core(&core) - .run_and_extract_stdout(); + let (tempdir, _) = CommandBuilder::new("index update").core(&core).run(); CommandBuilder::new("index info") - .temp_dir(tempdir.clone()) .core(&core) + .temp_dir(Arc::new(tempdir)) .stdout_regex( r#"\{ "blocks_indexed": 1, @@ -90,31 +82,46 @@ fn json_without_satoshi_index() { fn transactions() { let core = mockcore::spawn(); - let tempdir = Arc::new(TempDir::new().unwrap()); - - CommandBuilder::new("index update") - .temp_dir(tempdir.clone()) - .core(&core) - .run_and_extract_stdout(); + let (tempdir, _) = CommandBuilder::new("index update").core(&core).run(); let index_path = tempdir.path().join("index.redb"); - assert!(CommandBuilder::new(format!( + let (tempdir, stdout) = CommandBuilder::new(format!( "--index {} index info --transactions", index_path.display() )) + .temp_dir(Arc::new(tempdir)) .core(&core) - .run_and_deserialize_output::>() - .is_empty()); + .stdout_regex(".*") + .run(); + + let output: Vec = match serde_json::from_str(&stdout) { + Ok(output) => output, + Err(err) => panic!("Failed to deserialize JSON: {err}\n{stdout}"), + }; + + assert!(output.is_empty()); core.mine_blocks(10); - let output = CommandBuilder::new(format!( + let (tempdir, _) = CommandBuilder::new("index update") + .temp_dir(Arc::new(tempdir)) + .core(&core) + .run(); + + let (tempdir, stdout) = CommandBuilder::new(format!( "--index {} index info --transactions", index_path.display() )) + .temp_dir(Arc::new(tempdir)) .core(&core) - .run_and_deserialize_output::>(); + .stdout_regex(".*") + .run(); + + let output: Vec = match serde_json::from_str(&stdout) { + Ok(output) => output, + Err(err) => panic!("Failed to deserialize JSON: {err}\n{stdout}"), + }; assert_eq!(output[0].start, 0); assert_eq!(output[0].end, 1); @@ -122,12 +129,24 @@ fn transactions() { core.mine_blocks(10); - let output = CommandBuilder::new(format!( + let (tempdir, _) = CommandBuilder::new("index update") + .temp_dir(Arc::new(tempdir)) + .core(&core) + .run(); + + let (_, stdout) = CommandBuilder::new(format!( "--index {} index info --transactions", index_path.display() )) + .temp_dir(Arc::new(tempdir)) .core(&core) - .run_and_deserialize_output::>(); + .stdout_regex(".*") + .run(); + + let output: Vec = match serde_json::from_str(&stdout) { + Ok(output) => output, + Err(err) => panic!("Failed to deserialize JSON: {err}\n{stdout}"), + }; assert_eq!(output[1].start, 1); assert_eq!(output[1].end, 11); From 47d0dc428d219da9d4b7efa4ea6b568412dbe9ae Mon Sep 17 00:00:00 2001 From: raphjaph Date: Thu, 12 Dec 2024 18:37:21 -0500 Subject: [PATCH 5/6] Amend --- tests/info.rs | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/tests/info.rs b/tests/info.rs index 00e3c52463..56bd3ff7b6 100644 --- a/tests/info.rs +++ b/tests/info.rs @@ -84,16 +84,11 @@ fn transactions() { let (tempdir, _) = CommandBuilder::new("index update").core(&core).run(); - let index_path = tempdir.path().join("index.redb"); - - let (tempdir, stdout) = CommandBuilder::new(format!( - "--index {} index info --transactions", - index_path.display() - )) - .temp_dir(Arc::new(tempdir)) - .core(&core) - .stdout_regex(".*") - .run(); + let (tempdir, stdout) = CommandBuilder::new("index info --transactions") + .temp_dir(Arc::new(tempdir)) + .core(&core) + .stdout_regex(".*") + .run(); let output: Vec = match serde_json::from_str(&stdout) { Ok(output) => output, @@ -109,14 +104,11 @@ fn transactions() { .core(&core) .run(); - let (tempdir, stdout) = CommandBuilder::new(format!( - "--index {} index info --transactions", - index_path.display() - )) - .temp_dir(Arc::new(tempdir)) - .core(&core) - .stdout_regex(".*") - .run(); + let (tempdir, stdout) = CommandBuilder::new("index info --transactions") + .temp_dir(Arc::new(tempdir)) + .core(&core) + .stdout_regex(".*") + .run(); let output: Vec = match serde_json::from_str(&stdout) { Ok(output) => output, @@ -134,14 +126,11 @@ fn transactions() { .core(&core) .run(); - let (_, stdout) = CommandBuilder::new(format!( - "--index {} index info --transactions", - index_path.display() - )) - .temp_dir(Arc::new(tempdir)) - .core(&core) - .stdout_regex(".*") - .run(); + let (_, stdout) = CommandBuilder::new("index info --transactions") + .temp_dir(Arc::new(tempdir)) + .core(&core) + .stdout_regex(".*") + .run(); let output: Vec = match serde_json::from_str(&stdout) { Ok(output) => output, From 8382db723bf06ddaa93a7581e7716d20ac46787e Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 12 Dec 2024 15:48:03 -0800 Subject: [PATCH 6/6] Avoid arc weirdness --- tests/command_builder.rs | 6 ++--- tests/info.rs | 47 +++++++++++++--------------------------- 2 files changed, 18 insertions(+), 35 deletions(-) diff --git a/tests/command_builder.rs b/tests/command_builder.rs index 2524fe46ea..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] - pub(crate) 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 56bd3ff7b6..4a6eb910d1 100644 --- a/tests/info.rs +++ b/tests/info.rs @@ -9,7 +9,7 @@ fn json_with_satoshi_index() { .run(); CommandBuilder::new("--index-sats index info") - .temp_dir(Arc::new(tempdir)) + .temp_dir(tempdir) .core(&core) .stdout_regex( r#"\{ @@ -48,7 +48,7 @@ fn json_without_satoshi_index() { CommandBuilder::new("index info") .core(&core) - .temp_dir(Arc::new(tempdir)) + .temp_dir(tempdir) .stdout_regex( r#"\{ "blocks_indexed": 1, @@ -84,36 +84,25 @@ fn transactions() { let (tempdir, _) = CommandBuilder::new("index update").core(&core).run(); - let (tempdir, stdout) = CommandBuilder::new("index info --transactions") - .temp_dir(Arc::new(tempdir)) + let output = CommandBuilder::new("index info --transactions") + .temp_dir(tempdir.clone()) .core(&core) - .stdout_regex(".*") - .run(); - - let output: Vec = match serde_json::from_str(&stdout) { - Ok(output) => output, - Err(err) => panic!("Failed to deserialize JSON: {err}\n{stdout}"), - }; + .run_and_deserialize_output::>(); assert!(output.is_empty()); core.mine_blocks(10); - let (tempdir, _) = CommandBuilder::new("index update") - .temp_dir(Arc::new(tempdir)) + CommandBuilder::new("index update") + .temp_dir(tempdir.clone()) .core(&core) .run(); - let (tempdir, stdout) = CommandBuilder::new("index info --transactions") - .temp_dir(Arc::new(tempdir)) + let output = CommandBuilder::new("index info --transactions") + .temp_dir(tempdir.clone()) .core(&core) .stdout_regex(".*") - .run(); - - let output: Vec = match serde_json::from_str(&stdout) { - Ok(output) => output, - Err(err) => panic!("Failed to deserialize JSON: {err}\n{stdout}"), - }; + .run_and_deserialize_output::>(); assert_eq!(output[0].start, 0); assert_eq!(output[0].end, 1); @@ -121,21 +110,15 @@ fn transactions() { core.mine_blocks(10); - let (tempdir, _) = CommandBuilder::new("index update") - .temp_dir(Arc::new(tempdir)) + CommandBuilder::new("index update") + .temp_dir(tempdir.clone()) .core(&core) .run(); - let (_, stdout) = CommandBuilder::new("index info --transactions") - .temp_dir(Arc::new(tempdir)) + let output = CommandBuilder::new("index info --transactions") + .temp_dir(tempdir.clone()) .core(&core) - .stdout_regex(".*") - .run(); - - let output: Vec = match serde_json::from_str(&stdout) { - Ok(output) => output, - Err(err) => panic!("Failed to deserialize JSON: {err}\n{stdout}"), - }; + .run_and_deserialize_output::>(); assert_eq!(output[1].start, 1); assert_eq!(output[1].end, 11);