Files
status-go/pkg/backend/node/status_node_rpc_client_test.go
Igor Sirotin fa25c4fc01 refactor: rename walletdatabase to walletdb and split it
Part of the Go project layout migration, item 4.

internal/db/walletdatabase -> internal/db/walletdb, and its one 45-line
file splits along the two jobs it was doing:

  open.go     DbInitializer, InitializeDB, OpenDB
  migrate.go  walletCustomSteps, doMigration, MigrateDB

scripts/migration_check.sh listed this migration directory as
"walletdatabase/migrations/sql" and appdatabase's as
"appdatabase/migrations/sql". Neither path has existed since those
packages moved under internal/db/, so the check has been silently
skipping both. Both are corrected here.

refs #7067
2026-08-21 16:46:09 +01:00

86 lines
2.2 KiB
Go

package node
import (
"database/sql"
"fmt"
"io/ioutil"
"os"
accsmanagement "github.com/status-im/status-go/internal/accounts-management"
"github.com/status-im/status-go/internal/db/appdatabase"
"github.com/status-im/status-go/internal/db/multiaccounts"
"github.com/status-im/status-go/internal/db/multiaccounts/accounts"
"github.com/status-im/status-go/internal/db/walletdb"
"github.com/status-im/status-go/internal/testutils"
)
type TestServiceAPI struct{}
func setupTestDBs() (appDB *sql.DB, walletDB *sql.DB, closeFn func() error, err error) {
appDB, err = testutils.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
if err != nil {
return nil, nil, nil, fmt.Errorf("failed to setup app db: %w", err)
}
walletDB, err = testutils.SetupTestMemorySQLDB(walletdb.DbInitializer{})
if err != nil {
return nil, nil, nil, fmt.Errorf("failed to setup wallet db: %w", err)
}
return appDB, walletDB, func() error {
appErr := appDB.Close()
walletErr := walletDB.Close()
if appErr != nil {
return fmt.Errorf("failed to close app db: %w", appErr)
}
if walletErr != nil {
return fmt.Errorf("failed to close wallet db: %w", walletErr)
}
return nil
}, err
}
func setupTestMultiDB() (*multiaccounts.Database, func() error, error) {
tmpfile, err := ioutil.TempFile("", "tests")
if err != nil {
return nil, nil, err
}
db, err := multiaccounts.InitializeDB(tmpfile.Name())
if err != nil {
return nil, nil, err
}
return db, func() error {
err := db.Close()
if err != nil {
return err
}
return os.Remove(tmpfile.Name())
}, nil
}
func createStatusNode() (*StatusNode, func() error, func() error, error) {
appDB, walletDB, stop1, err := setupTestDBs()
if err != nil {
return nil, nil, nil, err
}
accsDB, err := accounts.NewDB(appDB)
if err != nil {
return nil, nil, nil, err
}
accountsManager, err := accsmanagement.NewAccountsManager(testutils.MustCreateTestLogger())
if err != nil {
return nil, nil, nil, err
}
accountsManager.SetPersistence(accsDB)
statusNode := New(nil, accountsManager, testutils.MustCreateTestLogger())
statusNode.SetAppDB(appDB)
statusNode.SetWalletDB(walletDB)
ma, stop2, err := setupTestMultiDB()
statusNode.SetMultiaccountsDB(ma)
return statusNode, stop1, stop2, err
}