Skip to content

Commit

Permalink
tests: small fixes for upcoming 24.11
Browse files Browse the repository at this point in the history
  • Loading branch information
daywalker90 committed Nov 18, 2024
1 parent bed9600 commit 6c9aec3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 68 deletions.
46 changes: 12 additions & 34 deletions tests/test_holdinvoice_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ def test_inputs(node_factory, bitcoind, get_plugin): # noqa: F811
amount_msat=holdrpc.Amount(msat=800000),
label=generate_random_label(),
)
with pytest.raises(
_InactiveRpcError, match=r"missing required parameter: cltv"
):
with pytest.raises(_InactiveRpcError, match=r"missing required parameter: cltv"):
hold_stub.HoldInvoice(request)

request = holdrpc.HoldInvoiceRequest(
Expand All @@ -158,7 +156,7 @@ def test_inputs(node_factory, bitcoind, get_plugin): # noqa: F811
assert isinstance(result, holdrpc.HoldInvoiceResponse) is True
assert result.payment_hash is not None

decode_result = l2.rpc.decodepay(result.bolt11)
decode_result = l2.rpc.decode(result.bolt11)
assert "routes" in decode_result
assert len(decode_result["routes"]) == 1
assert len(decode_result["routes"][0]) == 1
Expand Down Expand Up @@ -225,9 +223,7 @@ def test_valid_hold_then_settle(node_factory, bitcoind, get_plugin): # noqa: F8
assert (isinstance(result, holdrpc.HoldInvoiceResponse)) is True
assert result.payment_hash is not None

request_lookup = holdrpc.HoldInvoiceLookupRequest(
payment_hash=result.payment_hash
)
request_lookup = holdrpc.HoldInvoiceLookupRequest(payment_hash=result.payment_hash)
result_lookup = hold_stub.HoldInvoiceLookup(request_lookup)
assert result_lookup is not None
assert isinstance(result_lookup, holdrpc.HoldInvoiceLookupResponse) is True
Expand All @@ -237,9 +233,7 @@ def test_valid_hold_then_settle(node_factory, bitcoind, get_plugin): # noqa: F8
assert result_lookup.htlc_expiry == 0

# test that it won't settle if it's still open
request_settle = holdrpc.HoldInvoiceSettleRequest(
payment_hash=result.payment_hash
)
request_settle = holdrpc.HoldInvoiceSettleRequest(payment_hash=result.payment_hash)
with pytest.raises(
_InactiveRpcError,
match=r"Holdinvoice is in wrong state: \\\'OPEN\\\'\\",
Expand All @@ -257,9 +251,7 @@ def test_valid_hold_then_settle(node_factory, bitcoind, get_plugin): # noqa: F8
)
result_lookup = hold_stub.HoldInvoiceLookup(request_lookup)
assert result_lookup is not None
assert (
isinstance(result_lookup, holdrpc.HoldInvoiceLookupResponse) is True
)
assert isinstance(result_lookup, holdrpc.HoldInvoiceLookupResponse) is True

if result_lookup.state == holdrpc.Holdstate.ACCEPTED:
break
Expand All @@ -276,17 +268,13 @@ def test_valid_hold_then_settle(node_factory, bitcoind, get_plugin): # noqa: F8
]
assert doublecheck[0]["status"] == "unpaid"

request_settle = holdrpc.HoldInvoiceSettleRequest(
payment_hash=result.payment_hash
)
request_settle = holdrpc.HoldInvoiceSettleRequest(payment_hash=result.payment_hash)
result_settle = hold_stub.HoldInvoiceSettle(request_settle)
assert result_settle is not None
assert isinstance(result_settle, holdrpc.HoldInvoiceSettleResponse) is True
assert result_settle.state == holdrpc.Holdstate.SETTLED

request_lookup = holdrpc.HoldInvoiceLookupRequest(
payment_hash=result.payment_hash
)
request_lookup = holdrpc.HoldInvoiceLookupRequest(payment_hash=result.payment_hash)
result_lookup = hold_stub.HoldInvoiceLookup(request_lookup)
assert result_lookup is not None
assert isinstance(result_lookup, holdrpc.HoldInvoiceLookupResponse) is True
Expand Down Expand Up @@ -371,9 +359,7 @@ def test_valid_hold_then_cancel(node_factory, bitcoind, get_plugin): # noqa: F8
assert (isinstance(result, holdrpc.HoldInvoiceResponse)) is True
assert result.payment_hash is not None

