From 2fbffab421861948bae46c1e982e1a195cc6fa9b Mon Sep 17 00:00:00 2001 From: Andras Banki-Horvath Date: Tue, 19 Mar 2024 15:18:53 +0100 Subject: [PATCH] itest: ensure that native SQL LND won't start if it has any KV invoices --- itest/list_on_test.go | 4 ++++ itest/lnd_misc_test.go | 39 +++++++++++++++++++++++++++++++++++++ lntest/node/harness_node.go | 4 ++-- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/itest/list_on_test.go b/itest/list_on_test.go index 1de36b962..7a618402f 100644 --- a/itest/list_on_test.go +++ b/itest/list_on_test.go @@ -578,4 +578,8 @@ var allTestCases = []*lntest.TestCase{ Name: "open channel locked balance", TestFunc: testOpenChannelLockedBalance, }, + { + Name: "nativesql no migration", + TestFunc: testNativeSQLNoMigration, + }, } diff --git a/itest/lnd_misc_test.go b/itest/lnd_misc_test.go index a88abb7b3..58a57ed29 100644 --- a/itest/lnd_misc_test.go +++ b/itest/lnd_misc_test.go @@ -1,6 +1,7 @@ package itest import ( + "context" "encoding/hex" "fmt" "io/ioutil" @@ -1242,3 +1243,41 @@ func testSignVerifyMessageWithAddr(ht *lntest.HarnessTest) { require.False(ht, respValid.Valid, "external signature did validate") } + +// testNativeSQLNoMigration tests that nodes that have invoices would not start +// up with native SQL enabled, as we don't currently support migration of KV +// invoices to the new SQL schema. +func testNativeSQLNoMigration(ht *lntest.HarnessTest) { + alice := ht.Alice + + // Make sure we run the test with SQLite or Postgres. + if alice.Cfg.DBBackend != node.BackendSqlite && + alice.Cfg.DBBackend != node.BackendPostgres { + + ht.Skip("node not running with SQLite or Postgres") + } + + // Skip the test if the node is already running with native SQL. + if alice.Cfg.NativeSQL { + ht.Skip("node already running with native SQL") + } + + alice.RPC.AddInvoice(&lnrpc.Invoice{ + Value: 10_000, + }) + + alice.SetExtraArgs([]string{"--db.use-native-sql"}) + + // Restart the node manually as we're really only interested in the + // startup error. + require.NoError(ht, alice.Stop()) + require.NoError(ht, alice.StartLndCmd(context.Background())) + + // We expect the node to fail to start up with native SQL enabled, as we + // have an invoice in the KV store. + require.Error(ht, alice.WaitForProcessExit()) + + // Reset the extra args and restart alice. + alice.SetExtraArgs(nil) + require.NoError(ht, alice.Start(ht.Context())) +} diff --git a/lntest/node/harness_node.go b/lntest/node/harness_node.go index 71d55d9ea..fb0eea014 100644 --- a/lntest/node/harness_node.go +++ b/lntest/node/harness_node.go @@ -629,7 +629,7 @@ func (hn *HarnessNode) cleanup() error { // waitForProcessExit Launch a new goroutine which that bubbles up any // potential fatal process errors to the goroutine running the tests. -func (hn *HarnessNode) waitForProcessExit() error { +func (hn *HarnessNode) WaitForProcessExit() error { var err error errChan := make(chan error, 1) @@ -752,7 +752,7 @@ func (hn *HarnessNode) Stop() error { } // Wait for lnd process to exit in the end. - return hn.waitForProcessExit() + return hn.WaitForProcessExit() } // CloseConn closes the grpc connection.