mirror of
https://github.com/status-im/status-go.git
synced 2025-01-09 06:12:55 +00:00
2df9df10ab
interface for initializing db, which is implemented for appdatabase and walletdatabase. TBD for multiaccounts DB. Unified DB initializion for all tests using helpers and new interface. Reduced sqlcipher kdf iterations for all tests to 1.
63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
package localnotifications
|
|
|
|
import (
|
|
"database/sql"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/status-im/status-go/appdatabase"
|
|
"github.com/status-im/status-go/t/helpers"
|
|
)
|
|
|
|
func setupAppTestDb(t *testing.T) (*sql.DB, func()) {
|
|
db, cleanup, err := helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, "local-notifications-tests-")
|
|
require.NoError(t, err)
|
|
return db, func() { require.NoError(t, cleanup()) }
|
|
}
|
|
|
|
func setupTestDB(t *testing.T, db *sql.DB) (*Database, func()) {
|
|
return NewDB(db, 1777), func() {
|
|
require.NoError(t, db.Close())
|
|
}
|
|
}
|
|
|
|
func TestWalletPreferences(t *testing.T) {
|
|
appDB, appStop := setupAppTestDb(t)
|
|
defer appStop()
|
|
|
|
db, stop := setupTestDB(t, appDB)
|
|
defer stop()
|
|
|
|
enabled := true
|
|
require.NoError(t, db.ChangeWalletPreference(enabled))
|
|
rst, err := db.GetWalletPreference()
|
|
require.NoError(t, err)
|
|
require.Equal(t, enabled, rst.Enabled)
|
|
|
|
enabled = false
|
|
require.NoError(t, db.ChangeWalletPreference(enabled))
|
|
rst, err = db.GetWalletPreference()
|
|
require.Equal(t, enabled, rst.Enabled)
|
|
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
func TestPreferences(t *testing.T) {
|
|
appDB, appStop := setupAppTestDb(t)
|
|
defer appStop()
|
|
|
|
db, stop := setupTestDB(t, appDB)
|
|
defer stop()
|
|
|
|
enabled := true
|
|
|
|
require.NoError(t, db.ChangeWalletPreference(enabled))
|
|
rst, err := db.GetPreferences()
|
|
|
|
require.Equal(t, 1, len(rst))
|
|
require.Equal(t, enabled, rst[0].Enabled)
|
|
|
|
require.NoError(t, err)
|
|
}
|