Skip to content

Commit

Permalink
itest: add test paying again fails
Browse files Browse the repository at this point in the history
  • Loading branch information
JssDWt committed Sep 24, 2024
1 parent b566989 commit 21683e1
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions itest/tests/test_pay_again_fails.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from binascii import hexlify
from bitcoin.wallet import CBitcoinSecret
from pyln.testing.fixtures import (
bitcoind,
directory,
db_provider,
executor,
jsonschemas,
node_cls,
node_factory,
setup_logging,
teardown_checks,
test_base_dir,
test_name,
)
from pyln.testing.utils import wait_for
from fixtures import whatthefee, swapd_factory, postgres_factory
import grpc
import hashlib
import os


def test_pay_again_fails(node_factory, swapd_factory):
user = node_factory.get_node()
swapper = swapd_factory.get_swapd()
swapper.lightning_node.openchannel(user, 1000000)
wait_for(
lambda: all(
channel["state"] == "CHANNELD_NORMAL"
for channel in swapper.lightning_node.rpc.listpeerchannels()["channels"]
)
)
user_node_id = user.info["id"]
secret_key = CBitcoinSecret.from_secret_bytes(os.urandom(32))
public_key = secret_key.pub
preimage = os.urandom(32)
h = hashlib.sha256(preimage).digest()
add_fund_resp = swapper.rpc.add_fund_init(user, public_key, h)
txid = user.bitcoin.rpc.sendtoaddress(add_fund_resp.address, 100_000 / 10**8)
user.bitcoin.generate_block(1)

wait_for(
lambda: len(swapper.internal_rpc.get_swap(add_fund_resp.address).outputs) > 0
)

payment_request = user.rpc.invoice(
100_000_000,
"swap-success",
"swap-success",
preimage=hexlify(preimage).decode("ASCII"),
)["bolt11"]
swapper.rpc.get_swap_payment(payment_request)
wait_for(
lambda: user.rpc.listinvoices(payment_hash=hexlify(h).decode("ASCII"))[
"invoices"
][0]["status"]
== "paid"
)
try:
swapper.rpc.get_swap_payment(payment_request)
except grpc._channel._InactiveRpcError as e:
assert e.details() == "swap already paid"

0 comments on commit 21683e1

Please sign in to comment.