From b96bea999e758ace521e67a1b6fe1cee82f155ea Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Tue, 22 Aug 2023 15:25:30 -0700 Subject: [PATCH 01/10] Use JSON for all command output --- src/arguments.rs | 2 +- src/lib.rs | 33 +++++++++++++++------------ src/subcommand.rs | 27 ++++++++++++++++------ src/subcommand/epochs.rs | 6 ++--- src/subcommand/find.rs | 7 ++---- src/subcommand/index.rs | 10 ++++---- src/subcommand/info.rs | 8 +++---- src/subcommand/list.rs | 10 ++++---- src/subcommand/parse.rs | 7 +++--- src/subcommand/preview.rs | 6 ++--- src/subcommand/server.rs | 4 ++-- src/subcommand/subsidy.rs | 8 +++---- src/subcommand/supply.rs | 8 +++---- src/subcommand/traits.rs | 8 +++---- src/subcommand/wallet.rs | 2 +- src/subcommand/wallet/balance.rs | 6 ++--- src/subcommand/wallet/cardinals.rs | 12 ++++------ src/subcommand/wallet/create.rs | 8 +++---- src/subcommand/wallet/inscribe.rs | 14 +++++------- src/subcommand/wallet/inscriptions.rs | 6 ++--- src/subcommand/wallet/outputs.rs | 6 ++--- src/subcommand/wallet/receive.rs | 6 ++--- src/subcommand/wallet/restore.rs | 5 ++-- src/subcommand/wallet/sats.rs | 8 +++---- src/subcommand/wallet/send.rs | 9 +++----- src/subcommand/wallet/transactions.rs | 6 ++--- tests/wallet/cardinals.rs | 4 ++-- 27 files changed, 106 insertions(+), 130 deletions(-) diff --git a/src/arguments.rs b/src/arguments.rs index c3af6814d6..17c6050ebb 100644 --- a/src/arguments.rs +++ b/src/arguments.rs @@ -10,7 +10,7 @@ pub(crate) struct Arguments { } impl Arguments { - pub(crate) fn run(self) -> Result { + pub(crate) fn run(self) -> SubcommandResult { self.subcommand.run(self.options) } } diff --git a/src/lib.rs b/src/lib.rs index 1ef8d220ab..1287aa0a4d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,7 +27,7 @@ use { options::Options, outgoing::Outgoing, representation::Representation, - subcommand::Subcommand, + subcommand::{Subcommand, SubcommandResult}, tally::Tally, }, anyhow::{anyhow, bail, Context, Error}, @@ -180,22 +180,25 @@ pub fn main() { }) .expect("Error setting handler"); - if let Err(err) = Arguments::parse().run() { - eprintln!("error: {err}"); - err - .chain() - .skip(1) - .for_each(|cause| eprintln!("because: {cause}")); - if env::var_os("RUST_BACKTRACE") - .map(|val| val == "1") - .unwrap_or_default() - { - eprintln!("{}", err.backtrace()); - } + match Arguments::parse().run() { + Err(err) => { + eprintln!("error: {err}"); + err + .chain() + .skip(1) + .for_each(|cause| eprintln!("because: {cause}")); + if env::var_os("RUST_BACKTRACE") + .map(|val| val == "1") + .unwrap_or_default() + { + eprintln!("{}", err.backtrace()); + } - gracefully_shutdown_indexer(); + gracefully_shutdown_indexer(); - process::exit(1); + process::exit(1); + } + Ok(output) => output.print_json(), } gracefully_shutdown_indexer(); diff --git a/src/subcommand.rs b/src/subcommand.rs index a1e97b017e..afab4b00be 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -13,12 +13,6 @@ pub mod supply; pub mod traits; pub mod wallet; -fn print_json(output: impl Serialize) -> Result { - serde_json::to_writer_pretty(io::stdout(), &output)?; - println!(); - Ok(()) -} - #[derive(Debug, Parser)] pub(crate) enum Subcommand { #[clap(about = "List the first satoshis of each reward epoch")] @@ -48,7 +42,7 @@ pub(crate) enum Subcommand { } impl Subcommand { - pub(crate) fn run(self, options: Options) -> Result { + pub(crate) fn run(self, options: Options) -> SubcommandResult { match self { Self::Epochs => epochs::run(), Self::Preview(preview) => preview.run(), @@ -70,3 +64,22 @@ impl Subcommand { } } } + +#[derive(Serialize, Deserialize)] +pub(crate) struct Empty {} + +pub(crate) trait Output: Send { + fn print_json(&self); +} + +impl Output for T +where + T: Serialize + Send, +{ + fn print_json(&self) { + serde_json::to_writer_pretty(io::stdout(), self).ok(); + println!(); + } +} + +pub(crate) type SubcommandResult = Result>; diff --git a/src/subcommand/epochs.rs b/src/subcommand/epochs.rs index 53293cb025..39534a65ca 100644 --- a/src/subcommand/epochs.rs +++ b/src/subcommand/epochs.rs @@ -5,13 +5,11 @@ pub struct Output { pub starting_sats: Vec, } -pub(crate) fn run() -> Result { +pub(crate) fn run() -> SubcommandResult { let mut starting_sats = Vec::new(); for sat in Epoch::STARTING_SATS { starting_sats.push(sat); } - print_json(Output { starting_sats })?; - - Ok(()) + Ok(Box::new(Output { starting_sats })) } diff --git a/src/subcommand/find.rs b/src/subcommand/find.rs index fdf314cc48..fb81e19b33 100644 --- a/src/subcommand/find.rs +++ b/src/subcommand/find.rs @@ -12,16 +12,13 @@ pub struct Output { } impl Find { - pub(crate) fn run(self, options: Options) -> Result { + pub(crate) fn run(self, options: Options) -> SubcommandResult { let index = Index::open(&options)?; index.update()?; match index.find(self.sat.0)? { - Some(satpoint) => { - print_json(Output { satpoint })?; - Ok(()) - } + Some(satpoint) => Ok(Box::new(Output { satpoint })), None => Err(anyhow!("sat has not been mined as of index height")), } } diff --git a/src/subcommand/index.rs b/src/subcommand/index.rs index 0193011636..aea938a8a3 100644 --- a/src/subcommand/index.rs +++ b/src/subcommand/index.rs @@ -9,7 +9,7 @@ pub(crate) enum IndexSubcommand { } impl IndexSubcommand { - pub(crate) fn run(self, options: Options) -> Result { + pub(crate) fn run(self, options: Options) -> SubcommandResult { match self { Self::Export(export) => export.run(options), Self::Run => index::run(options), @@ -30,20 +30,20 @@ pub(crate) struct Export { } impl Export { - pub(crate) fn run(self, options: Options) -> Result { + pub(crate) fn run(self, options: Options) -> SubcommandResult { let index = Index::open(&options)?; index.update()?; index.export(&self.tsv, self.include_addresses)?; - Ok(()) + Ok(Box::new(Empty {})) } } -pub(crate) fn run(options: Options) -> Result { +pub(crate) fn run(options: Options) -> SubcommandResult { let index = Index::open(&options)?; index.update()?; - Ok(()) + Ok(Box::new(Empty {})) } diff --git a/src/subcommand/info.rs b/src/subcommand/info.rs index aa96de00b4..737cdd2228 100644 --- a/src/subcommand/info.rs +++ b/src/subcommand/info.rs @@ -15,7 +15,7 @@ pub struct TransactionsOutput { } impl Info { - pub(crate) fn run(self, options: Options) -> Result { + pub(crate) fn run(self, options: Options) -> SubcommandResult { let index = Index::open(&options)?; index.update()?; let info = index.info()?; @@ -32,11 +32,9 @@ impl Info { elapsed: (end.starting_timestamp - start.starting_timestamp) as f64 / 1000.0 / 60.0, }); } - print_json(output)?; + Ok(Box::new(output)) } else { - print_json(info)?; + Ok(Box::new(info)) } - - Ok(()) } } diff --git a/src/subcommand/list.rs b/src/subcommand/list.rs index 4ec93b14b0..dfad38efa6 100644 --- a/src/subcommand/list.rs +++ b/src/subcommand/list.rs @@ -18,7 +18,7 @@ pub struct Output { } impl List { - pub(crate) fn run(self, options: Options) -> Result { + pub(crate) fn run(self, options: Options) -> SubcommandResult { let index = Index::open(&options)?; index.update()?; @@ -47,9 +47,7 @@ impl List { }); } - print_json(outputs)?; - - Ok(()) + Ok(Box::new(outputs)) } Some(crate::index::List::Spent) => Err(anyhow!("output spent.")), None => Err(anyhow!("output not found")), @@ -92,8 +90,8 @@ mod tests { offset: u64, rarity: Rarity, name: String, - ) -> Output { - Output { + ) -> super::Output { + super::Output { output, start, end, diff --git a/src/subcommand/parse.rs b/src/subcommand/parse.rs index 73c815d3de..40854b9b73 100644 --- a/src/subcommand/parse.rs +++ b/src/subcommand/parse.rs @@ -12,10 +12,9 @@ pub struct Output { } impl Parse { - pub(crate) fn run(self) -> Result { - print_json(Output { + pub(crate) fn run(self) -> SubcommandResult { + Ok(Box::new(Output { object: self.object, - })?; - Ok(()) + })) } } diff --git a/src/subcommand/preview.rs b/src/subcommand/preview.rs index 915fb136f2..6926e2e631 100644 --- a/src/subcommand/preview.rs +++ b/src/subcommand/preview.rs @@ -16,7 +16,7 @@ impl Drop for KillOnDrop { } impl Preview { - pub(crate) fn run(self) -> Result { + pub(crate) fn run(self) -> SubcommandResult { let tmpdir = TempDir::new()?; let rpc_port = TcpListener::bind("127.0.0.1:0")?.local_addr()?.port(); @@ -102,8 +102,6 @@ impl Preview { options, subcommand: Subcommand::Server(self.server), } - .run()?; - - Ok(()) + .run() } } diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 185b461c53..1f4f93453d 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -137,7 +137,7 @@ pub(crate) struct Server { } impl Server { - pub(crate) fn run(self, options: Options, index: Arc, handle: Handle) -> Result { + pub(crate) fn run(self, options: Options, index: Arc, handle: Handle) -> SubcommandResult { Runtime::new()?.block_on(async { let block_index_state = BlockIndexState { block_index: RwLock::new(BlockIndex::new(&index)?), @@ -272,7 +272,7 @@ impl Server { (None, None) => unreachable!(), } - Ok(()) + Ok(Box::new(Empty {}) as Box) }) } diff --git a/src/subcommand/subsidy.rs b/src/subcommand/subsidy.rs index e293d6d7c6..0a7fbb54ce 100644 --- a/src/subcommand/subsidy.rs +++ b/src/subcommand/subsidy.rs @@ -14,7 +14,7 @@ pub struct Output { } impl Subsidy { - pub(crate) fn run(self) -> Result { + pub(crate) fn run(self) -> SubcommandResult { let first = self.height.starting_sat(); let subsidy = self.height.subsidy(); @@ -23,12 +23,10 @@ impl Subsidy { bail!("block {} has no subsidy", self.height); } - print_json(Output { + Ok(Box::new(Output { first: first.0, subsidy, name: first.name(), - })?; - - Ok(()) + })) } } diff --git a/src/subcommand/supply.rs b/src/subcommand/supply.rs index 4a4b468cca..dcf86d3ed5 100644 --- a/src/subcommand/supply.rs +++ b/src/subcommand/supply.rs @@ -8,7 +8,7 @@ pub struct Output { pub last_mined_in_block: u64, } -pub(crate) fn run() -> Result { +pub(crate) fn run() -> SubcommandResult { let mut last = 0; loop { @@ -18,12 +18,10 @@ pub(crate) fn run() -> Result { last += 1; } - print_json(Output { + Ok(Box::new(Output { supply: Sat::SUPPLY, first: 0, last: Sat::SUPPLY - 1, last_mined_in_block: last, - })?; - - Ok(()) + })) } diff --git a/src/subcommand/traits.rs b/src/subcommand/traits.rs index bfb4999be6..9ef2726655 100644 --- a/src/subcommand/traits.rs +++ b/src/subcommand/traits.rs @@ -21,8 +21,8 @@ pub struct Output { } impl Traits { - pub(crate) fn run(self) -> Result { - print_json(Output { + pub(crate) fn run(self) -> SubcommandResult { + Ok(Box::new(Output { number: self.sat.n(), decimal: self.sat.decimal().to_string(), degree: self.sat.degree().to_string(), @@ -33,8 +33,6 @@ impl Traits { period: self.sat.period(), offset: self.sat.third(), rarity: self.sat.rarity(), - })?; - - Ok(()) + })) } } diff --git a/src/subcommand/wallet.rs b/src/subcommand/wallet.rs index 875ed5200f..2972c7615f 100644 --- a/src/subcommand/wallet.rs +++ b/src/subcommand/wallet.rs @@ -54,7 +54,7 @@ pub(crate) enum Wallet { } impl Wallet { - pub(crate) fn run(self, options: Options) -> Result { + pub(crate) fn run(self, options: Options) -> SubcommandResult { match self { Self::Balance => balance::run(options), Self::Create(create) => create.run(options), diff --git a/src/subcommand/wallet/balance.rs b/src/subcommand/wallet/balance.rs index 9813634118..be08751479 100644 --- a/src/subcommand/wallet/balance.rs +++ b/src/subcommand/wallet/balance.rs @@ -5,7 +5,7 @@ pub struct Output { pub cardinal: u64, } -pub(crate) fn run(options: Options) -> Result { +pub(crate) fn run(options: Options) -> SubcommandResult { let index = Index::open(&options)?; index.update()?; @@ -24,7 +24,5 @@ pub(crate) fn run(options: Options) -> Result { } } - print_json(Output { cardinal: balance })?; - - Ok(()) + Ok(Box::new(Output { cardinal: balance })) } diff --git a/src/subcommand/wallet/cardinals.rs b/src/subcommand/wallet/cardinals.rs index 4df85204fd..ccbb187fcb 100644 --- a/src/subcommand/wallet/cardinals.rs +++ b/src/subcommand/wallet/cardinals.rs @@ -1,12 +1,12 @@ use {super::*, crate::wallet::Wallet, std::collections::BTreeSet}; #[derive(Serialize, Deserialize)] -pub struct Cardinal { +pub struct CardinalUtxo { pub output: OutPoint, pub amount: u64, } -pub(crate) fn run(options: Options) -> Result { +pub(crate) fn run(options: Options) -> SubcommandResult { let index = Index::open(&options)?; index.update()?; @@ -24,15 +24,13 @@ pub(crate) fn run(options: Options) -> Result { if inscribed_utxos.contains(output) { None } else { - Some(Cardinal { + Some(CardinalUtxo { output: *output, amount: amount.to_sat(), }) } }) - .collect::>(); + .collect::>(); - print_json(cardinal_utxos)?; - - Ok(()) + Ok(Box::new(cardinal_utxos)) } diff --git a/src/subcommand/wallet/create.rs b/src/subcommand/wallet/create.rs index a236f8ee80..18d66b1d6a 100644 --- a/src/subcommand/wallet/create.rs +++ b/src/subcommand/wallet/create.rs @@ -17,7 +17,7 @@ pub(crate) struct Create { } impl Create { - pub(crate) fn run(self, options: Options) -> Result { + pub(crate) fn run(self, options: Options) -> SubcommandResult { let mut entropy = [0; 16]; rand::thread_rng().fill_bytes(&mut entropy); @@ -25,11 +25,9 @@ impl Create { initialize_wallet(&options, mnemonic.to_seed(self.passphrase.clone()))?; - print_json(Output { + Ok(Box::new(Output { mnemonic, passphrase: Some(self.passphrase), - })?; - - Ok(()) + })) } } diff --git a/src/subcommand/wallet/inscribe.rs b/src/subcommand/wallet/inscribe.rs index f712890656..ab140b5a82 100644 --- a/src/subcommand/wallet/inscribe.rs +++ b/src/subcommand/wallet/inscribe.rs @@ -59,7 +59,7 @@ pub(crate) struct Inscribe { } impl Inscribe { - pub(crate) fn run(self, options: Options) -> Result { + pub(crate) fn run(self, options: Options) -> SubcommandResult { let inscription = Inscription::from_file(options.chain(), &self.file)?; let index = Index::open(&options)?; @@ -110,12 +110,12 @@ impl Inscribe { Self::calculate_fee(&unsigned_commit_tx, &utxos) + Self::calculate_fee(&reveal_tx, &utxos); if self.dry_run { - print_json(Output { + Ok(Box::new(Output { commit: unsigned_commit_tx.txid(), reveal: reveal_tx.txid(), inscription: reveal_tx.txid().into(), fees, - })?; + })) } else { if !self.no_backup { Inscribe::backup_recovery_key(&client, recovery_key_pair, options.chain().network())?; @@ -133,15 +133,13 @@ impl Inscribe { .send_raw_transaction(&reveal_tx) .context("Failed to send reveal transaction")?; - print_json(Output { + Ok(Box::new(Output { commit, reveal, inscription: reveal.into(), fees, - })?; - }; - - Ok(()) + })) + } } fn calculate_fee(tx: &Transaction, utxos: &BTreeMap) -> u64 { diff --git a/src/subcommand/wallet/inscriptions.rs b/src/subcommand/wallet/inscriptions.rs index 2b9395e378..bb8397089f 100644 --- a/src/subcommand/wallet/inscriptions.rs +++ b/src/subcommand/wallet/inscriptions.rs @@ -8,7 +8,7 @@ pub struct Output { pub postage: u64, } -pub(crate) fn run(options: Options) -> Result { +pub(crate) fn run(options: Options) -> SubcommandResult { let index = Index::open(&options)?; index.update()?; @@ -35,7 +35,5 @@ pub(crate) fn run(options: Options) -> Result { } } - print_json(&output)?; - - Ok(()) + Ok(Box::new(output)) } diff --git a/src/subcommand/wallet/outputs.rs b/src/subcommand/wallet/outputs.rs index d064cd312f..dee75fe70e 100644 --- a/src/subcommand/wallet/outputs.rs +++ b/src/subcommand/wallet/outputs.rs @@ -6,7 +6,7 @@ pub struct Output { pub amount: u64, } -pub(crate) fn run(options: Options) -> Result { +pub(crate) fn run(options: Options) -> SubcommandResult { let index = Index::open(&options)?; index.update()?; @@ -18,7 +18,5 @@ pub(crate) fn run(options: Options) -> Result { }); } - print_json(outputs)?; - - Ok(()) + Ok(Box::new(outputs)) } diff --git a/src/subcommand/wallet/receive.rs b/src/subcommand/wallet/receive.rs index 94228ff364..1eb35d417c 100644 --- a/src/subcommand/wallet/receive.rs +++ b/src/subcommand/wallet/receive.rs @@ -5,12 +5,10 @@ pub struct Output { pub address: Address, } -pub(crate) fn run(options: Options) -> Result { +pub(crate) fn run(options: Options) -> SubcommandResult { let address = options .bitcoin_rpc_client_for_wallet_command(false)? .get_new_address(None, Some(bitcoincore_rpc::json::AddressType::Bech32m))?; - print_json(Output { address })?; - - Ok(()) + Ok(Box::new(Output { address })) } diff --git a/src/subcommand/wallet/restore.rs b/src/subcommand/wallet/restore.rs index 3e54bfc016..f2afbcf5d1 100644 --- a/src/subcommand/wallet/restore.rs +++ b/src/subcommand/wallet/restore.rs @@ -13,9 +13,8 @@ pub(crate) struct Restore { } impl Restore { - pub(crate) fn run(self, options: Options) -> Result { + pub(crate) fn run(self, options: Options) -> SubcommandResult { initialize_wallet(&options, self.mnemonic.to_seed(self.passphrase))?; - - Ok(()) + Ok(Box::new(Empty {})) } } diff --git a/src/subcommand/wallet/sats.rs b/src/subcommand/wallet/sats.rs index 8006e7477b..79cd2f510d 100644 --- a/src/subcommand/wallet/sats.rs +++ b/src/subcommand/wallet/sats.rs @@ -24,7 +24,7 @@ pub struct OutputRare { } impl Sats { - pub(crate) fn run(&self, options: Options) -> Result { + pub(crate) fn run(&self, options: Options) -> SubcommandResult { let index = Index::open(&options)?; index.update()?; @@ -42,7 +42,7 @@ impl Sats { output: outpoint, }); } - print_json(output)?; + Ok(Box::new(output)) } else { let mut output = Vec::new(); for (outpoint, sat, offset, rarity) in rare_sats(utxos) { @@ -53,10 +53,8 @@ impl Sats { rarity, }); } - print_json(output)?; + Ok(Box::new(output)) } - - Ok(()) } } diff --git a/src/subcommand/wallet/send.rs b/src/subcommand/wallet/send.rs index ac8faf52c4..8aa015a297 100644 --- a/src/subcommand/wallet/send.rs +++ b/src/subcommand/wallet/send.rs @@ -19,7 +19,7 @@ pub struct Output { } impl Send { - pub(crate) fn run(self, options: Options) -> Result { + pub(crate) fn run(self, options: Options) -> SubcommandResult { let address = self .address .clone() @@ -49,8 +49,7 @@ impl Send { Outgoing::Amount(amount) => { Self::lock_inscriptions(&client, inscriptions, unspent_outputs)?; let txid = Self::send_amount(&client, amount, address, self.fee_rate.n())?; - print_json(Output { transaction: txid })?; - return Ok(()); + return Ok(Box::new(Output { transaction: txid })); } }; @@ -82,9 +81,7 @@ impl Send { let txid = client.send_raw_transaction(&signed_tx)?; - println!("{txid}"); - - Ok(()) + Ok(Box::new(Output { transaction: txid })) } fn lock_inscriptions( diff --git a/src/subcommand/wallet/transactions.rs b/src/subcommand/wallet/transactions.rs index 9e5961f911..9f63779652 100644 --- a/src/subcommand/wallet/transactions.rs +++ b/src/subcommand/wallet/transactions.rs @@ -13,7 +13,7 @@ pub struct Output { } impl Transactions { - pub(crate) fn run(self, options: Options) -> Result { + pub(crate) fn run(self, options: Options) -> SubcommandResult { let mut output = Vec::new(); for tx in options .bitcoin_rpc_client_for_wallet_command(false)? @@ -30,8 +30,6 @@ impl Transactions { }); } - print_json(output)?; - - Ok(()) + Ok(Box::new(output)) } } diff --git a/tests/wallet/cardinals.rs b/tests/wallet/cardinals.rs index c52a3bdbb9..0cfaa05a18 100644 --- a/tests/wallet/cardinals.rs +++ b/tests/wallet/cardinals.rs @@ -1,6 +1,6 @@ use { super::*, - ord::subcommand::wallet::{cardinals::Cardinal, outputs::Output}, + ord::subcommand::wallet::{cardinals::CardinalUtxo, outputs::Output}, }; #[test] @@ -16,7 +16,7 @@ fn cardinals() { let cardinal_outputs = CommandBuilder::new("wallet cardinals") .rpc_server(&rpc_server) - .run_and_check_output::>(); + .run_and_check_output::>(); assert_eq!(all_outputs.len() - cardinal_outputs.len(), 1); } From 69a10adfb361585e3d6c7d0661b25a2f77eecf3b Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Tue, 22 Aug 2023 19:22:31 -0700 Subject: [PATCH 02/10] Fix some tests --- src/subcommand.rs | 2 +- tests/index.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/subcommand.rs b/src/subcommand.rs index afab4b00be..eea4a3a9aa 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -66,7 +66,7 @@ impl Subcommand { } #[derive(Serialize, Deserialize)] -pub(crate) struct Empty {} +pub struct Empty {} pub(crate) trait Output: Send { fn print_json(&self); diff --git a/tests/index.rs b/tests/index.rs index b232d8ef4f..658df96647 100644 --- a/tests/index.rs +++ b/tests/index.rs @@ -1,4 +1,4 @@ -use {super::*, crate::command_builder::ToArgs}; +use {super::*, crate::command_builder::ToArgs, ord::subcommand::Empty}; #[test] fn custom_index_path() { @@ -11,7 +11,7 @@ fn custom_index_path() { CommandBuilder::new(format!("--index {} index run", index_path.display())) .rpc_server(&rpc_server) - .run_and_extract_stdout(); + .run_and_check_output::(); assert!(index_path.is_file()) } @@ -27,13 +27,13 @@ fn re_opening_database_does_not_trigger_schema_check() { CommandBuilder::new(format!("--index {} index run", index_path.display())) .rpc_server(&rpc_server) - .run_and_extract_stdout(); + .run_and_check_output::(); assert!(index_path.is_file()); CommandBuilder::new(format!("--index {} index run", index_path.display())) .rpc_server(&rpc_server) - .run_and_extract_stdout(); + .run_and_check_output::(); } #[test] From 5451df601efb03bc6a311f066c7529c0845626c9 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 23 Aug 2023 10:40:23 -0700 Subject: [PATCH 03/10] Fix test --- tests/index.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/index.rs b/tests/index.rs index 658df96647..ca24b03f97 100644 --- a/tests/index.rs +++ b/tests/index.rs @@ -80,6 +80,7 @@ fn export_inscription_number_to_id_tsv() { let tsv = CommandBuilder::new("index export --tsv foo.tsv") .rpc_server(&rpc_server) .temp_dir(temp_dir) + .stdout_regex(r"\{\}\n") .run_and_extract_file("foo.tsv"); let entries: std::collections::BTreeMap = tsv From 335964a2162318cefac4bcc7a56919a300d1e855 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 23 Aug 2023 10:49:29 -0700 Subject: [PATCH 04/10] Rename --- tests/command_builder.rs | 2 +- tests/epochs.rs | 2 +- tests/find.rs | 2 +- tests/index.rs | 6 +++--- tests/info.rs | 6 +++--- tests/json_api.rs | 4 ++-- tests/lib.rs | 4 ++-- tests/list.rs | 2 +- tests/parse.rs | 4 ++-- tests/server.rs | 9 ++++----- tests/subsidy.rs | 8 ++++---- tests/supply.rs | 2 +- tests/traits.rs | 4 ++-- tests/wallet/balance.rs | 8 ++++---- tests/wallet/cardinals.rs | 4 ++-- tests/wallet/create.rs | 12 ++++++------ tests/wallet/inscribe.rs | 30 +++++++++++++++--------------- tests/wallet/inscriptions.rs | 14 +++++++------- tests/wallet/outputs.rs | 4 ++-- tests/wallet/receive.rs | 2 +- tests/wallet/restore.rs | 4 ++-- tests/wallet/sats.rs | 4 ++-- tests/wallet/send.rs | 8 ++++---- tests/wallet/transactions.rs | 10 +++++----- 24 files changed, 77 insertions(+), 78 deletions(-) diff --git a/tests/command_builder.rs b/tests/command_builder.rs index 84c14f168a..c2e9dadd53 100644 --- a/tests/command_builder.rs +++ b/tests/command_builder.rs @@ -154,7 +154,7 @@ impl CommandBuilder { stdout.into() } - pub(crate) fn run_and_check_output(self) -> T { + pub(crate) fn run_and_deserialize_output(self) -> T { let stdout = self.stdout_regex(".*").run_and_extract_stdout(); serde_json::from_str(&stdout) .unwrap_or_else(|err| panic!("Failed to deserialize JSON: {err}\n{stdout}")) diff --git a/tests/epochs.rs b/tests/epochs.rs index 648e9e1739..ef49c266d0 100644 --- a/tests/epochs.rs +++ b/tests/epochs.rs @@ -3,7 +3,7 @@ use {super::*, ord::subcommand::epochs::Output, ord::Sat}; #[test] fn empty() { assert_eq!( - CommandBuilder::new("epochs").run_and_check_output::(), + CommandBuilder::new("epochs").run_and_deserialize_output::(), Output { starting_sats: vec![ Sat(0), diff --git a/tests/find.rs b/tests/find.rs index 2efbcea850..63d55497f0 100644 --- a/tests/find.rs +++ b/tests/find.rs @@ -6,7 +6,7 @@ fn find_command_returns_satpoint_for_sat() { assert_eq!( CommandBuilder::new("--index-sats find 0") .rpc_server(&rpc_server) - .run_and_check_output::(), + .run_and_deserialize_output::(), Output { satpoint: "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0:0" .parse() diff --git a/tests/index.rs b/tests/index.rs index ca24b03f97..6fe6ad94e0 100644 --- a/tests/index.rs +++ b/tests/index.rs @@ -11,7 +11,7 @@ fn custom_index_path() { CommandBuilder::new(format!("--index {} index run", index_path.display())) .rpc_server(&rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); assert!(index_path.is_file()) } @@ -27,13 +27,13 @@ fn re_opening_database_does_not_trigger_schema_check() { CommandBuilder::new(format!("--index {} index run", index_path.display())) .rpc_server(&rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); assert!(index_path.is_file()); CommandBuilder::new(format!("--index {} index run", index_path.display())) .rpc_server(&rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); } #[test] diff --git a/tests/info.rs b/tests/info.rs index 1d8d3675e4..414651b175 100644 --- a/tests/info.rs +++ b/tests/info.rs @@ -77,7 +77,7 @@ fn transactions() { index_path.display() )) .rpc_server(&rpc_server) - .run_and_check_output::>() + .run_and_deserialize_output::>() .is_empty()); rpc_server.mine_blocks(10); @@ -87,7 +87,7 @@ fn transactions() { index_path.display() )) .rpc_server(&rpc_server) - .run_and_check_output::>(); + .run_and_deserialize_output::>(); assert_eq!(output[0].start, 0); assert_eq!(output[0].end, 1); @@ -100,7 +100,7 @@ fn transactions() { index_path.display() )) .rpc_server(&rpc_server) - .run_and_check_output::>(); + .run_and_deserialize_output::>(); assert_eq!(output[1].start, 1); assert_eq!(output[1].end, 11); diff --git a/tests/json_api.rs b/tests/json_api.rs index 893d7c7673..bf6170233c 100644 --- a/tests/json_api.rs +++ b/tests/json_api.rs @@ -93,7 +93,7 @@ fn get_sat_with_inscription_on_common_sat_and_more_inscriptions() { )) .write("foo.txt", "FOO") .rpc_server(&rpc_server) - .run_and_check_output(); + .run_and_deserialize_output(); rpc_server.mine_blocks(1); let inscription_id = InscriptionId::from(reveal); @@ -197,7 +197,7 @@ fn create_210_inscriptions( let Inscribe { reveal, .. } = CommandBuilder::new("wallet inscribe --fee-rate 1 foo.txt") .write("foo.txt", "FOO") .rpc_server(rpc_server) - .run_and_check_output(); + .run_and_deserialize_output(); rpc_server.mine_blocks(1); blessed_inscriptions.push(InscriptionId::from(reveal)); } diff --git a/tests/lib.rs b/tests/lib.rs index 037b97110c..8d95f50a47 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -55,7 +55,7 @@ fn inscribe(rpc_server: &test_bitcoincore_rpc::Handle) -> Inscribe { let output = CommandBuilder::new("wallet inscribe --fee-rate 1 foo.txt") .write("foo.txt", "FOO") .rpc_server(rpc_server) - .run_and_check_output(); + .run_and_deserialize_output(); rpc_server.mine_blocks(1); @@ -88,7 +88,7 @@ struct Create { fn create_wallet(rpc_server: &test_bitcoincore_rpc::Handle) { CommandBuilder::new(format!("--chain {} wallet create", rpc_server.network())) .rpc_server(rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); } mod command_builder; diff --git a/tests/list.rs b/tests/list.rs index 8b82267d3b..d66fd47caa 100644 --- a/tests/list.rs +++ b/tests/list.rs @@ -7,7 +7,7 @@ fn output_found() { "--index-sats list 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0", ) .rpc_server(&rpc_server) - .run_and_check_output::>(); + .run_and_deserialize_output::>(); assert_eq!( output, diff --git a/tests/parse.rs b/tests/parse.rs index 241ae0467c..1877c25ec7 100644 --- a/tests/parse.rs +++ b/tests/parse.rs @@ -3,7 +3,7 @@ use {super::*, ord::subcommand::parse::Output, ord::Object}; #[test] fn name() { assert_eq!( - CommandBuilder::new("parse a").run_and_check_output::(), + CommandBuilder::new("parse a").run_and_deserialize_output::(), Output { object: Object::Integer(2099999997689999), } @@ -14,7 +14,7 @@ fn name() { fn hash() { assert_eq!( CommandBuilder::new("parse 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef") - .run_and_check_output::(), + .run_and_deserialize_output::(), Output { object: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" .parse::() diff --git a/tests/server.rs b/tests/server.rs index 4ded70df60..c893cc901b 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -1,4 +1,4 @@ -use {super::*, crate::command_builder::ToArgs}; +use {super::*, crate::command_builder::ToArgs, ord::subcommand::wallet::send::Output}; #[test] fn run() { @@ -148,17 +148,16 @@ fn inscription_page_after_send() { )) .rpc_server(&rpc_server) .stdout_regex(".*") - .run_and_extract_stdout(); + .run_and_deserialize_output::() + .transaction; rpc_server.mine_blocks(1); - let send = txid.trim(); - let ord_server = TestServer::spawn_with_args(&rpc_server, &[]); ord_server.assert_response_regex( format!("/inscription/{inscription}"), format!( - r".*

Inscription 0

.*
address
\s*
bc1qcqgs2pps4u4yedfyl5pysdjjncs8et5utseepv
.*
location
\s*
{send}:0:0
.*", + r".*

Inscription 0

.*
address
\s*
bc1qcqgs2pps4u4yedfyl5pysdjjncs8et5utseepv
.*
location
\s*
{txid}:0:0
.*", ), ) } diff --git a/tests/subsidy.rs b/tests/subsidy.rs index 4ee2a7bf84..624f3fc1d1 100644 --- a/tests/subsidy.rs +++ b/tests/subsidy.rs @@ -3,7 +3,7 @@ use {super::*, ord::subcommand::subsidy::Output}; #[test] fn genesis() { assert_eq!( - CommandBuilder::new("subsidy 0").run_and_check_output::(), + CommandBuilder::new("subsidy 0").run_and_deserialize_output::(), Output { first: 0, subsidy: 5000000000, @@ -15,7 +15,7 @@ fn genesis() { #[test] fn second_block() { assert_eq!( - CommandBuilder::new("subsidy 1").run_and_check_output::(), + CommandBuilder::new("subsidy 1").run_and_deserialize_output::(), Output { first: 5000000000, subsidy: 5000000000, @@ -27,7 +27,7 @@ fn second_block() { #[test] fn second_to_last_block_with_subsidy() { assert_eq!( - CommandBuilder::new("subsidy 6929998").run_and_check_output::(), + CommandBuilder::new("subsidy 6929998").run_and_deserialize_output::(), Output { first: 2099999997689998, subsidy: 1, @@ -39,7 +39,7 @@ fn second_to_last_block_with_subsidy() { #[test] fn last_block_with_subsidy() { assert_eq!( - CommandBuilder::new("subsidy 6929999").run_and_check_output::(), + CommandBuilder::new("subsidy 6929999").run_and_deserialize_output::(), Output { first: 2099999997689999, subsidy: 1, diff --git a/tests/supply.rs b/tests/supply.rs index 581224e474..9e5f396af2 100644 --- a/tests/supply.rs +++ b/tests/supply.rs @@ -3,7 +3,7 @@ use {super::*, ord::subcommand::supply::Output}; #[test] fn genesis() { assert_eq!( - CommandBuilder::new("supply").run_and_check_output::(), + CommandBuilder::new("supply").run_and_deserialize_output::(), Output { supply: 2099999997690000, first: 0, diff --git a/tests/traits.rs b/tests/traits.rs index da2d1232e8..3eb4aa6fa1 100644 --- a/tests/traits.rs +++ b/tests/traits.rs @@ -3,7 +3,7 @@ use {super::*, ord::subcommand::traits::Output, ord::Rarity}; #[test] fn traits_command_prints_sat_traits() { assert_eq!( - CommandBuilder::new("traits 0").run_and_check_output::(), + CommandBuilder::new("traits 0").run_and_deserialize_output::(), Output { number: 0, decimal: "0.0".into(), @@ -21,7 +21,7 @@ fn traits_command_prints_sat_traits() { #[test] fn traits_command_for_last_sat() { assert_eq!( - CommandBuilder::new("traits 2099999997689999").run_and_check_output::(), + CommandBuilder::new("traits 2099999997689999").run_and_deserialize_output::(), Output { number: 2099999997689999, decimal: "6929999.0".into(), diff --git a/tests/wallet/balance.rs b/tests/wallet/balance.rs index bd686b99a5..79557aa562 100644 --- a/tests/wallet/balance.rs +++ b/tests/wallet/balance.rs @@ -8,7 +8,7 @@ fn wallet_balance() { assert_eq!( CommandBuilder::new("wallet balance") .rpc_server(&rpc_server) - .run_and_check_output::() + .run_and_deserialize_output::() .cardinal, 0 ); @@ -18,7 +18,7 @@ fn wallet_balance() { assert_eq!( CommandBuilder::new("wallet balance") .rpc_server(&rpc_server) - .run_and_check_output::() + .run_and_deserialize_output::() .cardinal, 50 * COIN_VALUE ); @@ -32,7 +32,7 @@ fn wallet_balance_only_counts_cardinal_utxos() { assert_eq!( CommandBuilder::new("wallet balance") .rpc_server(&rpc_server) - .run_and_check_output::() + .run_and_deserialize_output::() .cardinal, 0 ); @@ -42,7 +42,7 @@ fn wallet_balance_only_counts_cardinal_utxos() { assert_eq!( CommandBuilder::new("wallet balance") .rpc_server(&rpc_server) - .run_and_check_output::() + .run_and_deserialize_output::() .cardinal, 100 * COIN_VALUE - 10_000 ); diff --git a/tests/wallet/cardinals.rs b/tests/wallet/cardinals.rs index 0cfaa05a18..db966c39a8 100644 --- a/tests/wallet/cardinals.rs +++ b/tests/wallet/cardinals.rs @@ -12,11 +12,11 @@ fn cardinals() { let all_outputs = CommandBuilder::new("wallet outputs") .rpc_server(&rpc_server) - .run_and_check_output::>(); + .run_and_deserialize_output::>(); let cardinal_outputs = CommandBuilder::new("wallet cardinals") .rpc_server(&rpc_server) - .run_and_check_output::>(); + .run_and_deserialize_output::>(); assert_eq!(all_outputs.len() - cardinal_outputs.len(), 1); } diff --git a/tests/wallet/create.rs b/tests/wallet/create.rs index cc8d5ec35c..929152d810 100644 --- a/tests/wallet/create.rs +++ b/tests/wallet/create.rs @@ -8,7 +8,7 @@ fn create() { CommandBuilder::new("wallet create") .rpc_server(&rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); assert!(rpc_server.wallets().contains("ord")); } @@ -17,7 +17,7 @@ fn create() { fn seed_phrases_are_twelve_words_long() { let Create { mnemonic } = CommandBuilder::new("wallet create") .rpc_server(&test_bitcoincore_rpc::spawn()) - .run_and_check_output::(); + .run_and_deserialize_output::(); assert_eq!(mnemonic.word_count(), 12); } @@ -28,7 +28,7 @@ fn wallet_creates_correct_mainnet_taproot_descriptor() { CommandBuilder::new("wallet create") .rpc_server(&rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); assert_eq!(rpc_server.descriptors().len(), 2); assert_regex_match!( @@ -49,7 +49,7 @@ fn wallet_creates_correct_test_network_taproot_descriptor() { CommandBuilder::new("--chain signet wallet create") .rpc_server(&rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); assert_eq!(rpc_server.descriptors().len(), 2); assert_regex_match!( @@ -68,7 +68,7 @@ fn detect_wrong_descriptors() { CommandBuilder::new("wallet create") .rpc_server(&rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); rpc_server.import_descriptor("wpkh([aslfjk])#a23ad2l".to_string()); @@ -89,7 +89,7 @@ fn create_with_different_name() { CommandBuilder::new("--wallet inscription-wallet wallet create") .rpc_server(&rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); assert!(rpc_server.wallets().contains("inscription-wallet")); } diff --git a/tests/wallet/inscribe.rs b/tests/wallet/inscribe.rs index 47527a8284..12430f1526 100644 --- a/tests/wallet/inscribe.rs +++ b/tests/wallet/inscribe.rs @@ -35,7 +35,7 @@ fn inscribe_works_with_huge_expensive_inscriptions() { )) .write("foo.txt", [0; 350_000]) .rpc_server(&rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); } #[test] @@ -61,7 +61,7 @@ fn inscribe_no_backup() { CommandBuilder::new("wallet inscribe hello.txt --no-backup --fee-rate 1") .write("hello.txt", "HELLOWORLD") .rpc_server(&rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); assert_eq!(rpc_server.descriptors().len(), 2); } @@ -205,7 +205,7 @@ fn inscribe_with_optional_satpoint_arg() { )) .write("foo.txt", "FOO") .rpc_server(&rpc_server) - .run_and_check_output(); + .run_and_deserialize_output(); rpc_server.mine_blocks(1); @@ -227,7 +227,7 @@ fn inscribe_with_fee_rate() { CommandBuilder::new("--index-sats wallet inscribe degenerate.png --fee-rate 2.0") .write("degenerate.png", [1; 520]) .rpc_server(&rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); let tx1 = &rpc_server.mempool()[0]; let mut fee = 0; @@ -270,7 +270,7 @@ fn inscribe_with_commit_fee_rate() { ) .write("degenerate.png", [1; 520]) .rpc_server(&rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); let tx1 = &rpc_server.mempool()[0]; let mut fee = 0; @@ -308,14 +308,14 @@ fn inscribe_with_wallet_named_foo() { CommandBuilder::new("--wallet foo wallet create") .rpc_server(&rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); rpc_server.mine_blocks(1); CommandBuilder::new("--wallet foo wallet inscribe degenerate.png --fee-rate 1") .write("degenerate.png", [1; 520]) .rpc_server(&rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); } #[test] @@ -327,14 +327,14 @@ fn inscribe_with_dry_run_flag() { CommandBuilder::new("wallet inscribe --dry-run degenerate.png --fee-rate 1") .write("degenerate.png", [1; 520]) .rpc_server(&rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); assert!(rpc_server.mempool().is_empty()); CommandBuilder::new("wallet inscribe degenerate.png --fee-rate 1") .write("degenerate.png", [1; 520]) .rpc_server(&rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); assert_eq!(rpc_server.mempool().len(), 2); } @@ -349,14 +349,14 @@ fn inscribe_with_dry_run_flag_fees_inscrease() { CommandBuilder::new("wallet inscribe --dry-run degenerate.png --fee-rate 1") .write("degenerate.png", [1; 520]) .rpc_server(&rpc_server) - .run_and_check_output::() + .run_and_deserialize_output::() .fees; let total_fee_normal = CommandBuilder::new("wallet inscribe --dry-run degenerate.png --fee-rate 1.1") .write("degenerate.png", [1; 520]) .rpc_server(&rpc_server) - .run_and_check_output::() + .run_and_deserialize_output::() .fees; assert!(total_fee_dry_run < total_fee_normal); @@ -370,7 +370,7 @@ fn inscribe_to_specific_destination() { let destination = CommandBuilder::new("wallet receive") .rpc_server(&rpc_server) - .run_and_check_output::() + .run_and_deserialize_output::() .address; let txid = CommandBuilder::new(format!( @@ -379,7 +379,7 @@ fn inscribe_to_specific_destination() { )) .write("degenerate.png", [1; 520]) .rpc_server(&rpc_server) - .run_and_check_output::() + .run_and_deserialize_output::() .reveal; let reveal_tx = &rpc_server.mempool()[1]; // item 0 is the commit, item 1 is the reveal. @@ -427,14 +427,14 @@ fn inscribe_works_with_postage() { CommandBuilder::new("wallet inscribe foo.txt --postage 5btc --fee-rate 10".to_string()) .write("foo.txt", [0; 350]) .rpc_server(&rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); rpc_server.mine_blocks(1); let inscriptions = CommandBuilder::new("wallet inscriptions".to_string()) .write("foo.txt", [0; 350]) .rpc_server(&rpc_server) - .run_and_check_output::>(); + .run_and_deserialize_output::>(); pretty_assert_eq!(inscriptions[0].postage, 5 * COIN_VALUE); } diff --git a/tests/wallet/inscriptions.rs b/tests/wallet/inscriptions.rs index 3951e8f072..4d0f9c8a03 100644 --- a/tests/wallet/inscriptions.rs +++ b/tests/wallet/inscriptions.rs @@ -17,7 +17,7 @@ fn inscriptions() { let output = CommandBuilder::new("wallet inscriptions") .rpc_server(&rpc_server) - .run_and_check_output::>(); + .run_and_deserialize_output::>(); assert_eq!(output.len(), 1); assert_eq!(output[0].inscription, inscription.parse().unwrap()); @@ -29,7 +29,7 @@ fn inscriptions() { let address = CommandBuilder::new("wallet receive") .rpc_server(&rpc_server) - .run_and_check_output::() + .run_and_deserialize_output::() .address; let stdout = CommandBuilder::new(format!( @@ -47,7 +47,7 @@ fn inscriptions() { let output = CommandBuilder::new("wallet inscriptions") .rpc_server(&rpc_server) - .run_and_check_output::>(); + .run_and_deserialize_output::>(); assert_eq!(output.len(), 1); assert_eq!(output[0].inscription, inscription.parse().unwrap()); @@ -76,7 +76,7 @@ fn inscriptions_includes_locked_utxos() { let output = CommandBuilder::new("wallet inscriptions") .rpc_server(&rpc_server) - .run_and_check_output::>(); + .run_and_deserialize_output::>(); assert_eq!(output.len(), 1); assert_eq!(output[0].inscription, inscription.parse().unwrap()); @@ -93,13 +93,13 @@ fn inscriptions_with_postage() { let output = CommandBuilder::new("wallet inscriptions") .rpc_server(&rpc_server) - .run_and_check_output::>(); + .run_and_deserialize_output::>(); assert_eq!(output[0].postage, 10000); let address = CommandBuilder::new("wallet receive") .rpc_server(&rpc_server) - .run_and_check_output::() + .run_and_deserialize_output::() .address; CommandBuilder::new(format!( @@ -115,7 +115,7 @@ fn inscriptions_with_postage() { let output = CommandBuilder::new("wallet inscriptions") .rpc_server(&rpc_server) - .run_and_check_output::>(); + .run_and_deserialize_output::>(); assert_eq!(output[0].postage, 9889); } diff --git a/tests/wallet/outputs.rs b/tests/wallet/outputs.rs index de75585fc4..fcef95d39c 100644 --- a/tests/wallet/outputs.rs +++ b/tests/wallet/outputs.rs @@ -11,7 +11,7 @@ fn outputs() { let output = CommandBuilder::new("wallet outputs") .rpc_server(&rpc_server) - .run_and_check_output::>(); + .run_and_deserialize_output::>(); assert_eq!(output[0].output, outpoint); assert_eq!(output[0].amount, amount); @@ -30,7 +30,7 @@ fn outputs_includes_locked_outputs() { let output = CommandBuilder::new("wallet outputs") .rpc_server(&rpc_server) - .run_and_check_output::>(); + .run_and_deserialize_output::>(); assert_eq!(output[0].output, outpoint); assert_eq!(output[0].amount, amount); diff --git a/tests/wallet/receive.rs b/tests/wallet/receive.rs index 15aba71879..3f5f9120d4 100644 --- a/tests/wallet/receive.rs +++ b/tests/wallet/receive.rs @@ -7,7 +7,7 @@ fn receive() { let output = CommandBuilder::new("wallet receive") .rpc_server(&rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); assert!(output.address.is_valid_for_network(Network::Bitcoin)); } diff --git a/tests/wallet/restore.rs b/tests/wallet/restore.rs index 6ed175eada..141f7e2a20 100644 --- a/tests/wallet/restore.rs +++ b/tests/wallet/restore.rs @@ -7,7 +7,7 @@ fn restore_generates_same_descriptors() { let Create { mnemonic } = CommandBuilder::new("wallet create") .rpc_server(&rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); (mnemonic, rpc_server.descriptors()) }; @@ -29,7 +29,7 @@ fn restore_generates_same_descriptors_with_passphrase() { let Create { mnemonic } = CommandBuilder::new(["wallet", "create", "--passphrase", passphrase]) .rpc_server(&rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); (mnemonic, rpc_server.descriptors()) }; diff --git a/tests/wallet/sats.rs b/tests/wallet/sats.rs index e835833a2c..0d6ec2657b 100644 --- a/tests/wallet/sats.rs +++ b/tests/wallet/sats.rs @@ -11,7 +11,7 @@ fn sats() { let output = CommandBuilder::new("--index-sats wallet sats") .rpc_server(&rpc_server) - .run_and_check_output::>(); + .run_and_deserialize_output::>(); assert_eq!(output[0].sat, 50 * COIN_VALUE); assert_eq!(output[0].output.to_string(), format!("{second_coinbase}:0")); @@ -26,7 +26,7 @@ fn sats_from_tsv_success() { let output = CommandBuilder::new("--index-sats wallet sats --tsv foo.tsv") .write("foo.tsv", "nvtcsezkbtg") .rpc_server(&rpc_server) - .run_and_check_output::>(); + .run_and_deserialize_output::>(); assert_eq!(output[0].sat, "nvtcsezkbtg"); assert_eq!(output[0].output.to_string(), format!("{second_coinbase}:0")); diff --git a/tests/wallet/send.rs b/tests/wallet/send.rs index 996be6e737..0a1c4bb473 100644 --- a/tests/wallet/send.rs +++ b/tests/wallet/send.rs @@ -96,7 +96,7 @@ fn send_on_mainnnet_works_with_wallet_named_foo() { CommandBuilder::new("--wallet foo wallet create") .rpc_server(&rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); CommandBuilder::new(format!( "--wallet foo wallet send --fee-rate 1 bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 {txid}:0:0" @@ -151,7 +151,7 @@ fn send_does_not_use_inscribed_sats_as_cardinal_utxos() { )) .write("degenerate.png", [1; 100]) .rpc_server(&rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); let txid = rpc_server.mine_blocks_with_subsidy(1, 100)[0].txdata[0].txid(); CommandBuilder::new(format!( @@ -221,7 +221,7 @@ fn send_btc_with_fee_rate() { "wallet send --fee-rate 13.3 bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 1btc", ) .rpc_server(&rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); let tx = &rpc_server.mempool()[0]; let mut fee = 0; @@ -271,7 +271,7 @@ fn send_btc_locks_inscriptions() { let output = CommandBuilder::new("wallet send --fee-rate 1 bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 1btc") .rpc_server(&rpc_server) - .run_and_check_output::(); + .run_and_deserialize_output::(); assert_eq!( output.transaction, diff --git a/tests/wallet/transactions.rs b/tests/wallet/transactions.rs index d3f275711e..8f3fd4ffc9 100644 --- a/tests/wallet/transactions.rs +++ b/tests/wallet/transactions.rs @@ -9,7 +9,7 @@ fn transactions() { CommandBuilder::new("wallet transactions") .rpc_server(&rpc_server) - .run_and_check_output::>(); + .run_and_deserialize_output::>(); assert_eq!(rpc_server.loaded_wallets().len(), 1); assert_eq!(rpc_server.loaded_wallets().first().unwrap(), "ord"); @@ -18,7 +18,7 @@ fn transactions() { let output = CommandBuilder::new("wallet transactions") .rpc_server(&rpc_server) - .run_and_check_output::>(); + .run_and_deserialize_output::>(); assert_regex_match!(output[0].transaction.to_string(), "[[:xdigit:]]{64}"); assert_eq!(output[0].confirmations, 1); @@ -38,7 +38,7 @@ fn transactions_with_limit() { let output = CommandBuilder::new("wallet transactions") .rpc_server(&rpc_server) - .run_and_check_output::>(); + .run_and_deserialize_output::>(); assert_regex_match!(output[0].transaction.to_string(), "[[:xdigit:]]{64}"); assert_eq!(output[0].confirmations, 1); @@ -47,14 +47,14 @@ fn transactions_with_limit() { let output = CommandBuilder::new("wallet transactions") .rpc_server(&rpc_server) - .run_and_check_output::>(); + .run_and_deserialize_output::>(); assert_regex_match!(output[1].transaction.to_string(), "[[:xdigit:]]{64}"); assert_eq!(output[1].confirmations, 2); let output = CommandBuilder::new("wallet transactions --limit 1") .rpc_server(&rpc_server) - .run_and_check_output::>(); + .run_and_deserialize_output::>(); assert_regex_match!(output[0].transaction.to_string(), "[[:xdigit:]]{64}"); assert_eq!(output[0].confirmations, 1); From 4f77ee6d56c3a193ed62e236db5b265ea2389c5d Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 23 Aug 2023 10:52:09 -0700 Subject: [PATCH 05/10] Fix test --- tests/wallet/inscriptions.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/wallet/inscriptions.rs b/tests/wallet/inscriptions.rs index 4d0f9c8a03..107d2dd360 100644 --- a/tests/wallet/inscriptions.rs +++ b/tests/wallet/inscriptions.rs @@ -1,6 +1,6 @@ use { super::*, - ord::subcommand::wallet::{inscriptions::Output, receive}, + ord::subcommand::wallet::{inscriptions, receive, send}, }; #[test] @@ -17,7 +17,7 @@ fn inscriptions() { let output = CommandBuilder::new("wallet inscriptions") .rpc_server(&rpc_server) - .run_and_deserialize_output::>(); + .run_and_deserialize_output::>(); assert_eq!(output.len(), 1); assert_eq!(output[0].inscription, inscription.parse().unwrap()); @@ -32,22 +32,21 @@ fn inscriptions() { .run_and_deserialize_output::() .address; - let stdout = CommandBuilder::new(format!( + let txid = CommandBuilder::new(format!( "wallet send --fee-rate 1 {} {inscription}", address.assume_checked() )) .rpc_server(&rpc_server) .expected_exit_code(0) .stdout_regex(".*") - .run_and_extract_stdout(); + .run_and_deserialize_output::() + .transaction; rpc_server.mine_blocks(1); - let txid = Txid::from_str(stdout.trim()).unwrap(); - let output = CommandBuilder::new("wallet inscriptions") .rpc_server(&rpc_server) - .run_and_deserialize_output::>(); + .run_and_deserialize_output::>(); assert_eq!(output.len(), 1); assert_eq!(output[0].inscription, inscription.parse().unwrap()); @@ -76,7 +75,7 @@ fn inscriptions_includes_locked_utxos() { let output = CommandBuilder::new("wallet inscriptions") .rpc_server(&rpc_server) - .run_and_deserialize_output::>(); + .run_and_deserialize_output::>(); assert_eq!(output.len(), 1); assert_eq!(output[0].inscription, inscription.parse().unwrap()); @@ -93,7 +92,7 @@ fn inscriptions_with_postage() { let output = CommandBuilder::new("wallet inscriptions") .rpc_server(&rpc_server) - .run_and_deserialize_output::>(); + .run_and_deserialize_output::>(); assert_eq!(output[0].postage, 10000); @@ -115,7 +114,7 @@ fn inscriptions_with_postage() { let output = CommandBuilder::new("wallet inscriptions") .rpc_server(&rpc_server) - .run_and_deserialize_output::>(); + .run_and_deserialize_output::>(); assert_eq!(output[0].postage, 9889); } From 56c208374004cb30d8442b58fc61039067e2f706 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 23 Aug 2023 11:30:23 -0700 Subject: [PATCH 06/10] Fix tests --- src/subcommand/wallet/create.rs | 8 ++++---- tests/lib.rs | 9 ++------- tests/wallet/create.rs | 16 ++++++++-------- tests/wallet/inscribe.rs | 2 +- tests/wallet/restore.rs | 17 +++++++++-------- tests/wallet/send.rs | 10 +++++----- 6 files changed, 29 insertions(+), 33 deletions(-) diff --git a/src/subcommand/wallet/create.rs b/src/subcommand/wallet/create.rs index 18d66b1d6a..4efb9579a4 100644 --- a/src/subcommand/wallet/create.rs +++ b/src/subcommand/wallet/create.rs @@ -1,9 +1,9 @@ use super::*; -#[derive(Serialize)] -struct Output { - mnemonic: Mnemonic, - passphrase: Option, +#[derive(Serialize, Deserialize)] +pub struct Output { + pub mnemonic: Mnemonic, + pub passphrase: Option, } #[derive(Debug, Parser)] diff --git a/tests/lib.rs b/tests/lib.rs index 8d95f50a47..1f3b7106ec 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -2,13 +2,13 @@ use { self::{command_builder::CommandBuilder, expected::Expected, test_server::TestServer}, - bip39::Mnemonic, bitcoin::{ address::{Address, NetworkUnchecked}, blockdata::constants::COIN_VALUE, Network, OutPoint, Txid, }, executable_path::executable_path, + ord::subcommand::wallet::create, pretty_assertions::assert_eq as pretty_assert_eq, regex::Regex, reqwest::{StatusCode, Url}, @@ -80,15 +80,10 @@ fn envelope(payload: &[&[u8]]) -> bitcoin::Witness { bitcoin::Witness::from_slice(&[script.into_bytes(), Vec::new()]) } -#[derive(Deserialize)] -struct Create { - mnemonic: Mnemonic, -} - fn create_wallet(rpc_server: &test_bitcoincore_rpc::Handle) { CommandBuilder::new(format!("--chain {} wallet create", rpc_server.network())) .rpc_server(rpc_server) - .run_and_deserialize_output::(); + .run_and_deserialize_output::(); } mod command_builder; diff --git a/tests/wallet/create.rs b/tests/wallet/create.rs index 929152d810..c5f267e418 100644 --- a/tests/wallet/create.rs +++ b/tests/wallet/create.rs @@ -1,4 +1,4 @@ -use super::*; +use {super::*, ord::subcommand::wallet::create::Output}; #[test] fn create() { @@ -8,16 +8,16 @@ fn create() { CommandBuilder::new("wallet create") .rpc_server(&rpc_server) - .run_and_deserialize_output::(); + .run_and_deserialize_output::(); assert!(rpc_server.wallets().contains("ord")); } #[test] fn seed_phrases_are_twelve_words_long() { - let Create { mnemonic } = CommandBuilder::new("wallet create") + let Output { mnemonic, .. } = CommandBuilder::new("wallet create") .rpc_server(&test_bitcoincore_rpc::spawn()) - .run_and_deserialize_output::(); + .run_and_deserialize_output(); assert_eq!(mnemonic.word_count(), 12); } @@ -28,7 +28,7 @@ fn wallet_creates_correct_mainnet_taproot_descriptor() { CommandBuilder::new("wallet create") .rpc_server(&rpc_server) - .run_and_deserialize_output::(); + .run_and_deserialize_output::(); assert_eq!(rpc_server.descriptors().len(), 2); assert_regex_match!( @@ -49,7 +49,7 @@ fn wallet_creates_correct_test_network_taproot_descriptor() { CommandBuilder::new("--chain signet wallet create") .rpc_server(&rpc_server) - .run_and_deserialize_output::(); + .run_and_deserialize_output::(); assert_eq!(rpc_server.descriptors().len(), 2); assert_regex_match!( @@ -68,7 +68,7 @@ fn detect_wrong_descriptors() { CommandBuilder::new("wallet create") .rpc_server(&rpc_server) - .run_and_deserialize_output::(); + .run_and_deserialize_output::(); rpc_server.import_descriptor("wpkh([aslfjk])#a23ad2l".to_string()); @@ -89,7 +89,7 @@ fn create_with_different_name() { CommandBuilder::new("--wallet inscription-wallet wallet create") .rpc_server(&rpc_server) - .run_and_deserialize_output::(); + .run_and_deserialize_output::(); assert!(rpc_server.wallets().contains("inscription-wallet")); } diff --git a/tests/wallet/inscribe.rs b/tests/wallet/inscribe.rs index 12430f1526..4af22348e1 100644 --- a/tests/wallet/inscribe.rs +++ b/tests/wallet/inscribe.rs @@ -308,7 +308,7 @@ fn inscribe_with_wallet_named_foo() { CommandBuilder::new("--wallet foo wallet create") .rpc_server(&rpc_server) - .run_and_deserialize_output::(); + .run_and_deserialize_output::(); rpc_server.mine_blocks(1); diff --git a/tests/wallet/restore.rs b/tests/wallet/restore.rs index 141f7e2a20..5106c5eb33 100644 --- a/tests/wallet/restore.rs +++ b/tests/wallet/restore.rs @@ -1,13 +1,13 @@ -use super::*; +use {super::*, ord::subcommand::wallet::create, ord::subcommand::Empty}; #[test] fn restore_generates_same_descriptors() { let (mnemonic, descriptors) = { let rpc_server = test_bitcoincore_rpc::spawn(); - let Create { mnemonic } = CommandBuilder::new("wallet create") + let create::Output { mnemonic, .. } = CommandBuilder::new("wallet create") .rpc_server(&rpc_server) - .run_and_deserialize_output::(); + .run_and_deserialize_output(); (mnemonic, rpc_server.descriptors()) }; @@ -16,7 +16,7 @@ fn restore_generates_same_descriptors() { CommandBuilder::new(["wallet", "restore", &mnemonic.to_string()]) .rpc_server(&rpc_server) - .run_and_extract_stdout(); + .run_and_deserialize_output::(); assert_eq!(rpc_server.descriptors(), descriptors); } @@ -27,9 +27,10 @@ fn restore_generates_same_descriptors_with_passphrase() { let (mnemonic, descriptors) = { let rpc_server = test_bitcoincore_rpc::spawn(); - let Create { mnemonic } = CommandBuilder::new(["wallet", "create", "--passphrase", passphrase]) - .rpc_server(&rpc_server) - .run_and_deserialize_output::(); + let create::Output { mnemonic, .. } = + CommandBuilder::new(["wallet", "create", "--passphrase", passphrase]) + .rpc_server(&rpc_server) + .run_and_deserialize_output(); (mnemonic, rpc_server.descriptors()) }; @@ -44,7 +45,7 @@ fn restore_generates_same_descriptors_with_passphrase() { &mnemonic.to_string(), ]) .rpc_server(&rpc_server) - .run_and_extract_stdout(); + .run_and_deserialize_output::(); assert_eq!(rpc_server.descriptors(), descriptors); } diff --git a/tests/wallet/send.rs b/tests/wallet/send.rs index 0a1c4bb473..a66d6123ba 100644 --- a/tests/wallet/send.rs +++ b/tests/wallet/send.rs @@ -10,19 +10,19 @@ fn inscriptions_can_be_sent() { rpc_server.mine_blocks(1); - let stdout = CommandBuilder::new(format!( + let output = CommandBuilder::new(format!( "wallet send --fee-rate 1 bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 {inscription}", )) .rpc_server(&rpc_server) .stdout_regex(r".*") - .run_and_extract_stdout(); + .run_and_deserialize_output::(); let txid = rpc_server.mempool()[0].txid(); - assert_eq!(format!("{txid}\n"), stdout); + assert_eq!(txid, output.transaction); rpc_server.mine_blocks(1); - let send_txid = stdout.trim(); + let send_txid = output.transaction; let ord_server = TestServer::spawn_with_args(&rpc_server, &[]); ord_server.assert_response_regex( @@ -96,7 +96,7 @@ fn send_on_mainnnet_works_with_wallet_named_foo() { CommandBuilder::new("--wallet foo wallet create") .rpc_server(&rpc_server) - .run_and_deserialize_output::(); + .run_and_deserialize_output::(); CommandBuilder::new(format!( "--wallet foo wallet send --fee-rate 1 bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 {txid}:0:0" From 8aac61a200d9ba3e335d8032991f93495d31ed62 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 23 Aug 2023 11:34:31 -0700 Subject: [PATCH 07/10] Fix test --- tests/wallet/send.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/wallet/send.rs b/tests/wallet/send.rs index a66d6123ba..fb1457f717 100644 --- a/tests/wallet/send.rs +++ b/tests/wallet/send.rs @@ -69,16 +69,16 @@ fn send_inscribed_sat() { rpc_server.mine_blocks(1); - let stdout = CommandBuilder::new(format!( + let output = CommandBuilder::new(format!( "wallet send --fee-rate 1 bc1qcqgs2pps4u4yedfyl5pysdjjncs8et5utseepv {inscription}", )) .rpc_server(&rpc_server) .stdout_regex("[[:xdigit:]]{64}\n") - .run_and_extract_stdout(); + .run_and_deserialize_output::(); rpc_server.mine_blocks(1); - let send_txid = stdout.trim(); + let send_txid = output.transaction; let ord_server = TestServer::spawn_with_args(&rpc_server, &[]); ord_server.assert_response_regex( From 4a6ceb12bea643a48998bc8da1595a9aed5133c5 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 23 Aug 2023 11:41:02 -0700 Subject: [PATCH 08/10] Fix the rest of the tests --- tests/wallet/send.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/tests/wallet/send.rs b/tests/wallet/send.rs index fb1457f717..77401c0501 100644 --- a/tests/wallet/send.rs +++ b/tests/wallet/send.rs @@ -73,7 +73,6 @@ fn send_inscribed_sat() { "wallet send --fee-rate 1 bc1qcqgs2pps4u4yedfyl5pysdjjncs8et5utseepv {inscription}", )) .rpc_server(&rpc_server) - .stdout_regex("[[:xdigit:]]{64}\n") .run_and_deserialize_output::(); rpc_server.mine_blocks(1); @@ -102,8 +101,7 @@ fn send_on_mainnnet_works_with_wallet_named_foo() { "--wallet foo wallet send --fee-rate 1 bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 {txid}:0:0" )) .rpc_server(&rpc_server) - .stdout_regex(r"[[:xdigit:]]{64}\n") - .run_and_extract_stdout(); + .run_and_deserialize_output::(); } #[test] @@ -129,15 +127,13 @@ fn send_on_mainnnet_works_with_wallet_named_ord() { let txid = rpc_server.mine_blocks_with_subsidy(1, 1_000_000)[0].txdata[0].txid(); create_wallet(&rpc_server); - let stdout = CommandBuilder::new(format!( + let output = CommandBuilder::new(format!( "wallet send --fee-rate 1 bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 {txid}:0:0" )) .rpc_server(&rpc_server) - .stdout_regex(r".*") - .run_and_extract_stdout(); + .run_and_deserialize_output::(); - let txid = rpc_server.mempool()[0].txid(); - assert_eq!(format!("{txid}\n"), stdout); + assert_eq!(rpc_server.mempool()[0].txid(), output.transaction); } #[test] @@ -324,8 +320,7 @@ fn wallet_send_with_fee_rate() { "wallet send bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 {inscription} --fee-rate 2.0" )) .rpc_server(&rpc_server) - .stdout_regex("[[:xdigit:]]{64}\n") - .run_and_extract_stdout(); + .run_and_deserialize_output::(); let tx = &rpc_server.mempool()[0]; let mut fee = 0; @@ -376,8 +371,7 @@ fn wallet_send_with_fee_rate_and_target_postage() { "wallet send bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 {inscription} --fee-rate 2.0 --postage 77000sat" )) .rpc_server(&rpc_server) - .stdout_regex("[[:xdigit:]]{64}\n") - .run_and_extract_stdout(); + .run_and_deserialize_output::(); let tx = &rpc_server.mempool()[0]; let mut fee = 0; From 074108b48d444b572ca5a20645508b2ce40c4d65 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 23 Aug 2023 11:56:58 -0700 Subject: [PATCH 09/10] Fix tests --- tests/wallet/send.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/wallet/send.rs b/tests/wallet/send.rs index 69b985dfc8..9b3def4bc5 100644 --- a/tests/wallet/send.rs +++ b/tests/wallet/send.rs @@ -206,8 +206,7 @@ fn can_send_after_dust_limit_from_an_inscription() { "wallet send --fee-rate 1 bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 {output}:330" )) .rpc_server(&rpc_server) - .stdout_regex("[[:xdigit:]]{64}\n") - .run_and_extract_stdout(); + .run_and_deserialize_output::(); } #[test] @@ -280,8 +279,7 @@ fn splitting_merged_inscriptions_is_possible() { reveal_txid, )) .rpc_server(&rpc_server) - .stdout_regex("[[:xdigit:]]{64}\n") - .run_and_extract_stdout(); + .run_and_deserialize_output::(); rpc_server.mine_blocks(1); @@ -291,8 +289,7 @@ fn splitting_merged_inscriptions_is_possible() { reveal_txid, )) .rpc_server(&rpc_server) - .stdout_regex("[[:xdigit:]]{64}\n") - .run_and_extract_stdout(); + .run_and_deserialize_output::(); rpc_server.mine_blocks(1); @@ -302,8 +299,7 @@ fn splitting_merged_inscriptions_is_possible() { reveal_txid, )) .rpc_server(&rpc_server) - .stdout_regex("[[:xdigit:]]{64}\n") - .run_and_extract_stdout(); + .run_and_deserialize_output::(); } #[test] From 3c02dd3b2967f0b432436dfdf483571cc591e269 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 23 Aug 2023 12:07:58 -0700 Subject: [PATCH 10/10] Fix --- src/subcommand/wallet.rs | 2 +- src/subcommand/wallet/inscribe.rs | 12 +++++------ tests/index.rs | 4 ++-- tests/lib.rs | 33 ++++++++++++------------------- tests/wallet/inscriptions.rs | 6 +++--- tests/wallet/send.rs | 2 +- 6 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/subcommand/wallet.rs b/src/subcommand/wallet.rs index 2972c7615f..4bfd6ef401 100644 --- a/src/subcommand/wallet.rs +++ b/src/subcommand/wallet.rs @@ -17,7 +17,7 @@ use { pub mod balance; pub mod cardinals; pub mod create; -pub(crate) mod inscribe; +pub mod inscribe; pub mod inscriptions; pub mod outputs; pub mod receive; diff --git a/src/subcommand/wallet/inscribe.rs b/src/subcommand/wallet/inscribe.rs index ab140b5a82..98c2328c2b 100644 --- a/src/subcommand/wallet/inscribe.rs +++ b/src/subcommand/wallet/inscribe.rs @@ -19,12 +19,12 @@ use { std::collections::BTreeSet, }; -#[derive(Serialize)] -struct Output { - commit: Txid, - inscription: InscriptionId, - reveal: Txid, - fees: u64, +#[derive(Serialize, Deserialize)] +pub struct Output { + pub commit: Txid, + pub inscription: InscriptionId, + pub reveal: Txid, + pub fees: u64, } #[derive(Debug, Parser)] diff --git a/tests/index.rs b/tests/index.rs index 6fe6ad94e0..091fe3229b 100644 --- a/tests/index.rs +++ b/tests/index.rs @@ -97,6 +97,6 @@ fn export_inscription_number_to_id_tsv() { assert_eq!( entries.get(&2).unwrap(), - &ord::Object::from_str(&inscription).unwrap() - ) + &ord::Object::InscriptionId(inscription), + ); } diff --git a/tests/lib.rs b/tests/lib.rs index e4e7664822..3e2eda203f 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -5,21 +5,22 @@ use { bitcoin::{ address::{Address, NetworkUnchecked}, blockdata::constants::COIN_VALUE, - Network, OutPoint, Txid, + Network, OutPoint, }, executable_path::executable_path, - ord::inscription_id::InscriptionId, - ord::rarity::Rarity, - ord::subcommand::wallet::send::Output, - ord::templates::inscription::InscriptionJson, - ord::templates::inscriptions::InscriptionsJson, - ord::templates::output::OutputJson, - ord::templates::sat::SatJson, - ord::SatPoint, + ord::{ + inscription_id::InscriptionId, + rarity::Rarity, + templates::{ + inscription::InscriptionJson, inscriptions::InscriptionsJson, output::OutputJson, + sat::SatJson, + }, + SatPoint, + }, pretty_assertions::assert_eq as pretty_assert_eq, regex::Regex, reqwest::{StatusCode, Url}, - serde::{de::DeserializeOwned, Deserialize}, + serde::de::DeserializeOwned, std::{ fs, net::TcpListener, @@ -30,8 +31,7 @@ use { time::Duration, }, tempfile::TempDir, - test_bitcoincore_rpc::Sent, - test_bitcoincore_rpc::TransactionTemplate, + test_bitcoincore_rpc::{Sent, TransactionTemplate}, }; macro_rules! assert_regex_match { @@ -48,14 +48,7 @@ macro_rules! assert_regex_match { }; } -#[derive(Deserialize, Debug)] -struct Inscribe { - #[allow(dead_code)] - commit: Txid, - inscription: String, - reveal: Txid, - fees: u64, -} +type Inscribe = ord::subcommand::wallet::inscribe::Output; fn inscribe(rpc_server: &test_bitcoincore_rpc::Handle) -> Inscribe { rpc_server.mine_blocks(1); diff --git a/tests/wallet/inscriptions.rs b/tests/wallet/inscriptions.rs index 107d2dd360..20ac3283f0 100644 --- a/tests/wallet/inscriptions.rs +++ b/tests/wallet/inscriptions.rs @@ -20,7 +20,7 @@ fn inscriptions() { .run_and_deserialize_output::>(); assert_eq!(output.len(), 1); - assert_eq!(output[0].inscription, inscription.parse().unwrap()); + assert_eq!(output[0].inscription, inscription); assert_eq!(output[0].location, format!("{reveal}:0:0").parse().unwrap()); assert_eq!( output[0].explorer, @@ -49,7 +49,7 @@ fn inscriptions() { .run_and_deserialize_output::>(); assert_eq!(output.len(), 1); - assert_eq!(output[0].inscription, inscription.parse().unwrap()); + assert_eq!(output[0].inscription, inscription); assert_eq!(output[0].location, format!("{txid}:0:0").parse().unwrap()); } @@ -78,7 +78,7 @@ fn inscriptions_includes_locked_utxos() { .run_and_deserialize_output::>(); assert_eq!(output.len(), 1); - assert_eq!(output[0].inscription, inscription.parse().unwrap()); + assert_eq!(output[0].inscription, inscription); assert_eq!(output[0].location, format!("{reveal}:0:0").parse().unwrap()); } diff --git a/tests/wallet/send.rs b/tests/wallet/send.rs index 9b3def4bc5..79db26942a 100644 --- a/tests/wallet/send.rs +++ b/tests/wallet/send.rs @@ -1,4 +1,4 @@ -use super::*; +use {super::*, ord::subcommand::wallet::send::Output}; #[test] fn inscriptions_can_be_sent() {