-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add smoke tests with pyln-testing
- Loading branch information
1 parent
ea3f498
commit b350cac
Showing
6 changed files
with
1,198 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
set -x | ||
|
||
script_dir=$(dirname -- "$(readlink -f -- "$0")") | ||
cargo_toml_path="$script_dir/../Cargo.toml" | ||
version=$(awk -F'=' '/^\[package\]/ { in_package = 1 } in_package && /version/ { gsub(/[" ]/, "", $2); print $2; exit }' "$cargo_toml_path") | ||
|
||
artifact_url="https://github.com/BoltzExchange/hold/releases/download/v$version/hold-linux-amd64.tar.gz" | ||
archive_file="$script_dir/hold.tar.gz" | ||
|
||
if ! curl -L "$artifact_url" -o "$archive_file"; then | ||
exit 1 | ||
fi | ||
|
||
if ! tar -xzvf "$archive_file" -C "$script_dir"; then | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
from __future__ import annotations | ||
|
||
from hashlib import sha256 | ||
from pathlib import Path | ||
from threading import Thread | ||
|
||
from pyln.client import RpcError | ||
from pyln.testing.fixtures import * | ||
|
||
|
||
def new_preimage() -> tuple[str, str]: | ||
preimage = os.urandom(32) | ||
return preimage.hex(), sha256(preimage).hexdigest() | ||
|
||
|
||
@pytest.fixture | ||
def plugin_path() -> Path: | ||
return Path.cwd() / "build" / "hold-linux-amd64" | ||
|
||
|
||
def pay_with_thread(rpc: any, bolt11: str) -> None: | ||
logger = logging.getLogger(__name__) | ||
try: | ||
rpc.dev_pay(bolt11, dev_use_shadow=False) | ||
except RpcError as e: | ||
logger.info("error paying invoice with payment hash: %s", e) | ||
|
||
|
||
def test_holdinvoice(node_factory: NodeFactory, plugin_path: Path) -> None: | ||
node = node_factory.get_node(options={"important-plugin": plugin_path}) | ||
|
||
amount = 1_000 | ||
_, payment_hash = new_preimage() | ||
res = node.rpc.call( | ||
"holdinvoice", | ||
{ | ||
"amount": amount, | ||
"payment_hash": payment_hash, | ||
}, | ||
) | ||
|
||
decoded = node.rpc.call("decode", [res["bolt11"]]) | ||
|
||
assert decoded["payment_hash"] == payment_hash | ||
assert decoded["amount_msat"] == amount | ||
|
||
|
||
def test_listholdinvoices(node_factory: NodeFactory, plugin_path: Path) -> None: | ||
node = node_factory.get_node(options={"important-plugin": plugin_path}) | ||
|
||
hashes = [new_preimage()[0] for _ in range(5)] | ||
invoices = [ | ||
node.rpc.call( | ||
"holdinvoice", | ||
{ | ||
"amount": 1_000, | ||
"payment_hash": payment_hash, | ||
}, | ||
)["bolt11"] | ||
for payment_hash in hashes | ||
] | ||
|
||
assert len(node.rpc.call("listholdinvoices")["holdinvoices"]) == len(hashes) | ||
assert node.rpc.call( | ||
"listholdinvoices", {"payment_hash": hashes[0]} | ||
) == node.rpc.call("listholdinvoices", {"bolt11": invoices[0]}) | ||
|
||
|
||
def test_settle( | ||
node_factory: NodeFactory, bitcoind: BitcoinD, plugin_path: Path | ||
) -> None: | ||
l1 = node_factory.get_node(options={"important-plugin": plugin_path}) | ||
l2 = node_factory.get_node() | ||
|
||
l1.rpc.connect(l2.info["id"], "localhost", l2.port) | ||
cl1, _ = l1.fundchannel(l2, 1_000_000) | ||
cl2, _ = l2.fundchannel(l1, 1_000_000) | ||
|
||
bitcoind.generate_block(6) | ||
|
||
l1.wait_channel_active(cl1) | ||
l1.wait_channel_active(cl2) | ||
|
||
preimage, payment_hash = new_preimage() | ||
amount = 1_000 | ||
invoice = l1.rpc.call( | ||
"holdinvoice", {"amount": amount, "payment_hash": payment_hash} | ||
)["bolt11"] | ||
|
||
Thread(target=pay_with_thread, args=(l2, invoice)).start() | ||
time.sleep(1) | ||
|
||
assert ( | ||
l1.rpc.call( | ||
"listholdinvoices", | ||
{ | ||
"payment_hash": payment_hash, | ||
}, | ||
)["holdinvoices"][0]["state"] | ||
== "accepted" | ||
) | ||
|
||
l1.rpc.call("settleholdinvoice", {"preimage": preimage}) | ||
|
||
assert ( | ||
l1.rpc.call( | ||
"listholdinvoices", | ||
{ | ||
"payment_hash": payment_hash, | ||
}, | ||
)["holdinvoices"][0]["state"] | ||
== "paid" | ||
) | ||
|
||
|
||
def test_cancel( | ||
node_factory: NodeFactory, bitcoind: BitcoinD, plugin_path: Path | ||
) -> None: | ||
l1 = node_factory.get_node(options={"important-plugin": plugin_path}) | ||
l2 = node_factory.get_node() | ||
|
||
l1.rpc.connect(l2.info["id"], "localhost", l2.port) | ||
cl1, _ = l1.fundchannel(l2, 1_000_000) | ||
cl2, _ = l2.fundchannel(l1, 1_000_000) | ||
|
||
bitcoind.generate_block(6) | ||
|
||
l1.wait_channel_active(cl1) | ||
l1.wait_channel_active(cl2) | ||
|
||
_, payment_hash = new_preimage() | ||
amount = 1_000 | ||
invoice = l1.rpc.call( | ||
"holdinvoice", {"amount": amount, "payment_hash": payment_hash} | ||
)["bolt11"] | ||
|
||
Thread(target=pay_with_thread, args=(l2, invoice)).start() | ||
time.sleep(1) | ||
|
||
assert ( | ||
l1.rpc.call( | ||
"listholdinvoices", | ||
{ | ||
"payment_hash": payment_hash, | ||
}, | ||
)["holdinvoices"][0]["state"] | ||
== "accepted" | ||
) | ||
|
||
l1.rpc.call("cancelholdinvoice", {"payment_hash": payment_hash}) | ||
|
||
assert ( | ||
l1.rpc.call( | ||
"listholdinvoices", | ||
{ | ||
"payment_hash": payment_hash, | ||
}, | ||
)["holdinvoices"][0]["state"] | ||
== "cancelled" | ||
) |