@@ -18,7 +18,7 @@ use crate::ln::msgs;
1818use crate :: ln:: msgs:: ChannelMessageHandler ;
1919use crate :: ln:: channelmanager:: { PaymentId , RAACommitmentOrder , RecipientOnionFields } ;
2020use crate :: util:: ser:: Writeable ;
21- use crate :: util:: test_channel_signer:: ops;
21+ use crate :: util:: test_channel_signer:: { EnforcementState , ops} ;
2222use crate :: util:: test_utils;
2323
2424/// Helper to run operations with a simulated asynchronous signer.
@@ -49,6 +49,56 @@ pub fn with_async_signer<'a, DoFn, T>(node: &Node, peer_id: &PublicKey, channel_
4949 res
5050}
5151
52+ #[ cfg( feature = "std" ) ]
53+ #[ test]
54+ fn test_open_channel ( ) {
55+ // Simulate acquiring the signature for `funding_created` asynchronously.
56+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
57+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
58+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
59+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
60+
61+ // Open an outbound channel simulating an async signer.
62+ let channel_id_0 = EnforcementState :: with_default_unavailable (
63+ ops:: GET_PER_COMMITMENT_POINT ,
64+ || nodes[ 0 ] . node . create_channel ( nodes[ 1 ] . node . get_our_node_id ( ) , 100000 , 10001 , 42 , None , None )
65+ ) . expect ( "Failed to create channel" ) ;
66+
67+ {
68+ let msgs = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
69+ assert ! ( msgs. is_empty( ) , "Expected no message events; got {:?}" , msgs) ;
70+ }
71+
72+ nodes[ 0 ] . set_channel_signer_ops_available ( & nodes[ 1 ] . node . get_our_node_id ( ) , & channel_id_0, ops:: GET_PER_COMMITMENT_POINT , true ) ;
73+ nodes[ 0 ] . node . signer_unblocked ( None ) ;
74+
75+ // nodes[0] --- open_channel --> nodes[1]
76+ let mut open_chan_msg = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendOpenChannel , nodes[ 1 ] . node. get_our_node_id( ) ) ;
77+
78+ // Handle an inbound channel simulating an async signer.
79+ EnforcementState :: with_default_unavailable (
80+ ops:: GET_PER_COMMITMENT_POINT ,
81+ || nodes[ 1 ] . node . handle_open_channel ( & nodes[ 0 ] . node . get_our_node_id ( ) , & open_chan_msg)
82+ ) ;
83+
84+ {
85+ let msgs = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
86+ assert ! ( msgs. is_empty( ) , "Expected no message events; got {:?}" , msgs) ;
87+ }
88+
89+ let channel_id_1 = {
90+ let channels = nodes[ 1 ] . node . list_channels ( ) ;
91+ assert_eq ! ( channels. len( ) , 1 , "expected one channel, not {}" , channels. len( ) ) ;
92+ channels[ 0 ] . channel_id
93+ } ;
94+
95+ nodes[ 1 ] . set_channel_signer_ops_available ( & nodes[ 0 ] . node . get_our_node_id ( ) , & channel_id_1, ops:: GET_PER_COMMITMENT_POINT , true ) ;
96+ nodes[ 1 ] . node . signer_unblocked ( None ) ;
97+
98+ // nodes[0] <-- accept_channel --- nodes[1]
99+ get_event_msg ! ( nodes[ 1 ] , MessageSendEvent :: SendAcceptChannel , nodes[ 0 ] . node. get_our_node_id( ) ) ;
100+ }
101+
52102#[ cfg( test) ]
53103fn do_test_funding_created ( masks : & Vec < u32 > ) {
54104 // Simulate acquiring the signature for `funding_created` asynchronously.
0 commit comments