Skip to content

Commit

Permalink
update test case
Browse files Browse the repository at this point in the history
  • Loading branch information
gpBlockchain committed Dec 23, 2024
1 parent 2ec0171 commit e536a0a
Show file tree
Hide file tree
Showing 35 changed files with 672 additions and 273 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ fiber_test_cases := \
test_cases/fiber/devnet/new_invoice \
test_cases/fiber/devnet/send_payment \
test_cases/fiber/devnet/shutdown_channel \
test_cases/fiber/devnet/update_channel
test_cases/fiber/devnet/update_channel \
test_cases/fiber/devnet/watch_tower



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_accept_chanel_same_channel_same_time(self):
self.fiber2.get_client(), self.fiber1.get_peer_id(), "CHANNEL_READY"
)

@pytest.mark.skip("检查是否有问题")
@pytest.mark.skip("https://github.com/nervosnetwork/fiber/issues/246")
def test_accept_channel_diff_channel_same_time(self):
"""
accept channel: Accept multiple different channels at the same time
Expand Down
7 changes: 7 additions & 0 deletions test_cases/fiber/devnet/accept_channel/test_funding_amount.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ def test_udt_funding_amount_lt_account(self):
print(after_account2)
assert after_account2[-1]["balance"] == (10000 + 1 - 9999) * 100000000

@pytest.mark.skip("无法再次 accept")
def test_ckb_funding_amount_gt_account(self):
"""
funding_amount > account
Expand Down Expand Up @@ -507,6 +508,12 @@ def test_ckb_funding_amount_gt_account(self):
120,
)
# 失败了, 好像不能再次accept_channel
self.fiber2.get_client().accept_channel(
{
"temporary_channel_id": temporary_channel["temporary_channel_id"],
"funding_amount": hex(1000 * 100000000),
}
)

def test_funding_amount_over_flow(self):
"""
Expand Down
10 changes: 8 additions & 2 deletions test_cases/fiber/devnet/cancel_invoice/test_cancel_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ def test_cancel_invoice_that_statue_is_expired(self):
)
assert result["status"] == "Cancelled"

@pytest.mark.skip("https://github.com/nervosnetwork/fiber/issues/305")
def test_send_failed_that_invoice_cancel(self):
"""
取消后,发送失败,下次交易不受影响
Expand Down Expand Up @@ -342,7 +341,14 @@ def test_cancel_invoice_that_statue_is_receive(self):
{"payment_hash": invoice["invoice"]["data"]["payment_hash"]}
)
channels = self.fiber2.get_client().list_channels({})
assert channels == before_channel
assert (
channels["channels"][0]["local_balance"]
== before_channel["channels"][0]["local_balance"]
)
assert (
channels["channels"][0]["latest_commitment_transaction_hash"]
!= before_channel["channels"][0]["latest_commitment_transaction_hash"]
)

