@@ -164,11 +164,11 @@ def teardown_class(cls):
164164 cls .node .clean ()
165165
166166 def faucet (
167- self ,
168- account_private_key ,
169- ckb_balance ,
170- udt_owner_private_key = None ,
171- udt_balance = 1000 * 1000000000 ,
167+ self ,
168+ account_private_key ,
169+ ckb_balance ,
170+ udt_owner_private_key = None ,
171+ udt_balance = 1000 * 1000000000 ,
172172 ):
173173 if ckb_balance > 60 :
174174 account = self .Ckb_cli .util_key_info_by_private_key (account_private_key )
@@ -192,7 +192,7 @@ def faucet(
192192 self .Miner .miner_until_tx_committed (self .node , tx_hash )
193193
194194 def generate_account (
195- self , ckb_balance , udt_owner_private_key = None , udt_balance = 1000 * 1000000000
195+ self , ckb_balance , udt_owner_private_key = None , udt_balance = 1000 * 1000000000
196196 ):
197197 # error
198198 # if self.debug:
@@ -249,15 +249,19 @@ def start_new_fiber(self, account_private_key, config=None):
249249 fiber .start (self .node )
250250 return fiber
251251
252- def wait_for_channel_state (self , client , peer_id , expected_state , timeout = 120 ):
252+ def wait_for_channel_state (
253+ self , client , peer_id , expected_state , timeout = 120 , include_closed = False
254+ ):
253255 """Wait for a channel to reach a specific state.
254256 1. NEGOTIATING_FUNDING
255257 2. CHANNEL_READY
256- 3. Closed
258+ 3. CLOSED
257259
258260 """
259261 for _ in range (timeout ):
260- channels = client .list_channels ({"peer_id" : peer_id })
262+ channels = client .list_channels (
263+ {"peer_id" : peer_id , "include_closed" : include_closed }
264+ )
261265 if len (channels ["channels" ]) == 0 :
262266 time .sleep (1 )
263267 continue
@@ -282,28 +286,41 @@ def get_account_udt_script(self, account_private_key):
282286 "args" : self .udtContract .get_owner_arg_by_lock_arg (account1 ["lock_arg" ]),
283287 }
284288
285- def open_channel (self , fiber1 : Fiber , fiber2 : Fiber , fiber1_balance , fiber2_balance , fiber1_fee = 1000 ,
286- fiber2_fee = 1000 ):
287- fiber1 .get_client ().open_channel ({
288- "peer_id" : fiber2 .get_peer_id (),
289- "funding_amount" : hex (fiber1_balance + fiber2_balance + 62 * 100000000 ),
290- "tlc_fee_proportional_millionths" : hex (fiber1_fee ),
291- "public" : True ,
292- })
293- self .wait_for_channel_state (fiber1 .get_client (), fiber2 .get_peer_id (), "CHANNEL_READY" )
294- channels = fiber1 .get_client ().list_channels (
295- {"peer_id" : fiber2 .get_peer_id ()}
289+ def open_channel (
290+ self ,
291+ fiber1 : Fiber ,
292+ fiber2 : Fiber ,
293+ fiber1_balance ,
294+ fiber2_balance ,
295+ fiber1_fee = 1000 ,
296+ fiber2_fee = 1000 ,
297+ ):
298+ fiber1 .get_client ().open_channel (
299+ {
300+ "peer_id" : fiber2 .get_peer_id (),
301+ "funding_amount" : hex (fiber1_balance + fiber2_balance + 62 * 100000000 ),
302+ "tlc_fee_proportional_millionths" : hex (fiber1_fee ),
303+ "public" : True ,
304+ }
305+ )
306+ self .wait_for_channel_state (
307+ fiber1 .get_client (), fiber2 .get_peer_id (), "CHANNEL_READY"
308+ )
309+ channels = fiber1 .get_client ().list_channels ({"peer_id" : fiber2 .get_peer_id ()})
310+ payment = fiber1 .get_client ().send_payment (
311+ {
312+ "target_pubkey" : fiber2 .get_client ().node_info ()["public_key" ],
313+ "amount" : hex (fiber2_balance ),
314+ "keysend" : True ,
315+ }
316+ )
317+ fiber2 .get_client ().update_channel (
318+ {
319+ "channel_id" : channels ["channels" ][0 ]["channel_id" ],
320+ "tlc_fee_proportional_millionths" : hex (fiber2_fee ),
321+ }
296322 )
297- payment = fiber1 .get_client ().send_payment ({
298- "target_pubkey" : fiber2 .get_client ().node_info ()["public_key" ],
299- "amount" : hex (fiber2_balance ),
300- "keysend" : True ,
301- })
302- fiber2 .get_client ().update_channel ({
303- "channel_id" : channels ["channels" ][0 ]["channel_id" ],
304- "tlc_fee_proportional_millionths" : hex (fiber2_fee ),
305- })
306- self .wait_payment_state (fiber1 , payment ['payment_hash' ], "Success" )
323+ self .wait_payment_state (fiber1 , payment ["payment_hash" ], "Success" )
307324 # channels = fiber1.get_client().list_channels({"peer_id": fiber2.get_peer_id()})
308325 # assert channels["channels"][0]["local_balance"] == hex(fiber1_balance)
309326 # assert channels["channels"][0]["remote_balance"] == hex(fiber2_balance)
@@ -346,15 +363,15 @@ def wait_and_check_tx_pool_fee(self, fee_rate, check=True, try_size=120):
346363 )
347364 if check :
348365 assert (
349- int (pool_tx_detail_info ["score_sortkey" ]["fee" ], 16 )
350- * 1000
351- / int (pool_tx_detail_info ["score_sortkey" ]["weight" ], 16 )
352- == fee_rate
366+ int (pool_tx_detail_info ["score_sortkey" ]["fee" ], 16 )
367+ * 1000
368+ / int (pool_tx_detail_info ["score_sortkey" ]["weight" ], 16 )
369+ == fee_rate
353370 )
354371 return pool ["pending" ][0 ]
355372
356373 def wait_invoice_state (
357- self , client , payment_hash , status = "Paid" , timeout = 120 , interval = 1
374+ self , client , payment_hash , status = "Paid" , timeout = 120 , interval = 1
358375 ):
359376 """
360377 status:
@@ -497,11 +514,11 @@ def get_fiber_env(self, new_fiber_count=0):
497514 state_name = channel ["state" ]["state_name" ]
498515 local_balance = int (channel ["local_balance" ], 16 ) / 100000000
499516 offered_tlc_balance = (
500- int (channel ["offered_tlc_balance" ], 16 ) / 100000000
517+ int (channel ["offered_tlc_balance" ], 16 ) / 100000000
501518 )
502519 remote_balance = int (channel ["remote_balance" ], 16 ) / 100000000
503520 received_tlc_balance = (
504- int (channel ["received_tlc_balance" ], 16 ) / 100000000
521+ int (channel ["received_tlc_balance" ], 16 ) / 100000000
505522 )
506523 created_at_hex = int (channel ["created_at" ], 16 ) / 1000
507524 created_at = datetime .datetime .fromtimestamp (created_at_hex ).strftime (
0 commit comments