Skip to content

Commit 9a37135

Browse files
benthecarmandunxen
authored andcommitted
Support creating coinbase funding transactions in tests
1 parent a2e01d5 commit 9a37135

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use alloc::rc::Rc;
4646
use crate::sync::{Arc, Mutex, LockTestExt, RwLock};
4747
use core::mem;
4848
use core::iter::repeat;
49-
use bitcoin::{PackedLockTime, TxMerkleNode};
49+
use bitcoin::{PackedLockTime, TxIn, TxMerkleNode};
5050

5151
pub const CHAN_CONFIRM_DEPTH: u32 = 10;
5252

@@ -1005,7 +1005,23 @@ macro_rules! reload_node {
10051005
};
10061006
}
10071007

1008-
pub fn create_funding_transaction<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, expected_counterparty_node_id: &PublicKey, expected_chan_value: u64, expected_user_chan_id: u128) -> (ChannelId, Transaction, OutPoint) {
1008+
pub fn create_funding_transaction<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>,
1009+
expected_counterparty_node_id: &PublicKey, expected_chan_value: u64, expected_user_chan_id: u128)
1010+
-> (ChannelId, Transaction, OutPoint)
1011+
{
1012+
internal_create_funding_transaction(node, expected_counterparty_node_id, expected_chan_value, expected_user_chan_id, false)
1013+
}
1014+
1015+
pub fn create_coinbase_funding_transaction<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>,
1016+
expected_counterparty_node_id: &PublicKey, expected_chan_value: u64, expected_user_chan_id: u128)
1017+
-> (ChannelId, Transaction, OutPoint)
1018+
{
1019+
internal_create_funding_transaction(node, expected_counterparty_node_id, expected_chan_value, expected_user_chan_id, true)
1020+
}
1021+
1022+
fn internal_create_funding_transaction<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>,
1023+
expected_counterparty_node_id: &PublicKey, expected_chan_value: u64, expected_user_chan_id: u128,
1024+
coinbase: bool) -> (ChannelId, Transaction, OutPoint) {
10091025
let chan_id = *node.network_chan_count.borrow();
10101026

10111027
let events = node.node.get_and_clear_pending_events();
@@ -1016,7 +1032,16 @@ pub fn create_funding_transaction<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, expected_
10161032
assert_eq!(*channel_value_satoshis, expected_chan_value);
10171033
assert_eq!(user_channel_id, expected_user_chan_id);
10181034

1019-
let tx = Transaction { version: chan_id as i32, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: vec![TxOut {
1035+
let input = if coinbase {
1036+
vec![TxIn {
1037+
previous_output: bitcoin::OutPoint::null(),
1038+
..Default::default()
1039+
}]
1040+
} else {
1041+
Vec::new()
1042+
};
1043+
1044+
let tx = Transaction { version: chan_id as i32, lock_time: PackedLockTime::ZERO, input, output: vec![TxOut {
10201045
value: *channel_value_satoshis, script_pubkey: output_script.clone(),
10211046
}]};
10221047
let funding_outpoint = OutPoint { txid: tx.txid(), index: 0 };
@@ -1025,6 +1050,7 @@ pub fn create_funding_transaction<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, expected_
10251050
_ => panic!("Unexpected event"),
10261051
}
10271052
}
1053+
10281054
pub fn sign_funding_transaction<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: &Node<'a, 'b, 'c>, channel_value: u64, expected_temporary_channel_id: ChannelId) -> Transaction {
10291055
let (temporary_channel_id, tx, funding_output) = create_funding_transaction(node_a, &node_b.node.get_our_node_id(), channel_value, 42);
10301056
assert_eq!(temporary_channel_id, expected_temporary_channel_id);

0 commit comments

Comments
 (0)