invoice_balance = 1 * 100000000
invoice = self.fiber1.get_client().new_invoice(
Expand Down
45 changes: 22 additions & 23 deletions test_cases/fiber/devnet/graph_channels/test_graph_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ def test_update_channel_info(self):
update_channel_param = {
"enabled": True,
"tlc_minimum_value": hex(100),
"tlc_maximum_value": hex(100 * 100000000),
"tlc_fee_proportional_millionths": hex(2000),
}
account3_private_key = self.generate_account(1000)
Expand Down Expand Up @@ -250,9 +249,9 @@ def test_update_channel_info(self):
node_info = self.fiber1.get_client().node_info()
print("node1_channels:", node1_channels)
key = (
"node2_to_node1_fee_rate"
"fee_rate_of_node1"
if node3_channels["channels"][0]["node1"] == node_info["public_key"]
else "node1_to_node2_fee_rate"
else "fee_rate_of_node2"
)
print("key:", key)
assert (
Expand All @@ -261,19 +260,19 @@ def test_update_channel_info(self):
)
print("node2_channels", node2_channels)
key = (
"node2_to_node1_fee_rate"
"fee_rate_of_node1"
if node3_channels["channels"][0]["node1"] == node_info["public_key"]
else "node1_to_node2_fee_rate"
else "fee_rate_of_node2"
)
assert (
node2_channels["channels"][0][key]
== update_channel_param["tlc_fee_proportional_millionths"]
)
print("node3_channels", node3_channels)
key = (
"node2_to_node1_fee_rate"
"fee_rate_of_node1"
if node3_channels["channels"][0]["node1"] == node_info["public_key"]
else "node1_to_node2_fee_rate"
else "fee_rate_of_node2"
)
assert (
node3_channels["channels"][0][key]
Expand Down Expand Up @@ -315,11 +314,11 @@ def test_channel_info_check(self):
assert open_channel_tx_hash in node3_channels["channels"][0]["channel_outpoint"]

# funding_tx_block_number
tx = self.node.getClient().get_transaction(open_channel_tx_hash)
assert (
node1_channels["channels"][0]["funding_tx_block_number"]
== tx["tx_status"]["block_number"]
)
# tx = self.node.getClient().get_transaction(open_channel_tx_hash)
# assert (
# node1_channels["channels"][0]["funding_tx_block_number"]
# == tx["tx_status"]["block_number"]
# )
# funding_tx_index
# todo funding_tx_index 是错的
# assert node1_channels["channels"][0]["funding_tx_index"] == tx["tx_status"]["tx_index"]
Expand All @@ -337,38 +336,38 @@ def test_channel_info_check(self):

# last_updated_timestamp
# created_timestamp
# node1_to_node2_fee_rate
# fee_rate_of_node2
assert (
node1_channels["channels"][0]["node1_to_node2_fee_rate"]
node1_channels["channels"][0]["fee_rate_of_node2"]
== node2_info["tlc_fee_proportional_millionths"]
)
assert (
node2_channels["channels"][0]["node1_to_node2_fee_rate"]
node2_channels["channels"][0]["fee_rate_of_node2"]
== node2_info["tlc_fee_proportional_millionths"]
)
assert (
node3_channels["channels"][0]["node1_to_node2_fee_rate"]
node3_channels["channels"][0]["fee_rate_of_node2"]
== node2_info["tlc_fee_proportional_millionths"]
)

# node2_to_node1_fee_rate
# fee_rate_of_node1
assert (
node1_channels["channels"][0]["node2_to_node1_fee_rate"]
node1_channels["channels"][0]["fee_rate_of_node1"]
== node1_info["tlc_fee_proportional_millionths"]
)
assert (
node2_channels["channels"][0]["node2_to_node1_fee_rate"]
node2_channels["channels"][0]["fee_rate_of_node1"]
== node1_info["tlc_fee_proportional_millionths"]
)
assert (
node3_channels["channels"][0]["node2_to_node1_fee_rate"]
node3_channels["channels"][0]["fee_rate_of_node1"]
== node1_info["tlc_fee_proportional_millionths"]
)

# capacity
assert node1_channels["channels"][0]["capacity"] == hex(262 * 100000000)
assert node2_channels["channels"][0]["capacity"] == hex(262 * 100000000)
assert node3_channels["channels"][0]["capacity"] == hex(262 * 100000000)
assert node1_channels["channels"][0]["capacity"] == hex(138 * 100000000)
assert node2_channels["channels"][0]["capacity"] == hex(138 * 100000000)
assert node3_channels["channels"][0]["capacity"] == hex(138 * 100000000)

# chain_hash
assert node1_channels["channels"][0]["chain_hash"] == node1_info["chain_hash"]
Expand Down
2 changes: 1 addition & 1 deletion test_cases/fiber/devnet/graph_nodes/test_graph_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_change_node_info(self):
self.fiber1.stop()
self.fiber1.prepare({"fiber_auto_accept_amount": "100000001"})
self.fiber1.start()
time.sleep(1)
time.sleep(3)
node_info = self.fiber1.get_client().node_info()
print("before_node_info:", before_node_info)
print("after_node_info:", node_info)
Expand Down
24 changes: 19 additions & 5 deletions test_cases/fiber/devnet/list_channels/test_list_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,22 @@ def test_check_channel_result(self):
assert int(channels["channels"][0]["created_at"], 16) / 1000 > begin_time
assert int(channels["channels"][0]["created_at"], 16) / 1000 < time.time()

@pytest.mark.skip("close channels can't found")
# force shutdown latest_commitment_transaction_hash == hash
self.fiber1.get_client().shutdown_channel(
{
"channel_id": channels["channels"][0]["channel_id"],
"close_script": {
"code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
"hash_type": "type",
"args": self.account1["lock_arg"],
},
"fee_rate": "0x3FC",
"force": True,
}
)
tx_hash = self.wait_and_check_tx_pool_fee(1000, False, 120)
assert tx_hash == channels["channels"][0]["latest_commitment_transaction_hash"]

def test_close_channels(self):
temporary_channel_id = self.fiber1.get_client().open_channel(
{
Expand All @@ -285,7 +300,6 @@ def test_close_channels(self):
"fee_rate": "0x3FC",
}
)
# todo query shutdown_channel
# self.wait_for_channel_state(self.fiber1.get_client(), self.fiber2.get_peer_id(), "Closed")
# time.sleep(5)
# self.fiber1.get_client().list_channels({})
self.wait_for_channel_state(
self.fiber1.get_client(), self.fiber2.get_peer_id(), "CLOSED", 120, True
)
16 changes: 11 additions & 5 deletions test_cases/fiber/devnet/new_invoice/test_amount.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,18 @@ def test_amount_is_zero_or_gt_local_amount(self):
time.sleep(1)

# 4. send_payment return Failed to build route
payment = self.fiber1.get_client().send_payment(
{
"invoice": invoice["invoice_address"],
}
with pytest.raises(Exception) as exc_info:
payment = self.fiber1.get_client().send_payment(
{
"invoice": invoice["invoice_address"],
}
)
expected_error_message = "no path found"
assert expected_error_message in exc_info.value.args[0], (
f"Expected substring '{expected_error_message}' "
f"not found in actual string '{exc_info.value.args[0]}'"
)
self.wait_payment_state(self.fiber1, payment["payment_hash"], "Failed")

amount = int(channels["channels"][0]["local_balance"], 16)
invoice = self.fiber2.get_client().new_invoice(
{
Expand Down
28 changes: 14 additions & 14 deletions test_cases/fiber/devnet/new_invoice/test_expiry.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,21 @@ def test_0x(self):
== int(after_channel["channels"][0]["local_balance"], 16) + amount
)

@pytest.mark.skip("wait https://github.com/chenyukang/fiber/pull/2")
# @pytest.mark.skip("wait https://github.com/chenyukang/fiber/pull/2")
def test_0x1(self):
# 1. Open a channel between fiber1 and fiber2
# temporary_channel = self.fiber1.get_client().open_channel(
# {
# "peer_id": self.fiber2.get_peer_id(),
# "funding_amount": hex(1000 * 100000000),
# "public": True,
# }
# )
#
# # 2. Check the channel state to ensure it is ready
# self.wait_for_channel_state(
# self.fiber1.get_client(), self.fiber2.get_peer_id(), "CHANNEL_READY"
# )
temporary_channel = self.fiber1.get_client().open_channel(
{
"peer_id": self.fiber2.get_peer_id(),
"funding_amount": hex(1000 * 100000000),
"public": True,
}
)

# 2. Check the channel state to ensure it is ready
self.wait_for_channel_state(
self.fiber1.get_client(), self.fiber2.get_peer_id(), "CHANNEL_READY"
)

# 3. Create a new invoice with a normal amount
invoice = self.fiber2.get_client().new_invoice(
Expand Down Expand Up @@ -145,7 +145,7 @@ def test_0x1(self):
"invoice": invoice["invoice_address"],
}
)
self.wait_payment_state(self.fiber1, payment["payment_hash"], "Success")
self.wait_payment_state(self.fiber1, payment["payment_hash"], "Failed")

def test_overflow(self):
with pytest.raises(Exception) as exc_info:
Expand Down
8 changes: 4 additions & 4 deletions test_cases/fiber/devnet/open_channel/test_ckb_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_account_mutil_cell_gt_funding_amount(self):
)
channels = new_fiber.get_client().graph_channels()
assert len(channels["channels"]) == 1
assert channels["channels"][0]["capacity"] == hex(1052 * 100000000)
assert channels["channels"][0]["capacity"] == hex(928 * 100000000)

def test_account_mutil_cell_gt_funding_amount_2(self):
"""
Expand Down Expand Up @@ -126,7 +126,7 @@ def test_account_mutil_cell_gt_funding_amount_2(self):
)
channels = new_fiber.get_client().graph_channels()
assert len(channels["channels"]) == 1
assert channels["channels"][0]["capacity"] == hex(1052 * 100000000)
assert channels["channels"][0]["capacity"] == hex(928 * 100000000)

# FiberTest.debug = True

Expand Down Expand Up @@ -163,7 +163,7 @@ def test_config_not_eq(self):
)
channels = new_fiber.get_client().graph_channels()
assert len(channels["channels"]) == 1
assert channels["channels"][0]["capacity"] == hex(1052 * 100000000)
assert channels["channels"][0]["capacity"] == hex(928 * 100000000)
node3_info = new_fiber.get_client().node_info()
fiber3_pub = node3_info["public_key"]
payment = self.fiber2.get_client().send_payment(
Expand Down Expand Up @@ -196,7 +196,7 @@ def test_config_eq(self):
)
channels = new_fiber.get_client().graph_channels()
assert len(channels["channels"]) == 1
assert channels["channels"][0]["capacity"] == hex(1052 * 100000000)
assert channels["channels"][0]["capacity"] == hex(928 * 100000000)
node3_info = new_fiber.get_client().node_info()
fiber3_pub = node3_info["public_key"]
payment = self.fiber2.get_client().send_payment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def test_other_node_check_commitment_fee_rate(self):
验证对方的commit fee
Returns:
"""
commitment_fee_rate = 1000
commitment_fee_rate = 21978021
temporary_channel_id = self.fiber1.get_client().open_channel(
{
"peer_id": self.fiber2.get_peer_id(),
Expand Down
10 changes: 3 additions & 7 deletions test_cases/fiber/devnet/open_channel/test_funding_amount.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ def test_funding_amount_udt_0xfffffffffffffffffffffffffffffffffffff(self):
f"not found in actual string '{exc_info.value.args[0]}'"
)

@pytest.mark.skip("https://github.com/nervosnetwork/fiber/issues/346")
def test_funding_amount_udt_0xfffffffffffffffffffffffffffffff(self):
"""
1. funding_udt_type_script is None ,funding_amount > account balance
Expand Down Expand Up @@ -156,13 +155,10 @@ def test_funding_amount_udt_0xfffffffffffffffffffffffffffffff(self):
# "tlc_fee_proportional_millionths": "0x4B0",
}
)
# expected_error_message = "The funding amount (21267647932558653966460912964485513215) should be less than 18446744073709551615"
# assert expected_error_message in exc_info.value.args[0], (
# f"Expected substring '{expected_error_message}' "
# f"not found in actual string '{exc_info.value.args[0]}'"
# )
self.wait_for_channel_state(
self.fiber1.get_client(), self.fiber2.get_peer_id(), "CHANNEL_READY"
)

@pytest.mark.skip("https://github.com/nervosnetwork/fiber/issues/373")
def test_funding_amount_udt_gt_account_balance(self):
account3_private = self.generate_account(
1000, self.fiber1.account_private, 1000 * 100000000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,12 +707,13 @@ def test_udt_max_tlc_value_in_flight_not_eq_default(self):
)
before_channel = self.fiber1.get_client().list_channels({})

self.fiber1.get_client().send_payment(
payment = self.fiber1.get_client().send_payment(
{
"invoice": invoice["invoice_address"],
}
)
time.sleep(10)

self.wait_payment_state(self.fiber1, payment["payment_hash"], "Success")
after_channel = self.fiber1.get_client().list_channels({})
assert int(before_channel["channels"][0]["local_balance"], 16) - int(
after_channel["channels"][0]["local_balance"], 16
Expand All @@ -738,12 +739,12 @@ def test_udt_max_tlc_value_in_flight_not_eq_default(self):
)
before_channel = self.fiber1.get_client().list_channels({})

self.fiber1.get_client().send_payment(
payment = self.fiber1.get_client().send_payment(
{
"invoice": invoice["invoice_address"],
}
)
time.sleep(10)
self.wait_payment_state(self.fiber1, payment["payment_hash"], "Success")
after_channel = self.fiber1.get_client().list_channels({})
assert int(before_channel["channels"][0]["local_balance"], 16) - int(
after_channel["channels"][0]["local_balance"], 16
Expand Down
Loading

0 comments on commit e536a0a

Please sign in to comment.