From 5c7f22b2f2aeed27fb180f027309c7cb919ee28b Mon Sep 17 00:00:00 2001 From: Jesse de Wit Date: Tue, 3 Jan 2023 14:29:45 +0100 Subject: [PATCH] update tests to use new lspd startup --- itest/cln_lspd_node.go | 10 +++++----- itest/lnd_lspd_node.go | 28 ++++++++++++++++------------ itest/lspd_node.go | 26 ++++++++++++++++++++------ 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/itest/cln_lspd_node.go b/itest/cln_lspd_node.go index c8731d3..4080523 100644 --- a/itest/cln_lspd_node.go +++ b/itest/cln_lspd_node.go @@ -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") } diff --git a/itest/lnd_lspd_node.go b/itest/lnd_lspd_node.go index e096361..01115c0 100644 --- a/itest/lnd_lspd_node.go +++ b/itest/lnd_lspd_node.go @@ -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") diff --git a/itest/lspd_node.go b/itest/lspd_node.go index c4601bc..16ac1a2 100644 --- a/itest/lspd_node.go +++ b/itest/lspd_node.go @@ -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...)