Skip to content

Commit 22bc2f5

Browse files
committed
DEMO: Simple proptest that repros the bug in lightningdevkit#1935
1 parent f6a9382 commit 22bc2f5

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

lightning/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ core2 = { version = "0.3.0", optional = true, default-features = false }
5151
[dev-dependencies]
5252
hex = "0.4"
5353
regex = "1.5.6"
54+
proptest = "1"
5455

5556
[dev-dependencies.bitcoin]
5657
version = "0.29.0"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Seeds for failure cases proptest has generated in the past. It is
2+
# automatically read and these particular cases re-run before any
3+
# novel cases are generated.
4+
#
5+
# It is recommended to check this file in to source control so that
6+
# everyone who runs the test benefits from these saved cases.
7+
cc 15e12e1f6dd9cfa0f0e3ae317db6c67b066f0450d694f7ffd3ca740e51524d9e # shrinks to keys_manager = , channel_value_sat = 0, params = [0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

lightning/src/chain/keysinterface.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,3 +1428,43 @@ impl PhantomKeysManager {
14281428
pub fn dyn_sign() {
14291429
let _signer: Box<dyn BaseSign>;
14301430
}
1431+
1432+
#[cfg(test)]
1433+
mod test {
1434+
use std::fmt::{self, Debug};
1435+
1436+
use proptest::strategy::{BoxedStrategy, Strategy};
1437+
use proptest::arbitrary::{any, Arbitrary};
1438+
use proptest::proptest;
1439+
1440+
use super::*;
1441+
1442+
impl Debug for KeysManager {
1443+
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
1444+
Ok(())
1445+
}
1446+
}
1447+
1448+
impl Arbitrary for KeysManager {
1449+
type Parameters = ();
1450+
type Strategy = BoxedStrategy<Self>;
1451+
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
1452+
(any::<[u8; 32]>(), any::<u64>(), any::<u32>())
1453+
.prop_map(|(seed, secs, nanos)| {
1454+
KeysManager::new(&seed, secs, nanos)
1455+
})
1456+
.boxed()
1457+
}
1458+
}
1459+
1460+
#[test]
1461+
fn derive_channel_keys_doesnt_panic() {
1462+
proptest!(|(
1463+
keys_manager in any::<KeysManager>(),
1464+
channel_value_sat in any::<u64>(),
1465+
params in any::<[u8; 32]>(),
1466+
)| {
1467+
keys_manager.derive_channel_keys(channel_value_sat, &params);
1468+
});
1469+
}
1470+
}

0 commit comments

Comments
 (0)