request_lookup = holdrpc.HoldInvoiceLookupRequest(
payment_hash=result.payment_hash
)
request_lookup = holdrpc.HoldInvoiceLookupRequest(payment_hash=result.payment_hash)
result_lookup = hold_stub.HoldInvoiceLookup(request_lookup)
assert result_lookup is not None
assert isinstance(result_lookup, holdrpc.HoldInvoiceLookupResponse) is True
Expand All @@ -383,9 +369,7 @@ def test_valid_hold_then_cancel(node_factory, bitcoind, get_plugin): # noqa: F8
assert result_lookup.htlc_expiry == 0

# test that it won't settle if it's still open
request_settle = holdrpc.HoldInvoiceSettleRequest(
payment_hash=result.payment_hash
)
request_settle = holdrpc.HoldInvoiceSettleRequest(payment_hash=result.payment_hash)
with pytest.raises(
_InactiveRpcError,
match=r"Holdinvoice is in wrong state: \\\'OPEN\\\'\\",
Expand All @@ -403,9 +387,7 @@ def test_valid_hold_then_cancel(node_factory, bitcoind, get_plugin): # noqa: F8
)
result_lookup = hold_stub.HoldInvoiceLookup(request_lookup)
assert result_lookup is not None
assert (
isinstance(result_lookup, holdrpc.HoldInvoiceLookupResponse) is True
)
assert isinstance(result_lookup, holdrpc.HoldInvoiceLookupResponse) is True

if result_lookup.state == holdrpc.Holdstate.ACCEPTED:
break
Expand All @@ -422,17 +404,13 @@ def test_valid_hold_then_cancel(node_factory, bitcoind, get_plugin): # noqa: F8
]
assert doublecheck[0]["status"] == "unpaid"

request_cancel = holdrpc.HoldInvoiceCancelRequest(
payment_hash=result.payment_hash
)
request_cancel = holdrpc.HoldInvoiceCancelRequest(payment_hash=result.payment_hash)
result_cancel = hold_stub.HoldInvoiceCancel(request_cancel)
assert result_cancel is not None
assert isinstance(result_cancel, holdrpc.HoldInvoiceCancelResponse) is True
assert result_cancel.state == holdrpc.Holdstate.CANCELED

request_lookup = holdrpc.HoldInvoiceLookupRequest(
payment_hash=result.payment_hash
)
request_lookup = holdrpc.HoldInvoiceLookupRequest(payment_hash=result.payment_hash)
result_lookup = hold_stub.HoldInvoiceLookup(request_lookup)
assert result_lookup is not None
assert isinstance(result_lookup, holdrpc.HoldInvoiceLookupResponse) is True
Expand Down
54 changes: 20 additions & 34 deletions tests/test_holdinvoice_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ def test_inputs(node_factory, get_plugin): # noqa: F811
)
assert result is not None
assert isinstance(result, dict) is True
expected_message = (
"should be positive msat" " or 'any': invalid token '\"0msat\"'"
)
expected_message = "should be positive msat or 'any': invalid token '\"0msat\"'"
assert expected_message in result["message"]

# Negative expiry value
Expand All @@ -155,7 +153,7 @@ def test_inputs(node_factory, get_plugin): # noqa: F811
assert result is not None
assert isinstance(result, dict) is True
expected_message = (
"expiry: should be an unsigned " "64 bit integer: invalid token '-3600'"
"expiry: should be an unsigned 64 bit integer: invalid token '-3600'"
)
assert result["message"] == expected_message

Expand All @@ -173,7 +171,7 @@ def test_inputs(node_factory, get_plugin): # noqa: F811
assert result is not None
assert isinstance(result, dict) is True
expected_message = (
"fallbacks: should be an array: " "invalid token '\"invalid_fallback\"'"
"fallbacks: should be an array: invalid token '\"invalid_fallback\"'"
)
assert result["message"] == expected_message

Expand All @@ -189,7 +187,7 @@ def test_inputs(node_factory, get_plugin): # noqa: F811
)
assert result is not None
assert isinstance(result, dict) is True
expected_message = "cltv: should be an integer: " "invalid token '-144'"
expected_message = "cltv: should be an integer: invalid token '-144'"
assert result["message"] == expected_message

# Missing cltv option
Expand Down Expand Up @@ -249,9 +247,7 @@ def test_valid_hold_then_settle(node_factory, bitcoind, get_plugin): # noqa: F8
expected_message = "Holdinvoice is in wrong state: 'OPEN'"
assert result_settle["message"] == expected_message

threading.Thread(
target=pay_with_thread, args=(l1, invoice["bolt11"])
).start()
threading.Thread(target=pay_with_thread, args=(l1, invoice["bolt11"])).start()

