Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
gpBlockchain committed Dec 20, 2024
1 parent a9917d1 commit 2ec0171
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
54 changes: 41 additions & 13 deletions framework/basic_fiber.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ def teardown_class(cls):
cls.node.clean()

def faucet(
self,
account_private_key,
ckb_balance,
udt_owner_private_key=None,
udt_balance=1000 * 1000000000,
self,
account_private_key,
ckb_balance,
udt_owner_private_key=None,
udt_balance=1000 * 1000000000,
):
if ckb_balance > 60:
account = self.Ckb_cli.util_key_info_by_private_key(account_private_key)
Expand All @@ -192,7 +192,7 @@ def faucet(
self.Miner.miner_until_tx_committed(self.node, tx_hash)

def generate_account(
self, ckb_balance, udt_owner_private_key=None, udt_balance=1000 * 1000000000
self, ckb_balance, udt_owner_private_key=None, udt_balance=1000 * 1000000000
):
# error
# if self.debug:
Expand Down Expand Up @@ -263,6 +263,8 @@ def wait_for_channel_state(self, client, peer_id, expected_state, timeout=120):
continue
if channels["channels"][0]["state"]["state_name"] == expected_state:
self.logger.debug(f"Channel reached expected state: {expected_state}")
# todo wait broading
time.sleep(2)
return channels["channels"][0]["channel_id"]
self.logger.debug(
f"Waiting for channel state: {expected_state}, current state: {channels['channels'][0]['state']['state_name']}"
Expand All @@ -280,6 +282,32 @@ def get_account_udt_script(self, account_private_key):
"args": self.udtContract.get_owner_arg_by_lock_arg(account1["lock_arg"]),
}

def open_channel(self, fiber1: Fiber, fiber2: Fiber, fiber1_balance, fiber2_balance, fiber1_fee=1000,
fiber2_fee=1000):
fiber1.get_client().open_channel({
"peer_id": fiber2.get_peer_id(),
"funding_amount": hex(fiber1_balance + fiber2_balance + 62 * 100000000),
"tlc_fee_proportional_millionths": hex(fiber1_fee),
"public": True,
})
self.wait_for_channel_state(fiber1.get_client(), fiber2.get_peer_id(), "CHANNEL_READY")
channels = fiber1.get_client().list_channels(
{"peer_id": fiber2.get_peer_id()}
)
payment = fiber1.get_client().send_payment({
"target_pubkey": fiber2.get_client().node_info()["public_key"],
"amount": hex(fiber2_balance),
"keysend": True,
})
fiber2.get_client().update_channel({
"channel_id": channels["channels"][0]["channel_id"],
"tlc_fee_proportional_millionths": hex(fiber2_fee),
})
self.wait_payment_state(fiber1, payment['payment_hash'], "Success")
# channels = fiber1.get_client().list_channels({"peer_id": fiber2.get_peer_id()})
# assert channels["channels"][0]["local_balance"] == hex(fiber1_balance)
# assert channels["channels"][0]["remote_balance"] == hex(fiber2_balance)

def get_account_script(self, account_private_key):
account1 = self.Ckb_cli.util_key_info_by_private_key(account_private_key)
return {
Expand Down Expand Up @@ -318,15 +346,15 @@ def wait_and_check_tx_pool_fee(self, fee_rate, check=True, try_size=120):
)
if check:
assert (
int(pool_tx_detail_info["score_sortkey"]["fee"], 16)
* 1000
/ int(pool_tx_detail_info["score_sortkey"]["weight"], 16)
== fee_rate
int(pool_tx_detail_info["score_sortkey"]["fee"], 16)
* 1000
/ int(pool_tx_detail_info["score_sortkey"]["weight"], 16)
== fee_rate
)
return pool["pending"][0]

def wait_invoice_state(
self, client, payment_hash, status="Paid", timeout=120, interval=1
self, client, payment_hash, status="Paid", timeout=120, interval=1
):
"""
status:
Expand Down Expand Up @@ -469,11 +497,11 @@ def get_fiber_env(self, new_fiber_count=0):
state_name = channel["state"]["state_name"]
local_balance = int(channel["local_balance"], 16) / 100000000
offered_tlc_balance = (
int(channel["offered_tlc_balance"], 16) / 100000000
int(channel["offered_tlc_balance"], 16) / 100000000
)
remote_balance = int(channel["remote_balance"], 16) / 100000000
received_tlc_balance = (
int(channel["received_tlc_balance"], 16) / 100000000
int(channel["received_tlc_balance"], 16) / 100000000
)
created_at_hex = int(channel["created_at"], 16) / 1000
created_at = datetime.datetime.fromtimestamp(created_at_hex).strftime(
Expand Down
3 changes: 3 additions & 0 deletions source/template/fiber/dev_config.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ fiber:
chain: dev.toml
announce_listening_addr: true
announce_private_addr: true
gossip_store_maintenance_interval_ms: 1000
gossip_network_maintenance_interval_ms: 1000

rpc:
listening_addr: {{ rpc_listening_addr | default("127.0.0.1:8227") }}

Expand Down

0 comments on commit 2ec0171

Please sign in to comment.