Skip to content

Commit ef47d90

Browse files
committed
itest: allow lnd node to be replaced in tapd harness
This commit allows us to update the lnd related config of a tapd harness, which will in turn allow us to connect an existing tapd node to a freshly restored lnd while keeping all the tapdb data intact.
1 parent f35de11 commit ef47d90

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

itest/tapd_harness.go

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,6 @@ func newTapdHarness(t *testing.T, ht *harnessTest, cfg tapdConfig,
150150
}
151151
}
152152

153-
if cfg.LndNode == nil || cfg.LndNode.Cfg == nil {
154-
return nil, fmt.Errorf("lnd node configuration cannot be nil")
155-
}
156-
lndMacPath := filepath.Join(
157-
cfg.LndNode.Cfg.DataDir, "chain", "bitcoin", cfg.NetParams.Name,
158-
"admin.macaroon",
159-
)
160-
161153
tapCfg := tapcfg.DefaultConfig()
162154
tapCfg.LogDir = "."
163155
tapCfg.MaxLogFiles = 99
@@ -196,10 +188,9 @@ func newTapdHarness(t *testing.T, ht *harnessTest, cfg tapdConfig,
196188
fmt.Sprintf("127.0.0.1:%d", nextAvailablePort()),
197189
}
198190

199-
tapCfg.Lnd = &tapcfg.LndConfig{
200-
Host: cfg.LndNode.Cfg.RPCAddr(),
201-
MacaroonPath: lndMacPath,
202-
TLSPath: cfg.LndNode.Cfg.TLSCertPath,
191+
// Update the config with the lnd node's connection info.
192+
if err := updateConfigWithNode(&tapCfg, cfg.LndNode); err != nil {
193+
return nil, err
203194
}
204195

205196
// Configure the universe server to ensure that valid proofs from tapd
@@ -297,6 +288,26 @@ func newTapdHarness(t *testing.T, ht *harnessTest, cfg tapdConfig,
297288
}, nil
298289
}
299290

291+
// updateConfigWithNode updates the tapd configuration with the connection
292+
// information of the given lnd node.
293+
func updateConfigWithNode(cfg *tapcfg.Config, lnd *node.HarnessNode) error {
294+
if lnd == nil || lnd.Cfg == nil {
295+
return fmt.Errorf("lnd node configuration cannot be nil")
296+
}
297+
lndMacPath := filepath.Join(
298+
lnd.Cfg.DataDir, "chain", "bitcoin", cfg.ChainConf.Network,
299+
"admin.macaroon",
300+
)
301+
302+
cfg.Lnd = &tapcfg.LndConfig{
303+
Host: lnd.Cfg.RPCAddr(),
304+
MacaroonPath: lndMacPath,
305+
TLSPath: lnd.Cfg.TLSCertPath,
306+
}
307+
308+
return nil
309+
}
310+
300311
// rpcHost returns the RPC host for the tapd server.
301312
func (hs *tapdHarness) rpcHost() string {
302313
return hs.clientCfg.RpcConf.RawRPCListeners[0]

0 commit comments

Comments
 (0)