Skip to content

Commit 26ce0fa

Browse files
committed
test(bdk): use anyhow::Error in more doc tests
1 parent 7917287 commit 26ce0fa

File tree

7 files changed

+14
-19
lines changed

7 files changed

+14
-19
lines changed

crates/bdk/src/descriptor/error.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
// licenses.
1111

1212
//! Descriptor errors
13-
1413
use core::fmt;
1514

1615
/// Errors related to the parsing and usage of descriptors

crates/bdk/src/descriptor/policy.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use crate::collections::{BTreeMap, HashSet, VecDeque};
4040
use alloc::string::String;
4141
use alloc::vec::Vec;
4242
use core::cmp::max;
43+
4344
use core::fmt;
4445

4546
use serde::ser::SerializeMap;

crates/bdk/src/wallet/coin_selection.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
//! # use bdk_chain::PersistBackend;
3232
//! # use bdk::*;
3333
//! # use bdk::wallet::coin_selection::decide_change;
34+
//! # use anyhow::Error;
3435
//! # const TXIN_BASE_WEIGHT: usize = (32 + 4 + 4) * 4;
3536
//! #[derive(Debug)]
3637
//! struct AlwaysSpendEverything;
@@ -96,7 +97,7 @@
9697
//!
9798
//! // inspect, sign, broadcast, ...
9899
//!
99-
//! # Ok::<(), CreateTxError<<() as PersistBackend<ChangeSet>>::WriteError>>(())
100+
//! # Ok::<(), anyhow::Error>(())
100101
//! ```
101102
102103
use crate::types::FeeRate;

crates/bdk/src/wallet/error.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ pub enum CreateTxError<P> {
119119
MiniscriptPsbt(MiniscriptPsbtError),
120120
}
121121

122-
#[cfg(feature = "std")]
123122
impl<P> fmt::Display for CreateTxError<P>
124123
where
125124
P: fmt::Display,
@@ -263,7 +262,6 @@ pub enum BuildFeeBumpError {
263262
FeeRateUnavailable,
264263
}
265264

