Skip to content

Commit 8fcbbb6

Browse files
committed
Add e2e tests and CI/CD pipeline with nigiri integration
Add comprehensive end-to-end testing: - E2E test covering full L402 payment flow - Test verifies proxy strips Authorization headers before upstream - Tests use real LND backend via nigiri - CLN tests skipped pending nigiri REST API fix Improve nigiri network setup script: - Add CI environment detection for --ci flag - Wait for chopsticks (faucet) service readiness - Wait for LND credentials to be written to volumes - Generate and save CLN rune for test access Set up GitHub Actions CI/CD: - Create separate e2e.yml workflow for integration tests - Install nigiri and start test network in CI - Add tmate for interactive debugging on failures - Keep main go.yml pipeline fast (unit tests + linting only) This allows fast feedback on unit tests while running slower e2e tests in parallel. Signed-off-by: Gustavo Chain <me@qustavo.cc>
1 parent cba66d4 commit 8fcbbb6

4 files changed

Lines changed: 76 additions & 6 deletions

File tree

.github/workflows/e2e.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# End-to-end tests using nigiri for Lightning Network integration
2+
3+
name: E2E Tests
4+
5+
on:
6+
push:
7+
branches: [ "main" ]
8+
pull_request:
9+
branches: [ "main" ]
10+
11+
jobs:
12+
13+
e2e:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Set up Go
19+
uses: actions/setup-go@v4
20+
with:
21+
go-version: '1.24'
22+
23+
- name: Install nigiri
24+
run: curl https://getnigiri.vulpem.com | bash
25+
26+
- name: Start test network
27+
run: bash scripts/network.sh start
28+
29+
- name: Run e2e tests
30+
run: go test -v ./tests/...
31+
32+
- name: Stop test network
33+
if: always()
34+
run: bash scripts/network.sh stop

pkg/lightning/cln.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ func NewCLNBackend(cfg CLNConfig) (*CLNBackend, error) {
4444
return nil, fmt.Errorf("failed to add CLN cert to pool")
4545
}
4646
tlsConfig = &tls.Config{RootCAs: pool}
47-
} else {
48-
tlsConfig = &tls.Config{}
4947
}
5048

5149
client := &http.Client{

scripts/network.sh

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ EOF
1919

2020
cmd_start() {
2121
echo "Starting l402 integration network..."
22-
nigiri start --ln
22+
local nigiri_flags="--ln"
23+
if [[ -n "${CI:-}" ]]; then
24+
nigiri_flags="$nigiri_flags --ci"
25+
fi
26+
27+
nigiri start $nigiri_flags
2328
echo
2429

2530
echo -n "✓ Waiting for LND to become active "
@@ -36,6 +41,15 @@ cmd_start() {
3641
done
3742
echo
3843

44+
# Wait for chopsticks (faucet service) to be ready before trying to fund wallets.
45+
# Chopsticks may not respond to requests immediately after container starts.
46+
echo -n "✓ Waiting for faucet service "
47+
until curl -s http://localhost:3000 > /dev/null 2>&1; do
48+
sleep 1
49+
echo -n "."
50+
done
51+
echo
52+
3953
echo -n "✓ Funding onchain wallets"
4054
nigiri faucet lnd 1 btc
4155
nigiri faucet cln 1 btc
@@ -52,6 +66,22 @@ cmd_start() {
5266
done
5367
echo
5468

69+
# Wait for LND certificates and macaroons to be written to volumes.
70+
# Containers may report "ready" before files are actually written to the host filesystem,
71+
# causing tests to fail when trying to read credentials. This wait ensures files exist.
72+
echo -n "✓ Waiting for LND credentials to be written "
73+
until [[ -f ~/.nigiri/volumes/lnd/tls.cert && -f ~/.nigiri/volumes/lnd/data/chain/bitcoin/regtest/admin.macaroon ]]; do
74+
sleep 1
75+
echo -n "."
76+
done
77+
echo
78+
79+
# Generate and save CLN rune for authentication in tests
80+
echo -n "✓ Generating CLN rune "
81+
nigiri cln createrune | jq -r .rune > ~/.nigiri/volumes/lightningd/rune
82+
echo
83+
echo "✓ Rune saved to ~/.nigiri/volumes/lightningd/rune"
84+
5585
echo "Opening channels LND <-> CLN"
5686
CLN_PUBKEY=$(nigiri cln getinfo | jq -r .id)
5787
nigiri lnd connect $CLN_PUBKEY@cln:9935

tests/e2e_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/url"
99
"os"
1010
"path/filepath"
11+
"strings"
1112
"testing"
1213
"time"
1314

@@ -26,9 +27,16 @@ func TestL402Flow(t *testing.T) {
2627
t.Skipf("Could not create a LND backend (is nigiri running?): %v", err)
2728
}
2829

30+
// Read CLN rune from file generated by network.sh
31+
runeBytes, err := os.ReadFile(rootPath("lightningd/rune"))
32+
if err != nil {
33+
t.Skipf("Could not read CLN rune (is nigiri running?): %v", err)
34+
}
35+
rune := strings.TrimSpace(string(runeBytes))
36+
2937
cln, err := lightning.NewCLNBackend(lightning.CLNConfig{
3038
BaseURL: "http://localhost:9835",
31-
Rune: "1MOhfL2S_VjoqFKG-erWqmB9Kt5WU_MyNor6IMa65BQ9MA==",
39+
Rune: rune,
3240
})
3341
if err != nil {
3442
t.Skipf("Could not create a CLN backend (is nigiri running?): %v", err)
@@ -96,9 +104,9 @@ func newTestUpstream(t *testing.T) *httptest.Server {
96104
}
97105

98106
func newTestProxy(t *testing.T, ln lightning.Backend, upstream string) *httptest.Server {
99-
t.Log("Waiting for LND")
107+
t.Log("Waiting for Proxy")
100108
if err := ln.Wait(t.Context()); err != nil {
101-
t.Skipf("Waiting for LND (is nigiri running?): %v", err)
109+
t.Skipf("Waiting for proxy (is nigiri running?): %v", err)
102110
}
103111

104112
srvURL, err := url.Parse(upstream)

0 commit comments

Comments
 (0)