Skip to content

Commit

Permalink
[ci] Add github actions and use latest proptest
Browse files Browse the repository at this point in the history
  • Loading branch information
LLFourn committed Dec 21, 2023
1 parent 7d98b1a commit dac0641
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 20 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
on:
push:
branches:
- master
pull_request:


# Make sure CI fails on all warnings, including Clippy lints
env:
RUSTFLAGS: "-Dwarnings"
RUSTDOCFLAGS: "-Dwarnings"

jobs:
fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- run: cargo fmt --all -- --check

clippy_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: Swatinem/rust-cache@v2
- run: cargo clippy --all-targets --all-features --tests

build-msrv:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/[email protected]
# don't want dev-dependencies for MSRV check
- run: sed -i 's/\[dev-dependencies]/[ignore-this-warning-fren]/g' Cargo.toml
- run: cargo build --release

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo test --release

doc-build:
name: doc-build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo doc --no-deps
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ readme = "README.md"
[dependencies]
# No dependencies! Please do not add any please!

[dev-dependencies]
rand = "0.7"
proptest = "0.10"
bitcoin = "0.30"

[features]
default = ["std"]
std = []

[dev-dependencies]
rand = "0.8"
proptest = "1.4"
bitcoin = "0.30"
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
`bdk_coin_select` is a tool to help you select inputs for making Bitcoin (ticker: BTC) transactions.
It's got zero dependencies so you can paste it into your project without concern.

> ⚠ This work is only ready to use by those who expect (potentially catastrophic) bugs and will have
> the time to investigate them and contribute back to this crate.
## Constructing the `CoinSelector`

The main structure is [`CoinSelector`](crate::CoinSelector). To construct it, we specify a list of
Expand Down
9 changes: 4 additions & 5 deletions src/coin_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,9 @@ impl Candidate {
}
}

/// A structure that represents the weight costs of a drain (a.k.a. change) output.
/// Represents the weight costs of a drain (a.k.a. change) output.
///
/// This structure can also represent multiple outputs.
/// May also represent multiple outputs.
#[derive(Default, Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub struct DrainWeights {
/// The weight of including this drain output.
Expand Down Expand Up @@ -659,9 +659,8 @@ impl DrainWeights {
/// A drain (A.K.A. change) output.
/// Technically it could represent multiple outputs.
///
/// These are usually created by a [`change_policy`].
///
/// [`change_policy`]: crate::change_policy
/// This is returned from [`CoinSelector::drain`]. Note if `drain` returns a drain where `is_none()`
/// returns true then **no change should be added** to the transaction.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default)]
pub struct Drain {
/// Weight of adding drain output and spending the drain output.
Expand Down
4 changes: 2 additions & 2 deletions tests/bnb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use proptest::{prelude::*, proptest, test_runner::*};

fn test_wv(mut rng: impl RngCore) -> impl Iterator<Item = Candidate> {
core::iter::repeat_with(move || {
let value = rng.gen_range(0, 1_000);
let value = rng.gen_range(0..1_000);
let mut candidate = Candidate {
value,
weight: 100,
input_count: rng.gen_range(1, 2),
input_count: rng.gen_range(1..2),
is_segwit: rng.gen_bool(0.5),
};
// HACK: set is_segwit = true for all these tests because you can't actually lower bound
Expand Down
6 changes: 3 additions & 3 deletions tests/changeless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use rand::{prelude::IteratorRandom, Rng, RngCore};

fn test_wv(mut rng: impl RngCore) -> impl Iterator<Item = Candidate> {
core::iter::repeat_with(move || {
let value = rng.gen_range(0, 1_000);
let value = rng.gen_range(0..1_000);
Candidate {
value,
weight: rng.gen_range(0, 100),
input_count: rng.gen_range(1, 2),
weight: rng.gen_range(0..100),
input_count: rng.gen_range(1..2),
is_segwit: rng.gen_bool(0.5),
}
})
Expand Down
6 changes: 3 additions & 3 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ impl StrategyParams {
pub fn gen_candidates(n: usize) -> Vec<Candidate> {
let mut rng = TestRng::deterministic_rng(RngAlgorithm::ChaCha);
core::iter::repeat_with(move || {
let value = rng.gen_range(1, 500_001);
let weight = rng.gen_range(1, 2001);
let input_count = rng.gen_range(1, 3);
let value = rng.gen_range(1..500_001);
let weight = rng.gen_range(1..2001);
let input_count = rng.gen_range(1..3);
let is_segwit = rng.gen_bool(0.01);

Candidate {
Expand Down
6 changes: 3 additions & 3 deletions tests/waste.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,11 @@ proptest! {

fn test_wv(mut rng: impl RngCore) -> impl Iterator<Item = Candidate> {
core::iter::repeat_with(move || {
let value = rng.gen_range(0, 1_000);
let value = rng.gen_range(0..1_000);
Candidate {
value,
weight: rng.gen_range(0, 100),
input_count: rng.gen_range(1, 2),
weight: rng.gen_range(0..100),
input_count: rng.gen_range(1..2),
is_segwit: rng.gen_bool(0.5),
}
})
Expand Down

0 comments on commit dac0641

Please sign in to comment.