From 3a2fd51f2f92cb96267b7284d389342d89f698ac Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 10 Oct 2018 12:55:14 +0200 Subject: [PATCH 1/3] lnd_test+lntest: move copyFile() -> lntest.CopyFile() --- lnd_test.go | 28 ++++------------------------ lntest/harness.go | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/lnd_test.go b/lnd_test.go index 719388182..681aa5f2d 100644 --- a/lnd_test.go +++ b/lnd_test.go @@ -5522,26 +5522,6 @@ func testMaxPendingChannels(net *lntest.NetworkHarness, t *harnessTest) { } } -func copyFile(dest, src string) error { - s, err := os.Open(src) - if err != nil { - return err - } - defer s.Close() - - d, err := os.Create(dest) - if err != nil { - return err - } - - if _, err := io.Copy(d, s); err != nil { - d.Close() - return err - } - - return d.Close() -} - // waitForTxInMempool polls until finding one transaction in the provided // miner's mempool. An error is returned if *one* transaction isn't found within // the given timeout. @@ -6154,7 +6134,7 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) { // With the temporary file created, copy Bob's current state into the // temporary file we created above. Later after more updates, we'll // restore this state. - if err := copyFile(bobTempDbFile, net.Bob.DBPath()); err != nil { + if err := lntest.CopyFile(bobTempDbFile, net.Bob.DBPath()); err != nil { t.Fatalf("unable to copy database files: %v", err) } @@ -6394,7 +6374,7 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness // With the temporary file created, copy Carol's current state into the // temporary file we created above. Later after more updates, we'll // restore this state. - if err := copyFile(carolTempDbFile, carol.DBPath()); err != nil { + if err := lntest.CopyFile(carolTempDbFile, carol.DBPath()); err != nil { t.Fatalf("unable to copy database files: %v", err) } @@ -6710,7 +6690,7 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness, // With the temporary file created, copy Carol's current state into the // temporary file we created above. Later after more updates, we'll // restore this state. - if err := copyFile(carolTempDbFile, carol.DBPath()); err != nil { + if err := lntest.CopyFile(carolTempDbFile, carol.DBPath()); err != nil { t.Fatalf("unable to copy database files: %v", err) } @@ -7110,7 +7090,7 @@ func testDataLossProtection(net *lntest.NetworkHarness, t *harnessTest) { // With the temporary file created, copy the current state into // the temporary file we created above. Later after more // updates, we'll restore this state. - if err := copyFile(tempDbFile, node.DBPath()); err != nil { + if err := lntest.CopyFile(tempDbFile, node.DBPath()); err != nil { t.Fatalf("unable to copy database files: %v", err) } diff --git a/lntest/harness.go b/lntest/harness.go index 1de4cb8ba..95c8bcd1b 100644 --- a/lntest/harness.go +++ b/lntest/harness.go @@ -3,7 +3,9 @@ package lntest import ( "errors" "fmt" + "io" "io/ioutil" + "os" "strings" "sync" "time" @@ -1266,3 +1268,24 @@ func (n *NetworkHarness) sendCoins(ctx context.Context, amt btcutil.Amount, expectedBalance := initialBalance.ConfirmedBalance + int64(amt) return target.WaitForBalance(expectedBalance, true) } + +// CopyFile copies the file src to dest. +func CopyFile(dest, src string) error { + s, err := os.Open(src) + if err != nil { + return err + } + defer s.Close() + + d, err := os.Create(dest) + if err != nil { + return err + } + + if _, err := io.Copy(d, s); err != nil { + d.Close() + return err + } + + return d.Close() +} From 4d05e6bbd8dd2f345ded746feee6aa1cf2ce7123 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 10 Oct 2018 13:04:13 +0200 Subject: [PATCH 2/3] lnd_test+lntest: keep btcd debug logs from test run MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Useful for debugging 🤷 --- lnd_test.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lnd_test.go b/lnd_test.go index 681aa5f2d..b8588cce7 100644 --- a/lnd_test.go +++ b/lnd_test.go @@ -12516,7 +12516,13 @@ func TestLightningNetworkDaemon(t *testing.T) { // setting of accepting non-standard transactions on simnet to reject them. // Transactions on the lightning network should always be standard to get // better guarantees of getting included in to blocks. - args := []string{"--rejectnonstd", "--txindex"} + logDir := "./.backendlogs" + args := []string{ + "--rejectnonstd", + "--txindex", + "--debuglevel=debug", + "--logdir=" + logDir, + } handlers := &rpcclient.NotificationHandlers{ OnTxAccepted: func(hash *chainhash.Hash, amt btcutil.Amount) { lndHarness.OnTxAccepted(hash) @@ -12526,7 +12532,21 @@ func TestLightningNetworkDaemon(t *testing.T) { if err != nil { ht.Fatalf("unable to create mining node: %v", err) } - defer btcdHarness.TearDown() + defer func() { + btcdHarness.TearDown() + + // After shutting down the chain backend, we'll make a copy of + // the log file before deleting the temporary log dir. + logFile := logDir + "/" + harnessNetParams.Name + "/btcd.log" + err := lntest.CopyFile("./output_btcd_chainbackend.log", + logFile) + if err != nil { + fmt.Printf("unable to copy file: %v\n", err) + } + if err = os.RemoveAll(logDir); err != nil { + fmt.Printf("Cannot remove dir %s: %v\n", logDir, err) + } + }() // First create the network harness to gain access to its // 'OnTxAccepted' call back. From 8854db51913d4e2887fa4656a6090ba66ec870de Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Mon, 29 Oct 2018 06:17:25 +0100 Subject: [PATCH 3/3] gitignore: ignore temp backend logs folder --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 2812f1653..0ed921b1f 100644 --- a/.gitignore +++ b/.gitignore @@ -29,7 +29,9 @@ lnd-debug lncli lncli-debug +# Integration test log files output*.log +/.backendlogs cmd/cmd *.key