Skip to content

Commit

Permalink
Merge bitcoindevkit#1425: chore: add print_stdout/print_stderr li…
Browse files Browse the repository at this point in the history
…nts 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 bitcoindevkit#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
  • Loading branch information
notmandatory committed Aug 29, 2024
2 parents 775e4ae + e063ad8 commit a8d52e6
Show file tree
Hide file tree
Showing 19 changed files with 41 additions and 38 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ members = [

[workspace.package]
authors = ["Bitcoin Dev Kit Developers"]

[workspace.lints.clippy]
print_stdout = "deny"
print_stderr = "deny"
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv="1.63.0"
msrv="1.63.0"
3 changes: 3 additions & 0 deletions crates/bitcoind_rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ readme = "README.md"

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

[lints]
workspace = true

[dependencies]
bitcoin = { version = "0.32.0", default-features = false }
bitcoincore-rpc = { version = "0.19.0" }
Expand Down
10 changes: 2 additions & 8 deletions crates/bitcoind_rpc/tests/test_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn test_sync_local_chain() -> anyhow::Result<()> {
};

// See if the emitter outputs the right blocks.
println!("first sync:");

while let Some(emission) = emitter.next_block()? {
let height = emission.block_height();
let hash = emission.block_hash();
Expand Down Expand Up @@ -76,7 +76,7 @@ pub fn test_sync_local_chain() -> anyhow::Result<()> {
.collect::<Vec<_>>();

// See if the emitter outputs the right blocks.
println!("after reorg:");

let mut exp_height = exp_hashes.len() - reorged_blocks.len();
while let Some(emission) = emitter.next_block()? {
let height = emission.block_height();
Expand Down Expand Up @@ -132,7 +132,6 @@ pub fn test_sync_local_chain() -> anyhow::Result<()> {
fn test_into_tx_graph() -> anyhow::Result<()> {
let env = TestEnv::new()?;

println!("getting new addresses!");
let addr_0 = env
.rpc_client()
.get_new_address(None, None)?
Expand All @@ -145,11 +144,8 @@ fn test_into_tx_graph() -> anyhow::Result<()> {
.rpc_client()
.get_new_address(None, None)?
.assume_checked();
println!("got new addresses!");

println!("mining block!");
env.mine_blocks(101, None)?;
println!("mined blocks!");

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

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

// the mempool emission (that follows the first block emission after reorg) should only
// include mempool txs introduced at reorg height or greater
Expand Down
3 changes: 3 additions & 0 deletions crates/chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ readme = "README.md"

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

[lints]
workspace = true

[dependencies]
bitcoin = { version = "0.32.0", default-features = false }
bdk_core = { path = "../core", version = "0.1", default-features = false }
Expand Down
12 changes: 3 additions & 9 deletions crates/chain/tests/test_local_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ enum ExpectedResult<'a> {

impl<'a> TestLocalChain<'a> {
fn run(mut self) {
println!("[TestLocalChain] test: {}", self.name);
let got_changeset = match self.chain.apply_update(self.update) {
Ok(changeset) => changeset,
Err(got_err) => {
Expand Down Expand Up @@ -255,7 +254,7 @@ fn update_local_chain() {
(4, None)
],
init_changeset: &[
(0, Some(h!("_"))),
(0, Some(h!("_"))),
(1, Some(h!("B'"))),
(2, Some(h!("C'"))),
(3, Some(h!("D"))),
Expand Down Expand Up @@ -437,8 +436,6 @@ fn local_chain_disconnect_from() {
];

for (i, t) in test_cases.into_iter().enumerate() {
println!("Case {}: {}", i, t.name);

let mut chain = t.original;
let result = chain.disconnect_from(t.disconnect_from.into());
assert_eq!(
Expand Down Expand Up @@ -491,7 +488,6 @@ fn checkpoint_from_block_ids() {
];

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

for (i, t) in test_cases.into_iter().enumerate() {
println!("Running [{}] '{}'", i, t.name);

for t in test_cases.into_iter() {
let chain = CheckPoint::from_block_ids(
genesis_block().chain(t.chain.iter().copied().map(BlockId::from)),
)
Expand Down Expand Up @@ -792,7 +787,6 @@ fn local_chain_apply_header_connected_to() {
];

for (i, t) in test_cases.into_iter().enumerate() {
println!("running test case {}: '{}'", i, t.name);
let mut chain = t.chain;
let result = chain.apply_header_connected_to(&t.header, t.height, t.connected_to);
let exp_result = t
Expand Down
3 changes: 3 additions & 0 deletions crates/electrum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ description = "Fetch data from electrum in the form BDK accepts"
license = "MIT OR Apache-2.0"
readme = "README.md"

[lints]
workspace = true

[dependencies]
bdk_core = { path = "../core", version = "0.1" }
electrum-client = { version = "0.21", features = [ "proxy" ], default-features = false }
Expand Down
3 changes: 3 additions & 0 deletions crates/esplora/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ readme = "README.md"

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

[lints]
workspace = true

[dependencies]
bdk_core = { path = "../core", version = "0.1", default-features = false }
esplora-client = { version = "0.9.0", default-features = false }
Expand Down
10 changes: 2 additions & 8 deletions crates/esplora/src/async_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ mod test {
#[tokio::test]
pub async fn test_finalize_chain_update() -> anyhow::Result<()> {
struct TestCase<'a> {
#[allow(dead_code)]
name: &'a str,
/// Initial blockchain height to start the env with.
initial_env_height: u32,
Expand Down Expand Up @@ -542,9 +543,7 @@ mod test {
},
];

for (i, t) in test_cases.into_iter().enumerate() {
println!("[{}] running test case: {}", i, t.name);

for t in test_cases.into_iter() {
let env = TestEnv::new()?;
let base_url = format!("http://{}", &env.electrsd.esplora_url.clone().unwrap());
let client = Builder::new(base_url.as_str()).build_async()?;
Expand Down Expand Up @@ -590,7 +589,6 @@ mod test {
chain.apply_update(update)?;
chain
};
println!("local chain height: {}", local_chain.tip().height());

// extend env chain
if let Some(to_mine) = t
Expand Down Expand Up @@ -633,10 +631,6 @@ mod test {
// apply update
let mut updated_local_chain = local_chain.clone();
updated_local_chain.apply_update(update)?;
println!(
"updated local chain height: {}",
updated_local_chain.tip().height()
);

assert!(
{
Expand Down
11 changes: 2 additions & 9 deletions crates/esplora/src/blocking_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ mod test {
#[test]
pub fn test_finalize_chain_update() -> anyhow::Result<()> {
struct TestCase<'a> {
#[allow(dead_code)]
name: &'a str,
/// Initial blockchain height to start the env with.
initial_env_height: u32,
Expand Down Expand Up @@ -531,9 +532,7 @@ mod test {
},
];

for (i, t) in test_cases.into_iter().enumerate() {
println!("[{}] running test case: {}", i, t.name);

for t in test_cases.into_iter() {
let env = TestEnv::new()?;
let base_url = format!("http://{}", &env.electrsd.esplora_url.clone().unwrap());
let client = Builder::new(base_url.as_str()).build_blocking();
Expand Down Expand Up @@ -578,7 +577,6 @@ mod test {
chain.apply_update(update)?;
chain
};
println!("local chain height: {}", local_chain.tip().height());

// extend env chain
if let Some(to_mine) = t
Expand Down Expand Up @@ -620,10 +618,6 @@ mod test {
// apply update
let mut updated_local_chain = local_chain.clone();
updated_local_chain.apply_update(update)?;
println!(
"updated local chain height: {}",
updated_local_chain.tip().height()
);

assert!(
{
Expand Down Expand Up @@ -784,7 +778,6 @@ mod test {
];

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

let mock_anchors = t
Expand Down
3 changes: 3 additions & 0 deletions crates/file_store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ keywords = ["bitcoin", "persist", "persistence", "bdk", "file"]
authors = ["Bitcoin Dev Kit Developers"]
readme = "README.md"

[lints]
workspace = true

[dependencies]
bdk_chain = { path = "../chain", version = "0.18.0", features = [ "serde", "miniscript" ] }
bincode = { version = "1" }
Expand Down
2 changes: 0 additions & 2 deletions crates/file_store/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ mod test {

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

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

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

// First, we create the file with all the changesets!
let mut db = Store::<TestChangeSet>::create_new(&TEST_MAGIC_BYTES, &file_path).unwrap();
Expand Down
3 changes: 3 additions & 0 deletions crates/hwi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ description = "Utilities to use bdk with hardware wallets"
license = "MIT OR Apache-2.0"
readme = "README.md"

[lints]
workspace = true

[dependencies]
bdk_wallet = { path = "../wallet", version = "1.0.0-beta.2" }
hwi = { version = "0.9.0", features = [ "miniscript" ] }
3 changes: 3 additions & 0 deletions crates/testenv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ readme = "README.md"

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

[lints]
workspace = true

[dependencies]
bdk_chain = { path = "../chain", version = "0.18", default-features = false }
electrsd = { version = "0.28.0", features = [ "bitcoind_25_0", "esplora_a33e97e1", "legacy" ] }
Expand Down
3 changes: 3 additions & 0 deletions crates/wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ authors = ["Bitcoin Dev Kit Developers"]
edition = "2021"
rust-version = "1.63"

[lints]
workspace = true

[dependencies]
rand_core = { version = "0.6.0" }
miniscript = { version = "12.0.0", features = [ "serde" ], default-features = false }
Expand Down
1 change: 1 addition & 0 deletions crates/wallet/examples/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use bdk_wallet::{KeychainKind, Wallet};
///
/// This example demonstrates the interaction between a bdk wallet and miniscript policy.
#[allow(clippy::print_stdout)]
fn main() -> Result<(), Box<dyn Error>> {
// We start with a miniscript policy string
let policy_str = "or(
Expand Down
1 change: 1 addition & 0 deletions crates/wallet/examples/mnemonic_to_descriptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::str::FromStr;

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

Expand Down
1 change: 1 addition & 0 deletions crates/wallet/examples/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use bdk_wallet::signer::SignersContainer;
/// This example demos a Policy output for a 2of2 multisig between between 2 parties, where the wallet holds
/// one of the Extend Private key.
#[allow(clippy::print_stdout)]
fn main() -> Result<(), Box<dyn Error>> {
let secp = bitcoin::secp256k1::Secp256k1::new();

Expand Down
1 change: 0 additions & 1 deletion crates/wallet/src/wallet/coin_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,6 @@ mod test {
];

for (i, t) in test_cases.into_iter().enumerate() {
println!("Case {}: {}", i, t.name);
let (required, optional) =
filter_duplicates(to_utxo_vec(t.required), to_utxo_vec(t.optional));
assert_eq!(
Expand Down

0 comments on commit a8d52e6

Please sign in to comment.