Skip to content

Commit 2ec0171

Browse files
committed
add test
1 parent a9917d1 commit 2ec0171

File tree

2 files changed

+44
-13
lines changed

2 files changed

+44
-13
lines changed

framework/basic_fiber.py

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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:
@@ -263,6 +263,8 @@ def wait_for_channel_state(self, client, peer_id, expected_state, timeout=120):
263263
continue
264264
if channels["channels"][0]["state"]["state_name"] == expected_state:
265265
self.logger.debug(f"Channel reached expected state: {expected_state}")
266+
# todo wait broading
267+
time.sleep(2)
266268
return channels["channels"][0]["channel_id"]
267269
self.logger.debug(
268270
f"Waiting for channel state: {expected_state}, current state: {channels['channels'][0]['state']['state_name']}"
@@ -280,6 +282,32 @@ def get_account_udt_script(self, account_private_key):
280282
"args": self.udtContract.get_owner_arg_by_lock_arg(account1["lock_arg"]),
281283
}
282284

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()}
296+
)
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")
307+
# channels = fiber1.get_client().list_channels({"peer_id": fiber2.get_peer_id()})
308+
# assert channels["channels"][0]["local_balance"] == hex(fiber1_balance)
309+
# assert channels["channels"][0]["remote_balance"] == hex(fiber2_balance)
310+
283311
def get_account_script(self, account_private_key):
284312
account1 = self.Ckb_cli.util_key_info_by_private_key(account_private_key)
285313
return {
@@ -318,15 +346,15 @@ def wait_and_check_tx_pool_fee(self, fee_rate, check=True, try_size=120):
318346
)
319347
if check:
320348
assert (
321-
int(pool_tx_detail_info["score_sortkey"]["fee"], 16)
322-
* 1000
323-
/ int(pool_tx_detail_info["score_sortkey"]["weight"], 16)
324-
== fee_rate
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
325353
)
326354
return pool["pending"][0]
327355

328356
def wait_invoice_state(
329-
self, client, payment_hash, status="Paid", timeout=120, interval=1
357+
self, client, payment_hash, status="Paid", timeout=120, interval=1
330358
):
331359
"""
332360
status:
@@ -469,11 +497,11 @@ def get_fiber_env(self, new_fiber_count=0):
469497
state_name = channel["state"]["state_name"]
470498
local_balance = int(channel["local_balance"], 16) / 100000000
471499
offered_tlc_balance = (
472-
int(channel["offered_tlc_balance"], 16) / 100000000
500+
int(channel["offered_tlc_balance"], 16) / 100000000
473501
)
474502
remote_balance = int(channel["remote_balance"], 16) / 100000000
475503
received_tlc_balance = (
476-
int(channel["received_tlc_balance"], 16) / 100000000
504+
int(channel["received_tlc_balance"], 16) / 100000000
477505
)
478506
created_at_hex = int(channel["created_at"], 16) / 1000
479507
created_at = datetime.datetime.fromtimestamp(created_at_hex).strftime(

source/template/fiber/dev_config.yml.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ fiber:
33
chain: dev.toml
44
announce_listening_addr: true
55
announce_private_addr: true
6+
gossip_store_maintenance_interval_ms: 1000
7+
gossip_network_maintenance_interval_ms: 1000
8+
69
rpc:
710
listening_addr: {{ rpc_listening_addr | default("127.0.0.1:8227") }}
811

0 commit comments

Comments
 (0)