Skip to content

Commit 131ee96

Browse files
committed
add overflow test
1 parent 5861282 commit 131ee96

File tree

3 files changed

+127
-4
lines changed

3 files changed

+127
-4
lines changed

prepare.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
set -ex
22

3-
DEFAULT_FIBER_BRANCH="develop"
4-
DEFAULT_FIBER_URL="https://github.com/nervosnetwork/fiber.git"
3+
DEFAULT_FIBER_BRANCH="yukang-trivial-fix-on-funding"
4+
DEFAULT_FIBER_URL="https://github.com/chenyukang/fiber.git"
55

66
GitFIBERBranch="${GitBranch:-$DEFAULT_FIBER_BRANCH}"
77
GitFIBERUrl="${GitUrl:-$DEFAULT_FIBER_URL}"

test_cases/fiber/devnet/open_channel/test_funding_udt_type_script.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,126 @@ def test_funding_udt_type_script_is_white(self):
178178
tx_message["output_cells"][1]["args"]
179179
== self.fiber2.get_account()["lock_arg"]
180180
)
181+
182+
# @pytest.mark.skip("https://github.com/nervosnetwork/fiber/pull/720")
183+
def test_node1_2_udt_gt_u128_max(self):
184+
self.faucet(
185+
self.fiber1.account_private,
186+
0,
187+
self.fiber2.account_private,
188+
340282366920938463463374607431768211400,
189+
)
190+
self.faucet(
191+
self.fiber1.account_private, 0, self.fiber2.account_private, 1 * 100000000
192+
)
193+
# self.open_channel(self.fiber1, self.fiber2, 340282366920938463463374607431768211400 + 1 - 62 * 100000000, 1,
194+
# 1000, 1000,
195+
# self.get_account_udt_script(self.fiber2.account_private))
196+
temporary_channel = self.fiber1.get_client().open_channel(
197+
{
198+
"peer_id": self.fiber2.get_peer_id(),
199+
"funding_amount": hex(340282366920938463463374607431768211400 + 1),
200+
"tlc_fee_proportional_millionths": hex(1000),
201+
"public": True,
202+
"funding_udt_type_script": self.get_account_udt_script(
203+
self.fiber1.account_private
204+
),
205+
}
206+
)
207+
time.sleep(5)
208+
channel = self.fiber1.get_client().list_channels({})
209+
print("channel:", channel)
210+
assert channel["channels"] == []
211+
212+
def test_amount_eq_u128_max(self):
213+
self.faucet(
214+
self.fiber1.account_private,
215+
0,
216+
self.fiber2.account_private,
217+
340282366920938463463374607431768211455,
218+
)
219+
self.faucet(
220+
self.fiber1.account_private, 0, self.fiber2.account_private, 1 * 100000000
221+
)
222+
self.open_channel(
223+
self.fiber1,
224+
self.fiber2,
225+
340282366920938463463374607431768211455 - 1 - 62 * 100000000,
226+
1,
227+
1000,
228+
1000,
229+
self.get_account_udt_script(self.fiber2.account_private),
230+
)
231+
self.fiber1.get_client().shutdown_channel(
232+
{
233+
"channel_id": self.fiber1.get_client().list_channels({})["channels"][0][
234+
"channel_id"
235+
],
236+
"close_script": self.get_account_script(self.Config.ACCOUNT_PRIVATE_1),
237+
"fee_rate": "0x3FC",
238+
}
239+
)
240+
tx_hash = self.wait_and_check_tx_pool_fee(1000, False, 100)
241+
self.Miner.miner_until_tx_committed(self.node, tx_hash)
242+
tx_msg = self.get_tx_message(tx_hash)
243+
print("msg:", tx_msg)
244+
assert (
245+
tx_msg["input_cells"][0]["udt_capacity"]
246+
== 340282366920938463463374607431768211455
247+
)
248+
assert {
249+
"args": self.fiber2.get_account()["lock_arg"],
250+
"capacity": 14300000000,
251+
"udt_args": self.get_account_udt_script(self.fiber2.account_private)[
252+
"args"
253+
],
254+
"udt_capacity": 1,
255+
} in tx_msg["output_cells"]
256+
assert {
257+
"args": self.fiber1.get_account()["lock_arg"],
258+
"capacity": 14300000000 - tx_msg["fee"],
259+
"udt_args": self.get_account_udt_script(self.fiber2.account_private)[
260+
"args"
261+
],
262+
"udt_capacity": 340282366920938463463374607431768211454,
263+
} in tx_msg["output_cells"]
264+
265+
def test_node1_add_node2_amount_gt_u128_max(self):
266+
"""
267+
Returns:
268+
"""
269+
self.faucet(
270+
self.fiber2.account_private,
271+
0,
272+
self.fiber1.account_private,
273+
340282366920938463463374607431768211400,
274+
)
275+
self.faucet(
276+
self.fiber1.account_private, 0, self.fiber1.account_private, 1 * 100000000
277+
)
278+
temporary_channel = self.fiber1.get_client().open_channel(
279+
{
280+
"peer_id": self.fiber2.get_peer_id(),
281+
"funding_amount": hex(100000000 - 1),
282+
"tlc_fee_proportional_millionths": hex(1000),
283+
"public": True,
284+
"funding_udt_type_script": self.get_account_udt_script(
285+
self.fiber1.account_private
286+
),
287+
}
288+
)
289+
time.sleep(1)
290+
291+
with pytest.raises(Exception) as exc_info:
292+
self.fiber2.get_client().accept_channel(
293+
{
294+
"temporary_channel_id": temporary_channel["temporary_channel_id"],
295+
"funding_amount": hex(340282366920938463463374607431768211400 - 1),
296+
"tlc_fee_proportional_millionths": hex(1000),
297+
}
298+
)
299+
expected_error_message = "The total UDT funding amount should be less than 340282366920938463463374607431768211455"
300+
assert expected_error_message in exc_info.value.args[0], (
301+
f"Expected substring '{expected_error_message}' "
302+
f"not found in actual string '{exc_info.value.args[0]}'"
303+
)

test_cases/fiber/devnet/send_payment/params/test_max_fee_amount.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_fee(self):
7575
)
7676
self.wait_payment_state(self.fiber1, payment1["payment_hash"])
7777

78-
@pytest.mark.skip(reason="panic")
78+
# @pytest.mark.skip(reason="https://github.com/nervosnetwork/fiber/pull/717")
7979
def test_max_fee_0xffffffffffffffffffffffffffffffff(self):
8080
self.open_channel(self.fiber1, self.fiber2, 1000 * 100000000, 1000 * 100000000)
8181
invoice = self.fiber1.get_client().new_invoice(
@@ -96,7 +96,7 @@ def test_max_fee_0xffffffffffffffffffffffffffffffff(self):
9696
"max_fee_amount": "0xffffffffffffffffffffffffffffffff",
9797
}
9898
)
99-
expected_error_message = ""
99+
expected_error_message = "overflow"
100100
assert expected_error_message in exc_info.value.args[0], (
101101
f"Expected substring '{expected_error_message}' "
102102
f"not found in actual string '{exc_info.value.args[0]}'"

0 commit comments

Comments
 (0)