Skip to content

Commit ccbc596

Browse files
committed
Add test utilities for {dis}connecting a block
Replace direct uses of BlockNotifier in functional tests with utility functions. This is in preparation for signaling watch events back via a refactoring of ManyChannelMonitor and ChainWatchInterface. Those events will be processed by connect_block.
1 parent bcfe5f5 commit ccbc596

File tree

3 files changed

+127
-121
lines changed

3 files changed

+127
-121
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,41 +38,47 @@ use std::collections::HashMap;
3838
pub const CHAN_CONFIRM_DEPTH: u32 = 100;
3939

4040
pub fn confirm_transaction<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, tx: &Transaction) {
41-
let notifier = &node.block_notifier;
4241
let dummy_tx = Transaction { version: 0, lock_time: 0, input: Vec::new(), output: Vec::new() };
4342
let dummy_tx_count = tx.version as usize;
4443
let mut block = Block {
4544
header: BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 },
4645
txdata: vec![dummy_tx; dummy_tx_count],
4746
};
4847
block.txdata.push(tx.clone());
49-
notifier.block_connected(&block, 1);
48+
connect_block(node, &block, 1);
5049
for i in 2..CHAN_CONFIRM_DEPTH {
5150
block = Block {
5251
header: BlockHeader { version: 0x20000000, prev_blockhash: block.header.bitcoin_hash(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 },
5352
txdata: vec![],
5453
};
55-
notifier.block_connected(&block, i);
54+
connect_block(node, &block, i);
5655
}
5756
}
5857

5958
pub fn connect_blocks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, depth: u32, height: u32, parent: bool, prev_blockhash: BlockHash) -> BlockHash {
60-
let notifier = &node.block_notifier;
6159
let mut block = Block {
6260
header: BlockHeader { version: 0x2000000, prev_blockhash: if parent { prev_blockhash } else { Default::default() }, merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 },
6361
txdata: vec![],
6462
};
65-
notifier.block_connected(&block, height + 1);
63+
connect_block(node, &block, height + 1);
6664
for i in 2..depth + 1 {
6765
block = Block {
6866
header: BlockHeader { version: 0x20000000, prev_blockhash: block.header.bitcoin_hash(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 },
6967
txdata: vec![],
7068
};
71-
notifier.block_connected(&block, height + i);
69+
connect_block(node, &block, height + i);
7270
}
7371
block.header.bitcoin_hash()
7472
}
7573

74+
pub fn connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: &Block, height: u32) {
75+
node.block_notifier.block_connected(block, height)
76+
}
77+
78+
pub fn disconnect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, header: &BlockHeader, height: u32) {
79+
node.block_notifier.block_disconnected(header, height)
80+
}
81+
7682
pub struct TestChanMonCfg {
7783
pub tx_broadcaster: test_utils::TestBroadcaster,
7884
pub fee_estimator: test_utils::TestFeeEstimator,

0 commit comments

Comments
 (0)