Skip to content

Commit a8d52e6

Browse files
committed
Merge #1425: chore: add print_stdout/print_stderr lints to workspace level
e063ad8 fix(esplora+wallet+file_store): remove remaining `println!` usage (Leonardo Lima) b32b944 chore(examples): allow `clippy::print_stdout` in examples (Leonardo Lima) b614237 fix(tests)!: remove println! usage from tests (Leonardo Lima) eaa1917 chore: add `print_stdout`/`print_stderr` lints to workspace level (Leonardo Lima) Pull request description: potentially fixes #1362 <!-- You can erase any parts of this template not applicable to your Pull Request. --> ### Description It adds both `print_stdout` and `print_stderr` deny level lints on workspace level, but it does allow it on test fns through `clippy.toml` settings, and explicitly allow it on example code. <!-- Describe the purpose of this PR, what's being adding and/or fixed --> ### Notes to the reviewers It currently has the setting allowing it on test fns, but open for discussion below. <!-- In this section you can include notes directed to the reviewers, like explaining why some parts of the PR were done in a specific way --> ### Changelog notice - Add both `print_stdout` and `print_stderr` deny level lints on workspace level <!-- Notice the release manager should include in the release tag message changelog --> <!-- See https://keepachangelog.com/en/1.0.0/ for examples --> ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing #### New Features: * [x] I've added tests for the new feature * [x] I've added docs for the new feature ACKs for top commit: notmandatory: ACK e063ad8 Tree-SHA512: b3348efd86d09944eb36e4d87799eebc23f4e423861b3bad08365d286449f61b29ad332157eecfb7307191ef61d3b8285341e0ccb868581e54b570d6dd37547c
2 parents 775e4ae + e063ad8 commit a8d52e6

File tree

19 files changed

+41
-38
lines changed

19 files changed

