diff --git a/alby/alby_oauth_service_test.go b/alby/alby_oauth_service_test.go index 3b617964..ee1d9b08 100644 --- a/alby/alby_oauth_service_test.go +++ b/alby/alby_oauth_service_test.go @@ -3,19 +3,20 @@ package alby import ( "testing" - "github.com/getAlby/hub/config" - "github.com/getAlby/hub/events" - "github.com/getAlby/hub/tests" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/tyler-smith/go-bip32" "github.com/tyler-smith/go-bip39" + + "github.com/getAlby/hub/config" + "github.com/getAlby/hub/events" + "github.com/getAlby/hub/tests" ) func TestExistingEncryptedBackup(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() mnemonic := "limit reward expect search tissue call visa fit thank cream brave jump" unlockPassword := "123" @@ -40,11 +41,11 @@ func TestExistingEncryptedBackup(t *testing.T) { } func TestEncryptedBackup(t *testing.T) { - defer tests.RemoveTestService() mnemonic := "limit reward expect search tissue call visa fit thank cream brave jump" unlockPassword := "123" svc, err := tests.CreateTestServiceWithMnemonic(mnemonic, unlockPassword) require.NoError(t, err) + defer svc.Remove() albyOAuthSvc := NewAlbyOAuthService(svc.DB, svc.Cfg, svc.Keys, svc.EventPublisher) encryptedBackup, err := albyOAuthSvc.createEncryptedChannelBackup(&events.StaticChannelsBackupEvent{ diff --git a/db/db.go b/db/db.go index 7473df8f..97b106cb 100644 --- a/db/db.go +++ b/db/db.go @@ -13,24 +13,68 @@ import ( "github.com/getAlby/hub/logger" ) +type Config struct { + URI string + LogQueries bool + DriverName string +} + func NewDB(uri string, logDBQueries bool) (*gorm.DB, error) { - config := &gorm.Config{ + return NewDBWithConfig(&Config{ + URI: uri, + LogQueries: logDBQueries, + DriverName: "", + }) +} + +func NewDBWithConfig(cfg *Config) (*gorm.DB, error) { + gormConfig := &gorm.Config{ TranslateError: true, } - if logDBQueries { - config.Logger = gorm_logger.Default.LogMode(gorm_logger.Info) + if cfg.LogQueries { + gormConfig.Logger = gorm_logger.Default.LogMode(gorm_logger.Info) } - if strings.HasPrefix(uri, "postgresql://") { - return newPostgresDB(uri, config) + var ret *gorm.DB + + if IsPostgresURI(cfg.URI) { + pgConfig := postgres.Config{ + DriverName: cfg.DriverName, + DSN: cfg.URI, + } + var err error + ret, err = newPostgresDB(pgConfig, gormConfig) + if err != nil { + return nil, err + } + } else { + sqliteURI := cfg.URI + // avoid SQLITE_BUSY errors with _txlock=IMMEDIATE + if !strings.Contains(sqliteURI, "_txlock=") { + sqliteURI = sqliteURI + "?_txlock=IMMEDIATE" + } + sqliteConfig := sqlite.Config{ + DriverName: cfg.DriverName, + DSN: sqliteURI, + } + var err error + ret, err = newSqliteDB(sqliteConfig, gormConfig) + if err != nil { + return nil, err + } } - return newSqliteDB(uri, config) + err := migrations.Migrate(ret) + if err != nil { + logger.Logger.WithError(err).Error("Failed to migrate") + return nil, err + } + + return ret, nil } -func newSqliteDB(uri string, config *gorm.Config) (*gorm.DB, error) { - // avoid SQLITE_BUSY errors with _txlock=IMMEDIATE - gormDB, err := gorm.Open(sqlite.Open(uri+"?_txlock=IMMEDIATE"), config) +func newSqliteDB(sqliteConfig sqlite.Config, gormConfig *gorm.Config) (*gorm.DB, error) { + gormDB, err := gorm.Open(sqlite.New(sqliteConfig), gormConfig) if err != nil { return nil, err } @@ -75,27 +119,15 @@ func newSqliteDB(uri string, config *gorm.Config) (*gorm.DB, error) { return nil, err } - err = migrations.Migrate(gormDB) - if err != nil { - logger.Logger.WithError(err).Error("Failed to migrate") - return nil, err - } - return gormDB, nil } -func newPostgresDB(uri string, config *gorm.Config) (*gorm.DB, error) { - gormDB, err := gorm.Open(postgres.Open(uri), config) +func newPostgresDB(pgConfig postgres.Config, gormConfig *gorm.Config) (*gorm.DB, error) { + gormDB, err := gorm.Open(postgres.New(pgConfig), gormConfig) if err != nil { return nil, err } - err = migrations.Migrate(gormDB) - if err != nil { - logger.Logger.WithError(err).Error("Failed to migrate") - return nil, err - } - return gormDB, nil } @@ -120,3 +152,7 @@ func Stop(db *gorm.DB) error { } return nil } + +func IsPostgresURI(uri string) bool { + return strings.HasPrefix(uri, "postgresql://") +} diff --git a/db/migrations/202406061259_delete_content.go b/db/migrations/202406061259_delete_content.go index 1d9850e1..5c377d53 100644 --- a/db/migrations/202406061259_delete_content.go +++ b/db/migrations/202406061259_delete_content.go @@ -2,6 +2,7 @@ package migrations import ( _ "embed" + "testing" "github.com/go-gormigrate/gormigrate/v2" "gorm.io/gorm" @@ -19,8 +20,11 @@ var _202406061259_delete_content = &gormigrate.Migration{ return err } - if err := tx.Exec("VACUUM").Error; err != nil { - return err + // Cannot run when testing with txdb: VACUUM must be run outside of transaction. + if !testing.Testing() { + if err := tx.Exec("VACUUM").Error; err != nil { + return err + } } return nil diff --git a/db/migrations/202406071726_vacuum.go b/db/migrations/202406071726_vacuum.go index d405cbfd..347a16f2 100644 --- a/db/migrations/202406071726_vacuum.go +++ b/db/migrations/202406071726_vacuum.go @@ -2,6 +2,7 @@ package migrations import ( _ "embed" + "testing" "github.com/go-gormigrate/gormigrate/v2" "gorm.io/gorm" @@ -15,8 +16,11 @@ import ( var _202406071726_vacuum = &gormigrate.Migration{ ID: "202406071726_vacuum", Migrate: func(tx *gorm.DB) error { - if err := tx.Exec("VACUUM").Error; err != nil { - return err + // Cannot run when testing with txdb: VACUUM must be run outside of transaction. + if !testing.Testing() { + if err := tx.Exec("VACUUM").Error; err != nil { + return err + } } return nil diff --git a/go.mod b/go.mod index a15aafcc..d8c87c0d 100644 --- a/go.mod +++ b/go.mod @@ -32,6 +32,7 @@ require ( dario.cat/mergo v1.0.1 // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect + github.com/DATA-DOG/go-txdb v0.2.0 // indirect github.com/DataDog/datadog-go/v5 v5.3.0 // indirect github.com/DataDog/gostackparse v0.7.0 // indirect github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect diff --git a/go.sum b/go.sum index 222bf5c5..a52f9ad0 100644 --- a/go.sum +++ b/go.sum @@ -7,6 +7,8 @@ filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4 github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0= github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/DATA-DOG/go-txdb v0.2.0 h1:p1VAEZGN0U58Z5efRbI9mI6fDhcMn2+hV1sPBeOp/A8= +github.com/DATA-DOG/go-txdb v0.2.0/go.mod h1:Dqk6PhlGpMk1JZ3n8sjybgBLcW69nuijArOMubFCXM0= github.com/DataDog/appsec-internal-go v1.8.0 h1:1Tfn3LEogntRqZtf88twSApOCAAO3V+NILYhuQIo4J4= github.com/DataDog/appsec-internal-go v1.8.0/go.mod h1:wW0cRfWBo4C044jHGwYiyh5moQV2x0AhnwqMuiX7O/g= github.com/DataDog/datadog-agent/pkg/obfuscate v0.48.0 h1:bUMSNsw1iofWiju9yc1f+kBd33E3hMJtq9GuU602Iy8= diff --git a/lnclient/ldk/ldk_test.go b/lnclient/ldk/ldk_test.go index 0edf141b..a166182d 100644 --- a/lnclient/ldk/ldk_test.go +++ b/lnclient/ldk/ldk_test.go @@ -3,18 +3,19 @@ package ldk import ( "testing" - "github.com/getAlby/hub/tests" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/getAlby/hub/tests" ) func TestGetVssNodeIdentifier(t *testing.T) { mnemonic := "thought turkey ask pottery head say catalog desk pledge elbow naive mimic" expectedVssNodeIdentifier := "751636" - defer tests.RemoveTestService() svc, err := tests.CreateTestServiceWithMnemonic(mnemonic, "123") require.NoError(t, err) + defer svc.Remove() vssNodeIdentifier, err := GetVssNodeIdentifier(svc.Keys) require.NoError(t, err) @@ -25,9 +26,9 @@ func TestGetVssNodeIdentifier2(t *testing.T) { mnemonic := "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about" expectedVssNodeIdentifier := "770256" - defer tests.RemoveTestService() svc, err := tests.CreateTestServiceWithMnemonic(mnemonic, "123") require.NoError(t, err) + defer svc.Remove() vssNodeIdentifier, err := GetVssNodeIdentifier(svc.Keys) require.NoError(t, err) diff --git a/nip47/controllers/get_balance_controller_test.go b/nip47/controllers/get_balance_controller_test.go index 1db1f09c..5d2abe3d 100644 --- a/nip47/controllers/get_balance_controller_test.go +++ b/nip47/controllers/get_balance_controller_test.go @@ -25,9 +25,9 @@ const nip47GetBalanceJson = ` func TestHandleGetBalanceEvent(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() nip47Request := &models.Request{} err = json.Unmarshal([]byte(nip47GetBalanceJson), nip47Request) @@ -57,9 +57,9 @@ func TestHandleGetBalanceEvent(t *testing.T) { func TestHandleGetBalanceEvent_IsolatedApp_NoTransactions(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() nip47Request := &models.Request{} err = json.Unmarshal([]byte(nip47GetBalanceJson), nip47Request) @@ -90,9 +90,9 @@ func TestHandleGetBalanceEvent_IsolatedApp_NoTransactions(t *testing.T) { } func TestHandleGetBalanceEvent_IsolatedApp_Transactions(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() nip47Request := &models.Request{} err = json.Unmarshal([]byte(nip47GetBalanceJson), nip47Request) diff --git a/nip47/controllers/get_budget_controller_test.go b/nip47/controllers/get_budget_controller_test.go index 64df460d..f66fc820 100644 --- a/nip47/controllers/get_budget_controller_test.go +++ b/nip47/controllers/get_budget_controller_test.go @@ -26,9 +26,9 @@ const nip47GetBudgetJson = ` func TestHandleGetBudgetEvent_NoRenewal(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() nip47Request := &models.Request{} err = json.Unmarshal([]byte(nip47GetBudgetJson), nip47Request) @@ -71,9 +71,9 @@ func TestHandleGetBudgetEvent_NoRenewal(t *testing.T) { func TestHandleGetBudgetEvent_NoneUsed(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() nip47Request := &models.Request{} err = json.Unmarshal([]byte(nip47GetBudgetJson), nip47Request) @@ -118,9 +118,9 @@ func TestHandleGetBudgetEvent_NoneUsed(t *testing.T) { func TestHandleGetBudgetEvent_HalfUsed(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() nip47Request := &models.Request{} err = json.Unmarshal([]byte(nip47GetBudgetJson), nip47Request) @@ -172,9 +172,9 @@ func TestHandleGetBudgetEvent_HalfUsed(t *testing.T) { func TestHandleGetBudgetEvent_NoBudget(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() nip47Request := &models.Request{} err = json.Unmarshal([]byte(nip47GetBudgetJson), nip47Request) @@ -219,9 +219,9 @@ func TestHandleGetBudgetEvent_NoBudget(t *testing.T) { func TestHandleGetBudgetEvent_NoPayInvoicePermission(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() nip47Request := &models.Request{} err = json.Unmarshal([]byte(nip47GetBudgetJson), nip47Request) diff --git a/nip47/controllers/get_info_controller_test.go b/nip47/controllers/get_info_controller_test.go index 0ec97f4a..796e8488 100644 --- a/nip47/controllers/get_info_controller_test.go +++ b/nip47/controllers/get_info_controller_test.go @@ -25,9 +25,9 @@ const nip47GetInfoJson = ` func TestHandleGetInfoEvent_NoPermission(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -74,9 +74,9 @@ func TestHandleGetInfoEvent_NoPermission(t *testing.T) { func TestHandleGetInfoEvent_WithPermission(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -122,9 +122,9 @@ func TestHandleGetInfoEvent_WithPermission(t *testing.T) { func TestHandleGetInfoEvent_WithNotifications(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) diff --git a/nip47/controllers/list_transactions_controller_test.go b/nip47/controllers/list_transactions_controller_test.go index 4f5321aa..68e66e12 100644 --- a/nip47/controllers/list_transactions_controller_test.go +++ b/nip47/controllers/list_transactions_controller_test.go @@ -20,9 +20,9 @@ import ( func TestHandleListTransactionsEvent(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() const nip47ListTransactionsJson = ` { @@ -98,9 +98,9 @@ func TestHandleListTransactionsEvent(t *testing.T) { func TestHandleListTransactionsEvent_UnpaidOutgoingOnly(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() const nip47ListTransactionsJson = ` { @@ -160,9 +160,9 @@ func TestHandleListTransactionsEvent_UnpaidOutgoingOnly(t *testing.T) { func TestHandleListTransactionsEvent_UnpaidIncomingOnly(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() const nip47ListTransactionsJson = ` { @@ -222,9 +222,9 @@ func TestHandleListTransactionsEvent_UnpaidIncomingOnly(t *testing.T) { func TestHandleListTransactionsEvent_Unpaid(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() const nip47ListTransactionsJson = ` { @@ -282,9 +282,9 @@ func TestHandleListTransactionsEvent_Unpaid(t *testing.T) { func TestHandleListTransactionsEvent_Paid(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() const nip47ListTransactionsJson = ` { diff --git a/nip47/controllers/lookup_invoice_controller_test.go b/nip47/controllers/lookup_invoice_controller_test.go index 8cc61d64..6304b697 100644 --- a/nip47/controllers/lookup_invoice_controller_test.go +++ b/nip47/controllers/lookup_invoice_controller_test.go @@ -28,9 +28,9 @@ var nip47LookupInvoiceJson = ` func TestHandleLookupInvoiceEvent(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() nip47Request := &models.Request{} err = json.Unmarshal([]byte(nip47LookupInvoiceJson), nip47Request) diff --git a/nip47/controllers/make_invoice_controller_test.go b/nip47/controllers/make_invoice_controller_test.go index 980cba3b..1930eb88 100644 --- a/nip47/controllers/make_invoice_controller_test.go +++ b/nip47/controllers/make_invoice_controller_test.go @@ -41,9 +41,9 @@ const nip47MakeInvoiceJson = ` func TestHandleMakeInvoiceEvent(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() nip47Request := &models.Request{} err = json.Unmarshal([]byte(nip47MakeInvoiceJson), nip47Request) diff --git a/nip47/controllers/multi_pay_invoice_controller_test.go b/nip47/controllers/multi_pay_invoice_controller_test.go index 26981f04..c7fb72a6 100644 --- a/nip47/controllers/multi_pay_invoice_controller_test.go +++ b/nip47/controllers/multi_pay_invoice_controller_test.go @@ -73,9 +73,9 @@ const MockExpiredPaymentHash = "320c2c5a1492ccfd5bc7aa4ad9b657d6aaec3cfcc0d1d984 func TestHandleMultiPayInvoiceEvent_Success(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() var preimages = []string{"123preimage", "123preimage2"} @@ -151,9 +151,9 @@ func TestHandleMultiPayInvoiceEvent_Success(t *testing.T) { func TestHandleMultiPayInvoiceEvent_OneMalformedInvoice(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -212,9 +212,9 @@ func TestHandleMultiPayInvoiceEvent_OneMalformedInvoice(t *testing.T) { func TestHandleMultiPayInvoiceEvent_OneExpiredInvoice(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -274,9 +274,9 @@ func TestHandleMultiPayInvoiceEvent_OneExpiredInvoice(t *testing.T) { func TestHandleMultiPayInvoiceEvent_IsolatedApp_OneBudgetExceeded(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -356,9 +356,9 @@ func TestHandleMultiPayInvoiceEvent_LNClient_OnePaymentFailed(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() svc.LNClient.(*tests.MockLn).PayInvoiceResponses = []*lnclient.PayInvoiceResponse{{ Preimage: "123preimage", }, nil} diff --git a/nip47/controllers/multi_pay_keysend_controller_test.go b/nip47/controllers/multi_pay_keysend_controller_test.go index 9fdbbb1c..0956dd77 100644 --- a/nip47/controllers/multi_pay_keysend_controller_test.go +++ b/nip47/controllers/multi_pay_keysend_controller_test.go @@ -71,9 +71,9 @@ const nip47MultiPayKeysendOneOverflowingBudgetJson = ` func TestHandleMultiPayKeysendEvent_Success(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -122,9 +122,9 @@ func TestHandleMultiPayKeysendEvent_Success(t *testing.T) { func TestHandleMultiPayKeysendEvent_OneBudgetExceeded(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) diff --git a/nip47/controllers/pay_invoice_controller_test.go b/nip47/controllers/pay_invoice_controller_test.go index 4c474c74..0e21cd80 100644 --- a/nip47/controllers/pay_invoice_controller_test.go +++ b/nip47/controllers/pay_invoice_controller_test.go @@ -56,9 +56,9 @@ const nip47PayJsonExpiredInvoice = ` func TestHandlePayInvoiceEvent(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -107,9 +107,9 @@ func TestHandlePayInvoiceEvent(t *testing.T) { func TestHandlePayInvoiceEvent_0Amount(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -152,9 +152,9 @@ func TestHandlePayInvoiceEvent_0Amount(t *testing.T) { func TestHandlePayInvoiceEvent_MalformedInvoice(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -193,9 +193,9 @@ func TestHandlePayInvoiceEvent_MalformedInvoice(t *testing.T) { func TestHandlePayInvoiceEvent_ExpiredInvoice(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) diff --git a/nip47/controllers/pay_keysend_controller_test.go b/nip47/controllers/pay_keysend_controller_test.go index a5e2c476..938c9510 100644 --- a/nip47/controllers/pay_keysend_controller_test.go +++ b/nip47/controllers/pay_keysend_controller_test.go @@ -48,9 +48,9 @@ const nip47KeysendJsonWithPreimage = ` func TestHandlePayKeysendEvent(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -89,9 +89,9 @@ func TestHandlePayKeysendEvent(t *testing.T) { } func TestHandlePayKeysendEvent_WithPreimage(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) diff --git a/nip47/event_handler_legacy_test.go b/nip47/event_handler_legacy_test.go index 68b8c048..bcf6ff80 100644 --- a/nip47/event_handler_legacy_test.go +++ b/nip47/event_handler_legacy_test.go @@ -6,20 +6,21 @@ import ( "slices" "testing" + "github.com/nbd-wtf/go-nostr" + "github.com/nbd-wtf/go-nostr/nip04" + "github.com/stretchr/testify/assert" + "github.com/getAlby/hub/constants" "github.com/getAlby/hub/db" "github.com/getAlby/hub/nip47/models" "github.com/getAlby/hub/nip47/permissions" "github.com/getAlby/hub/tests" - "github.com/nbd-wtf/go-nostr" - "github.com/nbd-wtf/go-nostr/nip04" - "github.com/stretchr/testify/assert" ) func TestHandleResponse_LegacyApp_WithPermission(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() assert.NoError(t, err) + defer svc.Remove() nip47svc := NewNip47Service(svc.DB, svc.Cfg, svc.Keys, svc.EventPublisher) reqPrivateKey := nostr.GeneratePrivateKey() @@ -87,9 +88,9 @@ func TestHandleResponse_LegacyApp_WithPermission(t *testing.T) { } func TestHandleResponse_LegacyApp_NoPermission(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() assert.NoError(t, err) + defer svc.Remove() nip47svc := NewNip47Service(svc.DB, svc.Cfg, svc.Keys, svc.EventPublisher) reqPrivateKey := nostr.GeneratePrivateKey() @@ -140,9 +141,9 @@ func TestHandleResponse_LegacyApp_NoPermission(t *testing.T) { } func TestHandleResponse_LegacyApp_IncorrectPubkey(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() assert.NoError(t, err) + defer svc.Remove() nip47svc := NewNip47Service(svc.DB, svc.Cfg, svc.Keys, svc.EventPublisher) reqPrivateKey := nostr.GeneratePrivateKey() diff --git a/nip47/event_handler_test.go b/nip47/event_handler_test.go index 342f8fc9..84ec4897 100644 --- a/nip47/event_handler_test.go +++ b/nip47/event_handler_test.go @@ -7,15 +7,16 @@ import ( "testing" "time" + "github.com/nbd-wtf/go-nostr" + "github.com/nbd-wtf/go-nostr/nip04" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/getAlby/hub/constants" "github.com/getAlby/hub/db" "github.com/getAlby/hub/nip47/models" "github.com/getAlby/hub/nip47/permissions" "github.com/getAlby/hub/tests" - "github.com/nbd-wtf/go-nostr" - "github.com/nbd-wtf/go-nostr/nip04" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) // TODO: test HandleEvent @@ -23,9 +24,9 @@ import ( // TODO: test if an app doesn't exist it returns the right error code func TestCreateResponse(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() reqPrivateKey := nostr.GeneratePrivateKey() reqPubkey, err := nostr.GetPublicKey(reqPrivateKey) @@ -75,9 +76,9 @@ func TestCreateResponse(t *testing.T) { } func TestHandleResponse_WithPermission(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() nip47svc := NewNip47Service(svc.DB, svc.Cfg, svc.Keys, svc.EventPublisher) reqPrivateKey := nostr.GeneratePrivateKey() @@ -145,9 +146,9 @@ func TestHandleResponse_WithPermission(t *testing.T) { } func TestHandleResponse_DuplicateRequest(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() nip47svc := NewNip47Service(svc.DB, svc.Cfg, svc.Keys, svc.EventPublisher) reqPrivateKey := nostr.GeneratePrivateKey() @@ -201,9 +202,9 @@ func TestHandleResponse_DuplicateRequest(t *testing.T) { } func TestHandleResponse_NoPermission(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() nip47svc := NewNip47Service(svc.DB, svc.Cfg, svc.Keys, svc.EventPublisher) reqPrivateKey := nostr.GeneratePrivateKey() @@ -254,9 +255,9 @@ func TestHandleResponse_NoPermission(t *testing.T) { } func TestHandleResponse_NoApp(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() nip47svc := NewNip47Service(svc.DB, svc.Cfg, svc.Keys, svc.EventPublisher) reqPrivateKey := nostr.GeneratePrivateKey() @@ -299,9 +300,9 @@ func TestHandleResponse_NoApp(t *testing.T) { } func TestHandleResponse_OldRequestForPayment(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() nip47svc := NewNip47Service(svc.DB, svc.Cfg, svc.Keys, svc.EventPublisher) reqPrivateKey := nostr.GeneratePrivateKey() @@ -356,9 +357,9 @@ func TestHandleResponse_OldRequestForPayment(t *testing.T) { } func TestHandleResponse_IncorrectPubkey(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() nip47svc := NewNip47Service(svc.DB, svc.Cfg, svc.Keys, svc.EventPublisher) reqPrivateKey := nostr.GeneratePrivateKey() diff --git a/nip47/notifications/nip47_notifier_test.go b/nip47/notifications/nip47_notifier_test.go index 6f514255..7b38a249 100644 --- a/nip47/notifications/nip47_notifier_test.go +++ b/nip47/notifications/nip47_notifier_test.go @@ -3,10 +3,15 @@ package notifications import ( "context" "encoding/json" - "github.com/nbd-wtf/go-nostr" "testing" "time" + "github.com/nbd-wtf/go-nostr" + + "github.com/nbd-wtf/go-nostr/nip04" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/getAlby/hub/constants" "github.com/getAlby/hub/db" "github.com/getAlby/hub/events" @@ -14,9 +19,6 @@ import ( "github.com/getAlby/hub/nip47/permissions" "github.com/getAlby/hub/tests" "github.com/getAlby/hub/transactions" - "github.com/nbd-wtf/go-nostr/nip04" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) type mockConsumer struct { @@ -108,9 +110,9 @@ func doTestSendNotificationPaymentReceived(t *testing.T, svc *tests.TestService, } func TestSendNotification_PaymentReceived(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, ss, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -118,9 +120,9 @@ func TestSendNotification_PaymentReceived(t *testing.T) { } func TestSendNotification_Legacy_PaymentReceived(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, ss, err := tests.CreateLegacyApp(svc, nostr.GeneratePrivateKey()) assert.NoError(t, err) @@ -201,9 +203,9 @@ func doTestSendNotificationPaymentSent(t *testing.T, svc *tests.TestService, app } func TestSendNotification_PaymentSent(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, ss, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -211,9 +213,9 @@ func TestSendNotification_PaymentSent(t *testing.T) { } func TestSendNotification_Legacy_PaymentSent(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, ss, err := tests.CreateLegacyApp(svc, nostr.GeneratePrivateKey()) assert.NoError(t, err) @@ -254,16 +256,16 @@ func doTestSendNotificationNoPermission(t *testing.T, svc *tests.TestService) { } func TestSendNotification_NoPermission(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() _, _, err = tests.CreateApp(svc) assert.NoError(t, err) doTestSendNotificationNoPermission(t, svc) } func TestSendNotification_Legacy_NoPermission(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() + defer svc.Remove() require.NoError(t, err) _, _, err = tests.CreateLegacyApp(svc, nostr.GeneratePrivateKey()) assert.NoError(t, err) diff --git a/nip47/permissions/permissions_test.go b/nip47/permissions/permissions_test.go index 8424c53e..7d00cd5c 100644 --- a/nip47/permissions/permissions_test.go +++ b/nip47/permissions/permissions_test.go @@ -4,18 +4,19 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/getAlby/hub/constants" "github.com/getAlby/hub/db" "github.com/getAlby/hub/nip47/models" "github.com/getAlby/hub/tests" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestHasPermission_NoPermission(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -28,9 +29,9 @@ func TestHasPermission_NoPermission(t *testing.T) { } func TestHasPermission_Expired(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -85,9 +86,9 @@ func TestHasPermission_Expired(t *testing.T) { }*/ func TestHasPermission_OK(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -113,9 +114,9 @@ func TestHasPermission_OK(t *testing.T) { } func TestRequestMethodToScope_GetBudget(t *testing.T) { - defer tests.RemoveTestService() - _, err := tests.CreateTestService() + svc, err := tests.CreateTestService() assert.NoError(t, err) + defer svc.Remove() scope, err := RequestMethodToScope(models.GET_BUDGET_METHOD) assert.NoError(t, err) @@ -123,9 +124,9 @@ func TestRequestMethodToScope_GetBudget(t *testing.T) { } func TestRequestMethodsToScopes_GetBudget(t *testing.T) { - defer tests.RemoveTestService() - _, err := tests.CreateTestService() + svc, err := tests.CreateTestService() assert.NoError(t, err) + defer svc.Remove() scopes, err := RequestMethodsToScopes([]string{models.GET_BUDGET_METHOD}) assert.NoError(t, err) @@ -145,9 +146,9 @@ func TestRequestMethodsToScopes_GetInfo(t *testing.T) { } func TestGetPermittedMethods_AlwaysGranted(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -158,9 +159,9 @@ func TestGetPermittedMethods_AlwaysGranted(t *testing.T) { } func TestGetPermittedMethods_PayInvoiceScopeGivesAllPaymentMethods(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) diff --git a/service/keys/keys_test.go b/service/keys/keys_test.go index 08758740..90a72452 100644 --- a/service/keys/keys_test.go +++ b/service/keys/keys_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/getAlby/hub/config" - "github.com/getAlby/hub/db" + "github.com/getAlby/hub/tests/db" + "github.com/nbd-wtf/go-nostr" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -13,11 +14,10 @@ import ( "github.com/tyler-smith/go-bip39" ) -const testDB = "test.db" - func TestUseExistingMnemonic(t *testing.T) { - gormDb, err := db.NewDB(testDB, true) + gormDb, err := db.NewDB() require.NoError(t, err) + defer db.CloseDB(gormDb) mnemonic := "thought turkey ask pottery head say catalog desk pledge elbow naive mimic" unlockPassword := "123" @@ -59,8 +59,9 @@ func TestUseExistingMnemonic(t *testing.T) { } func TestGenerateNewMnemonic(t *testing.T) { - gormDb, err := db.NewDB(testDB, true) + gormDb, err := db.NewDB() require.NoError(t, err) + defer db.CloseDB(gormDb) unlockPassword := "123" diff --git a/tests/db/test_db.go b/tests/db/test_db.go new file mode 100644 index 00000000..70c6a814 --- /dev/null +++ b/tests/db/test_db.go @@ -0,0 +1,57 @@ +package db + +import ( + "os" + "testing" + + "github.com/DATA-DOG/go-txdb" + "gorm.io/gorm" + + "github.com/getAlby/hub/db" +) + +const defaultTestDB = "test.db" +const testDriver = "txdb" + +func init() { + if testing.Testing() { + uri := GetTestDatabaseURI() + if db.IsPostgresURI(uri) { + txdb.Register(testDriver, "pgx", uri) + } + } +} + +func GetTestDatabaseURI() string { + ret := os.Getenv("TEST_DATABASE_URI") + if ret == "" { + // TODO: use in-memory DB, or a temporary file + return defaultTestDB + } + + return ret +} + +func NewDB() (*gorm.DB, error) { + uri := GetTestDatabaseURI() + driverName := "" + if db.IsPostgresURI(uri) { + driverName = testDriver + } + + return db.NewDBWithConfig(&db.Config{ + URI: uri, + LogQueries: true, + DriverName: driverName, + }) +} + +func CloseDB(d *gorm.DB) { + if err := db.Stop(d); err != nil { + panic("failed to close database: " + err.Error()) + } + + if GetTestDatabaseURI() == defaultTestDB { + os.Remove(defaultTestDB) + } +} diff --git a/tests/test_service.go b/tests/test_service.go index 8c124ea7..f968a4aa 100644 --- a/tests/test_service.go +++ b/tests/test_service.go @@ -1,29 +1,27 @@ package tests import ( - "os" "strconv" "github.com/getAlby/hub/apps" + "github.com/getAlby/hub/tests/db" + + "github.com/sirupsen/logrus" + "gorm.io/gorm" "github.com/getAlby/hub/config" - "github.com/getAlby/hub/db" "github.com/getAlby/hub/events" "github.com/getAlby/hub/lnclient" "github.com/getAlby/hub/logger" "github.com/getAlby/hub/service/keys" - "github.com/sirupsen/logrus" - "gorm.io/gorm" ) -const testDB = "test.db" - func CreateTestService() (svc *TestService, err error) { return CreateTestServiceWithMnemonic("", "") } func CreateTestServiceWithMnemonic(mnemonic string, unlockPassword string) (svc *TestService, err error) { - gormDb, err := db.NewDB(testDB, true) + gormDb, err := db.NewDB() if err != nil { return nil, err } @@ -49,10 +47,14 @@ func CreateTestServiceWithMnemonic(mnemonic string, unlockPassword string) (svc keys := keys.NewKeys() if mnemonic != "" { - cfg.SetUpdate("Mnemonic", mnemonic, unlockPassword) + if err = cfg.SetUpdate("Mnemonic", mnemonic, unlockPassword); err != nil { + return nil, err + } } - keys.Init(cfg, unlockPassword) + if err = keys.Init(cfg, unlockPassword); err != nil { + return nil, err + } eventPublisher := events.NewEventPublisher() @@ -77,6 +79,6 @@ type TestService struct { DB *gorm.DB } -func RemoveTestService() { - os.Remove(testDB) +func (s *TestService) Remove() { + db.CloseDB(s.DB) } diff --git a/transactions/app_payments_test.go b/transactions/app_payments_test.go index 7ecfa18b..2237c5af 100644 --- a/transactions/app_payments_test.go +++ b/transactions/app_payments_test.go @@ -5,19 +5,20 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/getAlby/hub/constants" "github.com/getAlby/hub/db" "github.com/getAlby/hub/tests" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestSendPaymentSync_App_NoPermission(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -36,9 +37,9 @@ func TestSendPaymentSync_App_NoPermission(t *testing.T) { func TestSendPaymentSync_App_WithPermission(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -69,9 +70,9 @@ func TestSendPaymentSync_App_WithPermission(t *testing.T) { func TestSendPaymentSync_App_BudgetExceeded(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -110,9 +111,9 @@ func TestSendPaymentSync_App_BudgetExceeded(t *testing.T) { func TestSendPaymentSync_App_BudgetExceeded_SettledPayment(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -149,9 +150,9 @@ func TestSendPaymentSync_App_BudgetExceeded_SettledPayment(t *testing.T) { func TestSendPaymentSync_App_BudgetExceeded_UnsettledPayment(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -189,9 +190,9 @@ func TestSendPaymentSync_App_BudgetExceeded_UnsettledPayment(t *testing.T) { func TestSendPaymentSync_App_BudgetNotExceeded_FailedPayment(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) diff --git a/transactions/check_unsettled_transaction_test.go b/transactions/check_unsettled_transaction_test.go index db3da93e..39e0c9c2 100644 --- a/transactions/check_unsettled_transaction_test.go +++ b/transactions/check_unsettled_transaction_test.go @@ -5,18 +5,19 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/getAlby/hub/constants" "github.com/getAlby/hub/db" "github.com/getAlby/hub/lnclient" "github.com/getAlby/hub/tests" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestCheckUnsettledTransaction(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() dbTransaction := db.Transaction{ State: constants.TRANSACTION_STATE_PENDING, @@ -51,9 +52,9 @@ func TestCheckUnsettledTransaction(t *testing.T) { } func TestCheckUnsettledTransactions(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() dbTransaction := db.Transaction{ State: constants.TRANSACTION_STATE_PENDING, diff --git a/transactions/isolated_app_payments_test.go b/transactions/isolated_app_payments_test.go index f0454d84..c93b539d 100644 --- a/transactions/isolated_app_payments_test.go +++ b/transactions/isolated_app_payments_test.go @@ -4,19 +4,20 @@ import ( "context" "testing" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/getAlby/hub/constants" "github.com/getAlby/hub/db" "github.com/getAlby/hub/tests" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestSendPaymentSync_IsolatedApp_NoBalance(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -46,9 +47,9 @@ func TestSendPaymentSync_IsolatedApp_NoBalance(t *testing.T) { func TestSendPaymentSync_IsolatedApp_BalanceInsufficient(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -95,9 +96,9 @@ func TestSendPaymentSync_IsolatedApp_BalanceInsufficient(t *testing.T) { func TestSendPaymentSync_IsolatedApp_BalanceSufficient(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -137,9 +138,9 @@ func TestSendPaymentSync_IsolatedApp_BalanceSufficient(t *testing.T) { func TestSendPaymentSync_IsolatedApp_BalanceInsufficient_OutstandingPayment(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -183,9 +184,9 @@ func TestSendPaymentSync_IsolatedApp_BalanceInsufficient_OutstandingPayment(t *t func TestSendPaymentSync_IsolatedApp_BalanceInsufficient_SettledPayment(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -229,9 +230,9 @@ func TestSendPaymentSync_IsolatedApp_BalanceInsufficient_SettledPayment(t *testi func TestSendPaymentSync_IsolatedApp_BalanceSufficient_UnrelatedPayment(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -277,9 +278,9 @@ func TestSendPaymentSync_IsolatedApp_BalanceSufficient_UnrelatedPayment(t *testi func TestSendPaymentSync_IsolatedApp_BalanceSufficient_FailedPayment(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) diff --git a/transactions/keysend_test.go b/transactions/keysend_test.go index 94302827..feb3f0af 100644 --- a/transactions/keysend_test.go +++ b/transactions/keysend_test.go @@ -7,21 +7,22 @@ import ( "strconv" "testing" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/getAlby/hub/constants" "github.com/getAlby/hub/db" "github.com/getAlby/hub/db/queries" "github.com/getAlby/hub/lnclient" "github.com/getAlby/hub/tests" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestSendKeysend(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() mockEventConsumer := tests.NewMockEventConsumer() svc.EventPublisher.RegisterSubscriber(mockEventConsumer) @@ -51,9 +52,9 @@ func TestSendKeysend(t *testing.T) { func TestSendKeysend_CustomPreimage(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() customPreimage := "018465013e2337234a7e5530a21c4a8cf70d84231f4a8ff0b1e2cce3cb2bd03b" transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher) @@ -77,9 +78,9 @@ func TestSendKeysend_CustomPreimage(t *testing.T) { func TestSendKeysend_App_NoPermission(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -99,9 +100,9 @@ func TestSendKeysend_App_NoPermission(t *testing.T) { func TestSendKeysend_App_WithPermission(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -141,9 +142,9 @@ func TestSendKeysend_App_WithPermission(t *testing.T) { func TestSendKeysend_App_BudgetExceeded(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -179,9 +180,9 @@ func TestSendKeysend_App_BudgetExceeded(t *testing.T) { func TestSendKeysend_App_BudgetNotExceeded(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -222,9 +223,9 @@ func TestSendKeysend_App_BudgetNotExceeded(t *testing.T) { func TestSendKeysend_App_BalanceExceeded(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -260,9 +261,9 @@ func TestSendKeysend_App_BalanceExceeded(t *testing.T) { func TestSendKeysend_App_BalanceSufficient(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) @@ -311,9 +312,9 @@ func TestSendKeysend_App_BalanceSufficient(t *testing.T) { func TestSendKeysend_TLVs(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher) transaction, err := transactionsService.SendKeysend(ctx, uint64(1000), "fake destination", []lnclient.TLVRecord{ @@ -359,9 +360,9 @@ func TestSendKeysend_TLVs(t *testing.T) { func TestSendKeysend_IsolatedAppToNoApp(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() // setup for self payment svc.LNClient.(*tests.MockLn).Pubkey = "03cbd788f5b22bd56e2714bff756372d2293504c064e03250ed16a4dd80ad70e2c" @@ -424,9 +425,9 @@ func TestSendKeysend_IsolatedAppToNoApp(t *testing.T) { func TestSendKeysend_IsolatedAppToIsolatedApp(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() // setup for self payment svc.LNClient.(*tests.MockLn).Pubkey = "03cbd788f5b22bd56e2714bff756372d2293504c064e03250ed16a4dd80ad70e2c" diff --git a/transactions/list_transactions_test.go b/transactions/list_transactions_test.go index cd0bf142..4b8fd600 100644 --- a/transactions/list_transactions_test.go +++ b/transactions/list_transactions_test.go @@ -5,19 +5,20 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/getAlby/hub/constants" "github.com/getAlby/hub/db" "github.com/getAlby/hub/tests" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestListTransactions_Paid(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() mockPreimage := tests.MockLNClientTransaction.Preimage svc.DB.Create(&db.Transaction{ @@ -59,9 +60,9 @@ func TestListTransactions_Paid(t *testing.T) { func TestListTransactions_UnpaidIncoming(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() mockPreimage := tests.MockLNClientTransaction.Preimage svc.DB.Create(&db.Transaction{ @@ -126,9 +127,9 @@ func TestListTransactions_UnpaidIncoming(t *testing.T) { func TestListTransactions_UnpaidOutgoing(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() mockPreimage := tests.MockLNClientTransaction.Preimage svc.DB.Create(&db.Transaction{ @@ -193,9 +194,9 @@ func TestListTransactions_UnpaidOutgoing(t *testing.T) { func TestListTransactions_Unpaid(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() mockPreimage := tests.MockLNClientTransaction.Preimage svc.DB.Create(&db.Transaction{ @@ -254,9 +255,9 @@ func TestListTransactions_Unpaid(t *testing.T) { func TestListTransactions_Limit(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() mockPreimage := tests.MockLNClientTransaction.Preimage svc.DB.Create(&db.Transaction{ @@ -290,9 +291,9 @@ func TestListTransactions_Limit(t *testing.T) { func TestListTransactions_Offset(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() mockPreimage := tests.MockLNClientTransaction.Preimage svc.DB.Create(&db.Transaction{ @@ -346,9 +347,9 @@ func TestListTransactions_Offset(t *testing.T) { func TestListTransactions_FromUntil(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() mockPreimage := tests.MockLNClientTransaction.Preimage svc.DB.Create(&db.Transaction{ @@ -396,9 +397,9 @@ func TestListTransactions_FromUntil(t *testing.T) { func TestListTransactions_FromUntilUnpaidOutgoing(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() mockPreimage := tests.MockLNClientTransaction.Preimage svc.DB.Create(&db.Transaction{ @@ -458,9 +459,9 @@ func TestListTransactions_FromUntilUnpaidOutgoing(t *testing.T) { func TestListTransactions_FromUntilUnpaidIncoming(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() mockPreimage := tests.MockLNClientTransaction.Preimage svc.DB.Create(&db.Transaction{ diff --git a/transactions/lookup_transaction_test.go b/transactions/lookup_transaction_test.go index af64507c..a9dadab8 100644 --- a/transactions/lookup_transaction_test.go +++ b/transactions/lookup_transaction_test.go @@ -4,19 +4,20 @@ import ( "context" "testing" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/getAlby/hub/constants" "github.com/getAlby/hub/db" "github.com/getAlby/hub/tests" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestLookupTransaction_IncomingPayment(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() mockPreimage := tests.MockLNClientTransaction.Preimage svc.DB.Create(&db.Transaction{ @@ -41,9 +42,9 @@ func TestLookupTransaction_IncomingPayment(t *testing.T) { func TestLookupTransaction_OutgoingPayment(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() mockPreimage := tests.MockLNClientTransaction.Preimage svc.DB.Create(&db.Transaction{ diff --git a/transactions/make_invoice_test.go b/transactions/make_invoice_test.go index 58781c49..f0b76bcf 100644 --- a/transactions/make_invoice_test.go +++ b/transactions/make_invoice_test.go @@ -7,19 +7,20 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/getAlby/hub/constants" "github.com/getAlby/hub/db" "github.com/getAlby/hub/tests" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestMakeInvoice_NoApp(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() txMetadata := make(map[string]interface{}) txMetadata["randomkey"] = strings.Repeat("a", constants.INVOICE_METADATA_MAX_LENGTH-16) // json encoding adds 16 characters - {"randomkey":""} @@ -41,9 +42,9 @@ func TestMakeInvoice_NoApp(t *testing.T) { func TestMakeInvoice_MetadataTooLarge(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() metadata := make(map[string]interface{}) metadata["randomkey"] = strings.Repeat("a", constants.INVOICE_METADATA_MAX_LENGTH-15) // json encoding adds 16 characters @@ -59,9 +60,9 @@ func TestMakeInvoice_MetadataTooLarge(t *testing.T) { func TestMakeInvoice_App(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() app, _, err := tests.CreateApp(svc) assert.NoError(t, err) diff --git a/transactions/notifications_test.go b/transactions/notifications_test.go index fe5c7407..bba35f67 100644 --- a/transactions/notifications_test.go +++ b/transactions/notifications_test.go @@ -5,21 +5,22 @@ import ( "encoding/json" "testing" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/getAlby/hub/constants" "github.com/getAlby/hub/db" "github.com/getAlby/hub/events" "github.com/getAlby/hub/lnclient" "github.com/getAlby/hub/tests" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestNotifications_ReceivedKnownPayment(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() mockPreimage := tests.MockLNClientTransaction.Preimage svc.DB.Create(&db.Transaction{ @@ -53,9 +54,9 @@ func TestNotifications_ReceivedKnownPayment(t *testing.T) { func TestNotifications_ReceivedUnknownPayment(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher) @@ -80,9 +81,9 @@ func TestNotifications_ReceivedUnknownPayment(t *testing.T) { func TestNotifications_ReceivedKeysend(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher) @@ -146,9 +147,9 @@ func TestNotifications_ReceivedKeysend(t *testing.T) { func TestNotifications_SentKnownPayment(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() svc.DB.Create(&db.Transaction{ State: constants.TRANSACTION_STATE_PENDING, @@ -182,9 +183,9 @@ func TestNotifications_SentKnownPayment(t *testing.T) { func TestNotifications_SentUnknownPayment(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher) @@ -206,9 +207,9 @@ func TestNotifications_SentUnknownPayment(t *testing.T) { func TestNotifications_FailedKnownPayment(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() svc.DB.Create(&db.Transaction{ State: constants.TRANSACTION_STATE_PENDING, diff --git a/transactions/payments_test.go b/transactions/payments_test.go index 298ecb14..085492af 100644 --- a/transactions/payments_test.go +++ b/transactions/payments_test.go @@ -9,21 +9,22 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "gorm.io/gorm" + "github.com/getAlby/hub/constants" "github.com/getAlby/hub/db" "github.com/getAlby/hub/lnclient" "github.com/getAlby/hub/tests" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "gorm.io/gorm" ) func TestSendPaymentSync_NoApp(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() metadata := map[string]interface{}{ "a": 123, @@ -50,9 +51,9 @@ func TestSendPaymentSync_NoApp(t *testing.T) { func TestSendPaymentSync_0Amount(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() metadata := map[string]interface{}{ "a": 123, @@ -72,9 +73,9 @@ func TestSendPaymentSync_0Amount(t *testing.T) { func TestSendPaymentSync_MetadataTooLarge(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() metadata := make(map[string]interface{}) metadata["randomkey"] = strings.Repeat("a", constants.INVOICE_METADATA_MAX_LENGTH-15) // json encoding adds 16 characters @@ -90,9 +91,9 @@ func TestSendPaymentSync_MetadataTooLarge(t *testing.T) { func TestSendPaymentSync_Duplicate(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() svc.DB.Create(&db.Transaction{ State: constants.TRANSACTION_STATE_SETTLED, @@ -110,9 +111,9 @@ func TestSendPaymentSync_Duplicate(t *testing.T) { } func TestMarkSettled_Sent(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() dbTransaction := db.Transaction{ State: constants.TRANSACTION_STATE_PENDING, @@ -139,9 +140,9 @@ func TestMarkSettled_Sent(t *testing.T) { } func TestMarkSettled_Received(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() dbTransaction := db.Transaction{ State: constants.TRANSACTION_STATE_PENDING, @@ -168,9 +169,9 @@ func TestMarkSettled_Received(t *testing.T) { } func TestDoNotMarkSettledTwice(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() settledAt := time.Now().Add(time.Duration(-1) * time.Minute) dbTransaction := db.Transaction{ @@ -195,9 +196,9 @@ func TestDoNotMarkSettledTwice(t *testing.T) { } func TestMarkFailed(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() dbTransaction := db.Transaction{ State: constants.TRANSACTION_STATE_PENDING, @@ -224,9 +225,9 @@ func TestMarkFailed(t *testing.T) { } func TestDoNotMarkFailedTwice(t *testing.T) { - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() updatedAt := time.Now().Add(time.Duration(-1) * time.Minute) dbTransaction := db.Transaction{ @@ -253,9 +254,9 @@ func TestDoNotMarkFailedTwice(t *testing.T) { func TestSendPaymentSync_FailedRemovesFeeReserve(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() svc.LNClient.(*tests.MockLn).PayInvoiceErrors = append(svc.LNClient.(*tests.MockLn).PayInvoiceErrors, errors.New("Some error")) svc.LNClient.(*tests.MockLn).PayInvoiceResponses = append(svc.LNClient.(*tests.MockLn).PayInvoiceResponses, nil) @@ -285,9 +286,9 @@ func TestSendPaymentSync_FailedRemovesFeeReserve(t *testing.T) { func TestSendPaymentSync_PendingHasFeeReserve(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() // timeout will leave the payment as pending svc.LNClient.(*tests.MockLn).PayInvoiceErrors = append(svc.LNClient.(*tests.MockLn).PayInvoiceErrors, lnclient.NewTimeoutError()) diff --git a/transactions/receive_keysend_test.go b/transactions/receive_keysend_test.go index 3c07cb9e..a2c2a896 100644 --- a/transactions/receive_keysend_test.go +++ b/transactions/receive_keysend_test.go @@ -6,19 +6,20 @@ import ( "strconv" "testing" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/getAlby/hub/events" "github.com/getAlby/hub/lnclient" "github.com/getAlby/hub/tests" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestReceiveKeysendWithCustomKey(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher) app, _, err := tests.CreateApp(svc) @@ -63,9 +64,9 @@ func TestReceiveKeysendWithCustomKey(t *testing.T) { func TestReceiveKeysend(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher) _, _, err = tests.CreateApp(svc) diff --git a/transactions/self_payments_test.go b/transactions/self_payments_test.go index 32aa7196..8ebe7084 100644 --- a/transactions/self_payments_test.go +++ b/transactions/self_payments_test.go @@ -4,20 +4,21 @@ import ( "context" "testing" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/getAlby/hub/constants" "github.com/getAlby/hub/db" "github.com/getAlby/hub/db/queries" "github.com/getAlby/hub/tests" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestSendPaymentSync_SelfPayment_NoAppToNoApp(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() // pubkey matches mock invoice = self payment svc.LNClient.(*tests.MockLn).Pubkey = "03cbd788f5b22bd56e2714bff756372d2293504c064e03250ed16a4dd80ad70e2c" @@ -57,9 +58,9 @@ func TestSendPaymentSync_SelfPayment_NoAppToNoApp(t *testing.T) { func TestSendPaymentSync_SelfPayment_NoAppToIsolatedApp(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() // pubkey matches mock invoice = self payment svc.LNClient.(*tests.MockLn).Pubkey = "03cbd788f5b22bd56e2714bff756372d2293504c064e03250ed16a4dd80ad70e2c" @@ -112,9 +113,9 @@ func TestSendPaymentSync_SelfPayment_NoAppToIsolatedApp(t *testing.T) { func TestSendPaymentSync_SelfPayment_NoAppToApp(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() // pubkey matches mock invoice = self payment svc.LNClient.(*tests.MockLn).Pubkey = "03cbd788f5b22bd56e2714bff756372d2293504c064e03250ed16a4dd80ad70e2c" @@ -163,9 +164,9 @@ func TestSendPaymentSync_SelfPayment_NoAppToApp(t *testing.T) { func TestSendPaymentSync_SelfPayment_IsolatedAppToNoApp(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() // pubkey matches mock invoice = self payment svc.LNClient.(*tests.MockLn).Pubkey = "03cbd788f5b22bd56e2714bff756372d2293504c064e03250ed16a4dd80ad70e2c" @@ -235,9 +236,9 @@ func TestSendPaymentSync_SelfPayment_IsolatedAppToNoApp(t *testing.T) { func TestSendPaymentSync_SelfPayment_IsolatedAppToApp(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() // pubkey matches mock invoice = self payment svc.LNClient.(*tests.MockLn).Pubkey = "03cbd788f5b22bd56e2714bff756372d2293504c064e03250ed16a4dd80ad70e2c" @@ -311,9 +312,9 @@ func TestSendPaymentSync_SelfPayment_IsolatedAppToApp(t *testing.T) { func TestSendPaymentSync_SelfPayment_IsolatedAppToIsolatedApp(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() // pubkey matches mock invoice = self payment svc.LNClient.(*tests.MockLn).Pubkey = "03cbd788f5b22bd56e2714bff756372d2293504c064e03250ed16a4dd80ad70e2c" @@ -404,9 +405,9 @@ func TestSendPaymentSync_SelfPayment_IsolatedAppToIsolatedApp(t *testing.T) { func TestSendPaymentSync_SelfPayment_IsolatedAppToSelf(t *testing.T) { ctx := context.TODO() - defer tests.RemoveTestService() svc, err := tests.CreateTestService() require.NoError(t, err) + defer svc.Remove() // pubkey matches mock invoice = self payment svc.LNClient.(*tests.MockLn).Pubkey = "03cbd788f5b22bd56e2714bff756372d2293504c064e03250ed16a4dd80ad70e2c"