fix(tests): moved test db setup to a common place 't/helpers', created
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.
This commit is contained in:
parent
aa3d33a58f
commit
2df9df10ab
|
@ -31,9 +31,10 @@ import (
|
|||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/rpc"
|
||||
"github.com/status-im/status-go/services/typeddata"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
"github.com/status-im/status-go/t/utils"
|
||||
"github.com/status-im/status-go/transactions"
|
||||
"github.com/status-im/status-go/walletdatabase"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -57,21 +58,11 @@ var (
|
|||
)
|
||||
|
||||
func setupTestDB() (*sql.DB, func() error, error) {
|
||||
tmpfile, err := ioutil.TempFile("", "tests")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, "tests")
|
||||
}
|
||||
db, err := appdatabase.InitializeDB(tmpfile.Name(), "tests", sqlite.ReducedKDFIterationsNumber)
|
||||
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 setupTestWalletDB() (*sql.DB, func() error, error) {
|
||||
return helpers.SetupTestSQLDB(walletdatabase.DbInitializer{}, "tests")
|
||||
}
|
||||
|
||||
func setupTestMultiDB() (*multiaccounts.Database, func() error, error) {
|
||||
|
@ -92,24 +83,33 @@ func setupTestMultiDB() (*multiaccounts.Database, func() error, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func setupGethStatusBackend() (*GethStatusBackend, func() error, func() error, error) {
|
||||
func setupGethStatusBackend() (*GethStatusBackend, func() error, func() error, func() error, error) {
|
||||
db, stop1, err := setupTestDB()
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, nil, nil, err
|
||||
}
|
||||
backend := NewGethStatusBackend()
|
||||
backend.StatusNode().SetAppDB(db)
|
||||
|
||||
ma, stop2, err := setupTestMultiDB()
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, err
|
||||
}
|
||||
backend.StatusNode().SetMultiaccountsDB(ma)
|
||||
|
||||
return backend, stop1, stop2, err
|
||||
walletDb, stop3, err := setupTestWalletDB()
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, err
|
||||
}
|
||||
backend.StatusNode().SetWalletDB(walletDb)
|
||||
|
||||
return backend, stop1, stop2, stop3, err
|
||||
}
|
||||
|
||||
func TestBackendStartNodeConcurrently(t *testing.T) {
|
||||
utils.Init()
|
||||
|
||||
backend, stop1, stop2, err := setupGethStatusBackend()
|
||||
backend, stop1, stop2, stop3, err := setupGethStatusBackend()
|
||||
defer func() {
|
||||
err := stop1()
|
||||
if err != nil {
|
||||
|
@ -122,6 +122,12 @@ func TestBackendStartNodeConcurrently(t *testing.T) {
|
|||
require.NoError(t, backend.StopNode())
|
||||
}
|
||||
}()
|
||||
defer func() {
|
||||
err := stop3()
|
||||
if err != nil {
|
||||
require.NoError(t, backend.StopNode())
|
||||
}
|
||||
}()
|
||||
require.NoError(t, err)
|
||||
|
||||
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
|
@ -158,7 +164,7 @@ func TestBackendStartNodeConcurrently(t *testing.T) {
|
|||
func TestBackendRestartNodeConcurrently(t *testing.T) {
|
||||
utils.Init()
|
||||
|
||||
backend, stop1, stop2, err := setupGethStatusBackend()
|
||||
backend, stop1, stop2, stopWallet, err := setupGethStatusBackend()
|
||||
defer func() {
|
||||
err := stop1()
|
||||
if err != nil {
|
||||
|
@ -171,6 +177,12 @@ func TestBackendRestartNodeConcurrently(t *testing.T) {
|
|||
require.NoError(t, backend.StopNode())
|
||||
}
|
||||
}()
|
||||
defer func() {
|
||||
err := stopWallet()
|
||||
if err != nil {
|
||||
require.NoError(t, backend.StopNode())
|
||||
}
|
||||
}()
|
||||
require.NoError(t, err)
|
||||
|
||||
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
|
@ -200,7 +212,7 @@ func TestBackendRestartNodeConcurrently(t *testing.T) {
|
|||
func TestBackendGettersConcurrently(t *testing.T) {
|
||||
utils.Init()
|
||||
|
||||
backend, stop1, stop2, err := setupGethStatusBackend()
|
||||
backend, stop1, stop2, stopWallet, err := setupGethStatusBackend()
|
||||
defer func() {
|
||||
err := stop1()
|
||||
if err != nil {
|
||||
|
@ -213,6 +225,12 @@ func TestBackendGettersConcurrently(t *testing.T) {
|
|||
require.NoError(t, backend.StopNode())
|
||||
}
|
||||
}()
|
||||
defer func() {
|
||||
err := stopWallet()
|
||||
if err != nil {
|
||||
require.NoError(t, backend.StopNode())
|
||||
}
|
||||
}()
|
||||
require.NoError(t, err)
|
||||
|
||||
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
|
@ -299,7 +317,7 @@ func TestBackendConnectionChangesToOffline(t *testing.T) {
|
|||
func TestBackendCallRPCConcurrently(t *testing.T) {
|
||||
utils.Init()
|
||||
|
||||
backend, stop1, stop2, err := setupGethStatusBackend()
|
||||
backend, stop1, stop2, stopWallet, err := setupGethStatusBackend()
|
||||
defer func() {
|
||||
err := stop1()
|
||||
if err != nil {
|
||||
|
@ -312,6 +330,12 @@ func TestBackendCallRPCConcurrently(t *testing.T) {
|
|||
require.NoError(t, backend.StopNode())
|
||||
}
|
||||
}()
|
||||
defer func() {
|
||||
err := stopWallet()
|
||||
if err != nil {
|
||||
require.NoError(t, backend.StopNode())
|
||||
}
|
||||
}()
|
||||
require.NoError(t, err)
|
||||
|
||||
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
|
@ -389,7 +413,7 @@ func TestAppStateChange(t *testing.T) {
|
|||
func TestBlockedRPCMethods(t *testing.T) {
|
||||
utils.Init()
|
||||
|
||||
backend, stop1, stop2, err := setupGethStatusBackend()
|
||||
backend, stop1, stop2, stopWallet, err := setupGethStatusBackend()
|
||||
defer func() {
|
||||
err := stop1()
|
||||
if err != nil {
|
||||
|
@ -402,6 +426,12 @@ func TestBlockedRPCMethods(t *testing.T) {
|
|||
require.NoError(t, backend.StopNode())
|
||||
}
|
||||
}()
|
||||
defer func() {
|
||||
err := stopWallet()
|
||||
if err != nil {
|
||||
require.NoError(t, backend.StopNode())
|
||||
}
|
||||
}()
|
||||
require.NoError(t, err)
|
||||
|
||||
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
|
@ -443,7 +473,7 @@ func TestCallRPCWithStoppedNode(t *testing.T) {
|
|||
func TestStartStopMultipleTimes(t *testing.T) {
|
||||
utils.Init()
|
||||
|
||||
backend, stop1, stop2, err := setupGethStatusBackend()
|
||||
backend, stop1, stop2, stopWallet, err := setupGethStatusBackend()
|
||||
defer func() {
|
||||
err := stop1()
|
||||
if err != nil {
|
||||
|
@ -456,6 +486,12 @@ func TestStartStopMultipleTimes(t *testing.T) {
|
|||
require.NoError(t, backend.StopNode())
|
||||
}
|
||||
}()
|
||||
defer func() {
|
||||
err := stopWallet()
|
||||
if err != nil {
|
||||
require.NoError(t, backend.StopNode())
|
||||
}
|
||||
}()
|
||||
require.NoError(t, err)
|
||||
|
||||
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
|
@ -476,7 +512,7 @@ func TestStartStopMultipleTimes(t *testing.T) {
|
|||
func TestHashTypedData(t *testing.T) {
|
||||
utils.Init()
|
||||
|
||||
backend, stop1, stop2, err := setupGethStatusBackend()
|
||||
backend, stop1, stop2, stopWallet, err := setupGethStatusBackend()
|
||||
defer func() {
|
||||
err := stop1()
|
||||
if err != nil {
|
||||
|
@ -489,6 +525,12 @@ func TestHashTypedData(t *testing.T) {
|
|||
require.NoError(t, backend.StopNode())
|
||||
}
|
||||
}()
|
||||
defer func() {
|
||||
err := stopWallet()
|
||||
if err != nil {
|
||||
require.NoError(t, backend.StopNode())
|
||||
}
|
||||
}()
|
||||
require.NoError(t, err)
|
||||
|
||||
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
|
@ -854,7 +896,7 @@ func TestConvertAccount(t *testing.T) {
|
|||
|
||||
utils.Init()
|
||||
|
||||
backend, stop1, stop2, err := setupGethStatusBackend()
|
||||
backend, stop1, stop2, stopWallet, err := setupGethStatusBackend()
|
||||
defer func() {
|
||||
err := stop1()
|
||||
if err != nil {
|
||||
|
@ -867,6 +909,12 @@ func TestConvertAccount(t *testing.T) {
|
|||
require.NoError(t, backend.StopNode())
|
||||
}
|
||||
}()
|
||||
defer func() {
|
||||
err := stopWallet()
|
||||
if err != nil {
|
||||
require.NoError(t, backend.StopNode())
|
||||
}
|
||||
}()
|
||||
require.NoError(t, err)
|
||||
|
||||
backend.rootDataDir = rootDataDir
|
||||
|
|
|
@ -16,7 +16,7 @@ import (
|
|||
func TestHashMessage(t *testing.T) {
|
||||
utils.Init()
|
||||
|
||||
backend, stop1, stop2, err := setupGethStatusBackend()
|
||||
backend, stop1, stop2, stopWallet, err := setupGethStatusBackend()
|
||||
defer func() {
|
||||
err := stop1()
|
||||
if err != nil {
|
||||
|
@ -29,6 +29,12 @@ func TestHashMessage(t *testing.T) {
|
|||
require.NoError(t, backend.StopNode())
|
||||
}
|
||||
}()
|
||||
defer func() {
|
||||
err := stopWallet()
|
||||
if err != nil {
|
||||
require.NoError(t, backend.StopNode())
|
||||
}
|
||||
}()
|
||||
require.NoError(t, err)
|
||||
|
||||
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
|
|
|
@ -20,11 +20,12 @@ import (
|
|||
"github.com/status-im/status-go/services/wallet/bigint"
|
||||
w_common "github.com/status-im/status-go/services/wallet/common"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
)
|
||||
|
||||
func Test_GetDBFilename(t *testing.T) {
|
||||
// Test with a temp file instance
|
||||
db, stop, err := SetupTestSQLDB("test")
|
||||
db, stop, err := helpers.SetupTestSQLDB(DbInitializer{}, "test")
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
require.NoError(t, stop())
|
||||
|
@ -35,7 +36,7 @@ func Test_GetDBFilename(t *testing.T) {
|
|||
require.True(t, len(fn) > 0)
|
||||
|
||||
// Test with in memory instance
|
||||
mdb, err := InitializeDB(":memory:", "test", sqlite.ReducedKDFIterationsNumber)
|
||||
mdb, err := helpers.SetupTestMemorySQLDB(DbInitializer{})
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
require.NoError(t, mdb.Close())
|
||||
|
@ -115,11 +116,11 @@ func TestMigrateWalletJsonBlobs(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
// Validate that transfers table has no status column
|
||||
exists, err := ColumnExists(db, "transfers", "status")
|
||||
exists, err := helpers.ColumnExists(db, "transfers", "status")
|
||||
require.NoError(t, err)
|
||||
require.False(t, exists)
|
||||
|
||||
exists, err = ColumnExists(db, "transfers", "status")
|
||||
exists, err = helpers.ColumnExists(db, "transfers", "status")
|
||||
require.NoError(t, err)
|
||||
require.False(t, exists)
|
||||
|
||||
|
@ -196,7 +197,7 @@ func TestMigrateWalletJsonBlobs(t *testing.T) {
|
|||
err = migrations.MigrateTo(db, failMigrationSteps, customSteps[1].Version)
|
||||
require.Error(t, err)
|
||||
|
||||
exists, err = ColumnExists(db, "transfers", "status")
|
||||
exists, err = helpers.ColumnExists(db, "transfers", "status")
|
||||
require.NoError(t, err)
|
||||
require.False(t, exists)
|
||||
|
||||
|
@ -205,7 +206,7 @@ func TestMigrateWalletJsonBlobs(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
// Validate that the migration was run and transfers table has now status column
|
||||
exists, err = ColumnExists(db, "transfers", "status")
|
||||
exists, err = helpers.ColumnExists(db, "transfers", "status")
|
||||
require.NoError(t, err)
|
||||
require.True(t, exists)
|
||||
|
||||
|
@ -214,7 +215,7 @@ func TestMigrateWalletJsonBlobs(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
// Validate that the migration was run and transfers table has now txFrom column
|
||||
exists, err = ColumnExists(db, "transfers", "tx_from_address")
|
||||
exists, err = helpers.ColumnExists(db, "transfers", "tx_from_address")
|
||||
require.NoError(t, err)
|
||||
require.True(t, exists)
|
||||
|
||||
|
|
|
@ -4,10 +4,8 @@ import (
|
|||
"crypto/rand"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"math/big"
|
||||
"os"
|
||||
"sort"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -20,18 +18,13 @@ import (
|
|||
"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/sqlite"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
)
|
||||
|
||||
func setupTestDB(t *testing.T) (*sql.DB, func()) {
|
||||
tmpfile, err := ioutil.TempFile("", "settings-tests-")
|
||||
db, cleanup, err := helpers.SetupTestSQLDB(DbInitializer{}, "settings-tests-")
|
||||
require.NoError(t, err)
|
||||
db, err := InitializeDB(tmpfile.Name(), "settings-tests", sqlite.ReducedKDFIterationsNumber)
|
||||
require.NoError(t, err)
|
||||
return db, func() {
|
||||
require.NoError(t, db.Close())
|
||||
require.NoError(t, os.Remove(tmpfile.Name()))
|
||||
}
|
||||
return db, func() { require.NoError(t, cleanup()) }
|
||||
}
|
||||
|
||||
func TestGetNodeConfig(t *testing.T) {
|
||||
|
|
|
@ -3,27 +3,19 @@ package appmetrics
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func setupTestDB(t *testing.T) (*Database, func()) {
|
||||
tmpfile, err := ioutil.TempFile("", "appmetrics-tests-")
|
||||
db, cleanup, err := helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, "appmetrics-tests")
|
||||
require.NoError(t, err)
|
||||
db, err := appdatabase.InitializeDB(tmpfile.Name(), "appmetrics-tests", sqlite.ReducedKDFIterationsNumber)
|
||||
require.NoError(t, err)
|
||||
|
||||
return NewDB(db), func() {
|
||||
require.NoError(t, db.Close())
|
||||
require.NoError(t, os.Remove(tmpfile.Name()))
|
||||
}
|
||||
return NewDB(db), func() { require.NoError(t, cleanup()) }
|
||||
}
|
||||
|
||||
func TestSaveAppMetrics(t *testing.T) {
|
||||
|
|
|
@ -32,6 +32,7 @@ import (
|
|||
"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/walletdatabase"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -207,7 +208,13 @@ func main() {
|
|||
return
|
||||
}
|
||||
|
||||
db, err := appdatabase.InitializeDB(config.DataDir+"/"+installationID.String()+".db", "", sqlite.ReducedKDFIterationsNumber)
|
||||
walletDB, err := walletdatabase.InitializeDB(config.DataDir+"/"+installationID.String()+"-wallet.db", "", sqlite.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)
|
||||
if err != nil {
|
||||
logger.Error("failed to initialize app db", "error", err)
|
||||
return
|
||||
|
@ -216,7 +223,8 @@ func main() {
|
|||
options := []protocol.Option{
|
||||
protocol.WithPushNotifications(),
|
||||
protocol.WithPushNotificationServerConfig(&config.PushNotificationServerConfig),
|
||||
protocol.WithDatabase(db),
|
||||
protocol.WithDatabase(appDB),
|
||||
protocol.WithWalletDatabase(walletDB),
|
||||
protocol.WithTorrentConfig(&config.TorrentConfig),
|
||||
protocol.WithWalletConfig(&config.WalletConfig),
|
||||
protocol.WithRPCClient(backend.StatusNode().RPCClient()),
|
||||
|
|
|
@ -12,24 +12,15 @@ import (
|
|||
"github.com/status-im/status-go/multiaccounts/common"
|
||||
"github.com/status-im/status-go/multiaccounts/settings"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
)
|
||||
|
||||
func setupTestDB(t *testing.T) (*Database, func()) {
|
||||
db, stop, err := appdatabase.SetupTestSQLDB("settings-tests-")
|
||||
if err != nil {
|
||||
require.NoError(t, stop())
|
||||
}
|
||||
db, stop, err := helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, "settings-tests-")
|
||||
require.NoError(t, err)
|
||||
|
||||
d, err := NewDB(db)
|
||||
if err != nil {
|
||||
require.NoError(t, stop())
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
return d, func() {
|
||||
require.NoError(t, stop())
|
||||
}
|
||||
return d, func() { require.NoError(t, stop()) }
|
||||
}
|
||||
|
||||
func TestGetAddresses(t *testing.T) {
|
||||
|
|
|
@ -1,17 +1,13 @@
|
|||
package accounts
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func MockTestAccounts(tb testing.TB, db *sql.DB, accounts []*Account) {
|
||||
d, err := NewDB(db)
|
||||
require.NoError(tb, err)
|
||||
|
||||
err = d.SaveOrUpdateAccounts(accounts, false)
|
||||
func MockTestAccounts(tb testing.TB, d *Database, accounts []*Account) {
|
||||
err := d.SaveOrUpdateAccounts(accounts, false)
|
||||
require.NoError(tb, err)
|
||||
res, err := d.GetActiveAccounts()
|
||||
require.NoError(tb, err)
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"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"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -48,7 +49,7 @@ var (
|
|||
)
|
||||
|
||||
func setupTestDB(t *testing.T) (*Database, func()) {
|
||||
db, stop, err := appdatabase.SetupTestSQLDB("settings-tests-")
|
||||
db, stop, err := helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, "settings-tests-")
|
||||
if err != nil {
|
||||
require.NoError(t, stop())
|
||||
}
|
||||
|
|
|
@ -7,10 +7,11 @@ import (
|
|||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/protocol/identity"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
)
|
||||
|
||||
func openTestDB(t *testing.T) (*SocialLinksSettings, func()) {
|
||||
db, stop, err := appdatabase.SetupTestSQLDB("settings-social-links-tests-")
|
||||
db, stop, err := helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, "settings-social-links-tests-")
|
||||
if err != nil {
|
||||
require.NoError(t, stop())
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/multiaccounts"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
)
|
||||
|
||||
type TestServiceAPI struct{}
|
||||
|
@ -23,21 +23,7 @@ func (api *TestServiceAPI) SomeMethod(_ context.Context) (string, error) {
|
|||
}
|
||||
|
||||
func setupTestDB() (*sql.DB, func() error, error) {
|
||||
tmpfile, err := ioutil.TempFile("", "tests")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
db, err := appdatabase.InitializeDB(tmpfile.Name(), "tests", sqlite.ReducedKDFIterationsNumber)
|
||||
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
|
||||
return helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, "tests")
|
||||
}
|
||||
|
||||
func setupTestMultiDB() (*multiaccounts.Database, func() error, error) {
|
||||
|
|
|
@ -46,6 +46,7 @@ import (
|
|||
"github.com/status-im/status-go/services/wakuv2ext"
|
||||
"github.com/status-im/status-go/services/wallet"
|
||||
"github.com/status-im/status-go/services/wallet/thirdparty"
|
||||
"github.com/status-im/status-go/services/wallet/transfer"
|
||||
"github.com/status-im/status-go/services/web3provider"
|
||||
"github.com/status-im/status-go/timesource"
|
||||
"github.com/status-im/status-go/waku"
|
||||
|
@ -512,7 +513,7 @@ func (b *StatusNode) walletService(accountsDB *accounts.Database, accountsFeed *
|
|||
func (b *StatusNode) localNotificationsService(network uint64) (*localnotifications.Service, error) {
|
||||
var err error
|
||||
if b.localNotificationsSrvc == nil {
|
||||
b.localNotificationsSrvc, err = localnotifications.NewService(b.appDB, network)
|
||||
b.localNotificationsSrvc, err = localnotifications.NewService(b.appDB, transfer.NewDB(b.walletDB), network)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"context"
|
||||
"image"
|
||||
"image/png"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"math/big"
|
||||
"os"
|
||||
|
@ -23,6 +22,7 @@ import (
|
|||
"github.com/status-im/status-go/services/wallet/bigint"
|
||||
walletCommon "github.com/status-im/status-go/services/wallet/common"
|
||||
"github.com/status-im/status-go/services/wallet/thirdparty"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
_ "github.com/mutecomm/go-sqlcipher/v4" // require go-sqlcipher that overrides default implementation
|
||||
|
@ -44,9 +44,7 @@ type ManagerSuite struct {
|
|||
}
|
||||
|
||||
func (s *ManagerSuite) SetupTest() {
|
||||
dbPath, err := ioutil.TempFile("", "")
|
||||
s.NoError(err, "creating temp file for db")
|
||||
db, err := appdatabase.InitializeDB(dbPath.Name(), "", sqlite.ReducedKDFIterationsNumber)
|
||||
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
|
||||
s.NoError(err, "creating sqlite db instance")
|
||||
err = sqlite.Migrate(db)
|
||||
s.NoError(err, "protocol migrate")
|
||||
|
@ -138,7 +136,7 @@ func (m *testTokenManager) GetBalancesByChain(ctx context.Context, accounts, tok
|
|||
}
|
||||
|
||||
func (s *ManagerSuite) setupManagerForTokenPermissions() (*Manager, *testCollectiblesManager, *testTokenManager) {
|
||||
db, err := appdatabase.InitializeDB(sqlite.InMemoryPath, "", sqlite.ReducedKDFIterationsNumber)
|
||||
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
|
||||
s.NoError(err, "creating sqlite db instance")
|
||||
err = sqlite.Migrate(db)
|
||||
s.NoError(err, "protocol migrate")
|
||||
|
|
|
@ -3,7 +3,6 @@ package communities
|
|||
import (
|
||||
"crypto/ecdsa"
|
||||
"database/sql"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -18,6 +17,7 @@ import (
|
|||
"github.com/status-im/status-go/protocol/protobuf"
|
||||
"github.com/status-im/status-go/protocol/sqlite"
|
||||
"github.com/status-im/status-go/services/wallet/bigint"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
)
|
||||
|
||||
func TestPersistenceSuite(t *testing.T) {
|
||||
|
@ -33,10 +33,7 @@ type PersistenceSuite struct {
|
|||
func (s *PersistenceSuite) SetupTest() {
|
||||
s.db = nil
|
||||
|
||||
dbPath, err := ioutil.TempFile("", "")
|
||||
s.NoError(err, "creating temp file for db")
|
||||
|
||||
db, err := appdatabase.InitializeDB(dbPath.Name(), "", sqlite.ReducedKDFIterationsNumber)
|
||||
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
|
||||
s.NoError(err, "creating sqlite db instance")
|
||||
|
||||
err = sqlite.Migrate(db)
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
|
||||
"github.com/status-im/status-go/account"
|
||||
"github.com/status-im/status-go/account/generator"
|
||||
"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/multiaccounts"
|
||||
|
@ -28,8 +29,9 @@ import (
|
|||
"github.com/status-im/status-go/protocol/communities"
|
||||
"github.com/status-im/status-go/protocol/protobuf"
|
||||
"github.com/status-im/status-go/protocol/requests"
|
||||
"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/status-im/status-go/walletdatabase"
|
||||
)
|
||||
|
||||
type AccountManagerMock struct {
|
||||
|
@ -127,9 +129,20 @@ func newCommunitiesTestMessenger(shh types.Waku, privateKey *ecdsa.PrivateKey, l
|
|||
acc := generator.NewAccount(privateKey, nil)
|
||||
iai := acc.ToIdentifiedAccountInfo("")
|
||||
|
||||
walletDb, err := helpers.SetupTestMemorySQLDB(walletdatabase.DbInitializer{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
appDb, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
options := []Option{
|
||||
WithCustomLogger(logger),
|
||||
WithDatabaseConfig(":memory:", "somekey", sqlite.ReducedKDFIterationsNumber),
|
||||
WithDatabase(appDb),
|
||||
WithWalletDatabase(walletDb),
|
||||
WithMultiAccounts(madb),
|
||||
WithAccount(iai.ToMultiAccount()),
|
||||
WithDatasync(),
|
||||
|
|
|
@ -11,15 +11,17 @@ import (
|
|||
"go.uber.org/zap"
|
||||
|
||||
"github.com/status-im/status-go/account/generator"
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
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/eth-node/types"
|
||||
"github.com/status-im/status-go/multiaccounts"
|
||||
"github.com/status-im/status-go/multiaccounts/settings"
|
||||
"github.com/status-im/status-go/params"
|
||||
"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/status-im/status-go/waku"
|
||||
"github.com/status-im/status-go/walletdatabase"
|
||||
)
|
||||
|
||||
const DefaultProfileDisplayName = ""
|
||||
|
@ -80,9 +82,19 @@ func newMessengerWithKey(shh types.Waku, privateKey *ecdsa.PrivateKey, logger *z
|
|||
acc := generator.NewAccount(privateKey, nil)
|
||||
iai := acc.ToIdentifiedAccountInfo("")
|
||||
|
||||
walletDb, err := helpers.SetupTestMemorySQLDB(walletdatabase.DbInitializer{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
appDb, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
options := []Option{
|
||||
WithCustomLogger(logger),
|
||||
WithDatabaseConfig(":memory:", "somekey", sqlite.ReducedKDFIterationsNumber),
|
||||
WithDatabase(appDb),
|
||||
WithWalletDatabase(walletDb),
|
||||
WithMultiAccounts(madb),
|
||||
WithAccount(iai.ToMultiAccount()),
|
||||
WithDatasync(),
|
||||
|
|
|
@ -137,7 +137,7 @@ func (s *MessengerSyncSavedAddressesSuite) TestSyncExistingSavedAddresses() {
|
|||
IsTest: isTestChain2,
|
||||
}
|
||||
|
||||
savedAddressesManager := wallet.NewSavedAddressesManager(s.main.persistence.db)
|
||||
savedAddressesManager := s.main.savedAddressesManager
|
||||
|
||||
_, err := savedAddressesManager.UpdateMetadataAndUpsertSavedAddress(sa1)
|
||||
s.Require().NoError(err)
|
||||
|
|
|
@ -4,23 +4,24 @@ import (
|
|||
"crypto/ecdsa"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
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/eth-node/types"
|
||||
"github.com/status-im/status-go/multiaccounts/settings"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/protocol/encryption/multidevice"
|
||||
"github.com/status-im/status-go/protocol/sqlite"
|
||||
"github.com/status-im/status-go/protocol/tt"
|
||||
"github.com/status-im/status-go/services/stickers"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
"github.com/status-im/status-go/waku"
|
||||
"github.com/status-im/status-go/walletdatabase"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -162,12 +163,16 @@ func (s *MessengerSyncSettingsSuite) newMessengerWithOptions(shh types.Waku, pri
|
|||
}
|
||||
|
||||
func (s *MessengerSyncSettingsSuite) newMessengerWithKey(shh types.Waku, privateKey *ecdsa.PrivateKey) *Messenger {
|
||||
tmpFile, err := ioutil.TempFile("", "")
|
||||
walletDb, err := helpers.SetupTestMemorySQLDB(walletdatabase.DbInitializer{})
|
||||
s.Require().NoError(err)
|
||||
|
||||
appDb, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
|
||||
s.Require().NoError(err)
|
||||
|
||||
options := []Option{
|
||||
WithCustomLogger(s.logger),
|
||||
WithDatabaseConfig(tmpFile.Name(), "", sqlite.ReducedKDFIterationsNumber),
|
||||
WithDatabase(appDb),
|
||||
WithWalletDatabase(walletDb),
|
||||
WithDatasync(),
|
||||
}
|
||||
return s.newMessengerWithOptions(shh, privateKey, options)
|
||||
|
|
|
@ -4,30 +4,23 @@ import (
|
|||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
|
||||
gethrpc "github.com/ethereum/go-ethereum/rpc"
|
||||
)
|
||||
|
||||
func setupTestNetworkDB(t *testing.T) (*sql.DB, func()) {
|
||||
tmpfile, err := ioutil.TempFile("", "rpc-network-tests-")
|
||||
db, cleanup, err := helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, "rpc-network-tests")
|
||||
require.NoError(t, err)
|
||||
db, err := appdatabase.InitializeDB(tmpfile.Name(), "rpc-network-tests", sqlite.ReducedKDFIterationsNumber)
|
||||
require.NoError(t, err)
|
||||
return db, func() {
|
||||
require.NoError(t, db.Close())
|
||||
require.NoError(t, os.Remove(tmpfile.Name()))
|
||||
}
|
||||
return db, func() { require.NoError(t, cleanup()) }
|
||||
}
|
||||
|
||||
func TestBlockedRoutesCall(t *testing.T) {
|
||||
|
|
|
@ -2,15 +2,13 @@ package network
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
)
|
||||
|
||||
var initNetworks = []params.Network{
|
||||
|
@ -59,14 +57,9 @@ var initNetworks = []params.Network{
|
|||
}
|
||||
|
||||
func setupTestNetworkDB(t *testing.T) (*sql.DB, func()) {
|
||||
tmpfile, err := ioutil.TempFile("", "wallet-network-tests-")
|
||||
db, cleanup, err := helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, "wallet-network-tests")
|
||||
require.NoError(t, err)
|
||||
db, err := appdatabase.InitializeDB(tmpfile.Name(), "wallet-network-tests", sqlite.ReducedKDFIterationsNumber)
|
||||
require.NoError(t, err)
|
||||
return db, func() {
|
||||
require.NoError(t, db.Close())
|
||||
require.NoError(t, os.Remove(tmpfile.Name()))
|
||||
}
|
||||
return db, func() { require.NoError(t, cleanup()) }
|
||||
}
|
||||
|
||||
func TestInitNetwork(t *testing.T) {
|
||||
|
|
|
@ -3,26 +3,19 @@ package appmetrics
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/appmetrics"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func setupTestDB(t *testing.T) (*appmetrics.Database, func()) {
|
||||
tmpfile, err := ioutil.TempFile("", "appmetrics-service")
|
||||
db, cleanup, err := helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, "appmetrics-service")
|
||||
require.NoError(t, err)
|
||||
db, err := appdatabase.InitializeDB(tmpfile.Name(), "appmetrics-tests", sqlite.ReducedKDFIterationsNumber)
|
||||
require.NoError(t, err)
|
||||
return appmetrics.NewDB(db), func() {
|
||||
require.NoError(t, db.Close())
|
||||
require.NoError(t, os.Remove(tmpfile.Name()))
|
||||
}
|
||||
return appmetrics.NewDB(db), func() { require.NoError(t, cleanup()) }
|
||||
}
|
||||
|
||||
func TestValidateAppMetrics(t *testing.T) {
|
||||
|
|
|
@ -2,25 +2,18 @@ package browsers
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
)
|
||||
|
||||
func setupTestDB(t *testing.T) (*Database, func()) {
|
||||
tmpfile, err := ioutil.TempFile("", "browsers-tests-")
|
||||
db, cleanup, err := helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, "browsers-tests")
|
||||
require.NoError(t, err)
|
||||
db, err := appdatabase.InitializeDB(tmpfile.Name(), "browsers-tests", sqlite.ReducedKDFIterationsNumber)
|
||||
require.NoError(t, err)
|
||||
return NewDB(db), func() {
|
||||
require.NoError(t, db.Close())
|
||||
require.NoError(t, os.Remove(tmpfile.Name()))
|
||||
}
|
||||
return NewDB(db), func() { require.NoError(t, cleanup()) }
|
||||
}
|
||||
|
||||
func setupTestAPI(t *testing.T) (*API, func()) {
|
||||
|
|
|
@ -2,17 +2,17 @@ package collectibles
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/protocol/communities/token"
|
||||
"github.com/status-im/status-go/protocol/protobuf"
|
||||
"github.com/status-im/status-go/protocol/sqlite"
|
||||
"github.com/status-im/status-go/services/wallet/bigint"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
"github.com/status-im/status-go/walletdatabase"
|
||||
)
|
||||
|
||||
func TestDatabaseSuite(t *testing.T) {
|
||||
|
@ -82,10 +82,7 @@ func (s *DatabaseSuite) setupDatabase(db *sql.DB) error {
|
|||
func (s *DatabaseSuite) SetupTest() {
|
||||
s.db = nil
|
||||
|
||||
dbPath, err := ioutil.TempFile("", "status-go-community-tokens-db-")
|
||||
s.NoError(err, "creating temp file for db")
|
||||
|
||||
db, err := appdatabase.InitializeDB(dbPath.Name(), "", sqlite.ReducedKDFIterationsNumber)
|
||||
db, err := helpers.SetupTestMemorySQLDB(walletdatabase.DbInitializer{})
|
||||
s.NoError(err, "creating sqlite db instance")
|
||||
|
||||
err = sqlite.Migrate(db)
|
||||
|
|
|
@ -3,8 +3,6 @@ package ens
|
|||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -16,20 +14,15 @@ import (
|
|||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/params"
|
||||
statusRPC "github.com/status-im/status-go/rpc"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
"github.com/status-im/status-go/t/utils"
|
||||
"github.com/status-im/status-go/transactions/fake"
|
||||
)
|
||||
|
||||
func createDB(t *testing.T) (*sql.DB, func()) {
|
||||
tmpfile, err := ioutil.TempFile("", "service-ens-tests-")
|
||||
db, cleanup, err := helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, "service-ens-tests-")
|
||||
require.NoError(t, err)
|
||||
db, err := appdatabase.InitializeDB(tmpfile.Name(), "service-ens-tests", sqlite.ReducedKDFIterationsNumber)
|
||||
require.NoError(t, err)
|
||||
return db, func() {
|
||||
require.NoError(t, db.Close())
|
||||
require.NoError(t, os.Remove(tmpfile.Name()))
|
||||
}
|
||||
return db, func() { require.NoError(t, cleanup()) }
|
||||
}
|
||||
|
||||
func setupTestAPI(t *testing.T) (*API, func()) {
|
||||
|
|
|
@ -3,25 +3,19 @@ package gif
|
|||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/multiaccounts/accounts"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
)
|
||||
|
||||
func setupSQLTestDb(t *testing.T) (*sql.DB, func()) {
|
||||
tmpfile, err := ioutil.TempFile("", "local-notifications-tests-")
|
||||
db, cleanup, err := helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, "local-notifications-tests-")
|
||||
require.NoError(t, err)
|
||||
db, err := appdatabase.InitializeDB(tmpfile.Name(), "local-notifications-tests", sqlite.ReducedKDFIterationsNumber)
|
||||
require.NoError(t, err)
|
||||
return db, func() {
|
||||
require.NoError(t, os.Remove(tmpfile.Name()))
|
||||
}
|
||||
return db, func() { require.NoError(t, cleanup()) }
|
||||
}
|
||||
|
||||
func setupTestDB(t *testing.T, db *sql.DB) (*accounts.Database, func()) {
|
||||
|
|
|
@ -95,9 +95,8 @@ type Service struct {
|
|||
accountsDB *accounts.Database
|
||||
}
|
||||
|
||||
func NewService(appDB *sql.DB, chainID uint64) (*Service, error) {
|
||||
func NewService(appDB *sql.DB, walletDB *transfer.Database, chainID uint64) (*Service, error) {
|
||||
db := NewDB(appDB, chainID)
|
||||
walletDB := transfer.NewDB(appDB)
|
||||
accountsDB, err := accounts.NewDB(appDB)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package localnotifications
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strings"
|
||||
|
@ -14,16 +13,20 @@ import (
|
|||
"github.com/status-im/status-go/services/wallet/transfer"
|
||||
"github.com/status-im/status-go/services/wallet/walletevent"
|
||||
"github.com/status-im/status-go/signal"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
"github.com/status-im/status-go/t/utils"
|
||||
"github.com/status-im/status-go/walletdatabase"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
)
|
||||
|
||||
func createWalletDb(t *testing.T, db *sql.DB) (*transfer.Database, func()) {
|
||||
func createWalletDb(t *testing.T) (*transfer.Database, func()) {
|
||||
db, cleanup, err := helpers.SetupTestSQLDB(walletdatabase.DbInitializer{}, "local-notifications-tests-wallet-")
|
||||
require.NoError(t, err)
|
||||
return transfer.NewDB(db), func() {
|
||||
require.NoError(t, db.Close())
|
||||
require.NoError(t, cleanup())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,7 +34,10 @@ func TestServiceStartStop(t *testing.T) {
|
|||
db, stop := setupAppTestDb(t)
|
||||
defer stop()
|
||||
|
||||
s, err := NewService(db, 1777)
|
||||
walletDb, walletStop := createWalletDb(t)
|
||||
defer walletStop()
|
||||
|
||||
s, err := NewService(db, walletDb, 1777)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, s.Start())
|
||||
require.Equal(t, true, s.IsStarted())
|
||||
|
@ -44,8 +50,11 @@ func TestWalletSubscription(t *testing.T) {
|
|||
db, stop := setupAppTestDb(t)
|
||||
defer stop()
|
||||
|
||||
walletDb, walletStop := createWalletDb(t)
|
||||
defer walletStop()
|
||||
|
||||
feed := &event.Feed{}
|
||||
s, err := NewService(db, 1777)
|
||||
s, err := NewService(db, walletDb, 1777)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, s.Start())
|
||||
require.Equal(t, true, s.IsStarted())
|
||||
|
@ -67,10 +76,10 @@ func TestTransactionNotification(t *testing.T) {
|
|||
db, stop := setupAppTestDb(t)
|
||||
defer stop()
|
||||
|
||||
walletDb, stop := createWalletDb(t, db)
|
||||
defer stop()
|
||||
walletDb, walletStop := createWalletDb(t)
|
||||
defer walletStop()
|
||||
|
||||
s, err := NewService(db, 1777)
|
||||
s, err := NewService(db, walletDb, 1777)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, s.Start())
|
||||
require.Equal(t, true, s.IsStarted())
|
||||
|
|
|
@ -2,24 +2,18 @@ package localnotifications
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
)
|
||||
|
||||
func setupAppTestDb(t *testing.T) (*sql.DB, func()) {
|
||||
tmpfile, err := ioutil.TempFile("", "local-notifications-tests-")
|
||||
db, cleanup, err := helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, "local-notifications-tests-")
|
||||
require.NoError(t, err)
|
||||
db, err := appdatabase.InitializeDB(tmpfile.Name(), "local-notifications-tests", sqlite.ReducedKDFIterationsNumber)
|
||||
require.NoError(t, err)
|
||||
return db, func() {
|
||||
require.NoError(t, os.Remove(tmpfile.Name()))
|
||||
}
|
||||
return db, func() { require.NoError(t, cleanup()) }
|
||||
}
|
||||
|
||||
func setupTestDB(t *testing.T, db *sql.DB) (*Database, func()) {
|
||||
|
|
|
@ -2,8 +2,6 @@ package mailservers
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -11,18 +9,13 @@ import (
|
|||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/protocol/transport"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
)
|
||||
|
||||
func setupTestDB(t *testing.T) (*Database, func()) {
|
||||
tmpfile, err := ioutil.TempFile("", "mailservers-service")
|
||||
db, cleanup, err := helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, "maliservers-tests-")
|
||||
require.NoError(t, err)
|
||||
db, err := appdatabase.InitializeDB(tmpfile.Name(), "mailservers-tests", sqlite.ReducedKDFIterationsNumber)
|
||||
require.NoError(t, err)
|
||||
return NewDB(db), func() {
|
||||
require.NoError(t, db.Close())
|
||||
require.NoError(t, os.Remove(tmpfile.Name()))
|
||||
}
|
||||
return NewDB(db), func() { require.NoError(t, cleanup()) }
|
||||
}
|
||||
|
||||
func TestAddGetDeleteMailserver(t *testing.T) {
|
||||
|
|
|
@ -4,26 +4,19 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
)
|
||||
|
||||
func setupTestDB(t *testing.T) (*Database, func()) {
|
||||
tmpfile, err := ioutil.TempFile("", "perm-tests-")
|
||||
db, cleanup, err := helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, "perm-tests-")
|
||||
require.NoError(t, err)
|
||||
db, err := appdatabase.InitializeDB(tmpfile.Name(), "perm-tests", sqlite.ReducedKDFIterationsNumber)
|
||||
require.NoError(t, err)
|
||||
return NewDB(db), func() {
|
||||
require.NoError(t, db.Close())
|
||||
require.NoError(t, os.Remove(tmpfile.Name()))
|
||||
}
|
||||
return NewDB(db), func() { require.NoError(t, cleanup()) }
|
||||
}
|
||||
|
||||
func setupTestAPI(t *testing.T) (*API, func()) {
|
||||
|
|
|
@ -26,9 +26,9 @@ import (
|
|||
"github.com/status-im/status-go/multiaccounts"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/services/ext"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
"github.com/status-im/status-go/waku"
|
||||
"github.com/status-im/status-go/walletdatabase"
|
||||
)
|
||||
|
||||
func TestRequestMessagesErrors(t *testing.T) {
|
||||
|
@ -121,9 +121,8 @@ func TestInitProtocol(t *testing.T) {
|
|||
nodeWrapper := ext.NewTestNodeWrapper(nil, waku)
|
||||
service := New(config, nodeWrapper, nil, nil, db)
|
||||
|
||||
tmpdir := t.TempDir()
|
||||
|
||||
sqlDB, err := appdatabase.InitializeDB(fmt.Sprintf("%s/db.sql", tmpdir), "password", sqlite.ReducedKDFIterationsNumber)
|
||||
appDB, cleanupDB, err := helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, "db.sql")
|
||||
defer func() { require.NoError(t, cleanupDB()) }()
|
||||
require.NoError(t, err)
|
||||
|
||||
tmpfile, err := ioutil.TempFile("", "multi-accounts-tests-")
|
||||
|
@ -133,7 +132,11 @@ func TestInitProtocol(t *testing.T) {
|
|||
|
||||
acc := &multiaccounts.Account{KeyUID: "0xdeadbeef"}
|
||||
|
||||
err = service.InitProtocol("Test", privateKey, sqlDB, nil, multiAccounts, acc, nil, nil, nil, nil, zap.NewNop())
|
||||
walletDB, cleanupWalletDB, err := helpers.SetupTestSQLDB(walletdatabase.DbInitializer{}, "db-wallet.sql")
|
||||
defer func() { require.NoError(t, cleanupWalletDB()) }()
|
||||
require.NoError(t, err)
|
||||
|
||||
err = service.InitProtocol("Test", privateKey, appDB, walletDB, nil, multiAccounts, acc, nil, nil, nil, nil, zap.NewNop())
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
@ -185,11 +188,14 @@ func (s *ShhExtSuite) createAndAddNode() {
|
|||
s.Require().NoError(err)
|
||||
nodeWrapper := ext.NewTestNodeWrapper(nil, gethbridge.NewGethWakuWrapper(w))
|
||||
service := New(config, nodeWrapper, nil, nil, db)
|
||||
sqlDB, err := appdatabase.InitializeDB(fmt.Sprintf("%s/%d", s.dir, idx), "password", sqlite.ReducedKDFIterationsNumber)
|
||||
|
||||
appDB, cleanupDB, err := helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, fmt.Sprintf("%d", idx))
|
||||
s.Require().NoError(err)
|
||||
defer func() { s.Require().NoError(cleanupDB()) }()
|
||||
|
||||
tmpfile, err := ioutil.TempFile("", "multi-accounts-tests-")
|
||||
s.Require().NoError(err)
|
||||
|
||||
multiAccounts, err := multiaccounts.InitializeDB(tmpfile.Name())
|
||||
s.Require().NoError(err)
|
||||
|
||||
|
@ -198,7 +204,10 @@ func (s *ShhExtSuite) createAndAddNode() {
|
|||
|
||||
acc := &multiaccounts.Account{KeyUID: "0xdeadbeef"}
|
||||
|
||||
err = service.InitProtocol("Test", privateKey, sqlDB, nil, multiAccounts, acc, nil, nil, nil, nil, zap.NewNop())
|
||||
walletDB, err := helpers.SetupTestMemorySQLDB(&walletdatabase.DbInitializer{})
|
||||
s.Require().NoError(err)
|
||||
|
||||
err = service.InitProtocol("Test", privateKey, appDB, walletDB, nil, multiAccounts, acc, nil, nil, nil, nil, zap.NewNop())
|
||||
s.NoError(err)
|
||||
|
||||
stack.RegisterLifecycle(service)
|
||||
|
|
|
@ -12,6 +12,8 @@ import (
|
|||
"github.com/status-im/status-go/services/wallet/common"
|
||||
"github.com/status-im/status-go/services/wallet/testutils"
|
||||
"github.com/status-im/status-go/services/wallet/transfer"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
"github.com/status-im/status-go/walletdatabase"
|
||||
|
||||
eth "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
|
@ -37,17 +39,28 @@ func tokenFromSymbol(chainID *common.ChainID, symbol string) *Token {
|
|||
}
|
||||
|
||||
func setupTestActivityDBStorageChoice(tb testing.TB, inMemory bool) (deps FilterDependencies, close func()) {
|
||||
var db *sql.DB
|
||||
var db, appDb *sql.DB
|
||||
var err error
|
||||
cleanupDB := func() error { return nil }
|
||||
cleanupWalletDB := func() error { return nil }
|
||||
if inMemory {
|
||||
db, err = appdatabase.SetupTestMemorySQLDB("wallet-activity-tests")
|
||||
} else {
|
||||
db, cleanupDB, err = appdatabase.SetupTestSQLDB("wallet-activity-tests")
|
||||
}
|
||||
db, err = helpers.SetupTestMemorySQLDB(walletdatabase.DbInitializer{})
|
||||
require.NoError(tb, err)
|
||||
appDb, err = helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
|
||||
require.NoError(tb, err)
|
||||
} else {
|
||||
db, cleanupWalletDB, err = helpers.SetupTestSQLDB(walletdatabase.DbInitializer{}, "wallet-activity-tests")
|
||||
require.NoError(tb, err)
|
||||
appDb, cleanupDB, err = helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, "wallet-activity-tests")
|
||||
require.NoError(tb, err)
|
||||
}
|
||||
|
||||
accountsDb, err := accounts.NewDB(appDb)
|
||||
require.NoError(tb, err)
|
||||
|
||||
deps = FilterDependencies{
|
||||
db: db,
|
||||
accountsDb: accountsDb,
|
||||
tokenSymbol: func(token Token) string {
|
||||
switch token.TokenType {
|
||||
case Native:
|
||||
|
@ -71,8 +84,8 @@ func setupTestActivityDBStorageChoice(tb testing.TB, inMemory bool) (deps Filter
|
|||
}
|
||||
|
||||
return deps, func() {
|
||||
require.NoError(tb, db.Close())
|
||||
require.NoError(tb, cleanupDB())
|
||||
require.NoError(tb, cleanupWalletDB())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,7 +111,7 @@ type testData struct {
|
|||
nextIndex int
|
||||
}
|
||||
|
||||
func mockTestAccountsWithAddresses(tb testing.TB, db *sql.DB, addresses []eth.Address) {
|
||||
func mockTestAccountsWithAddresses(tb testing.TB, db *accounts.Database, addresses []eth.Address) {
|
||||
mockedAccounts := []*accounts.Account{}
|
||||
for _, address := range addresses {
|
||||
mockedAccounts = append(mockedAccounts, &accounts.Account{
|
||||
|
@ -273,7 +286,7 @@ func TestGetActivityEntriesWithSameTransactionForSenderAndReceiverInDB(t *testin
|
|||
// Add 4 extractable transactions with timestamps 1-4
|
||||
td, fromAddresses, toAddresses := fillTestData(t, deps.db)
|
||||
|
||||
mockTestAccountsWithAddresses(t, deps.db, append(fromAddresses, toAddresses...))
|
||||
mockTestAccountsWithAddresses(t, deps.accountsDb, append(fromAddresses, toAddresses...))
|
||||
|
||||
// Add another transaction with sender and receiver reversed
|
||||
receiverTr := td.tr1
|
||||
|
@ -322,7 +335,7 @@ func TestGetActivityEntriesFilterByTime(t *testing.T) {
|
|||
transfer.InsertTestTransfer(t, deps.db, trs[i].To, &trs[i])
|
||||
}
|
||||
|
||||
mockTestAccountsWithAddresses(t, deps.db, append(append(append(fromTds, toTds...), fromTrs...), toTrs...))
|
||||
mockTestAccountsWithAddresses(t, deps.accountsDb, append(append(append(fromTds, toTds...), fromTrs...), toTrs...))
|
||||
|
||||
// Test start only
|
||||
var filter Filter
|
||||
|
@ -462,7 +475,7 @@ func TestGetActivityEntriesCheckOffsetAndLimit(t *testing.T) {
|
|||
transfer.InsertTestTransfer(t, deps.db, trs[i].To, &trs[i])
|
||||
}
|
||||
|
||||
mockTestAccountsWithAddresses(t, deps.db, append(fromTrs, toTrs...))
|
||||
mockTestAccountsWithAddresses(t, deps.accountsDb, append(fromTrs, toTrs...))
|
||||
|
||||
var filter Filter
|
||||
// Get all
|
||||
|
@ -664,7 +677,7 @@ func TestGetActivityEntriesFilterByAddresses(t *testing.T) {
|
|||
transfer.InsertTestTransfer(t, deps.db, trs[i].To, &trs[i])
|
||||
}
|
||||
|
||||
mockTestAccountsWithAddresses(t, deps.db, append(append(append(fromTds, toTds...), fromTrs...), toTrs...))
|
||||
mockTestAccountsWithAddresses(t, deps.accountsDb, append(append(append(fromTds, toTds...), fromTrs...), toTrs...))
|
||||
|
||||
var filter Filter
|
||||
|
||||
|
@ -749,7 +762,7 @@ func TestGetActivityEntriesFilterByStatus(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
mockTestAccountsWithAddresses(t, deps.db, append(append(append(fromTds, toTds...), fromTrs...), toTrs...))
|
||||
mockTestAccountsWithAddresses(t, deps.accountsDb, append(append(append(fromTds, toTds...), fromTrs...), toTrs...))
|
||||
|
||||
var filter Filter
|
||||
filter.Statuses = allActivityStatusesFilter()
|
||||
|
@ -804,7 +817,7 @@ func TestGetActivityEntriesFilterByTokenType(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
mockTestAccountsWithAddresses(t, deps.db, append(append(append(fromTds, toTds...), fromTrs...), toTrs...))
|
||||
mockTestAccountsWithAddresses(t, deps.accountsDb, append(append(append(fromTds, toTds...), fromTrs...), toTrs...))
|
||||
|
||||
var filter Filter
|
||||
filter.FilterOutAssets = true
|
||||
|
@ -882,7 +895,7 @@ func TestGetActivityEntriesFilterByToAddresses(t *testing.T) {
|
|||
transfer.InsertTestTransfer(t, deps.db, trs[i].To, &trs[i])
|
||||
}
|
||||
|
||||
mockTestAccountsWithAddresses(t, deps.db, append(append(append(fromTds, toTds...), fromTrs...), toTrs...))
|
||||
mockTestAccountsWithAddresses(t, deps.accountsDb, append(append(append(fromTds, toTds...), fromTrs...), toTrs...))
|
||||
|
||||
var filter Filter
|
||||
filter.CounterpartyAddresses = allAddressesFilter()
|
||||
|
@ -946,7 +959,7 @@ func TestGetActivityEntriesFilterByNetworks(t *testing.T) {
|
|||
recordPresence(trs[i].ChainID, 4+i)
|
||||
transfer.InsertTestTransfer(t, deps.db, trs[i].To, &trs[i])
|
||||
}
|
||||
mockTestAccountsWithAddresses(t, deps.db, append(append(append(fromTds, toTds...), fromTrs...), toTrs...))
|
||||
mockTestAccountsWithAddresses(t, deps.accountsDb, append(append(append(fromTds, toTds...), fromTrs...), toTrs...))
|
||||
|
||||
var filter Filter
|
||||
chainIDs := allNetworksFilter()
|
||||
|
@ -1094,7 +1107,7 @@ func TestGetActivityEntriesNullAddresses(t *testing.T) {
|
|||
trs[3].To = eth.Address{}
|
||||
transfer.InsertTestPendingTransaction(t, deps.db, &trs[3])
|
||||
|
||||
mockTestAccountsWithAddresses(t, deps.db, []eth.Address{trs[0].From, trs[1].From, trs[2].From, trs[3].From})
|
||||
mockTestAccountsWithAddresses(t, deps.accountsDb, []eth.Address{trs[0].From, trs[1].From, trs[2].From, trs[3].From})
|
||||
|
||||
activities, err := getActivityEntries(context.Background(), deps, allAddressesFilter(), allNetworksFilter(), Filter{}, 0, 10)
|
||||
require.NoError(t, err)
|
||||
|
@ -1163,7 +1176,7 @@ func setupBenchmark(b *testing.B, inMemory bool, resultCount int) (deps FilterDe
|
|||
transfer.InsertTestPendingTransaction(b, deps.db, &trs[i])
|
||||
}
|
||||
|
||||
mockTestAccountsWithAddresses(b, deps.db, accounts)
|
||||
mockTestAccountsWithAddresses(b, deps.accountsDb, accounts)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -8,15 +8,16 @@ import (
|
|||
|
||||
eth "github.com/ethereum/go-ethereum/common"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/services/wallet/testutils"
|
||||
"github.com/status-im/status-go/services/wallet/transfer"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
"github.com/status-im/status-go/walletdatabase"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func setupTestFilterDB(t *testing.T) (db *sql.DB, close func()) {
|
||||
db, err := appdatabase.SetupTestMemorySQLDB("wallet-activity-tests-filter")
|
||||
db, err := helpers.SetupTestMemorySQLDB(walletdatabase.DbInitializer{})
|
||||
require.NoError(t, err)
|
||||
|
||||
return db, func() {
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
|
||||
"github.com/status-im/status-go/multiaccounts/accounts"
|
||||
"github.com/status-im/status-go/services/wallet/async"
|
||||
w_common "github.com/status-im/status-go/services/wallet/common"
|
||||
"github.com/status-im/status-go/services/wallet/token"
|
||||
|
@ -40,15 +41,17 @@ var (
|
|||
|
||||
type Service struct {
|
||||
db *sql.DB
|
||||
accountsDB *accounts.Database
|
||||
tokenManager *token.Manager
|
||||
eventFeed *event.Feed
|
||||
|
||||
scheduler *async.MultiClientScheduler
|
||||
}
|
||||
|
||||
func NewService(db *sql.DB, tokenManager *token.Manager, eventFeed *event.Feed) *Service {
|
||||
func NewService(db *sql.DB, tokenManager *token.Manager, eventFeed *event.Feed, accountsDb *accounts.Database) *Service {
|
||||
return &Service{
|
||||
db: db,
|
||||
accountsDB: accountsDb,
|
||||
tokenManager: tokenManager,
|
||||
eventFeed: eventFeed,
|
||||
scheduler: async.NewMultiClientScheduler(),
|
||||
|
@ -163,6 +166,7 @@ func (s *Service) Stop() {
|
|||
func (s *Service) getDeps() FilterDependencies {
|
||||
return FilterDependencies{
|
||||
db: s.db,
|
||||
accountsDb: s.accountsDB,
|
||||
tokenSymbol: func(t Token) string {
|
||||
info := s.tokenManager.LookupTokenIdentity(uint64(t.ChainID), t.Address, t.TokenType == Native)
|
||||
if info == nil {
|
||||
|
|
|
@ -6,16 +6,17 @@ import (
|
|||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/services/wallet/bigint"
|
||||
w_common "github.com/status-im/status-go/services/wallet/common"
|
||||
"github.com/status-im/status-go/services/wallet/thirdparty"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
"github.com/status-im/status-go/walletdatabase"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func setupOwnershipDBTest(t *testing.T) (*OwnershipDB, func()) {
|
||||
db, err := appdatabase.InitializeDB(":memory:", "wallet-collecitibles-ownership-db-tests", 1)
|
||||
db, err := helpers.SetupTestMemorySQLDB(walletdatabase.DbInitializer{})
|
||||
require.NoError(t, err)
|
||||
return NewOwnershipDB(db), func() {
|
||||
require.NoError(t, db.Close())
|
||||
|
|
|
@ -5,11 +5,12 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
"github.com/status-im/status-go/walletdatabase"
|
||||
)
|
||||
|
||||
func setupTestCurrencyDB(t *testing.T) (*DB, func()) {
|
||||
db, err := appdatabase.InitializeDB(":memory:", "wallet-currency-db-tests-", 1)
|
||||
db, err := helpers.SetupTestMemorySQLDB(walletdatabase.DbInitializer{})
|
||||
require.NoError(t, err)
|
||||
return NewCurrencyDB(db), func() {
|
||||
require.NoError(t, db.Close())
|
||||
|
|
|
@ -9,12 +9,13 @@ import (
|
|||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/protocol/sqlite"
|
||||
"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 := appdatabase.InitializeDB(":memory:", "wallet-history-balance_db-tests", 1)
|
||||
db, err := walletdatabase.InitializeDB(sqlite.InMemoryPath, "wallet-history-balance_db-tests", 1)
|
||||
require.NoError(t, err)
|
||||
return NewBalanceDB(db), func() {
|
||||
require.NoError(t, db.Close())
|
||||
|
|
|
@ -12,15 +12,14 @@ import (
|
|||
"github.com/ethereum/go-ethereum"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
"github.com/status-im/status-go/walletdatabase"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func setupBalanceTest(t *testing.T) (*Balance, func()) {
|
||||
db, err := appdatabase.InitializeDB(":memory:", "wallet-history-balance-tests", sqlite.ReducedKDFIterationsNumber)
|
||||
db, err := helpers.SetupTestMemorySQLDB(walletdatabase.DbInitializer{})
|
||||
require.NoError(t, err)
|
||||
return NewBalance(NewBalanceDB(db)), func() {
|
||||
require.NoError(t, db.Close())
|
||||
|
|
|
@ -14,18 +14,19 @@ import (
|
|||
|
||||
"github.com/golang/mock/gomock"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/params"
|
||||
statusRPC "github.com/status-im/status-go/rpc"
|
||||
"github.com/status-im/status-go/services/wallet/market"
|
||||
"github.com/status-im/status-go/services/wallet/thirdparty/cryptocompare"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
"github.com/status-im/status-go/transactions/fake"
|
||||
"github.com/status-im/status-go/walletdatabase"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func setupDummyServiceNoDependencies(t *testing.T) (service *Service, closeFn func()) {
|
||||
db, err := appdatabase.InitializeDB(":memory:", "wallet-history-service-tests", 1)
|
||||
db, err := helpers.SetupTestMemorySQLDB(walletdatabase.DbInitializer{})
|
||||
require.NoError(t, err)
|
||||
cryptoCompare := cryptocompare.NewClient()
|
||||
|
||||
|
|
|
@ -8,9 +8,8 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
"github.com/status-im/status-go/walletdatabase"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -20,7 +19,7 @@ const (
|
|||
)
|
||||
|
||||
func setupTestSavedAddressesDB(t *testing.T) (*SavedAddressesManager, func()) {
|
||||
db, err := appdatabase.InitializeDB(sqlite.InMemoryPath, "wallet-saved_addresses-tests", sqlite.ReducedKDFIterationsNumber)
|
||||
db, err := helpers.SetupTestMemorySQLDB(walletdatabase.DbInitializer{})
|
||||
require.NoError(t, err)
|
||||
|
||||
return &SavedAddressesManager{db}, func() {
|
||||
|
|
|
@ -103,7 +103,7 @@ func NewService(
|
|||
reader := NewReader(rpcClient, tokenManager, marketManager, accountsDB, NewPersistence(db), walletFeed)
|
||||
history := history.NewService(db, walletFeed, rpcClient, tokenManager, marketManager)
|
||||
currency := currency.NewService(db, walletFeed, tokenManager, marketManager)
|
||||
activity := activity.NewService(db, tokenManager, walletFeed)
|
||||
activity := activity.NewService(db, tokenManager, walletFeed, accountsDB)
|
||||
|
||||
openseaClient := opensea.NewClient(config.WalletConfig.OpenseaAPIKey, walletFeed)
|
||||
infuraClient := infura.NewClient(config.WalletConfig.InfuraAPIKey, config.WalletConfig.InfuraAPIKeySecret)
|
||||
|
|
|
@ -8,12 +8,13 @@ import (
|
|||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
"github.com/status-im/status-go/walletdatabase"
|
||||
)
|
||||
|
||||
func setupTestTokenDB(t *testing.T) (*Manager, func()) {
|
||||
db, err := appdatabase.InitializeDB(":memory:", "wallet-token-tests", 1)
|
||||
db, err := helpers.SetupTestMemorySQLDB(walletdatabase.DbInitializer{})
|
||||
require.NoError(t, err)
|
||||
return &Manager{db, nil, nil, nil, nil, nil, false}, func() {
|
||||
require.NoError(t, db.Close())
|
||||
|
|
|
@ -6,13 +6,14 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
"github.com/status-im/status-go/walletdatabase"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
)
|
||||
|
||||
func setupTestTransferDB(t *testing.T) (*BlockDAO, func()) {
|
||||
db, err := appdatabase.InitializeDB(sqlite.InMemoryPath, "wallet-tests", sqlite.ReducedKDFIterationsNumber)
|
||||
db, err := helpers.SetupTestMemorySQLDB(walletdatabase.DbInitializer{})
|
||||
require.NoError(t, err)
|
||||
return &BlockDAO{db}, func() {
|
||||
require.NoError(t, db.Close())
|
||||
|
|
|
@ -10,12 +10,13 @@ import (
|
|||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
w_common "github.com/status-im/status-go/services/wallet/common"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
"github.com/status-im/status-go/walletdatabase"
|
||||
)
|
||||
|
||||
func setupTestDB(t *testing.T) (*Database, *BlockDAO, func()) {
|
||||
db, err := appdatabase.SetupTestMemorySQLDB("wallet-transfer-tests")
|
||||
db, err := helpers.SetupTestMemorySQLDB(walletdatabase.DbInitializer{})
|
||||
require.NoError(t, err)
|
||||
return NewDB(db), &BlockDAO{db}, func() {
|
||||
require.NoError(t, db.Close())
|
||||
|
|
|
@ -7,14 +7,15 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
"github.com/status-im/status-go/walletdatabase"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
)
|
||||
|
||||
func setupTestTransactionDB(t *testing.T) (*TransactionManager, func()) {
|
||||
db, err := appdatabase.SetupTestMemorySQLDB("wallet-transfer-transaction-tests")
|
||||
db, err := helpers.SetupTestMemorySQLDB(walletdatabase.DbInitializer{})
|
||||
require.NoError(t, err)
|
||||
return &TransactionManager{db, nil, nil, nil, nil, nil, nil}, func() {
|
||||
require.NoError(t, db.Close())
|
||||
|
|
|
@ -3,8 +3,6 @@ package web3provider
|
|||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
|
@ -17,7 +15,7 @@ import (
|
|||
"github.com/status-im/status-go/multiaccounts/settings"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/services/permissions"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
"github.com/status-im/status-go/t/utils"
|
||||
"github.com/status-im/status-go/transactions/fake"
|
||||
|
||||
|
@ -26,14 +24,9 @@ import (
|
|||
)
|
||||
|
||||
func createDB(t *testing.T) (*sql.DB, func()) {
|
||||
tmpfile, err := ioutil.TempFile("", "provider-tests-")
|
||||
db, cleanup, err := helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, "provider-tests-")
|
||||
require.NoError(t, err)
|
||||
db, err := appdatabase.InitializeDB(tmpfile.Name(), "provider-tests", sqlite.ReducedKDFIterationsNumber)
|
||||
require.NoError(t, err)
|
||||
return db, func() {
|
||||
require.NoError(t, db.Close())
|
||||
require.NoError(t, os.Remove(tmpfile.Name()))
|
||||
}
|
||||
return db, func() { require.NoError(t, cleanup()) }
|
||||
}
|
||||
|
||||
func setupTestAPI(t *testing.T) (*API, func()) {
|
||||
|
|
|
@ -1,22 +1,24 @@
|
|||
package appdatabase
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/status-im/status-go/common/dbsetup"
|
||||
"github.com/status-im/status-go/protocol/sqlite"
|
||||
)
|
||||
|
||||
const kdfIterationsNumberForTests = 3200
|
||||
const kdfIterationsNumberForTests = 1
|
||||
|
||||
// SetupTestSQLDB creates a temporary sqlite database file, initialises and then returns with a teardown func
|
||||
func SetupTestSQLDB(prefix string) (*sql.DB, func() error, error) {
|
||||
func SetupTestSQLDB(dbInit dbsetup.DatabaseInitializer, prefix string) (*sql.DB, func() error, error) {
|
||||
tmpfile, err := ioutil.TempFile("", prefix)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
db, err := InitializeDB(tmpfile.Name(), prefix, kdfIterationsNumberForTests)
|
||||
|
||||
db, err := dbInit.Initialize(tmpfile.Name(), "password", kdfIterationsNumberForTests)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
@ -30,8 +32,8 @@ func SetupTestSQLDB(prefix string) (*sql.DB, func() error, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func SetupTestMemorySQLDB(prefix string) (*sql.DB, error) {
|
||||
db, err := InitializeDB(sqlite.InMemoryPath, prefix, kdfIterationsNumberForTests)
|
||||
func SetupTestMemorySQLDB(dbInit dbsetup.DatabaseInitializer) (*sql.DB, error) {
|
||||
db, err := dbInit.Initialize(sqlite.InMemoryPath, "password", kdfIterationsNumberForTests)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
|
@ -8,12 +8,13 @@ import (
|
|||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/services/wallet/bigint"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
"github.com/status-im/status-go/walletdatabase"
|
||||
)
|
||||
|
||||
func setupTestTransactionDB(t *testing.T) (*TransactionManager, func()) {
|
||||
db, err := appdatabase.SetupTestMemorySQLDB("wallet-transfer-transaction-tests")
|
||||
db, err := helpers.SetupTestMemorySQLDB(walletdatabase.DbInitializer{})
|
||||
require.NoError(t, err)
|
||||
return &TransactionManager{db, nil, nil, nil}, func() {
|
||||
require.NoError(t, db.Close())
|
||||
|
|
Loading…
Reference in New Issue