Skip to content

Commit fd35254

Browse files
committed
expose functional tests under _test_utils feature flag
introduce DynSigner and TestSignerFactory
1 parent 7754bbb commit fd35254

32 files changed

+1140
-523
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ lightning/net_graph-*.bin
1212
lightning-rapid-gossip-sync/res/full_graph.lngossip
1313
lightning-custom-message/target
1414
lightning-transaction-sync/target
15+
ext-functional-test-demo/target
1516
no-std-check/target
1617
msrv-no-dev-deps-check/target

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ members = [
1919
]
2020

2121
exclude = [
22+
"ext-functional-test-demo",
2223
"no-std-check",
2324
"msrv-no-dev-deps-check",
2425
"bench",

ci/ci-tests.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ cargo check --verbose --color always --features lightning-transaction-sync
138138
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
139139
popd
140140

141+
echo -e "\n\Running functional tests from outside the workspace"
142+
pushd ext-functional-test-demo
143+
cargo test --color always
144+
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
145+
popd
146+
141147
# Test that we can build downstream code with only the "release pins".
142148
pushd msrv-no-dev-deps-check
143149
PIN_RELEASE_DEPS

ext-functional-test-demo/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "ext-functional-tester"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
lightning = { path = "../lightning", features = ["_test_utils"] }

ext-functional-test-demo/src/main.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}
4+
5+
#[cfg(test)]
6+
mod tests {
7+
use lightning::util::dyn_signer::{DynKeysInterfaceTrait, DynSigner};
8+
use lightning::util::test_utils::{TestSignerFactory, SIGNER_FACTORY};
9+
use std::panic::catch_unwind;
10+
use std::sync::Arc;
11+
use std::time::Duration;
12+
13+
struct BrokenSignerFactory();
14+
15+
impl TestSignerFactory for BrokenSignerFactory {
16+
fn make_signer(
17+
&self, _seed: &[u8; 32], _now: Duration,
18+
) -> Box<dyn DynKeysInterfaceTrait<EcdsaSigner = DynSigner>> {
19+
panic!()
20+
}
21+
}
22+
23+
#[test]
24+
fn test_functional() {
25+
lightning::ln::functional_tests::test_insane_channel_opens();
26+
lightning::ln::functional_tests::fake_network_test();
27+
28+
SIGNER_FACTORY.set(Arc::new(BrokenSignerFactory()));
29+
catch_unwind(|| lightning::ln::functional_tests::fake_network_test()).unwrap_err();
30+
}
31+
}

fuzz/src/chanmon_consistency.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ use bitcoin::secp256k1::schnorr;
8181
use bitcoin::secp256k1::{self, Message, PublicKey, Scalar, Secp256k1, SecretKey};
8282

8383
use lightning::io::Cursor;
84+
use lightning::util::dyn_signer::DynSigner;
8485
use std::cmp::{self, Ordering};
8586
use std::mem;
8687
use std::sync::atomic;
@@ -391,6 +392,7 @@ impl SignerProvider for KeyProvider {
391392
channel_keys_id,
392393
);
393394
let revoked_commitment = self.make_enforcement_state_cell(keys.commitment_seed);
395+
let keys = DynSigner::new(keys);
394396
TestChannelSigner::new_with_revoked(keys, revoked_commitment, false)
395397
}
396398

@@ -399,6 +401,7 @@ impl SignerProvider for KeyProvider {
399401

400402
let inner: InMemorySigner = ReadableArgs::read(&mut reader, self)?;
401403
let state = self.make_enforcement_state_cell(inner.commitment_seed);
404+
let inner = DynSigner::new(inner);
402405

403406
Ok(TestChannelSigner::new_with_revoked(inner, state, false))
404407
}

fuzz/src/full_stack.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ use bitcoin::secp256k1::ecdsa::{RecoverableSignature, Signature};
7777
use bitcoin::secp256k1::schnorr;
7878
use bitcoin::secp256k1::{self, Message, PublicKey, Scalar, Secp256k1, SecretKey};
7979

80+
use lightning::util::dyn_signer::DynSigner;
8081
use std::cell::RefCell;
8182
use std::cmp;
8283
use std::convert::TryInto;
@@ -455,7 +456,7 @@ impl SignerProvider for KeyProvider {
455456
let ctr = channel_keys_id[0];
456457
let (inbound, state) = self.signer_state.borrow().get(&ctr).unwrap().clone();
457458
TestChannelSigner::new_with_revoked(
458-
if inbound {
459+
DynSigner::new(if inbound {
459460
InMemorySigner::new(
460461
&secp_ctx,
461462
SecretKey::from_slice(&[
@@ -527,7 +528,7 @@ impl SignerProvider for KeyProvider {
527528
channel_keys_id,
528529
channel_keys_id,
529530
)
530-
},
531+
}),
531532
state,
532533
false,
533534
)
@@ -536,6 +537,7 @@ impl SignerProvider for KeyProvider {
536537
fn read_chan_signer(&self, mut data: &[u8]) -> Result<TestChannelSigner, DecodeError> {
537538
let inner: InMemorySigner = ReadableArgs::read(&mut data, self)?;
538539
let state = Arc::new(Mutex::new(EnforcementState::new()));
540+
let inner = DynSigner::new(inner);
539541

540542
Ok(TestChannelSigner::new_with_revoked(inner, state, false))
541543
}

lightning-background-processor/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2557,6 +2557,8 @@ mod tests {
25572557
failure: PathFailure::OnPath { network_update: None },
25582558
path: path.clone(),
25592559
short_channel_id: Some(scored_scid),
2560+
error_code: None,
2561+
error_data: None,
25602562
});
25612563
let event = $receive.expect("PaymentPathFailed not handled within deadline");
25622564
match event {
@@ -2574,6 +2576,8 @@ mod tests {
25742576
failure: PathFailure::OnPath { network_update: None },
25752577
path: path.clone(),
25762578
short_channel_id: None,
2579+
error_code: None,
2580+
error_data: None,
25772581
});
25782582
let event = $receive.expect("PaymentPathFailed not handled within deadline");
25792583
match event {

lightning/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ rustdoc-args = ["--cfg", "docsrs"]
1717

1818
[features]
1919
# Internal test utilities exposed to other repo crates
20-
_test_utils = ["regex", "bitcoin/bitcoinconsensus", "lightning-types/_test_utils"]
20+
_test_utils = ["regex", "bitcoin/bitcoinconsensus", "ext-test-macro", "lightning-types/_test_utils"]
2121
# Unlog messages superior at targeted level.
2222
max_level_off = []
2323
max_level_error = []
@@ -50,6 +50,7 @@ backtrace = { version = "0.3", optional = true }
5050

5151
libm = { version = "0.2", default-features = false }
5252
delegate = "0.12.0"
53+
ext-test-macro = { path = "../ext-test-macro", optional = true }
5354

5455
[dev-dependencies]
5556
regex = "1.5.6"

lightning/src/chain/chainmonitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ where C::Target: chain::Filter,
464464
}
465465

466466

467-
#[cfg(test)]
467+
#[cfg(any(test, feature = "_test_utils"))]
468468
pub fn remove_monitor(&self, funding_txo: &OutPoint) -> ChannelMonitor<ChannelSigner> {
469469
self.monitors.write().unwrap().remove(funding_txo).unwrap().monitor
470470
}

0 commit comments

Comments
 (0)