+41
-38
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ members = [
2222

2323
[workspace.package]
2424
authors = ["Bitcoin Dev Kit Developers"]
25+
26+
[workspace.lints.clippy]
27+
print_stdout = "deny"
28+
print_stderr = "deny"

clippy.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
msrv="1.63.0"
1+
msrv="1.63.0"

crates/bitcoind_rpc/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ readme = "README.md"
1212

1313
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1414

15+
[lints]
16+
workspace = true
17+
1518
[dependencies]
1619
bitcoin = { version = "0.32.0", default-features = false }
1720
bitcoincore-rpc = { version = "0.19.0" }

crates/bitcoind_rpc/tests/test_emitter.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn test_sync_local_chain() -> anyhow::Result<()> {
3636
};
3737

3838
// See if the emitter outputs the right blocks.
39-
println!("first sync:");
39+
4040
while let Some(emission) = emitter.next_block()? {
4141
let height = emission.block_height();
4242
let hash = emission.block_hash();
@@ -76,7 +76,7 @@ pub fn test_sync_local_chain() -> anyhow::Result<()> {
7676
.collect::<Vec<_>>();
7777

7878
// See if the emitter outputs the right blocks.
79-
println!("after reorg:");
79+
8080
let mut exp_height = exp_hashes.len() - reorged_blocks.len();
8181
while let Some(emission) = emitter.next_block()? {
8282
let height = emission.block_height();
@@ -132,7 +132,6 @@ pub fn test_sync_local_chain() -> anyhow::Result<()> {
132132
fn test_into_tx_graph() -> anyhow::Result<()> {
133133
let env = TestEnv::new()?;
134134

135-
println!("getting new addresses!");
136135
let addr_0 = env
137136
.rpc_client()
138137
.get_new_address(None, None)?
@@ -145,11 +144,8 @@ fn test_into_tx_graph() -> anyhow::Result<()> {
145144
.rpc_client()
146145
.get_new_address(None, None)?
147146
.assume_checked();
148-
println!("got new addresses!");
149147

150-
println!("mining block!");
151148
env.mine_blocks(101, None)?;
152-
println!("mined blocks!");
153149

154150
let (mut chain, _) = LocalChain::from_genesis_hash(env.rpc_client().get_block_hash(0)?);
155151
let mut indexed_tx_graph = IndexedTxGraph::<BlockId, _>::new({
@@ -609,7 +605,6 @@ fn mempool_during_reorg() -> anyhow::Result<()> {
609605
// perform reorgs at different heights, these reorgs will not confirm transactions in the
610606
// mempool
611607
for reorg_count in 1..TIP_DIFF {
612-
println!("REORG COUNT: {}", reorg_count);
613608
env.reorg_empty_blocks(reorg_count)?;
614609

615610
// This is a map of mempool txids to tip height where the tx was introduced to the mempool
@@ -627,7 +622,6 @@ fn mempool_during_reorg() -> anyhow::Result<()> {
627622
// `next_header` emits the replacement block of the reorg
628623
if let Some(emission) = emitter.next_header()? {
629624
let height = emission.block_height();
630-
println!("\t- replacement height: {}", height);
631625

632626
// the mempool emission (that follows the first block emission after reorg) should only
633627
// include mempool txs introduced at reorg height or greater

crates/chain/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ readme = "README.md"
1212

1313
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1414

15+
[lints]
16+
workspace = true
17+
1518
[dependencies]
1619
bitcoin = { version = "0.32.0", default-features = false }
1720
bdk_core = { path = "../core", version = "0.1", default-features = false }

crates/chain/tests/test_local_chain.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ enum ExpectedResult<'a> {
3434

3535
impl<'a> TestLocalChain<'a> {
3636
fn run(mut self) {
37-
println!("[TestLocalChain] test: {}", self.name);
3837
let got_changeset = match self.chain.apply_update(self.update) {
3938
Ok(changeset) => changeset,
4039
Err(got_err) => {
@@ -255,7 +254,7 @@ fn update_local_chain() {
255254
(4, None)
256255
],
257256
init_changeset: &[
258-
(0, Some(h!("_"))),
257+
(0, Some(h!("_"))),
259258
(1, Some(h!("B'"))),
260259
(2, Some(h!("C'"))),
261260
(3, Some(h!("D"))),
@@ -437,8 +436,6 @@ fn local_chain_disconnect_from() {
437436
];
438437

439438
for (i, t) in test_cases.into_iter().enumerate() {
440-
println!("Case {}: {}", i, t.name);
441-
442439
let mut chain = t.original;
443440
let result = chain.disconnect_from(t.disconnect_from.into());
444441
assert_eq!(
@@ -491,7 +488,6 @@ fn checkpoint_from_block_ids() {
491488
];
492489

493490
for (i, t) in test_cases.into_iter().enumerate() {
494-
println!("running test case {}: '{}'", i, t.name);
495491
let result = CheckPoint::from_block_ids(
496492
t.blocks
497493
.iter()
@@ -583,6 +579,7 @@ fn checkpoint_query() {
583579
fn checkpoint_insert() {
584580
struct TestCase<'a> {
585581
/// The name of the test.
582+
#[allow(dead_code)]
586583
name: &'a str,
587584
/// The original checkpoint chain to call [`CheckPoint::insert`] on.
588585
chain: &'a [(u32, BlockHash)],
@@ -629,9 +626,7 @@ fn checkpoint_insert() {
629626
core::iter::once((0, h!("_"))).map(BlockId::from)
630627
}
631628

632-
for (i, t) in test_cases.into_iter().enumerate() {
633-
println!("Running [{}] '{}'", i, t.name);
634-
629+
for t in test_cases.into_iter() {
635630
let chain = CheckPoint::from_block_ids(
636631
genesis_block().chain(t.chain.iter().copied().map(BlockId::from)),
637632
)
@@ -792,7 +787,6 @@ fn local_chain_apply_header_connected_to() {
792787
];
793788

794789
for (i, t) in test_cases.into_iter().enumerate() {
795-
println!("running test case {}: '{}'", i, t.name);
796790
let mut chain = t.chain;
797791
let result = chain.apply_header_connected_to(&t.header, t.height, t.connected_to);
798792
let exp_result = t

crates/electrum/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ description = "Fetch data from electrum in the form BDK accepts"
99
license = "MIT OR Apache-2.0"
1010
readme = "README.md"
1111

12+
[lints]
13+
workspace = true
14+
1215
[dependencies]
1316
bdk_core = { path = "../core", version = "0.1" }
1417
electrum-client = { version = "0.21", features = [ "proxy" ], default-features = false }

crates/esplora/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ readme = "README.md"
1111

1212
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1313

14+
[lints]
15+
workspace = true
16+
1417
[dependencies]
1518
bdk_core = { path = "../core", version = "0.1", default-features = false }
1619
esplora-client = { version = "0.9.0", default-features = false }

crates/esplora/src/async_ext.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ mod test {
506506
#[tokio::test]
507507
pub async fn test_finalize_chain_update() -> anyhow::Result<()> {
508508
struct TestCase<'a> {
509+
#[allow(dead_code)]
509510
name: &'a str,
510511
/// Initial blockchain height to start the env with.
511512
initial_env_height: u32,
@@ -542,9 +543,7 @@ mod test {
542543
},
543544
];
544545

545-
for (i, t) in test_cases.into_iter().enumerate() {
546-
println!("[{}] running test case: {}", i, t.name);
547-
546+
for t in test_cases.into_iter() {
548547
let env = TestEnv::new()?;
549548
let base_url = format!("http://{}", &env.electrsd.esplora_url.clone().unwrap());
550549
let client = Builder::new(base_url.as_str()).build_async()?;
@@ -590,7 +589,6 @@ mod test {
590589
chain.apply_update(update)?;
591590
chain
592591
};
593-
println!("local chain height: {}", local_chain.tip().height());
594592

595593
// extend env chain
596594
if let Some(to_mine) = t
@@ -633,10 +631,6 @@ mod test {
633631
// apply update
634632
let mut updated_local_chain = local_chain.clone();
635633
updated_local_chain.apply_update(update)?;
636-
println!(
637-
"updated local chain height: {}",
638-
updated_local_chain.tip().height()
639-
);
640634

641635
assert!(
642636
{

crates/esplora/src/blocking_ext.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ mod test {
495495
#[test]
496496
pub fn test_finalize_chain_update() -> anyhow::Result<()> {
497497
struct TestCase<'a> {
498+
#[allow(dead_code)]
498499
name: &'a str,
499500
/// Initial blockchain height to start the env with.
500501
initial_env_height: u32,
@@ -531,9 +532,7 @@ mod test {
531532
},
532533
];
533534

534-
for (i, t) in test_cases.into_iter().enumerate() {
535-
println!("[{}] running test case: {}", i, t.name);
536-
535+
for t in test_cases.into_iter() {
537536
let env = TestEnv::new()?;
538537
let base_url = format!("http://{}", &env.electrsd.esplora_url.clone().unwrap());
539538
let client = Builder::new(base_url.as_str()).build_blocking();
@@ -578,7 +577,6 @@ mod test {
578577
chain.apply_update(update)?;
579578
chain
580579
};
581-
println!("local chain height: {}", local_chain.tip().height());
582580

583581
// extend env chain
584582
if let Some(to_mine) = t
@@ -620,10 +618,6 @@ mod test {
620618
// apply update
621619
let mut updated_local_chain = local_chain.clone();
622620
updated_local_chain.apply_update(update)?;
623-
println!(
624-
"updated local chain height: {}",
625-
updated_local_chain.tip().height()
626-
);
627621

628622
assert!(
629623
{
@@ -784,7 +778,6 @@ mod test {
784778
];
785779

786780
for (i, t) in test_cases.into_iter().enumerate() {
787-
println!("Case {}: {}", i, t.name);
788781
let mut chain = t.chain;
789782

790783
let mock_anchors = t

crates/file_store/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ keywords = ["bitcoin", "persist", "persistence", "bdk", "file"]
1010
authors = ["Bitcoin Dev Kit Developers"]
1111
readme = "README.md"
1212

13+
[lints]
14+
workspace = true
15+
1316
[dependencies]
1417
bdk_chain = { path = "../chain", version = "0.18.0", features = [ "serde", "miniscript" ] }
1518
bincode = { version = "1" }

crates/file_store/src/store.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ mod test {
340340

341341
for short_write_len in 1..last_changeset_bytes.len() - 1 {
342342
let file_path = temp_dir.path().join(format!("{}.dat", short_write_len));
343-
println!("Test file: {:?}", file_path);
344343

345344
// simulate creating a file, writing data where the last write is incomplete
346345
{
@@ -406,7 +405,6 @@ mod test {
406405

407406
for read_count in 0..changesets.len() {
408407
let file_path = temp_dir.path().join(format!("{}.dat", read_count));
409-
println!("Test file: {:?}", file_path);
410408

411409
// First, we create the file with all the changesets!
412410
let mut db = Store::<TestChangeSet>::create_new(&TEST_MAGIC_BYTES, &file_path).unwrap();

crates/hwi/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ description = "Utilities to use bdk with hardware wallets"
88
license = "MIT OR Apache-2.0"
99
readme = "README.md"
1010

11+
[lints]
12+
workspace = true
13+
1114
[dependencies]
1215
bdk_wallet = { path = "../wallet", version = "1.0.0-beta.2" }
1316
hwi = { version = "0.9.0", features = [ "miniscript" ] }

crates/testenv/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ readme = "README.md"
1212

1313
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1414

15+
[lints]
16+
workspace = true
17+
1518
[dependencies]
1619
bdk_chain = { path = "../chain", version = "0.18", default-features = false }
1720
electrsd = { version = "0.28.0", features = [ "bitcoind_25_0", "esplora_a33e97e1", "legacy" ] }

crates/wallet/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ authors = ["Bitcoin Dev Kit Developers"]
1212
edition = "2021"
1313
rust-version = "1.63"
1414

15+
[lints]
16+
workspace = true
17+
1518
[dependencies]
1619
rand_core = { version = "0.6.0" }
1720
miniscript = { version = "12.0.0", features = [ "serde" ], default-features = false }

crates/wallet/examples/compiler.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use bdk_wallet::{KeychainKind, Wallet};
3131
///
3232
/// This example demonstrates the interaction between a bdk wallet and miniscript policy.
3333
34+
#[allow(clippy::print_stdout)]
3435
fn main() -> Result<(), Box<dyn Error>> {
3536
// We start with a miniscript policy string
3637
let policy_str = "or(

crates/wallet/examples/mnemonic_to_descriptors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::str::FromStr;
1919

2020
/// This example demonstrates how to generate a mnemonic phrase
2121
/// using BDK and use that to generate a descriptor string.
22+
#[allow(clippy::print_stdout)]
2223
fn main() -> Result<(), anyhow::Error> {
2324
let secp = Secp256k1::new();
2425

crates/wallet/examples/policy.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use bdk_wallet::signer::SignersContainer;
2626
/// This example demos a Policy output for a 2of2 multisig between between 2 parties, where the wallet holds
2727
/// one of the Extend Private key.
2828
29+
#[allow(clippy::print_stdout)]
2930
fn main() -> Result<(), Box<dyn Error>> {
3031
let secp = bitcoin::secp256k1::Secp256k1::new();
3132

crates/wallet/src/wallet/coin_selection.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1579,7 +1579,6 @@ mod test {
15791579
];
15801580

15811581
for (i, t) in test_cases.into_iter().enumerate() {
1582-
println!("Case {}: {}", i, t.name);
15831582
let (required, optional) =
15841583
filter_duplicates(to_utxo_vec(t.required), to_utxo_vec(t.optional));
15851584
assert_eq!(

0 commit comments

Comments
 (0)