266-
#[cfg(feature = "std")]
267265
impl fmt::Display for BuildFeeBumpError {
268266
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
269267
match self {
@@ -304,7 +302,6 @@ pub enum SignError {
304302
MiniscriptPsbt(MiniscriptPsbtError),
305303
}
306304

307-
#[cfg(feature = "std")]
308305
impl fmt::Display for SignError {
309306
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
310307
match self {
@@ -327,7 +324,6 @@ pub enum AddUtxoError {
327324
UnknownUtxo(OutPoint),
328325
}
329326

330-
#[cfg(feature = "std")]
331327
impl fmt::Display for AddUtxoError {
332328
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
333329
match self {
@@ -362,7 +358,6 @@ pub enum AddForeignUtxoError {
362358
MissingUtxo,
363359
}
364360

365-
#[cfg(feature = "std")]
366361
impl fmt::Display for AddForeignUtxoError {
367362
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
368363
match self {
@@ -396,7 +391,6 @@ pub enum AllowShrinkingError {
396391
MissingScriptPubKey(ScriptBuf),
397392
}
398393

399-
#[cfg(feature = "std")]
400394
impl fmt::Display for AllowShrinkingError {
401395
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
402396
match self {

crates/bdk/src/wallet/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ pub enum InsertTxError {
283283
},
284284
}
285285

286-
#[cfg(feature = "std")]
287286
impl<P: core::fmt::Display + core::fmt::Debug> std::error::Error for NewError<P> {}
288287

289288
impl<D> Wallet<D> {
@@ -857,6 +856,7 @@ impl<D> Wallet<D> {
857856
/// # use bdk::wallet::ChangeSet;
858857
/// # use bdk::wallet::error::CreateTxError;
859858
/// # use bdk_chain::PersistBackend;
859+
/// # use anyhow::Error;
860860
/// # let descriptor = "wpkh(tpubD6NzVbkrYhZ4Xferm7Pz4VnjdcDPFyjVu5K4iZXQ4pVN8Cks4pHVowTBXBKRhX64pkRyJZJN5xAKj4UDNnLPb5p2sSKXhewoYx5GbTdUFWq/*)";
861861
/// # let mut wallet = doctest_wallet!();
862862
/// # let to_address = Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt").unwrap().assume_checked();
@@ -868,7 +868,7 @@ impl<D> Wallet<D> {
868868
/// };
869869
///
870870
/// // sign and broadcast ...
871-
/// # Ok::<(), CreateTxError<<() as PersistBackend<ChangeSet>>::WriteError>>(())
871+
/// # Ok::<(), anyhow::Error>(())
872872
/// ```
873873
///
874874
/// [`TxBuilder`]: crate::TxBuilder
@@ -1266,7 +1266,7 @@ impl<D> Wallet<D> {
12661266
/// builder
12671267
/// .add_recipient(to_address.script_pubkey(), 50_000)
12681268
/// .enable_rbf();
1269-
/// builder.finish().expect("psbt")
1269+
/// builder.finish()?
12701270
/// };
12711271
/// let _ = wallet.sign(&mut psbt, SignOptions::default())?;
12721272
/// let tx = psbt.extract_tx();
@@ -1275,7 +1275,7 @@ impl<D> Wallet<D> {
12751275
/// let mut builder = wallet.build_fee_bump(tx.txid())?;
12761276
/// builder
12771277
/// .fee_rate(bdk::FeeRate::from_sat_per_vb(5.0));
1278-
/// builder.finish().expect("psbt")
1278+
/// builder.finish()?
12791279
/// };
12801280
///
12811281
/// let _ = wallet.sign(&mut psbt, SignOptions::default())?;

crates/bdk/src/wallet/tx_builder.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
//! # use bdk::wallet::ChangeSet;
2121
//! # use bdk::wallet::error::CreateTxError;
2222
//! # use bdk::wallet::tx_builder::CreateTx;
23-
//! # let to_address = Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt").unwrap().assume_checked();
2423
//! # use bdk_chain::PersistBackend;
24+
//! # use anyhow::Error;
25+
//! # let to_address = Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt").unwrap().assume_checked();
2526
//! # let mut wallet = doctest_wallet!();
2627
//! // create a TxBuilder from a wallet
2728
//! let mut tx_builder = wallet.build_tx();
@@ -36,7 +37,7 @@
3637
//! // Turn on RBF signaling
3738
//! .enable_rbf();
3839
//! let psbt = tx_builder.finish()?;
39-
//! # Ok::<(), CreateTxError<<() as PersistBackend<ChangeSet>>::WriteError>>(())
40+
//! # Ok::<(), anyhow::Error>(())
4041
//! ```
4142
4243
use crate::collections::BTreeMap;
@@ -87,6 +88,7 @@ impl TxBuilderContext for BumpFee {}
8788
/// # use bdk::wallet::ChangeSet;
8889
/// # use bdk::wallet::error::CreateTxError;
8990
/// # use bdk_chain::PersistBackend;
91+
/// # use anyhow::Error;
9092
/// # let mut wallet = doctest_wallet!();
9193
/// # let addr1 = Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt").unwrap().assume_checked();
9294
/// # let addr2 = addr1.clone();
@@ -111,7 +113,7 @@ impl TxBuilderContext for BumpFee {}
111113
/// };
112114
///
113115
/// assert_eq!(psbt1.unsigned_tx.output[..2], psbt2.unsigned_tx.output[..2]);
114-
/// # Ok::<(), CreateTxError<<() as PersistBackend<ChangeSet>>::WriteError>>(())
116+
/// # Ok::<(), anyhow::Error>(())
115117
/// ```
116118
///
117119
/// At the moment [`coin_selection`] is an exception to the rule as it consumes `self`.
@@ -655,6 +657,7 @@ impl<'a, D, Cs: CoinSelectionAlgorithm> TxBuilder<'a, D, Cs, CreateTx> {
655657
/// # use bdk::wallet::error::CreateTxError;
656658
/// # use bdk::wallet::tx_builder::CreateTx;
657659
/// # use bdk_chain::PersistBackend;
660+
/// # use anyhow::Error;
658661
/// # let to_address =
659662
/// Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt")
660663
/// .unwrap()
@@ -670,7 +673,7 @@ impl<'a, D, Cs: CoinSelectionAlgorithm> TxBuilder<'a, D, Cs, CreateTx> {
670673
/// .fee_rate(bdk::FeeRate::from_sat_per_vb(5.0))
671674
/// .enable_rbf();
672675
/// let psbt = tx_builder.finish()?;
673-
/// # Ok::<(), CreateTxError<<() as PersistBackend<ChangeSet>>::WriteError>>(())
676+
/// # Ok::<(), anyhow::Error>(())
674677
/// ```
675678
///
676679
/// [`allow_shrinking`]: Self::allow_shrinking

crates/bdk/tests/wallet.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,6 @@ fn test_create_tx_with_default_rbf_csv() {
358358
}
359359

360360
#[test]
361-
// #[should_panic(
362-
// expected = "Cannot enable RBF with nSequence `Sequence(3)` given a required OP_CSV of `Sequence(6)`"
363-
// )]
364361
fn test_create_tx_with_custom_rbf_csv() {
365362
let (mut wallet, _) = get_funded_wallet(get_test_single_sig_csv());
366363
let addr = wallet.get_address(New);

0 commit comments

Comments
 (0)