Skip to content

Commit

Permalink
btcpayserver: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nixbitcoin committed Sep 15, 2020
1 parent f93c3c8 commit c9c844d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ env:
- PKG=elementsd STABLE=0
- PKG=electrs STABLE=1
- PKG=electrs STABLE=0
- PKG=nbxplorer STABLE=1
- PKG=nbxplorer STABLE=0
- PKG=btcpayserver STABLE=1
- PKG=btcpayserver STABLE=0
- PKG=liquid-swap STABLE=1
- PKG=lightning-loop STABLE=0
- PKG=nixops19_09 STABLE=1
Expand Down
7 changes: 7 additions & 0 deletions test/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ def run_tests(extra_tests):
)
)

assert_running("nbxplorer")
machine.wait_until_succeeds(log_has_string("nbxplorer", "BTC: RPC connection successful"))
extra_tests.pop("nbxplorer")()
assert_running("btcpayserver")
machine.wait_until_succeeds(log_has_string("btcpayserver", "Listening on"))
extra_tests.pop("btcpayserver")()

assert_running("spark-wallet")
extra_tests.pop("spark-wallet")()

Expand Down
15 changes: 15 additions & 0 deletions test/scenarios/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ def electrs():
machine.wait_for_open_port(4224) # prometeus metrics provider


def nbxplorer():
machine.wait_for_open_port(24444)


def btcpayserver():
machine.wait_for_open_port(23000)
# test lnd custom macaroon
assert_matches(
'sudo -u btcpayserver curl -s --cacert /secrets/lnd-cert --header "Grpc-Metadata-macaroon: $(xxd -ps -u -c 1000 /run/lnd/btcpayserver.macaroon)" -X GET https://127.0.0.1:8080/v1/getinfo | jq',
'"version"',
)


def spark_wallet():
machine.wait_for_open_port(9737)
spark_auth = re.search("login=(.*)", succeed("cat /secrets/spark-wallet-login"))[1]
Expand Down Expand Up @@ -31,6 +44,8 @@ def prestop():

extra_tests = {
"electrs": electrs,
"nbxplorer": nbxplorer,
"btcpayserver": btcpayserver,
"spark-wallet": spark_wallet,
"lightning-charge": lightning_charge,
"nanopos": nanopos,
Expand Down
24 changes: 23 additions & 1 deletion test/scenarios/withnetns.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
recurringdonations_ip = "169.254.1.20"
nginx_ip = "169.254.1.21"
lightningloop_ip = "169.254.1.22"
nbxplorer_ip = "169.254.1.23"
btcpayserver_ip = "169.254.1.24"


def electrs():
Expand All @@ -18,6 +20,20 @@ def electrs():
) # prometeus metrics provider


def nbxplorer():
machine.wait_until_succeeds("ip netns exec nb-nbxplorer nc -z %s 24444" % nbxplorer_ip)


def btcpayserver():
machine.wait_until_succeeds("ip netns exec nb-btcpayserver nc -z %s 23000" % btcpayserver_ip)
# test lnd custom macaroon
assert_matches(
'ip netns exec nb-btcpayserver sudo -u btcpayserver curl -s --cacert /secrets/lnd-cert --header "Grpc-Metadata-macaroon: $(xxd -ps -u -c 1000 /run/lnd/btcpayserver.macaroon)" -X GET https://%s:8080/v1/getinfo | jq'
% lnd_ip,
'"version"',
)


def spark_wallet():
machine.wait_until_succeeds("ip netns exec nb-spark-wallet nc -z %s 9737" % sparkwallet_ip)
spark_auth = re.search("login=(.*)", succeed("cat /secrets/spark-wallet-login"))[1]
Expand Down Expand Up @@ -50,13 +66,16 @@ def web_index():
def prestop():
ping_bitcoind = "ip netns exec nb-bitcoind ping -c 1 -w 1"
ping_nanopos = "ip netns exec nb-nanopos ping -c 1 -w 1"
ping_nbxplorer = "ip netns exec nb-nbxplorer ping -c 1 -w 1"

# Positive ping tests (non-exhaustive)
machine.succeed(
"%s %s &&" % (ping_bitcoind, bitcoind_ip)
+ "%s %s &&" % (ping_bitcoind, clightning_ip)
+ "%s %s &&" % (ping_bitcoind, lnd_ip)
+ "%s %s &&" % (ping_bitcoind, liquidd_ip)
+ "%s %s &&" % (ping_bitcoind, nbxplorer_ip)
+ "%s %s &&" % (ping_nbxplorer, btcpayserver_ip)
+ "%s %s &&" % (ping_nanopos, lightningcharge_ip)
+ "%s %s &&" % (ping_nanopos, nanopos_ip)
+ "%s %s" % (ping_nanopos, nginx_ip)
Expand All @@ -77,7 +96,8 @@ def prestop():
+ "%s %s ||" % (ping_nanopos, liquidd_ip)
+ "%s %s ||" % (ping_nanopos, electrs_ip)
+ "%s %s ||" % (ping_nanopos, sparkwallet_ip)
+ "%s %s" % (ping_nanopos, recurringdonations_ip)
+ "%s %s ||" % (ping_nanopos, recurringdonations_ip)
+ "%s %s" % (ping_nanopos, btcpayserver_ip)
)

# test that netns-exec can't be run for unauthorized namespace
Expand All @@ -94,6 +114,8 @@ def prestop():

extra_tests = {
"electrs": electrs,
"nbxplorer": nbxplorer,
"btcpayserver": btcpayserver,
"spark-wallet": spark_wallet,
"lightning-charge": lightning_charge,
"nanopos": nanopos,
Expand Down
5 changes: 5 additions & 0 deletions test/test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ import ./make-test.nix rec {

services.backups.enable = true;

services.btcpayserver.enable = true;
services.btcpayserver.lightningBackend = "lnd";
# needed to test macaroon creation
environment.systemPackages = with pkgs; [ openssl xxd ];

# to test that unused secrets are made inaccessible by 'setup-secrets'
systemd.services.generate-secrets.postStart = ''
install -o nobody -g nogroup -m777 <(:) /secrets/dummy
Expand Down

0 comments on commit c9c844d

Please sign in to comment.