Skip to content
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
32 changes: 13 additions & 19 deletions .github/workflows/code_coverage.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Code Coverage

# Generates code coverage reports using grcov and uploads results to Codecov.
# Generates code coverage reports using cargo-llvm-cov and uploads results to Codecov.
# Runs on every push and pull request to track test coverage metrics.
# Uploads coverage data to Codecov for tracking and produces an HTML report artifact for download.

Expand All @@ -14,38 +14,32 @@ jobs:
Coverage:
name: Code Coverage
runs-on: ubuntu-latest
env:
RUSTFLAGS: "-Cinstrument-coverage"
RUSTDOCFLAGS: "-Cinstrument-coverage"
LLVM_PROFILE_FILE: "./target/coverage/%p-%m.profraw"

steps:
- name: Checkout
uses: actions/checkout@v6
with:
persist-credentials: false
- name: Install lcov tools
run: sudo apt-get install lcov -y
# This action automatically reads and applies rust-toolchain.toml
- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly
components: llvm-tools-preview
cache: true
- name: Install grcov
run: if [[ ! -e ~/.cargo/bin/grcov ]]; then cargo install grcov; fi
- name: Test
run: cargo test --all-features
- name: Make coverage directory
run: mkdir coverage
- name: Run grcov
run: grcov . --binary-path ./target/debug/ -s . -t lcov --branch --ignore-not-existing --keep-only 'src/**' --ignore 'tests/**' --ignore 'examples/**' -o ./coverage/lcov.info
- name: Install cargo-llvm-cov
run: cargo install cargo-llvm-cov
- name: Generate coverage data
run: cargo llvm-cov --all-features --branch --quiet --ignore-filename-regex "test_utils" --lcov --output-path lcov.info
env:
RUSTFLAGS: "--cfg coverage_nightly"
- name: Generate HTML coverage report
run: genhtml -o coverage-report.html --ignore-errors unmapped ./coverage/lcov.info
run: cargo llvm-cov --all-features --branch --quiet --ignore-filename-regex "test_utils" --html
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not reusing the lcov.info file to produce a report with genhtml or something similar?
What's the purpose of keeping the html file in the artifacts if the .info file is enough for codecov?
If it is for auditing reasons, why not keeping only the lcov.info files instead of the bloated html?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove the html file generation altogether and keep only the lcov.info as artifacts. If we want to review them later we can pull them locally and generate an html ourselves. This avoids adding the lcov tools suite to the CI.
I can apply the changes if there are no concerns.

env:
RUSTFLAGS: "--cfg coverage_nightly"
- name: Codecov upload
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7
with:
files: ./coverage/lcov.info
files: ./lcov.info
flags: rust
name: codecov-bdk-wallet
token: ${{ secrets.CODECOV_TOKEN }}
Expand All @@ -54,4 +48,4 @@ jobs:
uses: actions/upload-artifact@v6
with:
name: coverage-report
path: coverage-report.html
path: target/llvm-cov/html
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ Cargo.lock
*.db
*.sqlite*
examples/test_data

# Coverage reports
lcov.info
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ rust-version = "1.85.0"
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage_nightly)'] }

[dependencies]
bdk_chain = { version = "0.23.1", features = ["miniscript", "serde"], default-features = false }
bitcoin = { version = "0.32.7", features = ["serde", "base64"], default-features = false }
Expand Down
1 change: 1 addition & 0 deletions src/descriptor/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub fn calc_checksum(desc: &str) -> Result<String, DescriptorError> {
}
}

#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod test {
use super::*;
Expand Down
1 change: 1 addition & 0 deletions src/descriptor/dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,7 @@ macro_rules! fragment {
});
}

#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod test {
use alloc::string::ToString;
Expand Down
1 change: 1 addition & 0 deletions src/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ impl DescriptorMeta for ExtendedDescriptor {
}
}

#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod test {
use alloc::string::ToString;
Expand Down
1 change: 1 addition & 0 deletions src/descriptor/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,7 @@ impl ExtractPolicy for Descriptor<DescriptorPublicKey> {
}
}

#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod test {
use super::*;
Expand Down
1 change: 1 addition & 0 deletions src/descriptor/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ expand_make_bipxx!(legacy, Legacy);
expand_make_bipxx!(segwit_v0, Segwitv0);
expand_make_bipxx!(segwit_v1, Tap);

#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod test {
// Test existing descriptor templates to make sure they are expanded to the right descriptors.
Expand Down
1 change: 1 addition & 0 deletions src/keys/bip39.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ impl<Ctx: ScriptContext> GeneratableKey<Ctx> for Mnemonic {
}
}

#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod test {
use super::WordCount;
Expand Down
1 change: 1 addition & 0 deletions src/keys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,7 @@ impl fmt::Display for KeyError {
#[cfg(feature = "std")]
impl std::error::Error for KeyError {}

#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod test {
use super::*;
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
docsrs,
doc(html_logo_url = "https://github.com/bitcoindevkit/bdk/raw/master/static/bdk.png")
)]
#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
#![no_std]
#![warn(missing_docs)]
#![allow(clippy::uninlined_format_args)]
Expand Down
1 change: 1 addition & 0 deletions src/wallet/coin_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ fn calculate_cs_result(
}
}

#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod test {
use assert_matches::assert_matches;
Expand Down
1 change: 1 addition & 0 deletions src/wallet/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ impl CaravanExport {
}
}

#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod test {
use alloc::string::ToString;
Expand Down
1 change: 1 addition & 0 deletions src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2928,6 +2928,7 @@ macro_rules! doctest_wallet {
}}
}

#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod test {
use super::*;
Expand Down
1 change: 1 addition & 0 deletions src/wallet/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,7 @@ impl PartialEq for SignersContainerKey {

impl Eq for SignersContainerKey {}

#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod signers_container_tests {
use super::*;
Expand Down
1 change: 1 addition & 0 deletions src/wallet/tx_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,7 @@ impl ChangeSpendPolicy {
}
}

#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod test {
const ORDERING_TEST_TX: &str = "0200000003c26f3eb7932f7acddc5ddd26602b77e7516079b03090a16e2c2f54\
Expand Down
1 change: 1 addition & 0 deletions src/wallet/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ pub struct TxDetails {
pub tx: Arc<Transaction>,
}

#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod test {
// When nSequence is lower than this flag the timelock is interpreted as block-height-based,
Expand Down