Skip to content

Overhaul integration testing #125

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

Merged
merged 1 commit into from
Apr 10, 2025
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
10 changes: 7 additions & 3 deletions client/src/client_sync/v17/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ macro_rules! impl_client_v17__getblock {
}

/// Gets a block by blockhash with verbose set to 0.
pub fn get_block_verbose_zero(&self, hash: BlockHash) -> Result<GetBlockVerbosityZero> {
pub fn get_block_verbose_zero(&self, hash: BlockHash) -> Result<GetBlockVerboseZero> {
self.call("getblock", &[into_json(hash)?, 0.into()])
}

/// Gets a block by blockhash with verbose set to 1.
pub fn get_block_verbose_one(&self, hash: BlockHash) -> Result<GetBlockVerbosityOne> {
pub fn get_block_verbose_one(&self, hash: BlockHash) -> Result<GetBlockVerboseOne> {
self.call("getblock", &[into_json(hash)?, 1.into()])
}
}
Expand Down Expand Up @@ -279,7 +279,11 @@ macro_rules! impl_client_v17__preciousblock {
() => {
impl Client {
pub fn precious_block(&self, hash: BlockHash) -> Result<()> {
self.call("preciousblock", &[into_json(hash)?])
match self.call("preciousblock", &[into_json(hash)?]) {
Ok(serde_json::Value::Null) => Ok(()),
Ok(res) => Err(Error::Returned(res.to_string())),
Err(err) => Err(err.into()),
}
}
}
};
Expand Down
7 changes: 6 additions & 1 deletion client/src/client_sync/v17/generating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,17 @@ macro_rules! impl_client_v17__generate {
}

/// Implements Bitcoin Core JSON-RPC API method `invalidateblock`
// This method does not appear in the output of `bitcoin-cli help`.
#[macro_export]
macro_rules! impl_client_v17__invalidateblock {
() => {
impl Client {
pub fn invalidate_block(&self, hash: BlockHash) -> Result<()> {
self.call("invalidateblock", &[into_json(hash)?])
match self.call("invalidateblock", &[into_json(hash)?]) {
Ok(serde_json::Value::Null) => Ok(()),
Ok(res) => Err(Error::Returned(res.to_string())),
Err(err) => Err(err.into()),
}
}
}
};
Expand Down
28 changes: 9 additions & 19 deletions client/src/client_sync/v17/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//!
//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`.

/// Implements Bitcoin Core JSON-RPC API method `createwallet`.
/// Implements Bitcoin Core JSON-RPC API method `addmultisigaddress`.
#[macro_export]
macro_rules! impl_client_v17__addmultisigaddress {
() => {
Expand Down Expand Up @@ -123,24 +123,16 @@ macro_rules! impl_client_v17__getnewaddress {
impl Client {
/// Gets a new address from `bitcoind` and parses it assuming its correct.
pub fn new_address(&self) -> Result<bitcoin::Address> {
use core::str::FromStr;

let json = self.get_new_address(None, None)?;
let address = bitcoin::Address::from_str(&json.0)
.expect("assume the address is valid")
.assume_checked(); // Assume bitcoind will return an valid address for the network its on.
Ok(address)
let model = json.into_model().unwrap();
Ok(model.0.assume_checked())
}

/// Gets a new address from `bitcoind` and parses it assuming its correct.
pub fn new_address_with_type(&self, ty: AddressType) -> Result<bitcoin::Address> {
use core::str::FromStr;

let json = self.get_new_address(None, Some(ty))?;
let address = bitcoin::Address::from_str(&json.0)
.expect("assume the address is valid")
.assume_checked(); // Assume bitcoind will return an valid address for the network its on.
Ok(address)
let model = json.into_model().unwrap();
Ok(model.0.assume_checked())
}

/// Gets a new address with label from `bitcoind` and parses it assuming its correct.
Expand All @@ -149,15 +141,13 @@ macro_rules! impl_client_v17__getnewaddress {
&self,
label: &str,
) -> Result<bitcoin::Address<bitcoin::address::NetworkUnchecked>> {
use core::str::FromStr;

let json = self.get_new_address(Some(label), None)?;
let address =
bitcoin::Address::from_str(&json.0).expect("assume the address is valid");
Ok(address)
let model = json.into_model().unwrap();
Ok(model.0)
}

fn get_new_address(
/// Gets a new address - low level RPC call.
pub fn get_new_address(
&self,
label: Option<&str>,
ty: Option<AddressType>,
Expand Down
5 changes: 4 additions & 1 deletion client/src/client_sync/v19/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::types::v19::*;
pub use crate::client_sync::{v17::AddressType, WalletCreateFundedPsbtInput};

crate::define_jsonrpc_minreq_client!("v19");
crate::impl_client_check_expected_server_version!({ [190100] });

// == Blockchain ==
crate::impl_client_v17__getbestblockhash!();
Expand Down Expand Up @@ -64,8 +65,9 @@ crate::impl_client_v17__prioritisetransaction!();
crate::impl_client_v17__submitblock!();

// == Network ==
crate::impl_client_v17__getaddednodeinfo!();
crate::impl_client_v17__getnettotals!();
crate::impl_client_v17__getnetworkinfo!();
crate::impl_client_check_expected_server_version!({ [190100] });
crate::impl_client_v17__getpeerinfo!();

// == Rawtransactions ==
Expand All @@ -82,6 +84,7 @@ crate::impl_client_v17__dumpwallet!();
crate::impl_client_v17__getaddressesbylabel!();
crate::impl_client_v17__getaddressinfo!();
crate::impl_client_v17__getbalance!();
crate::impl_client_v19__getbalances!();
crate::impl_client_v17__getnewaddress!();
crate::impl_client_v17__getrawchangeaddress!();
crate::impl_client_v17__getreceivedbyaddress!();
Expand Down
4 changes: 3 additions & 1 deletion client/src/client_sync/v20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::types::v20::*;
pub use crate::client_sync::{v17::AddressType, WalletCreateFundedPsbtInput};

crate::define_jsonrpc_minreq_client!("v20");
crate::impl_client_check_expected_server_version!({ [200200] });

// == Blockchain ==
crate::impl_client_v17__getbestblockhash!();
Expand Down Expand Up @@ -61,8 +62,9 @@ crate::impl_client_v17__prioritisetransaction!();
crate::impl_client_v17__submitblock!();

// == Network ==
crate::impl_client_v17__getaddednodeinfo!();
crate::impl_client_v17__getnettotals!();
crate::impl_client_v17__getnetworkinfo!();
crate::impl_client_check_expected_server_version!({ [200200] });
crate::impl_client_v17__getpeerinfo!();

// == Rawtransactions ==
Expand Down
4 changes: 3 additions & 1 deletion client/src/client_sync/v21/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::types::v21::*;
pub use crate::client_sync::{v17::AddressType, WalletCreateFundedPsbtInput};

crate::define_jsonrpc_minreq_client!("v21");
crate::impl_client_check_expected_server_version!({ [210200] });

// == Blockchain ==
crate::impl_client_v17__getbestblockhash!();
Expand Down Expand Up @@ -63,8 +64,9 @@ crate::impl_client_v17__prioritisetransaction!();
crate::impl_client_v17__submitblock!();

// == Network ==
crate::impl_client_v17__getaddednodeinfo!();
crate::impl_client_v17__getnettotals!();
crate::impl_client_v17__getnetworkinfo!();
crate::impl_client_check_expected_server_version!({ [210200] });
crate::impl_client_v17__getpeerinfo!();

// == Rawtransactions ==
Expand Down
4 changes: 3 additions & 1 deletion client/src/client_sync/v22/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::types::v22::*;
pub use crate::client_sync::{v17::AddressType, WalletCreateFundedPsbtInput};

crate::define_jsonrpc_minreq_client!("v22");
crate::impl_client_check_expected_server_version!({ [220100] });

// == Blockchain ==
crate::impl_client_v17__getbestblockhash!();
Expand Down Expand Up @@ -64,8 +65,9 @@ crate::impl_client_v17__prioritisetransaction!();
crate::impl_client_v17__submitblock!();

// == Network ==
crate::impl_client_v17__getaddednodeinfo!();
crate::impl_client_v17__getnettotals!();
crate::impl_client_v17__getnetworkinfo!();
crate::impl_client_check_expected_server_version!({ [220000, 220100] });
crate::impl_client_v17__getpeerinfo!();

// == Rawtransactions ==
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//!
//! We ignore option arguments unless they effect the shape of the returned JSON data.

pub mod wallet;

use std::collections::BTreeMap;
use std::path::Path;

Expand All @@ -18,6 +20,7 @@ use crate::types::v23::*;
pub use crate::client_sync::WalletCreateFundedPsbtInput;

crate::define_jsonrpc_minreq_client!("v23");
crate::impl_client_check_expected_server_version!({ [230200] });

// == Blockchain ==
crate::impl_client_v17__getbestblockhash!();
Expand Down Expand Up @@ -62,8 +65,9 @@ crate::impl_client_v17__prioritisetransaction!();
crate::impl_client_v17__submitblock!();

// == Network ==
crate::impl_client_v17__getaddednodeinfo!();
crate::impl_client_v17__getnettotals!();
crate::impl_client_v17__getnetworkinfo!();
crate::impl_client_check_expected_server_version!({ [230000, 230100, 230200] });
crate::impl_client_v17__getpeerinfo!();

// == Rawtransactions ==
Expand All @@ -74,7 +78,7 @@ crate::impl_client_v17__sendrawtransaction!();
// == Wallet ==
crate::impl_client_v17__addmultisigaddress!();
crate::impl_client_v17__bumpfee!();
crate::impl_client_v17__createwallet!();
crate::impl_client_v23__createwallet!();
crate::impl_client_v17__dumpprivkey!();
crate::impl_client_v17__dumpwallet!();
crate::impl_client_v17__getaddressesbylabel!();
Expand Down
58 changes: 58 additions & 0 deletions client/src/client_sync/v23/wallet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: CC0-1.0

//! Macros for implementing JSON-RPC methods on a client.
//!
//! Specifically this is methods found under the `== Wallet ==` section of the
//! API docs of Bitcoin Core `v23`.
//!
//! All macros require `Client` to be in scope.
//!
//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`.

/// Implements Bitcoin Core JSON-RPC API method `createwallet`.
#[macro_export]
macro_rules! impl_client_v23__createwallet {
() => {
impl Client {
/// Calls `createwallet` with `wallet` as the only argument.
pub fn create_wallet(&self, wallet: &str) -> Result<CreateWallet> {
self.call("createwallet", &[wallet.into()])
}

/// Creates a legacy wallet (i.e not a native descriptor wallet).
///
/// > createwallet "wallet_name" ( disable_private_keys blank "passphrase" avoid_reuse descriptors load_on_startup external_signer )
/// >
/// > Creates and loads a new wallet.
/// >
/// > Arguments:
/// > 1. wallet_name (string, required) The name for the new wallet. If this is a path, the wallet will be created at the path location.
/// > 2. disable_private_keys (boolean, optional, default=false) Disable the possibility of private keys (only watchonlys are possible in this mode).
/// > 3. blank (boolean, optional, default=false) Create a blank wallet. A blank wallet has no keys or HD seed. One can be set using sethdseed.
/// > 4. passphrase (string, optional) Encrypt the wallet with this passphrase.
/// > 5. avoid_reuse (boolean, optional, default=false) Keep track of coin reuse, and treat dirty and clean coins differently with privacy considerations in mind.
/// > 6. descriptors (boolean, optional, default=true) Create a native descriptor wallet. The wallet will use descriptors internally to handle address creation
/// > 7. load_on_startup (boolean, optional) Save wallet name to persistent settings and load on startup. True to add wallet to startup list, false to remove, null to leave unchanged.
/// > 8. external_signer (boolean, optional, default=false) Use an external signer such as a hardware wallet. Requires -signer to be configured. Wallet creation will fail if keys cannot be fetched. Requires disable_private_keys and descriptors set to true.
pub fn create_legacy_wallet(&self, wallet: &str) -> Result<CreateWallet> {
let disable_private_keys = false;
let blank = false;
let passphrase = String::new();
let avoid_reuse = false;
let descriptors = false;

self.call(
"createwallet",
&[
wallet.into(),
disable_private_keys.into(),
blank.into(),
passphrase.into(),
avoid_reuse.into(),
descriptors.into(),
],
)
}
}
};
}
6 changes: 4 additions & 2 deletions client/src/client_sync/v24.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::types::v24::*;
pub use crate::client_sync::{v23::AddressType, WalletCreateFundedPsbtInput};

crate::define_jsonrpc_minreq_client!("v24");
crate::impl_client_check_expected_server_version!({ [240200] });

// == Blockchain ==
crate::impl_client_v17__getbestblockhash!();
Expand Down Expand Up @@ -61,8 +62,9 @@ crate::impl_client_v17__prioritisetransaction!();
crate::impl_client_v17__submitblock!();

// == Network ==
crate::impl_client_v17__getaddednodeinfo!();
crate::impl_client_v17__getnettotals!();
crate::impl_client_v17__getnetworkinfo!();
crate::impl_client_check_expected_server_version!({ [240001, 240100, 240200] });
crate::impl_client_v17__getpeerinfo!();

// == Rawtransactions ==
Expand All @@ -73,7 +75,7 @@ crate::impl_client_v17__sendrawtransaction!();
// == Wallet ==
crate::impl_client_v17__addmultisigaddress!();
crate::impl_client_v17__bumpfee!();
crate::impl_client_v17__createwallet!();
crate::impl_client_v23__createwallet!();
crate::impl_client_v17__dumpprivkey!();
crate::impl_client_v17__dumpwallet!();
crate::impl_client_v17__getaddressesbylabel!();
Expand Down
6 changes: 4 additions & 2 deletions client/src/client_sync/v25.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::types::v25::*;
pub use crate::client_sync::{v23::AddressType, WalletCreateFundedPsbtInput};

crate::define_jsonrpc_minreq_client!("v25");
crate::impl_client_check_expected_server_version!({ [250200] });

// == Blockchain ==
crate::impl_client_v17__getbestblockhash!();
Expand Down Expand Up @@ -61,8 +62,9 @@ crate::impl_client_v17__prioritisetransaction!();
crate::impl_client_v17__submitblock!();

// == Network ==
crate::impl_client_v17__getaddednodeinfo!();
crate::impl_client_v17__getnettotals!();
crate::impl_client_v17__getnetworkinfo!();
crate::impl_client_check_expected_server_version!({ [250000, 250100, 250200] });
crate::impl_client_v17__getpeerinfo!();

// == Rawtransactions ==
Expand All @@ -73,7 +75,7 @@ crate::impl_client_v17__sendrawtransaction!();
// == Wallet ==
crate::impl_client_v17__addmultisigaddress!();
crate::impl_client_v17__bumpfee!();
crate::impl_client_v17__createwallet!();
crate::impl_client_v23__createwallet!();
crate::impl_client_v17__dumpprivkey!();
crate::impl_client_v17__dumpwallet!();
crate::impl_client_v17__getaddressesbylabel!();
Expand Down
6 changes: 4 additions & 2 deletions client/src/client_sync/v26/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::types::v26::*;
pub use crate::client_sync::{v23::AddressType, WalletCreateFundedPsbtInput};

crate::define_jsonrpc_minreq_client!("v26");
crate::impl_client_check_expected_server_version!({ [260000, 260100, 260200] });

// == Blockchain ==
crate::impl_client_v17__getbestblockhash!();
Expand Down Expand Up @@ -65,8 +66,9 @@ crate::impl_client_v17__prioritisetransaction!();
crate::impl_client_v17__submitblock!();

// == Network ==
crate::impl_client_v17__getaddednodeinfo!();
crate::impl_client_v17__getnettotals!();
crate::impl_client_v17__getnetworkinfo!();
crate::impl_client_check_expected_server_version!({ [260000, 260100, 260200] });
crate::impl_client_v17__getpeerinfo!();

// == Rawtransactions ==
Expand All @@ -77,7 +79,7 @@ crate::impl_client_v17__sendrawtransaction!();
// == Wallet ==
crate::impl_client_v17__addmultisigaddress!();
crate::impl_client_v17__bumpfee!();
crate::impl_client_v17__createwallet!();
crate::impl_client_v23__createwallet!();
crate::impl_client_v17__dumpprivkey!();
crate::impl_client_v17__dumpwallet!();
crate::impl_client_v17__getaddressesbylabel!();
Expand Down
6 changes: 4 additions & 2 deletions client/src/client_sync/v27.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::types::v27::*;
pub use crate::client_sync::{v23::AddressType, WalletCreateFundedPsbtInput};

crate::define_jsonrpc_minreq_client!("v27");
crate::impl_client_check_expected_server_version!({ [270000, 270100] });

// == Blockchain ==
crate::impl_client_v17__getbestblockhash!();
Expand Down Expand Up @@ -62,8 +63,9 @@ crate::impl_client_v17__prioritisetransaction!();
crate::impl_client_v17__submitblock!();

// == Network ==
crate::impl_client_v17__getaddednodeinfo!();
crate::impl_client_v17__getnettotals!();
crate::impl_client_v17__getnetworkinfo!();
crate::impl_client_check_expected_server_version!({ [270000, 270100] });
crate::impl_client_v17__getpeerinfo!();

// == Rawtransactions ==
Expand All @@ -74,7 +76,7 @@ crate::impl_client_v17__sendrawtransaction!();
// == Wallet ==
crate::impl_client_v17__addmultisigaddress!();
crate::impl_client_v17__bumpfee!();
crate::impl_client_v17__createwallet!();
crate::impl_client_v23__createwallet!();
crate::impl_client_v17__dumpprivkey!();
crate::impl_client_v17__dumpwallet!();
crate::impl_client_v17__getaddressesbylabel!();
Expand Down
Loading