Skip to content

Commit 1ab0a1a

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 5381c23 commit 1ab0a1a

File tree

4 files changed

+130
-124
lines changed

4 files changed

+130
-124
lines changed

lightning/src/ln/functional_test_utils.rs

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

4848
pub fn confirm_transaction<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, tx: &Transaction) {
49-
let notifier = &node.block_notifier;
5049
let dummy_tx = Transaction { version: 0, lock_time: 0, input: Vec::new(), output: Vec::new() };
5150
let dummy_tx_count = tx.version as usize;
5251
let mut block = Block {
5352
header: BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 },
5453
txdata: vec![dummy_tx; dummy_tx_count],
5554
};
5655
block.txdata.push(tx.clone());
57-
notifier.block_connected(&block, 1);
56+
connect_block(node, &block, 1);
5857
for i in 2..CHAN_CONFIRM_DEPTH {
5958
block = Block {
6059
header: BlockHeader { version: 0x20000000, prev_blockhash: block.header.block_hash(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 },
6160
txdata: vec![],
6261
};
63-
notifier.block_connected(&block, i);
62+
connect_block(node, &block, i);
6463
}
6564
}
6665

6766
pub fn connect_blocks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, depth: u32, height: u32, parent: bool, prev_blockhash: BlockHash) -> BlockHash {
68-
let notifier = &node.block_notifier;
6967
let mut block = Block {
7068
header: BlockHeader { version: 0x2000000, prev_blockhash: if parent { prev_blockhash } else { Default::default() }, merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 },
7169
txdata: vec![],
7270
};
73-
notifier.block_connected(&block, height + 1);
71+
connect_block(node, &block, height + 1);
7472
for i in 2..depth + 1 {
7573
block = Block {
7674
header: BlockHeader { version: 0x20000000, prev_blockhash: block.header.block_hash(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 },
7775
txdata: vec![],
7876
};
79-
notifier.block_connected(&block, height + i);
77+
connect_block(node, &block, height + i);
8078
}
8179
block.header.block_hash()
8280
}
8381

82+
pub fn connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: &Block, height: u32) {
83+
node.block_notifier.block_connected(block, height)
84+
}
85+
86+
pub fn disconnect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, header: &BlockHeader, height: u32) {
87+
node.block_notifier.block_disconnected(header, height)
88+
}
89+
8490
pub struct TestChanMonCfg {
8591
pub tx_broadcaster: test_utils::TestBroadcaster,
8692
pub fee_estimator: test_utils::TestFeeEstimator,

0 commit comments

Comments
 (0)