fix: use proper migrations for protocol's test database

- use `appdatabse.DbInitializer{}` in tests to ensure consistent migrations

- remove protocol's open database functions due to improper
  initialization caused by missing node config migration

- introduce `PushNotificationServerConfig` to resolve cyclic dependency
  issues
This commit is contained in:
Patryk Osmaczko 2023-10-02 11:28:42 +02:00 committed by osmaczko
parent ecc8b4cb55
commit 53423e58ba
36 changed files with 169 additions and 313 deletions

View File

@ -14,6 +14,7 @@ import (
"time"
"github.com/status-im/status-go/services/ens"
"github.com/status-im/status-go/sqlite"
"github.com/imdario/mergo"
@ -50,7 +51,6 @@ import (
"github.com/status-im/status-go/services/typeddata"
wcommon "github.com/status-im/status-go/services/wallet/common"
"github.com/status-im/status-go/signal"
"github.com/status-im/status-go/sqlite"
"github.com/status-im/status-go/transactions"
"github.com/status-im/status-go/walletdatabase"
)
@ -609,7 +609,7 @@ func (b *GethStatusBackend) loginAccount(request *requests.Login) error {
}
if acc.KDFIterations == 0 {
acc.KDFIterations = sqlite.ReducedKDFIterationsNumber
acc.KDFIterations = dbsetup.ReducedKDFIterationsNumber
}
err := b.ensureDBsOpened(acc, password)
@ -867,7 +867,7 @@ func (b *GethStatusBackend) ExportUnencryptedDatabase(acc multiaccounts.Account,
return err
}
err = dbsetup.DecryptDatabase(dbPath, directory, password, acc.KDFIterations)
err = sqlite.DecryptDB(dbPath, directory, password, acc.KDFIterations)
if err != nil {
b.log.Error("failed to initialize db", "err", err)
return err
@ -887,7 +887,7 @@ func (b *GethStatusBackend) ImportUnencryptedDatabase(acc multiaccounts.Account,
return err
}
err = dbsetup.EncryptDatabase(databasePath, path, password, acc.KDFIterations, signal.SendReEncryptionStarted, signal.SendReEncryptionFinished)
err = sqlite.EncryptDB(databasePath, path, password, acc.KDFIterations, signal.SendReEncryptionStarted, signal.SendReEncryptionFinished)
if err != nil {
b.log.Error("failed to initialize db", "err", err)
return err
@ -990,7 +990,7 @@ func (b *GethStatusBackend) changeAppDBPassword(account *multiaccounts.Account,
}
// Exporting database to a temporary file with a new password
err = dbsetup.ExportDB(dbPath, password, account.KDFIterations, tmpDbPath, newPassword, signal.SendReEncryptionStarted, signal.SendReEncryptionFinished)
err = sqlite.ExportDB(dbPath, password, account.KDFIterations, tmpDbPath, newPassword, signal.SendReEncryptionStarted, signal.SendReEncryptionFinished)
if err != nil {
return err
}
@ -1032,7 +1032,7 @@ func (b *GethStatusBackend) changeWalletDBPassword(account *multiaccounts.Accoun
}
// Exporting database to a temporary file with a new password
err = dbsetup.ExportDB(dbPath, password, account.KDFIterations, tmpDbPath, newPassword, signal.SendReEncryptionStarted, signal.SendReEncryptionFinished)
err = sqlite.ExportDB(dbPath, password, account.KDFIterations, tmpDbPath, newPassword, signal.SendReEncryptionStarted, signal.SendReEncryptionFinished)
if err != nil {
return err
}
@ -1300,7 +1300,7 @@ func (b *GethStatusBackend) generateOrImportAccount(mnemonic string, customizati
Name: request.DisplayName,
CustomizationColor: multiacccommon.CustomizationColor(request.CustomizationColor),
CustomizationColorClock: customizationColorClock,
KDFIterations: sqlite.ReducedKDFIterationsNumber,
KDFIterations: dbsetup.ReducedKDFIterationsNumber,
}
if request.ImagePath != "" {
iis, err := images.GenerateIdentityImages(request.ImagePath, 0, 0, 1000, 1000)

View File

@ -100,7 +100,7 @@ const (
func TestMigrateWalletJsonBlobs(t *testing.T) {
openDB := func() (*sql.DB, error) {
return sqlite.OpenDB(sqlite.InMemoryPath, "1234567890", sqlite.ReducedKDFIterationsNumber)
return sqlite.OpenDB(sqlite.InMemoryPath, "1234567890", dbsetup.ReducedKDFIterationsNumber)
}
db, err := openDB()
require.NoError(t, err)

View File

@ -17,7 +17,6 @@ import (
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/nodecfg"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/protocol/pushnotificationserver"
"github.com/status-im/status-go/t/helpers"
)
@ -205,7 +204,7 @@ func randomNodeConfig() *params.NodeConfig {
},
RegisterTopics: randomTopicSlice(),
RequireTopics: randomTopicLimits(),
PushNotificationServerConfig: pushnotificationserver.Config{
PushNotificationServerConfig: params.PushNotificationServerConfig{
Enabled: randomBool(),
GorushURL: randomString(),
Identity: privK,

View File

@ -19,11 +19,11 @@ import (
"github.com/status-im/status-go/account/generator"
"github.com/status-im/status-go/api"
"github.com/status-im/status-go/common/dbsetup"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/multiaccounts"
"github.com/status-im/status-go/multiaccounts/accounts"
"github.com/status-im/status-go/multiaccounts/settings"
"github.com/status-im/status-go/sqlite"
"github.com/status-im/status-go/logutils"
"github.com/status-im/status-go/params"
@ -396,7 +396,7 @@ func ImportAccount(seedPhrase string, backend *api.GethStatusBackend) error {
account := multiaccounts.Account{
KeyUID: generatedAccountInfo.KeyUID,
KDFIterations: sqlite.ReducedKDFIterationsNumber,
KDFIterations: dbsetup.ReducedKDFIterationsNumber,
}
settings, err := defaultSettings(generatedAccountInfo, derivedAddresses, &seedPhrase)
if err != nil {

View File

@ -20,6 +20,7 @@ import (
"github.com/status-im/status-go/account/generator"
"github.com/status-im/status-go/api"
"github.com/status-im/status-go/common/dbsetup"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/logutils"
@ -33,7 +34,6 @@ import (
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/requests"
wakuextn "github.com/status-im/status-go/services/wakuext"
"github.com/status-im/status-go/sqlite"
)
type testTimeSource struct{}
@ -461,7 +461,7 @@ func ImportAccount(seedPhrase string, backend *api.GethStatusBackend) error {
account := multiaccounts.Account{
KeyUID: generatedAccountInfo.KeyUID,
KDFIterations: sqlite.ReducedKDFIterationsNumber,
KDFIterations: dbsetup.ReducedKDFIterationsNumber,
}
settings, err := defaultSettings(generatedAccountInfo, derivedAddresses, &seedPhrase)
if err != nil {

View File

@ -18,6 +18,7 @@ import (
"github.com/status-im/status-go/account/generator"
"github.com/status-im/status-go/api"
"github.com/status-im/status-go/common/dbsetup"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/logutils"
"github.com/status-im/status-go/multiaccounts"
@ -28,7 +29,6 @@ import (
"github.com/status-im/status-go/protocol"
"github.com/status-im/status-go/protocol/identity/alias"
waku2extn "github.com/status-im/status-go/services/wakuv2ext"
"github.com/status-im/status-go/sqlite"
)
const (
@ -357,7 +357,7 @@ func ImportAccount(seedPhrase string, backend *api.GethStatusBackend) error {
account := multiaccounts.Account{
KeyUID: generatedAccountInfo.KeyUID,
KDFIterations: sqlite.ReducedKDFIterationsNumber,
KDFIterations: dbsetup.ReducedKDFIterationsNumber,
}
settings, err := defaultSettings(generatedAccountInfo, derivedAddresses, &seedPhrase)
if err != nil {

View File

@ -22,6 +22,7 @@ import (
"github.com/status-im/status-go/api"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/common/dbsetup"
gethbridge "github.com/status-im/status-go/eth-node/bridge/geth"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/logutils"
@ -31,7 +32,7 @@ import (
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/profiling"
"github.com/status-im/status-go/protocol"
"github.com/status-im/status-go/sqlite"
"github.com/status-im/status-go/protocol/pushnotificationserver"
"github.com/status-im/status-go/walletdatabase"
)
@ -208,21 +209,24 @@ func main() {
return
}
walletDB, err := walletdatabase.InitializeDB(config.DataDir+"/"+installationID.String()+"-wallet.db", "", sqlite.ReducedKDFIterationsNumber)
walletDB, err := walletdatabase.InitializeDB(config.DataDir+"/"+installationID.String()+"-wallet.db", "", dbsetup.ReducedKDFIterationsNumber)
if err != nil {
logger.Error("failed to initialize app db", "error", err)
return
}
appDB, err := appdatabase.InitializeDB(config.DataDir+"/"+installationID.String()+".db", "", sqlite.ReducedKDFIterationsNumber)
appDB, err := appdatabase.InitializeDB(config.DataDir+"/"+installationID.String()+".db", "", dbsetup.ReducedKDFIterationsNumber)
if err != nil {
logger.Error("failed to initialize app db", "error", err)
return
}
options := []protocol.Option{
protocol.WithPushNotifications(),
protocol.WithPushNotificationServerConfig(&config.PushNotificationServerConfig),
protocol.WithPushNotificationServerConfig(&pushnotificationserver.Config{
Enabled: config.PushNotificationServerConfig.Enabled,
Identity: config.PushNotificationServerConfig.Identity,
GorushURL: config.PushNotificationServerConfig.GorushURL,
}),
protocol.WithDatabase(appDB),
protocol.WithWalletDatabase(walletDB),
protocol.WithTorrentConfig(&config.TorrentConfig),

View File

@ -5,33 +5,20 @@ import (
"errors"
"github.com/ethereum/go-ethereum/log"
"github.com/status-im/status-go/sqlite"
)
const InMemoryPath = ":memory:"
// The reduced number of kdf iterations (for performance reasons) which is
// currently used for derivation of the database key
// https://github.com/status-im/status-go/pull/1343
// https://notes.status.im/i8Y_l7ccTiOYq09HVgoFwA
const ReducedKDFIterationsNumber = 3200
type DatabaseInitializer interface {
Initialize(path, password string, kdfIterationsNumber int) (*sql.DB, error)
}
// DecryptDatabase creates an unencrypted copy of the database and copies it
// over to the given directory
func DecryptDatabase(oldPath, newPath, password string, kdfIterationsNumber int) error {
return sqlite.DecryptDB(oldPath, newPath, password, kdfIterationsNumber)
}
// EncryptDatabase creates an encrypted copy of the database and copies it to the
// user path
func EncryptDatabase(oldPath, newPath, password string, kdfIterationsNumber int, onStart func(), onEnd func()) error {
return sqlite.EncryptDB(oldPath, newPath, password, kdfIterationsNumber, onStart, onEnd)
}
func ExportDB(path string, password string, kdfIterationsNumber int, newDbPath string, newPassword string, onStart func(), onEnd func()) error {
return sqlite.ExportDB(path, password, kdfIterationsNumber, newDbPath, newPassword, onStart, onEnd)
}
func ChangeDatabasePassword(path string, password string, kdfIterationsNumber int, newPassword string, onStart func(), onEnd func()) error {
return sqlite.ChangeEncryptionKey(path, password, kdfIterationsNumber, newPassword, onStart, onEnd)
}
// GetDBFilename takes an instance of sql.DB and returns the filename of the "main" database
func GetDBFilename(db *sql.DB) (string, error) {
if db == nil {

View File

@ -6,6 +6,7 @@ import (
"encoding/json"
"github.com/ethereum/go-ethereum/log"
"github.com/status-im/status-go/common/dbsetup"
"github.com/status-im/status-go/images"
"github.com/status-im/status-go/multiaccounts/common"
"github.com/status-im/status-go/multiaccounts/migrations"
@ -300,7 +301,7 @@ func (db *Database) SaveAccount(account Account) error {
}
if account.KDFIterations <= 0 {
account.KDFIterations = sqlite.ReducedKDFIterationsNumber
account.KDFIterations = dbsetup.ReducedKDFIterationsNumber
}
_, err = db.db.Exec("INSERT OR REPLACE INTO accounts (name, identicon, colorHash, colorId, customizationColor, customizationColorClock, keycardPairing, keyUid, kdfIterations) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", account.Name, account.Identicon, colorHash, account.ColorID, account.CustomizationColor, account.CustomizationColorClock, account.KeycardPairing, account.KeyUID, account.KDFIterations)
@ -322,7 +323,7 @@ func (db *Database) UpdateAccount(account Account) error {
}
if account.KDFIterations <= 0 {
account.KDFIterations = sqlite.ReducedKDFIterationsNumber
account.KDFIterations = dbsetup.ReducedKDFIterationsNumber
}
_, err = db.db.Exec("UPDATE accounts SET name = ?, identicon = ?, colorHash = ?, colorId = ?, customizationColor = ?, customizationColorClock = ?, keycardPairing = ?, kdfIterations = ? WHERE keyUid = ?", account.Name, account.Identicon, colorHash, account.ColorID, account.CustomizationColor, account.CustomizationColorClock, account.KeycardPairing, account.KDFIterations, account.KeyUID)

View File

@ -6,8 +6,8 @@ import (
"os"
"testing"
"github.com/status-im/status-go/common/dbsetup"
"github.com/status-im/status-go/images"
"github.com/status-im/status-go/protocol/sqlite"
"github.com/stretchr/testify/require"
@ -28,7 +28,7 @@ func setupTestDB(t *testing.T) (*Database, func()) {
func TestAccounts(t *testing.T) {
db, stop := setupTestDB(t)
defer stop()
expected := Account{Name: "string", KeyUID: "string", CustomizationColor: common.CustomizationColorBlue, ColorHash: ColorHash{{4, 3}, {4, 0}, {4, 3}, {4, 0}}, ColorID: 10, KDFIterations: sqlite.ReducedKDFIterationsNumber}
expected := Account{Name: "string", KeyUID: "string", CustomizationColor: common.CustomizationColorBlue, ColorHash: ColorHash{{4, 3}, {4, 0}, {4, 3}, {4, 0}}, ColorID: 10, KDFIterations: dbsetup.ReducedKDFIterationsNumber}
require.NoError(t, db.SaveAccount(expected))
accounts, err := db.GetAccounts()
require.NoError(t, err)
@ -39,7 +39,7 @@ func TestAccounts(t *testing.T) {
func TestAccountsUpdate(t *testing.T) {
db, stop := setupTestDB(t)
defer stop()
expected := Account{KeyUID: "string", CustomizationColor: common.CustomizationColorBlue, ColorHash: ColorHash{{4, 3}, {4, 0}, {4, 3}, {4, 0}}, ColorID: 10, KDFIterations: sqlite.ReducedKDFIterationsNumber}
expected := Account{KeyUID: "string", CustomizationColor: common.CustomizationColorBlue, ColorHash: ColorHash{{4, 3}, {4, 0}, {4, 3}, {4, 0}}, ColorID: 10, KDFIterations: dbsetup.ReducedKDFIterationsNumber}
require.NoError(t, db.SaveAccount(expected))
expected.Name = "chars"
expected.CustomizationColor = common.CustomizationColorMagenta
@ -54,7 +54,7 @@ func TestLoginUpdate(t *testing.T) {
db, stop := setupTestDB(t)
defer stop()
accounts := []Account{{Name: "first", KeyUID: "0x1", KDFIterations: sqlite.ReducedKDFIterationsNumber}, {Name: "second", KeyUID: "0x2", KDFIterations: sqlite.ReducedKDFIterationsNumber}}
accounts := []Account{{Name: "first", KeyUID: "0x1", KDFIterations: dbsetup.ReducedKDFIterationsNumber}, {Name: "second", KeyUID: "0x2", KDFIterations: dbsetup.ReducedKDFIterationsNumber}}
for _, acc := range accounts {
require.NoError(t, db.SaveAccount(acc))
}
@ -185,7 +185,7 @@ func TestDatabase_GetAccount(t *testing.T) {
db, stop := setupTestDB(t)
defer stop()
expected := Account{Name: "string", KeyUID: keyUID, ColorHash: ColorHash{{4, 3}, {4, 0}, {4, 3}, {4, 0}}, ColorID: 10, KDFIterations: sqlite.ReducedKDFIterationsNumber}
expected := Account{Name: "string", KeyUID: keyUID, ColorHash: ColorHash{{4, 3}, {4, 0}, {4, 3}, {4, 0}}, ColorID: 10, KDFIterations: dbsetup.ReducedKDFIterationsNumber}
require.NoError(t, db.SaveAccount(expected))
account, err := db.GetAccount(expected.KeyUID)

View File

@ -8,10 +8,10 @@ import (
"github.com/stretchr/testify/require"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/common/dbsetup"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/multiaccounts/errors"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/sqlite"
"github.com/status-im/status-go/t/helpers"
)
@ -71,7 +71,7 @@ func TestClosingsqlDB(t *testing.T) {
password := "settings-tests"
// Make connection with sql.DB
db, err := appdatabase.InitializeDB(testFileName, password, sqlite.ReducedKDFIterationsNumber)
db, err := appdatabase.InitializeDB(testFileName, password, dbsetup.ReducedKDFIterationsNumber)
// handle removing the test file on any exit
defer func() {
@ -96,7 +96,7 @@ func TestClosingsqlDB(t *testing.T) {
require.NoError(t, err)
// Make another connection with sql.DB
db2, err := appdatabase.InitializeDB(testFileName, password, sqlite.ReducedKDFIterationsNumber)
db2, err := appdatabase.InitializeDB(testFileName, password, dbsetup.ReducedKDFIterationsNumber)
require.NoError(t, err)
// Init settings.Database struct using second connection

View File

@ -22,7 +22,6 @@ import (
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/protocol/pushnotificationserver"
"github.com/status-im/status-go/static"
wakucommon "github.com/status-im/status-go/waku/common"
wakuv2common "github.com/status-im/status-go/wakuv2/common"
@ -489,7 +488,7 @@ type NodeConfig struct {
MailServerRegistryAddress string
// PushNotificationServerConfig is the config for the push notification server
PushNotificationServerConfig pushnotificationserver.Config `json:"PushNotificationServerConfig"`
PushNotificationServerConfig PushNotificationServerConfig `json:"PushNotificationServerConfig"`
OutputMessageCSVEnabled bool
@ -587,6 +586,12 @@ func (p *PushNotificationServer) UnmarshalText(data []byte) error {
return nil
}
type PushNotificationServerConfig struct {
Enabled bool
Identity *ecdsa.PrivateKey
GorushURL string
}
// ShhextConfig defines options used by shhext service.
type ShhextConfig struct {
PFSEnabled bool

View File

@ -1,10 +1,10 @@
package common
import (
"path/filepath"
"testing"
transport2 "github.com/status-im/status-go/protocol/transport"
"github.com/status-im/status-go/t/helpers"
"github.com/status-im/status-go/waku"
@ -22,6 +22,8 @@ import (
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/sqlite"
v1protocol "github.com/status-im/status-go/protocol/v1"
"github.com/status-im/status-go/appdatabase"
)
func TestMessageSenderSuite(t *testing.T) {
@ -32,7 +34,6 @@ type MessageSenderSuite struct {
suite.Suite
sender *MessageSender
tmpDir string
testMessage protobuf.ChatMessage
logger *zap.Logger
}
@ -52,12 +53,12 @@ func (s *MessageSenderSuite) SetupTest() {
s.logger, err = zap.NewDevelopment()
s.Require().NoError(err)
s.tmpDir = s.T().TempDir()
identity, err := crypto.GenerateKey()
s.Require().NoError(err)
database, err := sqlite.Open(filepath.Join(s.tmpDir, "sender-test.sql"), "some-key", sqlite.ReducedKDFIterationsNumber)
database, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
s.Require().NoError(err)
err = sqlite.Migrate(database)
s.Require().NoError(err)
encryptionProtocol := encryption.New(
@ -188,8 +189,11 @@ func (s *MessageSenderSuite) TestHandleDecodedMessagesDatasyncEncrypted() {
s.Require().NoError(err)
// Create sender encryption protocol.
senderDatabase, err := sqlite.Open(filepath.Join(s.tmpDir, "sender.db.sql"), "", sqlite.ReducedKDFIterationsNumber)
senderDatabase, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
s.Require().NoError(err)
err = sqlite.Migrate(senderDatabase)
s.Require().NoError(err)
senderEncryptionProtocol := encryption.New(
senderDatabase,
"installation-2",

View File

@ -3,12 +3,12 @@ package encryption
import (
"crypto/ecdsa"
"fmt"
"io/ioutil"
"testing"
"github.com/status-im/status-go/protocol/tt"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/protocol/sqlite"
"github.com/status-im/status-go/protocol/tt"
"github.com/status-im/status-go/t/helpers"
"github.com/stretchr/testify/suite"
"go.uber.org/zap"
@ -51,12 +51,12 @@ func setupUser(user string, s *EncryptionServiceMultiDeviceSuite, n int) error {
for i := 0; i < n; i++ {
installationID := fmt.Sprintf("%s%d", user, i+1)
dbFileName := fmt.Sprintf("sqlite-persistence-test-%s.sql", installationID)
dbPath, err := ioutil.TempFile("", dbFileName)
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
if err != nil {
return err
}
db, err := sqlite.Open(dbPath.Name(), "some-key", sqlite.ReducedKDFIterationsNumber)
err = sqlite.Migrate(db)
if err != nil {
return err
}

View File

@ -3,12 +3,12 @@ package encryption
import (
"errors"
"fmt"
"io/ioutil"
"os"
"testing"
"time"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/protocol/sqlite"
"github.com/status-im/status-go/t/helpers"
"github.com/stretchr/testify/suite"
"go.uber.org/zap"
@ -27,23 +27,17 @@ func TestEncryptionServiceTestSuite(t *testing.T) {
type EncryptionServiceTestSuite struct {
suite.Suite
logger *zap.Logger
alice *Protocol
bob *Protocol
aliceDBPath *os.File
bobDBPath *os.File
logger *zap.Logger
alice *Protocol
bob *Protocol
}
func (s *EncryptionServiceTestSuite) initDatabases(config encryptorConfig) {
var err error
s.aliceDBPath, err = ioutil.TempFile("", "alice.db.sql")
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
s.Require().NoError(err)
s.bobDBPath, err = ioutil.TempFile("", "bob.db.sql")
s.Require().NoError(err)
db, err := sqlite.Open(s.aliceDBPath.Name(), "alice-key", sqlite.ReducedKDFIterationsNumber)
err = sqlite.Migrate(db)
s.Require().NoError(err)
config.InstallationID = aliceInstallationID
s.alice = NewWithEncryptorConfig(
@ -53,7 +47,9 @@ func (s *EncryptionServiceTestSuite) initDatabases(config encryptorConfig) {
s.logger.With(zap.String("user", "alice")),
)
db, err = sqlite.Open(s.bobDBPath.Name(), "bob-key", sqlite.ReducedKDFIterationsNumber)
db, err = helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
s.Require().NoError(err)
err = sqlite.Migrate(db)
s.Require().NoError(err)
config.InstallationID = bobInstallationID
s.bob = NewWithEncryptorConfig(
@ -70,8 +66,6 @@ func (s *EncryptionServiceTestSuite) SetupTest() {
}
func (s *EncryptionServiceTestSuite) TearDownTest() {
os.Remove(s.aliceDBPath.Name())
os.Remove(s.bobDBPath.Name())
_ = s.logger.Sync()
}

View File

@ -1,17 +1,13 @@
package multidevice
import (
"database/sql"
"os"
"testing"
"github.com/stretchr/testify/suite"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/protocol/sqlite"
)
const (
dbPath = "/tmp/status-key-store.db"
"github.com/status-im/status-go/t/helpers"
)
func TestSQLLitePersistenceTestSuite(t *testing.T) {
@ -20,15 +16,13 @@ func TestSQLLitePersistenceTestSuite(t *testing.T) {
type SQLLitePersistenceTestSuite struct {
suite.Suite
// nolint: structcheck, megacheck
db *sql.DB
service *sqlitePersistence
}
func (s *SQLLitePersistenceTestSuite) SetupTest() {
os.Remove(dbPath)
db, err := sqlite.Open(dbPath, "test-key", sqlite.ReducedKDFIterationsNumber)
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
s.Require().NoError(err)
err = sqlite.Migrate(db)
s.Require().NoError(err)
s.service = newSQLitePersistence(db)

View File

@ -1,13 +1,14 @@
package encryption
import (
"path/filepath"
"testing"
dr "github.com/status-im/doubleratchet"
"github.com/stretchr/testify/suite"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/protocol/sqlite"
"github.com/status-im/status-go/t/helpers"
)
var (
@ -30,10 +31,9 @@ type SQLLitePersistenceKeysStorageTestSuite struct {
}
func (s *SQLLitePersistenceKeysStorageTestSuite) SetupTest() {
dir := s.T().TempDir()
key := "blahblahblah"
db, err := sqlite.Open(filepath.Join(dir, "db.sql"), key, sqlite.ReducedKDFIterationsNumber)
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
s.Require().NoError(err)
err = sqlite.Migrate(db)
s.Require().NoError(err)
p := newSQLitePersistence(db)

View File

@ -1,13 +1,13 @@
package encryption
import (
"database/sql"
"path/filepath"
"testing"
"github.com/stretchr/testify/suite"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/t/helpers"
"github.com/status-im/status-go/protocol/encryption/multidevice"
"github.com/status-im/status-go/protocol/sqlite"
@ -19,15 +19,13 @@ func TestSQLLitePersistenceTestSuite(t *testing.T) {
type SQLLitePersistenceTestSuite struct {
suite.Suite
// nolint: structcheck, megacheck
db *sql.DB
service *sqlitePersistence
}
func (s *SQLLitePersistenceTestSuite) SetupTest() {
dir := s.T().TempDir()
db, err := sqlite.Open(filepath.Join(dir, "db.sql"), "test-key", sqlite.ReducedKDFIterationsNumber)
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
s.Require().NoError(err)
err = sqlite.Migrate(db)
s.Require().NoError(err)
s.service = newSQLitePersistence(db)

View File

@ -1,13 +1,12 @@
package encryption
import (
"io/ioutil"
"os"
"testing"
"github.com/status-im/status-go/protocol/tt"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/protocol/sqlite"
"github.com/status-im/status-go/protocol/tt"
"github.com/status-im/status-go/t/helpers"
"github.com/stretchr/testify/suite"
"go.uber.org/zap"
@ -21,11 +20,9 @@ func TestProtocolServiceTestSuite(t *testing.T) {
type ProtocolServiceTestSuite struct {
suite.Suite
aliceDBPath *os.File
bobDBPath *os.File
alice *Protocol
bob *Protocol
logger *zap.Logger
alice *Protocol
bob *Protocol
logger *zap.Logger
}
func (s *ProtocolServiceTestSuite) SetupTest() {
@ -33,15 +30,9 @@ func (s *ProtocolServiceTestSuite) SetupTest() {
s.logger = tt.MustCreateTestLogger()
s.aliceDBPath, err = ioutil.TempFile("", "alice.db.sql")
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
s.Require().NoError(err)
aliceDBKey := "alice"
s.bobDBPath, err = ioutil.TempFile("", "bob.db.sql")
s.Require().NoError(err)
bobDBKey := "bob"
db, err := sqlite.Open(s.aliceDBPath.Name(), aliceDBKey, sqlite.ReducedKDFIterationsNumber)
err = sqlite.Migrate(db)
s.Require().NoError(err)
s.alice = New(
db,
@ -49,7 +40,9 @@ func (s *ProtocolServiceTestSuite) SetupTest() {
s.logger.With(zap.String("user", "alice")),
)
db, err = sqlite.Open(s.bobDBPath.Name(), bobDBKey, sqlite.ReducedKDFIterationsNumber)
db, err = helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
s.Require().NoError(err)
err = sqlite.Migrate(db)
s.Require().NoError(err)
s.bob = New(
db,
@ -59,8 +52,6 @@ func (s *ProtocolServiceTestSuite) SetupTest() {
}
func (s *ProtocolServiceTestSuite) TearDownTest() {
os.Remove(s.aliceDBPath.Name())
os.Remove(s.bobDBPath.Name())
_ = s.logger.Sync()
}

View File

@ -1,17 +1,17 @@
package sharedsecret
import (
"io/ioutil"
"os"
"testing"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/protocol/sqlite"
"github.com/status-im/status-go/protocol/tt"
"github.com/status-im/status-go/t/helpers"
"github.com/stretchr/testify/suite"
"go.uber.org/zap"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/protocol/sqlite"
)
func TestServiceTestSuite(t *testing.T) {
@ -21,25 +21,21 @@ func TestServiceTestSuite(t *testing.T) {
type SharedSecretTestSuite struct {
suite.Suite
service *SharedSecret
path string
logger *zap.Logger
}
func (s *SharedSecretTestSuite) SetupTest() {
s.logger = tt.MustCreateTestLogger()
dbFile, err := ioutil.TempFile(os.TempDir(), "sharedsecret")
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
s.Require().NoError(err)
s.path = dbFile.Name()
db, err := sqlite.Open(s.path, "", sqlite.ReducedKDFIterationsNumber)
err = sqlite.Migrate(db)
s.Require().NoError(err)
s.service = New(db, s.logger)
}
func (s *SharedSecretTestSuite) TearDownTest() {
os.Remove(s.path)
_ = s.logger.Sync()
}

View File

@ -5,7 +5,9 @@ import (
"github.com/stretchr/testify/require"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/protocol/sqlite"
"github.com/status-im/status-go/t/helpers"
)
func TestGetENSToBeVerified(t *testing.T) {
@ -13,9 +15,8 @@ func TestGetENSToBeVerified(t *testing.T) {
name := "test.eth"
updatedName := "test2.eth"
db, err := sqlite.Open(sqlite.InMemoryPath, "", sqlite.ReducedKDFIterationsNumber)
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
require.NoError(t, err)
err = sqlite.Migrate(db)
require.NoError(t, err)

View File

@ -4,7 +4,6 @@ import (
"bytes"
"database/sql"
"fmt"
"io/ioutil"
"math"
"sort"
"strconv"
@ -14,11 +13,13 @@ import (
"github.com/stretchr/testify/require"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/sqlite"
"github.com/status-im/status-go/t/helpers"
)
func TestTableUserMessagesAllFieldsCount(t *testing.T) {
@ -891,11 +892,12 @@ func TestPersistenceEmojiReactions(t *testing.T) {
}
func openTestDB() (*sql.DB, error) {
dbPath, err := ioutil.TempFile("", "status-go-test-db-")
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
if err != nil {
return nil, err
}
return sqlite.Open(dbPath.Name(), "", sqlite.ReducedKDFIterationsNumber)
return db, sqlite.Migrate(db)
}
func insertMinimalMessage(p *sqlitePersistence, id string) error {

View File

@ -3,14 +3,13 @@ package pushnotificationclient
import (
"bytes"
"crypto/ecdsa"
"io/ioutil"
"math/rand"
"os"
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/suite"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/crypto/ecies"
"github.com/status-im/status-go/eth-node/types"
@ -18,13 +17,13 @@ import (
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/sqlite"
"github.com/status-im/status-go/protocol/tt"
"github.com/status-im/status-go/t/helpers"
)
const testDeviceToken = "test-token"
type ClientSuite struct {
suite.Suite
tmpFile *os.File
persistence *Persistence
identity *ecdsa.PrivateKey
installationID string
@ -39,13 +38,12 @@ func TestClientSuite(t *testing.T) {
}
func (s *ClientSuite) SetupTest() {
tmpFile, err := ioutil.TempFile("", "")
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
s.Require().NoError(err)
err = sqlite.Migrate(db)
s.Require().NoError(err)
s.tmpFile = tmpFile
database, err := sqlite.Open(s.tmpFile.Name(), "", sqlite.ReducedKDFIterationsNumber)
s.Require().NoError(err)
s.persistence = NewPersistence(database)
s.persistence = NewPersistence(db)
identity, err := crypto.GenerateKey()
s.Require().NoError(err)

View File

@ -2,18 +2,18 @@ package pushnotificationclient
import (
"crypto/ecdsa"
"io/ioutil"
"os"
"testing"
"time"
"github.com/golang/protobuf/proto"
"github.com/stretchr/testify/suite"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/sqlite"
"github.com/status-im/status-go/t/helpers"
)
const (
@ -29,22 +29,16 @@ func TestSQLitePersistenceSuite(t *testing.T) {
type SQLitePersistenceSuite struct {
suite.Suite
tmpFile *os.File
persistence *Persistence
}
func (s *SQLitePersistenceSuite) SetupTest() {
tmpFile, err := ioutil.TempFile("", "")
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
s.Require().NoError(err)
s.tmpFile = tmpFile
database, err := sqlite.Open(s.tmpFile.Name(), "", sqlite.ReducedKDFIterationsNumber)
err = sqlite.Migrate(db)
s.Require().NoError(err)
s.persistence = NewPersistence(database)
}
func (s *SQLitePersistenceSuite) TearDownTest() {
_ = os.Remove(s.tmpFile.Name())
s.persistence = NewPersistence(db)
}
func (s *SQLitePersistenceSuite) TestSaveAndRetrieveServer() {

View File

@ -1,17 +1,17 @@
package pushnotificationserver
import (
"io/ioutil"
"os"
"testing"
"github.com/golang/protobuf/proto"
"github.com/stretchr/testify/suite"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/sqlite"
"github.com/status-im/status-go/t/helpers"
)
func TestSQLitePersistenceSuite(t *testing.T) {
@ -20,22 +20,16 @@ func TestSQLitePersistenceSuite(t *testing.T) {
type SQLitePersistenceSuite struct {
suite.Suite
tmpFile *os.File
persistence Persistence
}
func (s *SQLitePersistenceSuite) SetupTest() {
tmpFile, err := ioutil.TempFile("", "")
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
s.Require().NoError(err)
s.tmpFile = tmpFile
database, err := sqlite.Open(s.tmpFile.Name(), "", sqlite.ReducedKDFIterationsNumber)
err = sqlite.Migrate(db)
s.Require().NoError(err)
s.persistence = NewSQLitePersistence(database)
}
func (s *SQLitePersistenceSuite) TearDownTest() {
_ = os.Remove(s.tmpFile.Name())
s.persistence = NewSQLitePersistence(db)
}
func (s *SQLitePersistenceSuite) TestSaveAndRetrieve() {

View File

@ -3,18 +3,18 @@ package pushnotificationserver
import (
"crypto/ecdsa"
"crypto/rand"
"io/ioutil"
"os"
"testing"
"github.com/golang/protobuf/proto"
"github.com/stretchr/testify/suite"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/sqlite"
"github.com/status-im/status-go/protocol/tt"
"github.com/status-im/status-go/t/helpers"
)
func TestServerSuite(t *testing.T) {
@ -27,7 +27,6 @@ func TestServerSuite(t *testing.T) {
type ServerSuite struct {
suite.Suite
tmpFile *os.File
persistence Persistence
accessToken string
installationID string
@ -39,13 +38,12 @@ type ServerSuite struct {
}
func (s *ServerSuite) SetupTest() {
tmpFile, err := ioutil.TempFile("", "")
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
s.Require().NoError(err)
err = sqlite.Migrate(db)
s.Require().NoError(err)
s.tmpFile = tmpFile
database, err := sqlite.Open(s.tmpFile.Name(), "", sqlite.ReducedKDFIterationsNumber)
s.Require().NoError(err)
s.persistence = NewSQLitePersistence(database)
s.persistence = NewSQLitePersistence(db)
identity, err := crypto.GenerateKey()
s.Require().NoError(err)

View File

@ -2,8 +2,6 @@ package sqlite
import (
"database/sql"
"fmt"
"os"
"github.com/pkg/errors"
@ -14,87 +12,8 @@ import (
mvdsmigrations "github.com/vacp2p/mvds/persistenceutil"
)
// The reduced number of kdf iterations (for performance reasons) which is
// currently used for derivation of the database key
// https://github.com/status-im/status-go/pull/1343
// https://notes.status.im/i8Y_l7ccTiOYq09HVgoFwA
const ReducedKDFIterationsNumber = 3200
const InMemoryPath = ":memory:"
var migrationsTable = "status_protocol_go_" + sqlcipher.DefaultMigrationsTable
// MigrationConfig is a struct that allows to define bindata migrations.
type MigrationConfig struct {
AssetNames []string
AssetGetter func(name string) ([]byte, error)
}
// Open opens or initializes a new database for a given file path.
// MigrationConfig is optional but if provided migrations are applied automatically.
func Open(path, key string, kdfIterationNumber int) (*sql.DB, error) {
return openAndMigrate(path, key, kdfIterationNumber)
}
// OpenInMemory opens an in memory SQLite database.
// Number of KDF iterations is reduced to 0.
func OpenInMemory() (*sql.DB, error) {
return openAndMigrate(InMemoryPath, "", 0)
}
// OpenWithIter allows to open a new database with a custom number of kdf iterations.
// Higher kdf iterations number makes it slower to open the database.
func OpenWithIter(path, key string, kdfIter int) (*sql.DB, error) {
return openAndMigrate(path, key, kdfIter)
}
func open(path string, key string, kdfIter int) (*sql.DB, error) {
if path != InMemoryPath {
_, err := os.OpenFile(path, os.O_CREATE, 0600)
if err != nil {
return nil, err
}
}
db, err := sql.Open("sqlite3", path)
if err != nil {
return nil, err
}
keyString := fmt.Sprintf("PRAGMA key = '%s'", key)
// Disable concurrent access as not supported by the driver
db.SetMaxOpenConns(1)
if _, err = db.Exec("PRAGMA foreign_keys=ON"); err != nil {
return nil, err
}
if _, err = db.Exec(keyString); err != nil {
return nil, err
}
kdfString := fmt.Sprintf("PRAGMA kdf_iter = '%d'", kdfIter)
if _, err = db.Exec(kdfString); err != nil {
return nil, err
}
return db, nil
}
func openAndMigrate(path string, key string, kdfIter int) (*sql.DB, error) {
db, err := open(path, key, kdfIter)
if err != nil {
return nil, err
}
if err := Migrate(db); err != nil {
return nil, err
}
return db, nil
}
// applyMigrations allows to apply bindata migrations on the current *sql.DB.
// `assetNames` is a list of assets with migrations and `assetGetter` is responsible
// for returning the content of the asset with a given name.

View File

@ -1,42 +1,21 @@
package sqlite
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/t/helpers"
)
func TestOpen(t *testing.T) {
dir := t.TempDir()
dbPath := filepath.Join(dir, "db.sql")
// Open the db for the first time.
db, err := openAndMigrate(dbPath, "some-key", ReducedKDFIterationsNumber)
require.NoError(t, err)
// Insert some data.
_, err = db.Exec("CREATE TABLE test(name TEXT)")
require.NoError(t, err)
_, err = db.Exec(`INSERT INTO test (name) VALUES ("abc")`)
require.NoError(t, err)
db.Close()
// Open again with different key should fail
// because the file already exists and it should not
// be recreated.
_, err = openAndMigrate(dbPath, "different-key", ReducedKDFIterationsNumber)
require.Error(t, err)
}
// TestCommunitiesMigrationDirty tests the communities migration when
// dirty flag has been set to true.
// We first make it fail, then clean up so that it can be replayed, and
// then execute again, and we should be all migrated.
func TestCommunitiesMigrationDirty(t *testing.T) {
// Open the db for the first time.
db, err := open(InMemoryPath, "some-key", ReducedKDFIterationsNumber)
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
require.NoError(t, err)
// Create a communities table, so that migration will fail
@ -84,7 +63,7 @@ func TestCommunitiesMigrationDirty(t *testing.T) {
// dirty to false and then execute again, and we should be all migrated.
func TestCommunitiesMigrationNotDirty(t *testing.T) {
// Open the db for the first time.
db, err := open(InMemoryPath, "some-key", ReducedKDFIterationsNumber)
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
require.NoError(t, err)
// Create a communities table, so that migration will fail

View File

@ -1,11 +1,11 @@
package transport
import (
"io/ioutil"
"os"
"testing"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/protocol/sqlite"
"github.com/status-im/status-go/t/helpers"
"github.com/stretchr/testify/require"
@ -13,10 +13,11 @@ import (
)
func TestNewTransport(t *testing.T) {
dbPath, err := ioutil.TempFile("", "transport.sql")
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
require.NoError(t, err)
defer os.Remove(dbPath.Name())
db, err := sqlite.Open(dbPath.Name(), "some-key", sqlite.ReducedKDFIterationsNumber)
err = sqlite.Migrate(db)
require.NoError(t, err)
require.NoError(t, err)
logger := tt.MustCreateTestLogger()

View File

@ -1,13 +1,14 @@
package verification
import (
"io/ioutil"
"testing"
"time"
"github.com/stretchr/testify/suite"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/protocol/sqlite"
"github.com/status-im/status-go/t/helpers"
)
func TestPersistenceSuite(t *testing.T) {
@ -21,13 +22,10 @@ type PersistenceSuite struct {
}
func (s *PersistenceSuite) SetupTest() {
s.db = nil
dbPath, err := ioutil.TempFile("", "")
s.NoError(err, "creating temp file for db")
db, err := sqlite.Open(dbPath.Name(), "", sqlite.ReducedKDFIterationsNumber)
s.NoError(err, "creating sqlite db instance")
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
s.Require().NoError(err)
err = sqlite.Migrate(db)
s.Require().NoError(err)
s.db = &Persistence{db: db}
}

View File

@ -3,7 +3,6 @@ package server
import (
"database/sql"
"encoding/json"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
@ -12,17 +11,18 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/logutils"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/sqlite"
"github.com/status-im/status-go/t/helpers"
)
func setupTest(t *testing.T) (*sql.DB, *zap.Logger) {
dbPath, err := ioutil.TempFile("", "status-go-test-db-")
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
require.NoError(t, err)
db, err := sqlite.Open(dbPath.Name(), "", sqlite.ReducedKDFIterationsNumber)
err = sqlite.Migrate(db)
require.NoError(t, err)
logger := logutils.ZapLogger()

View File

@ -13,9 +13,9 @@ import (
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/status-im/status-go/common/dbsetup"
"github.com/status-im/status-go/images"
"github.com/status-im/status-go/multiaccounts"
"github.com/status-im/status-go/protocol/sqlite"
"github.com/status-im/status-go/server/servertest"
"github.com/status-im/status-go/t/utils"
)
@ -29,7 +29,7 @@ var (
ColorHash: multiaccounts.ColorHash{{4, 3}, {4, 0}, {4, 3}, {4, 0}},
ColorID: 10,
Images: images.SampleIdentityImages(),
KDFIterations: sqlite.ReducedKDFIterationsNumber,
KDFIterations: dbsetup.ReducedKDFIterationsNumber,
}
account1Hash = []byte{0x8f, 0xba, 0x35, 0x1, 0x2b, 0x9d, 0xad, 0xf0, 0x2d, 0x3c, 0x4d, 0x6, 0xb5, 0x22, 0x2, 0x47, 0xd4, 0x1c, 0xf4, 0x31, 0x2f, 0xb, 0x5b, 0x27, 0x5d, 0x43, 0x97, 0x58, 0x2d, 0xf0, 0xe1, 0xbe}
account2Hash = []byte{0x9, 0xf8, 0x5c, 0xe9, 0x92, 0x96, 0x2d, 0x88, 0x2b, 0x8e, 0x42, 0x3f, 0xa4, 0x93, 0x6c, 0xad, 0xe9, 0xc0, 0x1b, 0x8a, 0x8, 0x8c, 0x5e, 0x7a, 0x84, 0xa2, 0xf, 0x9f, 0x77, 0x58, 0x2c, 0x2c}

View File

@ -13,6 +13,7 @@ import (
"go.uber.org/zap"
"github.com/status-im/status-go/common/dbsetup"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/protocol/encryption/multidevice"
"github.com/status-im/status-go/protocol/tt"
@ -36,7 +37,6 @@ import (
"github.com/status-im/status-go/protocol/requests"
accservice "github.com/status-im/status-go/services/accounts"
"github.com/status-im/status-go/services/browsers"
"github.com/status-im/status-go/sqlite"
)
const (
@ -102,7 +102,7 @@ func (s *SyncDeviceSuite) prepareBackendWithAccount(mnemonic, tmpdir string) *ap
}
account := multiaccounts.Account{
KeyUID: generatedAccountInfo.KeyUID,
KDFIterations: sqlite.ReducedKDFIterationsNumber,
KDFIterations: dbsetup.ReducedKDFIterationsNumber,
}
err = accountManager.InitKeystore(filepath.Join(tmpdir, keystoreDir, account.KeyUID))
require.NoError(s.T(), err)

View File

@ -9,13 +9,13 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/status-im/status-go/protocol/sqlite"
"github.com/status-im/status-go/common/dbsetup"
"github.com/status-im/status-go/services/wallet/bigint"
"github.com/status-im/status-go/walletdatabase"
)
func setupBalanceDBTest(t *testing.T) (*BalanceDB, func()) {
db, err := walletdatabase.InitializeDB(sqlite.InMemoryPath, "wallet-history-balance_db-tests", 1)
db, err := walletdatabase.InitializeDB(dbsetup.InMemoryPath, "wallet-history-balance_db-tests", 1)
require.NoError(t, err)
return NewBalanceDB(db), func() {
require.NoError(t, db.Close())

View File

@ -12,7 +12,7 @@ import (
sqlcipher "github.com/mutecomm/go-sqlcipher/v4" // We require go sqlcipher that overrides default implementation
"github.com/status-im/status-go/protocol/sqlite"
"github.com/status-im/status-go/common/dbsetup"
)
const (
@ -80,7 +80,7 @@ func attachDatabaseWithDefaultSettings(db *sql.DB, attachedDbPath string, attach
}
if kdfIterationsNumber <= 0 {
kdfIterationsNumber = sqlite.ReducedKDFIterationsNumber
kdfIterationsNumber = dbsetup.ReducedKDFIterationsNumber
}
if _, err := db.Exec(fmt.Sprintf(`PRAGMA %s.busy_timeout = 60000`, attachedDbName)); err != nil {
@ -177,7 +177,7 @@ func openDB(path string, key string, kdfIterationsNumber int, cipherPageSize int
}
if kdfIterationsNumber <= 0 {
kdfIterationsNumber = sqlite.ReducedKDFIterationsNumber
kdfIterationsNumber = dbsetup.ReducedKDFIterationsNumber
}
if _, err := conn.Exec(fmt.Sprintf("PRAGMA cipher_page_size = %d", cipherPageSize), nil); err != nil {
@ -289,7 +289,7 @@ func ChangeEncryptionKey(path string, key string, kdfIterationsNumber int, newKe
}
if kdfIterationsNumber <= 0 {
kdfIterationsNumber = sqlite.ReducedKDFIterationsNumber
kdfIterationsNumber = dbsetup.ReducedKDFIterationsNumber
}
db, err := openDB(path, key, kdfIterationsNumber, V4CipherPageSize)

View File

@ -6,7 +6,6 @@ import (
"os"
"github.com/status-im/status-go/common/dbsetup"
"github.com/status-im/status-go/protocol/sqlite"
)
const kdfIterationsNumberForTests = 1
@ -33,7 +32,7 @@ func SetupTestSQLDB(dbInit dbsetup.DatabaseInitializer, prefix string) (*sql.DB,
}
func SetupTestMemorySQLDB(dbInit dbsetup.DatabaseInitializer) (*sql.DB, error) {
db, err := dbInit.Initialize(sqlite.InMemoryPath, "password", kdfIterationsNumberForTests)
db, err := dbInit.Initialize(dbsetup.InMemoryPath, "password", kdfIterationsNumberForTests)
if err != nil {
return nil, err
}