Skip to content

Commit a9a09d0

Browse files
committed
Run with mutagen on travis.
Sadly our test coverage isn't very good and I had to hunt for functions to mutate where we fail tests on every mutation mutagen creates, but committing the framework is a start.
1 parent 251cddf commit a9a09d0

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

.travis.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: rust
22
rust:
33
- stable
4-
- beta
4+
- nightly
55
# 1.22.0 is MSRV for rust-lightning in general:
66
- 1.22.0
77
# 1.34.2 is Debian stable, and we use it to run fuzzing on:
@@ -15,7 +15,7 @@ before_install:
1515
- sudo apt-get install -y binutils-dev libunwind8-dev libcurl4-openssl-dev libelf-dev libdw-dev cmake gcc binutils-dev libiberty-dev
1616

1717
script:
18-
# Support lightning-net-tokio only on Rust stable, beta, and 1.39.0
18+
# Support lightning-net-tokio only on Rust stable, nightly, and 1.39.0
1919
- if [ "$(rustup show | grep default | grep '1.39.0')" != "" ]; then export BUILD_NET_TOKIO=1; fi
2020
- if [ "$(rustup show | grep default | grep '1\.')" == "" ]; then export BUILD_NET_TOKIO=1; fi
2121
# Build the appropriate workspace(s)
@@ -27,6 +27,14 @@ script:
2727
- if [ "$BUILD_NET_TOKIO" != "1" ]; then RUSTFLAGS="-C link-dead-code" cargo test --verbose -p lightning; fi
2828
# Run lightning workspace fuzz tests for Rust 1.34.2
2929
- if [ "$(rustup show | grep default | grep 1.34.2)" != "" ]; then cd fuzz && cargo test --verbose && ./travis-fuzz.sh; fi
30+
# Run mutagen on nightly with TheBlueMatt's fork which exits with non-0 status
31+
# if any mutations resulted in anything except test failures to prevent regressions.
32+
- if [ "$(rustup show | grep default | grep nightly)" != "" ]; then
33+
rm -rf mutagen && git clone https://github.com/TheBlueMatt/mutagen &&
34+
cargo install --force --path mutagen/mutagen-runner &&
35+
cd lightning &&
36+
~/.cargo/bin/cargo-mutagen --features mutation_testing; fi
37+
# Generate codecov on stable
3038
- if [ "$(rustup show | grep default | grep stable)" != "" ]; then
3139
wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz &&
3240
tar xzf master.tar.gz &&

lightning/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,22 @@ Still missing tons of error-handling. See GitHub issues for suggested projects i
1313
[features]
1414
# Supports tracking channels with a non-bitcoin chain hashes. Currently enables all kinds of fun DoS attacks.
1515
non_bitcoin_chain_hash_routing = []
16-
fuzztarget = ["secp256k1/fuzztarget", "bitcoin/fuzztarget", "bitcoin_hashes/fuzztarget"]
1716
# Unlog messages superior at targeted level.
1817
max_level_off = []
1918
max_level_error = []
2019
max_level_warn = []
2120
max_level_info = []
2221
max_level_debug = []
2322

23+
# Testing only features, don't enable these unless you want to run rust-lightning tests!
24+
fuzztarget = ["secp256k1/fuzztarget", "bitcoin/fuzztarget", "bitcoin_hashes/fuzztarget"]
25+
mutation_testing = ["mutagen"]
26+
2427
[dependencies]
2528
bitcoin = "0.21"
2629
bitcoin_hashes = "0.7"
2730
secp256k1 = "0.15"
31+
mutagen = { git = "https://github.com/TheBlueMatt/mutagen", optional = true }
2832

2933
[dev-dependencies.bitcoin]
3034
version = "0.21"

lightning/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@ extern crate bitcoin_hashes;
2323
extern crate secp256k1;
2424
#[cfg(test)] extern crate rand;
2525
#[cfg(test)] extern crate hex;
26+
#[cfg(all(test, feature = "mutation_testing"))] extern crate mutagen;
2627

2728
#[macro_use]
2829
pub mod util;
2930
pub mod chain;
3031
pub mod ln;
32+
33+
#[cfg(all(
34+
any(feature = "mutation_testing", feature = "fuzztarget"),
35+
not(any(test, debug_assertions))
36+
))]
37+
const ERR: () = "You should never be building with feature = mutation_testing or feature = fuzztarget! They are used to compile with broken code for testing only!";

lightning/src/ln/channel.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ use std::default::Default;
3636
use std::{cmp,mem,fmt};
3737
use std::sync::{Arc};
3838

39+
#[cfg(all(test, feature = "mutation_testing"))]
40+
use mutagen::mutate;
41+
3942
#[cfg(test)]
4043
pub struct ChannelValueStat {
4144
pub value_to_self_msat: u64,
@@ -2371,6 +2374,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
23712374
Ok(())
23722375
}
23732376

2377+
#[cfg_attr(all(test, feature = "mutation_testing"), mutate)]
23742378
fn get_last_revoke_and_ack(&self) -> msgs::RevokeAndACK {
23752379
let next_per_commitment_point = PublicKey::from_secret_key(&self.secp_ctx, &self.build_local_commitment_secret(self.cur_local_commitment_transaction_number));
23762380
let per_commitment_secret = chan_utils::build_commitment_secret(self.local_keys.commitment_seed(), self.cur_local_commitment_transaction_number + 2);

0 commit comments

Comments
 (0)