diff --git a/src/subcommand/wallet.rs b/src/subcommand/wallet.rs index 86d5fd3b2d..6804e25211 100644 --- a/src/subcommand/wallet.rs +++ b/src/subcommand/wallet.rs @@ -1,5 +1,6 @@ use super::*; +mod balance; mod fund; mod init; mod utxos; @@ -54,16 +55,18 @@ fn get_wallet(options: Options) -> Result> { #[derive(Debug, Parser)] pub(crate) enum Wallet { - Init, + Balance, Fund, + Init, Utxos, } impl Wallet { pub(crate) fn run(self, options: Options) -> Result { match self { - Self::Init => init::run(options), + Self::Balance => balance::run(options), Self::Fund => fund::run(options), + Self::Init => init::run(options), Self::Utxos => utxos::run(options), } } diff --git a/src/subcommand/wallet/balance.rs b/src/subcommand/wallet/balance.rs new file mode 100644 index 0000000000..dc0553aca4 --- /dev/null +++ b/src/subcommand/wallet/balance.rs @@ -0,0 +1,6 @@ +use super::*; + +pub(crate) fn run(options: Options) -> Result { + println!("{}", get_wallet(options)?.get_balance()?); + Ok(()) +} diff --git a/tests/wallet.rs b/tests/wallet.rs index 864a0c3394..bea1d48f65 100644 --- a/tests/wallet.rs +++ b/tests/wallet.rs @@ -140,3 +140,47 @@ fn utxos() { .stdout_regex("^[[:xdigit:]]{64}:0 5000000000\n") .run() } + +#[test] +fn balance() { + let state = Test::new() + .command("--network regtest wallet init") + .expected_status(0) + .expected_stderr("Wallet initialized.\n") + .output() + .state; + + let state = Test::with_state(state) + .command("--network regtest wallet balance") + .expected_status(0) + .expected_stdout("0\n") + .output() + .state; + + let output = Test::with_state(state) + .command("--network regtest wallet fund") + .stdout_regex("^bcrt1.*\n") + .output(); + + output + .state + .client + .generate_to_address( + 101, + &Address::from_str( + output + .stdout + .strip_suffix('\n') + .ok_or("Failed to strip suffix") + .unwrap(), + ) + .unwrap(), + ) + .unwrap(); + + Test::with_state(output.state) + .command("--network regtest wallet balance") + .expected_status(0) + .expected_stdout("5000000000\n") + .run() +}