Skip to content

Commit 15b38c3

Browse files
committed
test(bdk): use anyhow::Error in more doc tests
1 parent 67178e7 commit 15b38c3

File tree

7 files changed

+14
-18
lines changed

7 files changed

+14
-18
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,7 @@ impl<D> Wallet<D> {
11291129
/// # use bdk::wallet::ChangeSet;
11301130
/// # use bdk::wallet::error::CreateTxError;
11311131
/// # use bdk_chain::PersistBackend;
1132+
/// # use anyhow::Error;
11321133
/// # let descriptor = "wpkh(tpubD6NzVbkrYhZ4Xferm7Pz4VnjdcDPFyjVu5K4iZXQ4pVN8Cks4pHVowTBXBKRhX64pkRyJZJN5xAKj4UDNnLPb5p2sSKXhewoYx5GbTdUFWq/*)";
11331134
/// # let mut wallet = doctest_wallet!();
11341135
/// # let to_address = Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt").unwrap().assume_checked();
@@ -1140,7 +1141,7 @@ impl<D> Wallet<D> {
11401141
/// };
11411142
///
11421143
/// // sign and broadcast ...
1143-
/// # Ok::<(), CreateTxError<<() as PersistBackend<ChangeSet>>::WriteError>>(())
1144+
/// # Ok::<(), anyhow::Error>(())
11441145
/// ```
11451146
///
11461147
/// [`TxBuilder`]: crate::TxBuilder
@@ -1538,7 +1539,7 @@ impl<D> Wallet<D> {
15381539
/// builder
15391540
/// .add_recipient(to_address.script_pubkey(), 50_000)
15401541
/// .enable_rbf();
1541-
/// builder.finish().expect("psbt")
1542+
/// builder.finish()?
15421543
/// };
15431544
/// let _ = wallet.sign(&mut psbt, SignOptions::default())?;
15441545
/// let tx = psbt.extract_tx();
@@ -1547,7 +1548,7 @@ impl<D> Wallet<D> {
15471548
/// let mut builder = wallet.build_fee_bump(tx.txid())?;
15481549
/// builder
15491550
/// .fee_rate(bdk::FeeRate::from_sat_per_vb(5.0));
1550-
/// builder.finish().expect("psbt")
1551+
/// builder.finish()?
15511552
/// };
15521553
///
15531554
/// 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
@@ -454,9 +454,6 @@ fn test_create_tx_with_default_rbf_csv() {
454454
}
455455

456456
#[test]
457-
// #[should_panic(
458-
// expected = "Cannot enable RBF with nSequence `Sequence(3)` given a required OP_CSV of `Sequence(6)`"
459-
// )]
460457
fn test_create_tx_with_custom_rbf_csv() {
461458
let (mut wallet, _) = get_funded_wallet(get_test_single_sig_csv());
462459
let addr = wallet.get_address(New);

0 commit comments

Comments
 (0)