timeout = 10
start_time = time.time()
Expand Down Expand Up @@ -309,7 +305,7 @@ def test_valid_hold_then_settle(node_factory, bitcoind, get_plugin): # noqa: F8
)
assert result_cancel_settled is not None
assert isinstance(result_cancel_settled, dict) is True
expected_message = "Holdinvoice is in wrong " "state: 'SETTLED'"
expected_message = "Holdinvoice is in wrong state: 'SETTLED'"
assert result_cancel_settled["message"] == expected_message


Expand Down Expand Up @@ -343,9 +339,7 @@ def test_fc_hold_then_settle(node_factory, bitcoind, get_plugin): # noqa: F811
assert isinstance(invoice, dict) is True
assert "payment_hash" in invoice

threading.Thread(
target=pay_with_thread, args=(l1, invoice["bolt11"])
).start()
threading.Thread(target=pay_with_thread, args=(l1, invoice["bolt11"])).start()

timeout = 10
start_time = time.time()
Expand Down Expand Up @@ -374,8 +368,8 @@ def test_fc_hold_then_settle(node_factory, bitcoind, get_plugin): # noqa: F811
)
assert doublecheck["status"] == "unpaid"

fc = l1.rpc.close(cl1, 1)
bitcoind.generate_block(1, wait_for_mempool=fc["txid"])
l1.rpc.close(cl1, 1)
bitcoind.generate_block(1, wait_for_mempool=1)
wait_for(
lambda: l1.rpc.listpeerchannels(l2.info["id"])["channels"][0]["state"]
== "ONCHAIN"
Expand Down Expand Up @@ -427,24 +421,22 @@ def test_fc_hold_then_settle(node_factory, bitcoind, get_plugin): # noqa: F811
wait_for(
lambda: any(
"ONCHAIN:All outputs resolved" in status_str
for status_str in l1.rpc.listpeerchannels(l2.info["id"])[
"channels"
][0]["status"]
for status_str in l1.rpc.listpeerchannels(l2.info["id"])["channels"][0][
"status"
]
)
)
wait_for(
lambda: any(
"ONCHAIN:All outputs resolved" in status_str
for status_str in l2.rpc.listpeerchannels(l1.info["id"])[
"channels"
][0]["status"]
for status_str in l2.rpc.listpeerchannels(l1.info["id"])["channels"][0][
"status"
]
)
)

payres = only_one(
l1.rpc.call("listpays", {"payment_hash": invoice["payment_hash"]})[
"pays"
]
l1.rpc.call("listpays", {"payment_hash": invoice["payment_hash"]})["pays"]
)
assert payres["status"] == "complete"

Expand Down Expand Up @@ -488,9 +480,7 @@ def test_valid_hold_then_cancel(node_factory, bitcoind, get_plugin): # noqa: F8
assert result_lookup["state"] == "OPEN"
assert "htlc_expiry" not in result_lookup

threading.Thread(
target=pay_with_thread, args=(l1, invoice["bolt11"])
).start()
threading.Thread(target=pay_with_thread, args=(l1, invoice["bolt11"])).start()

timeout = 10
start_time = time.time()
Expand Down Expand Up @@ -538,7 +528,7 @@ def test_valid_hold_then_cancel(node_factory, bitcoind, get_plugin): # noqa: F8
)
assert result_settle_canceled is not None
assert isinstance(result_settle_canceled, dict) is True
expected_message = "Holdinvoice is in wrong " "state: 'CANCELED'"
expected_message = "Holdinvoice is in wrong state: 'CANCELED'"
result_settle_canceled["message"] == expected_message


Expand Down Expand Up @@ -581,9 +571,7 @@ def test_hold_then_block_timeout(node_factory, bitcoind, get_plugin): # noqa: F
assert result_lookup["state"] == "OPEN"
assert "htlc_expiry" not in result_lookup

threading.Thread(
target=pay_with_thread, args=(l1, invoice["bolt11"])
).start()
threading.Thread(target=pay_with_thread, args=(l1, invoice["bolt11"])).start()

timeout = 10
start_time = time.time()
Expand Down Expand Up @@ -672,9 +660,7 @@ def test_hold_then_invoice_timeout(node_factory, bitcoind, get_plugin): # noqa:
assert result_lookup["state"] == "OPEN"
assert "htlc_expiry" not in result_lookup

threading.Thread(
target=pay_with_thread, args=(l1, invoice["bolt11"])
).start()
threading.Thread(target=pay_with_thread, args=(l1, invoice["bolt11"])).start()

timeout = 10
start_time = time.time()
Expand Down

0 comments on commit 6c9aec3

Please sign in to comment.