@@ -22,7 +22,7 @@ use crate::ln::ChannelId;
2222use crate :: ln:: functional_test_utils:: * ;
2323use crate :: ln:: msgs:: ChannelMessageHandler ;
2424use crate :: ln:: channelmanager:: { PaymentId , RecipientOnionFields } ;
25- use crate :: util:: test_channel_signer:: ops;
25+ use crate :: util:: test_channel_signer:: { EnforcementState , ops} ;
2626
2727/// Helper to run operations with a simulated asynchronous signer.
2828///
@@ -52,6 +52,55 @@ pub fn with_async_signer<DoFn, T>(node: &Node, peer_id: &PublicKey, channel_id:
5252 res
5353}
5454
55+
56+ #[ cfg( feature = "std" ) ]
57+ #[ test]
58+ fn test_open_channel ( ) {
59+ // Simulate acquiring the signature for `funding_created` asynchronously.
60+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
61+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
62+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
63+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
64+
65+ // Open an outbound channel simulating an async signer.
66+ let channel_value_satoshis = 100000 ;
67+ let user_channel_id = 42 ;
68+ nodes[ 0 ] . set_unborn_channel_signer_ops_unavailable ( ops:: GET_PER_COMMITMENT_POINT ) ;
69+ let channel_id_0 = nodes[ 0 ] . node . create_channel ( nodes[ 1 ] . node . get_our_node_id ( ) , channel_value_satoshis, 10001 , user_channel_id, None , None ) . unwrap ( ) ;
70+
71+ {
72+ let msgs = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
73+ assert ! ( msgs. is_empty( ) , "Expected no message events; got {:?}" , msgs) ;
74+ }
75+
76+ nodes[ 0 ] . set_channel_signer_ops_available ( & nodes[ 1 ] . node . get_our_node_id ( ) , & channel_id_0, ops:: GET_PER_COMMITMENT_POINT , true ) ;
77+ nodes[ 0 ] . node . signer_unblocked ( None ) ;
78+
79+ // nodes[0] --- open_channel --> nodes[1]
80+ let mut open_chan_msg = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendOpenChannel , nodes[ 1 ] . node. get_our_node_id( ) ) ;
81+
82+ // Handle an inbound channel simulating an async signer.
83+ nodes[ 1 ] . set_unborn_channel_signer_ops_unavailable ( ops:: GET_PER_COMMITMENT_POINT ) ;
84+ nodes[ 1 ] . node . handle_open_channel ( & nodes[ 0 ] . node . get_our_node_id ( ) , & open_chan_msg) ;
85+
86+ {
87+ let msgs = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
88+ assert ! ( msgs. is_empty( ) , "Expected no message events; got {:?}" , msgs) ;
89+ }
90+
91+ let channel_id_1 = {
92+ let channels = nodes[ 1 ] . node . list_channels ( ) ;
93+ assert_eq ! ( channels. len( ) , 1 , "expected one channel, not {}" , channels. len( ) ) ;
94+ channels[ 0 ] . channel_id
95+ } ;
96+
97+ nodes[ 1 ] . set_channel_signer_ops_available ( & nodes[ 0 ] . node . get_our_node_id ( ) , & channel_id_1, ops:: GET_PER_COMMITMENT_POINT , true ) ;
98+ nodes[ 1 ] . node . signer_unblocked ( None ) ;
99+
100+ // nodes[0] <-- accept_channel --- nodes[1]
101+ get_event_msg ! ( nodes[ 1 ] , MessageSendEvent :: SendAcceptChannel , nodes[ 0 ] . node. get_our_node_id( ) ) ;
102+ }
103+
55104#[ test]
56105fn test_async_commitment_signature_for_funding_created ( ) {
57106 do_test_async_funding_created ( vec ! [ ops:: SIGN_COUNTERPARTY_COMMITMENT ] ) ;
0 commit comments