@@ -6,6 +6,7 @@ use native::trade::order::api::NewOrder;
6
6
use native:: trade:: order:: api:: OrderType ;
7
7
use native:: trade:: position:: PositionState ;
8
8
use tests_e2e:: app:: submit_order;
9
+ use tests_e2e:: coordinator:: SignedChannelState ;
9
10
use tests_e2e:: setup;
10
11
use tests_e2e:: setup:: dummy_order;
11
12
use tests_e2e:: wait_until;
@@ -89,6 +90,34 @@ async fn can_open_close_open_close_position() {
89
90
. unwrap ( ) ;
90
91
tracing:: info!( %app_off_chain_balance, "Opened second position" ) ;
91
92
93
+ // rolling over before closing the second position
94
+ tracing:: info!( "Rollover second position" ) ;
95
+ let coordinator = test. coordinator ;
96
+ let app_pubkey = api:: get_node_id ( ) . 0 ;
97
+ let dlc_channels = coordinator. get_dlc_channels ( ) . await . unwrap ( ) ;
98
+ let dlc_channel = dlc_channels
99
+ . into_iter ( )
100
+ . find ( |chan| chan. counter_party == app_pubkey)
101
+ . unwrap ( ) ;
102
+
103
+ coordinator
104
+ . rollover ( & dlc_channel. dlc_channel_id . unwrap ( ) )
105
+ . await
106
+ . unwrap ( ) ;
107
+
108
+ wait_until ! ( test
109
+ . app
110
+ . rx
111
+ . position( )
112
+ . map( |p| PositionState :: Rollover == p. position_state)
113
+ . unwrap_or( false ) ) ;
114
+ wait_until ! ( test
115
+ . app
116
+ . rx
117
+ . position( )
118
+ . map( |p| PositionState :: Open == p. position_state)
119
+ . unwrap_or( false ) ) ;
120
+
92
121
tracing:: info!( "Closing second position" ) ;
93
122
94
123
let closing_order = NewOrder {
@@ -100,6 +129,16 @@ async fn can_open_close_open_close_position() {
100
129
101
130
wait_until ! ( test. app. rx. position_close( ) . is_some( ) ) ;
102
131
132
+ wait_until ! ( {
133
+ let dlc_channels = coordinator. get_dlc_channels( ) . await . unwrap( ) ;
134
+ let dlc_channel = dlc_channels
135
+ . into_iter( )
136
+ . find( |chan| chan. counter_party == app_pubkey)
137
+ . unwrap( ) ;
138
+
139
+ Some ( SignedChannelState :: Settled ) == dlc_channel. signed_channel_state
140
+ } ) ;
141
+
103
142
tokio:: time:: sleep ( std:: time:: Duration :: from_secs ( 5 ) ) . await ;
104
143
105
144
// - App off-chain balance is 1_235_000 sats (reserve + margin - 3_750 fee).
0 commit comments