update tests to use new lspd startup

This commit is contained in:
Jesse de Wit
2023-01-03 14:29:45 +01:00
parent 94ee938893
commit 5c7f22b2f2
3 changed files with 41 additions and 23 deletions

View File

@@ -59,12 +59,12 @@ func NewClnLspdNode(h *lntest.TestHarness, m *lntest.Miner, name string) LspNode
"--dev-allowdustreserve=true",
}
lightningNode := lntest.NewClnNode(h, m, name, args...)
lspbase, err := newLspd(h, name,
"RUN_CLN=true",
fmt.Sprintf("CLN_PLUGIN_ADDRESS=%s", pluginAddress),
fmt.Sprintf("CLN_SOCKET_DIR=%s", lightningNode.SocketDir()),
fmt.Sprintf("CLN_SOCKET_NAME=%s", lightningNode.SocketFile()),
cln := fmt.Sprintf(
`{ "pluginAddress": "%s", "socketPath": "%s" }`,
pluginAddress,
filepath.Join(lightningNode.SocketDir(), lightningNode.SocketFile()),
)
lspbase, err := newLspd(h, name, nil, &cln)
if err != nil {
h.T.Fatalf("failed to initialize lspd")
}

View File

@@ -1,6 +1,7 @@
package itest
import (
"encoding/base64"
"fmt"
"log"
"os"
@@ -47,13 +48,13 @@ func NewLndLspdNode(h *lntest.TestHarness, m *lntest.Miner, name string) LspNode
}
lightningNode := lntest.NewLndNode(h, m, name, args...)
tlsCert := strings.Replace(string(lightningNode.TlsCert()), "\n", "\\n", -1)
lspBase, err := newLspd(h, name,
"RUN_LND=true",
fmt.Sprintf("LND_CERT=\"%s\"", tlsCert),
fmt.Sprintf("LND_ADDRESS=%s", lightningNode.GrpcHost()),
fmt.Sprintf("LND_MACAROON_HEX=%x", lightningNode.Macaroon()),
lnd := fmt.Sprintf(
`{ "address": "%s", "cert": "%s", "macaroon": "%x" }`,
lightningNode.GrpcHost(),
base64.StdEncoding.EncodeToString(lightningNode.TlsCert()),
lightningNode.Macaroon(),
)
lspBase, err := newLspd(h, name, &lnd, nil)
if err != nil {
h.T.Fatalf("failed to initialize lspd")
}
@@ -111,13 +112,16 @@ func (c *LndLspNode) Start() {
split := strings.Split(string(scriptFile), "\n")
for i, s := range split {
if strings.HasPrefix(s, "export LND_CERT") {
tlsCert := strings.Replace(string(c.lightningNode.TlsCert()), "\n", "\\n", -1)
split[i] = fmt.Sprintf("export LND_CERT=\"%s\"", tlsCert)
}
if strings.HasPrefix(s, "export NODES") {
ext := fmt.Sprintf(
`"lnd": { "address": "%s", "cert": "%s", "macaroon": "%x" }}]'`,
c.lightningNode.GrpcHost(),
base64.StdEncoding.EncodeToString(c.lightningNode.TlsCert()),
c.lightningNode.Macaroon(),
)
start, _, _ := strings.Cut(s, `"lnd"`)
if strings.HasPrefix(s, "export LND_MACAROON_HEX") {
split[i] = fmt.Sprintf("export LND_MACAROON_HEX=%x", c.lightningNode.Macaroon())
split[i] = start + ext
}
}
newContent := strings.Join(split, "\n")

View File

@@ -57,7 +57,7 @@ type lspBase struct {
postgresBackend *PostgresContainer
}
func newLspd(h *lntest.TestHarness, name string, envExt ...string) (*lspBase, error) {
func newLspd(h *lntest.TestHarness, name string, lnd *string, cln *string, envExt ...string) (*lspBase, error) {
scriptDir := h.GetDirectory(fmt.Sprintf("lspd-%s", name))
log.Printf("%s: Creating LSPD in dir %s", name, scriptDir)
@@ -87,14 +87,28 @@ func newLspd(h *lntest.TestHarness, name string, envExt ...string) (*lspBase, er
eciesPubl := ecies.NewPrivateKeyFromBytes(lspdPrivateKeyBytes).PublicKey
host := "localhost"
grpcAddress := fmt.Sprintf("%s:%d", host, lspdPort)
var ext string
if lnd != nil {
ext = fmt.Sprintf(`"lnd": %s`, *lnd)
} else if cln != nil {
ext = fmt.Sprintf(`"cln": %s`, *cln)
} else {
h.T.Fatalf("%s: need either lnd or cln config", name)
}
nodes := fmt.Sprintf(
`NODES='[ { "lspdPrivateKey": "%x", "token": "hello", "host": "host:port",`+
` "publicChannelAmount": "1000183", "channelAmount": "100000", "channelPrivate": false,`+
` "targetConf": "6", "minHtlcMsat": "600", "baseFeeMsat": "1000", "feeRate": "0.000001",`+
` "timeLockDelta": "144", "channelFeePermyriad": "40", "channelMinimumFeeMsat": "2000000",`+
` "additionalChannelCapacity": "100000", "maxInactiveDuration": "3888000", %s}]'`,
lspdPrivateKeyBytes,
ext,
)
env := []string{
"NODE_NAME=lsp",
"NODE_PUBKEY=dunno",
"NODE_HOST=host:port",
"TOKEN=hello",
nodes,
fmt.Sprintf("DATABASE_URL=%s", postgresBackend.ConnectionString()),
fmt.Sprintf("LISTEN_ADDRESS=%s", grpcAddress),
fmt.Sprintf("LSPD_PRIVATE_KEY=%x", lspdPrivateKeyBytes),
}
env = append(env, envExt...)