Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

Commit

Permalink
lndsigner: add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aakselrod committed Feb 1, 2023
1 parent c72552d commit 4355bbd
Show file tree
Hide file tree
Showing 13 changed files with 1,747 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .github/workflows/docker-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Dockerized Tests

on:
push:
branches: [ "master", "main" ]
pull_request:
branches: [ "**" ]

jobs:
all-tests:
runs-on: ubuntu-latest

steps:
- name: Check out repository code
uses: actions/checkout@v3

- name: Run tests in docker container
run: make docker-test-all
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
ARG gover=1.19.5

FROM golang:$gover

ARG goplatform=amd64
ARG cppplatform=x86_64
ARG lnd=v0.15.5-beta
ARG bitcoind=24.0.1
ARG vault=1.12.2

RUN apt update && apt-get install -y zip

RUN cd /root && \
wget https://bitcoincore.org/bin/bitcoin-core-$bitcoind/bitcoin-${bitcoind}-${cppplatform}-linux-gnu.tar.gz && \
tar xfz bitcoin-$bitcoind-$cppplatform-linux-gnu.tar.gz && \
mv bitcoin-$bitcoind/bin/* /usr/local/bin/ && \
wget https://github.com/lightningnetwork/lnd/releases/download/$lnd/lnd-linux-$goplatform-$lnd.tar.gz && \
tar xfz lnd-linux-$goplatform-$lnd.tar.gz && \
mv lnd-linux-$goplatform-$lnd/* /usr/local/bin/ && \
wget https://releases.hashicorp.com/vault/$vault/vault_${vault}_linux_${goplatform}.zip && \
unzip vault_${vault}_linux_${goplatform}.zip && \
mv vault /usr/local/bin/ && \
go install github.com/go-delve/delve/cmd/dlv@latest && \
echo "export PATH='$PATH:/usr/local/go/bin:/root/go/bin'" >> .bashrc

VOLUME [ "/app" ]

WORKDIR /app
62 changes: 62 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.PHONY: docker docker-itest docker-test docker-test-all docker-check docker-shell itest test test-all

IMG_NAME := lndsigner-builder

GOVER := 1.19.5
GOPLATFORM := amd64
CPPPLATFORM := x86_64
LND := v0.15.5-beta
BITCOIND := 24.0.1
VAULT := 1.12.2

STAMPPREIMAGE := $(GOVER)$(GOPLATFORM)$(CPPPLATFORM)$(LND)$(BITCOIND)$(VAULT)

BUILDERSTAMP != echo $(STAMPPREIMAGE) | sha256sum | cut -d " " -f 1
IMAGE_BUILT != docker image ls $(IMG_NAME):$(BUILDERSTAMP) | grep $(BUILDERSTAMP) | wc -l

# docker-check checks if an image with the builderstamp already exists. If not,
# it builds one.
docker-check:
ifeq ($(IMAGE_BUILT), 0)
docker build -t $(IMG_NAME):$(BUILDERSTAMP) .
endif

# docker just tags the latest image to the builderstamp, in case the
# dependencies have been changed and a new image was built.
docker: docker-check
docker image tag $(IMG_NAME):$(BUILDERSTAMP) $(IMG_NAME):latest

# docker-itest runs itests in a docker container, then removes the container.
docker-itest: docker
docker run -t --rm \
--mount type=bind,source=$(CURDIR),target=/app $(IMG_NAME):latest \
make itest

# docker-test runs unit tests in a docker container, then removes the container.
docker-test: docker
docker run -t --rm \
--mount type=bind,source=$(CURDIR),target=/app $(IMG_NAME):latest \
make test

# docker-test-all runs unit and integration tests in a docker container, then
# removes the container.
docker-test-all: docker
docker run -t --rm \
--mount type=bind,source=$(CURDIR),target=/app $(IMG_NAME):latest \
make test-all

# docker-shell opens a shell to a dockerized environment with all dependencies
# and also dlv installed for easy debugging, then removes the container.
docker-shell: docker
docker run -it --rm \
--mount type=bind,source=$(CURDIR),target=/app $(IMG_NAME):latest \
bash -l

itest:
go install -race ./cmd/... && go test -v -count=1 -race -tags=itest -cover ./itest

test:
go test -v -count=1 -race -cover ./...

test-all:
go install -race ./cmd/... && go test -v -count=1 -race -tags=itest -cover ./...
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- [x] sign messages for network announcements
- [x] derive shared keys for peer connections
- [x] sign PSBTs for on-chain transactions, channel openings/closes, HTLC updates, etc.
- [ ] run itests
- [x] run itests
- [ ] do automated builds
- [ ] do reproducible builds
- [ ] perform musig2 ops
Expand Down Expand Up @@ -159,3 +159,20 @@ node 03c7926302ac72f51ef009dc169561734414b3c6bfd9fb0dc42cac93101c3c25bf
```

Now you can use the imported key as before.

## Testing
You can run unit tests and integration tests, together or separately, in Docker or on your host system. To run tests inside Docker, from the project directory, run one of:

* `$ make docker-test` for unit tests
* `$ make docker-itest` for integration tests
* `$ make docker-test-all` for integration and unit tests

To run tests directly on your development machine, you can use:

* `$ make test` for unit tests
* `$ make itest` for integration tests
* `$ make test-all` for integration and unit tests

Before running integration tests on your development machine, ensure you have all the required binaries (bitcoind, bitcoin-cli, lnd, lncli, vault).

To get a shell on a container that can run tests, you can use `make docker-shell`. Then, you can `make test`, `make itest`, or `make test-all` inside the container, just like you would directly on the host system.
37 changes: 37 additions & 0 deletions itest/gen_protos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
#
# Copyright (C) 2015-2022 Lightning Labs and The Lightning Network Developers
# Copyright (C) 2022 Bottlepay and The Lightning Network Developers

set -e

# generate compiles the *.pb.go stubs from the *.proto files.
function generate() {
echo "Generating root gRPC server protos"

PROTOS="walletunlocker.proto"

# For each of the sub-servers, we then generate their protos, but a restricted
# set as they don't yet require REST proxies, or swagger docs.
for file in $PROTOS; do
DIRECTORY=$(dirname "${file}")
echo "Generating protos from ${file}, into ${DIRECTORY}"

# Generate the protos.
protoc -I/usr/local/include -I. \
--go_out . --go_opt paths=source_relative \
--go-grpc_out . --go-grpc_opt paths=source_relative \
"${file}"
done
}

# format formats the *.proto files with the clang-format utility.
function format() {
find . -name "*.proto" -print0 | xargs -0 clang-format --style=file -i
}

# Compile and format the itest package.
pushd itest
format
generate
popd
Loading

0 comments on commit 4355bbd

Please sign in to comment.