fix: enable light client for mobile (#5654)
* fix_: enable light client for mobile * fix_: rename const name * fix_: disable store confirmation for mobile v1 by default
This commit is contained in:
parent
c68854299a
commit
6581f75c63
|
@ -6,6 +6,8 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
d_common "github.com/status-im/status-go/common"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/common/dbsetup"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
|
@ -46,6 +48,8 @@ type OldMobileUserUpgradingFromV1ToV2Test struct {
|
|||
tmpdir string
|
||||
}
|
||||
|
||||
type PostLoginCheckCallback func(b *GethStatusBackend)
|
||||
|
||||
func (s *OldMobileUserUpgradingFromV1ToV2Test) SetupTest() {
|
||||
utils.Init()
|
||||
s.tmpdir = s.T().TempDir()
|
||||
|
@ -56,11 +60,36 @@ func TestOldMobileUserUpgradingFromV1ToV2(t *testing.T) {
|
|||
suite.Run(t, new(OldMobileUserUpgradingFromV1ToV2Test))
|
||||
}
|
||||
|
||||
func (s *OldMobileUserUpgradingFromV1ToV2Test) loginMobileUser() {
|
||||
func (s *OldMobileUserUpgradingFromV1ToV2Test) loginMobileUser(check PostLoginCheckCallback) {
|
||||
b := NewGethStatusBackend()
|
||||
b.UpdateRootDataDir(s.tmpdir)
|
||||
s.Require().NoError(b.OpenAccounts())
|
||||
s.Require().NoError(b.Login(oldMobileUserKeyUID, oldMobileUserPasswd))
|
||||
|
||||
check(b)
|
||||
|
||||
s.Require().NoError(b.Logout())
|
||||
}
|
||||
|
||||
func (s *OldMobileUserUpgradingFromV1ToV2Test) TestOptimizeMobileWakuV2SettingsForMobileV1() {
|
||||
bkFunc := d_common.IsMobilePlatform
|
||||
d_common.IsMobilePlatform = func() bool {
|
||||
return true
|
||||
}
|
||||
defer func() {
|
||||
d_common.IsMobilePlatform = bkFunc
|
||||
}()
|
||||
|
||||
s.loginMobileUser(func(b *GethStatusBackend) {
|
||||
nc, err := b.GetNodeConfig()
|
||||
s.Require().NoError(err)
|
||||
s.Require().True(nc.WakuV2Config.LightClient)
|
||||
s.Require().False(nc.WakuV2Config.EnableStoreConfirmationForMessagesSent)
|
||||
})
|
||||
}
|
||||
|
||||
func (s *OldMobileUserUpgradingFromV1ToV2Test) TestLoginAndMigrationsStillWorkWithExistingMobileUser() {
|
||||
checkAfterLogin := func(b *GethStatusBackend) {
|
||||
db, err := accounts.NewDB(b.appDB)
|
||||
s.Require().NoError(err)
|
||||
accs, err := db.GetAllAccounts()
|
||||
|
@ -116,12 +145,10 @@ func (s *OldMobileUserUpgradingFromV1ToV2Test) loginMobileUser() {
|
|||
info, err = generator.ImportPrivateKey("c3ad0b50652318f845565c13761e5369ce75dcbc2a94616e15b829d4b07410fe")
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(info.KeyUID, keyKps[0].KeyUID)
|
||||
s.Require().NoError(b.Logout())
|
||||
}
|
||||
}
|
||||
|
||||
func (s *OldMobileUserUpgradingFromV1ToV2Test) TestLoginAndMigrationsStillWorkWithExistingMobileUser() {
|
||||
s.loginMobileUser()
|
||||
s.loginMobileUser() // Login twice to catch weird errors that only appear after logout
|
||||
s.loginMobileUser(checkAfterLogin)
|
||||
s.loginMobileUser(checkAfterLogin) // Login twice to catch weird errors that only appear after logout
|
||||
}
|
||||
|
||||
// TestAddWalletAccount we should be able to add a wallet account after upgrading from mobile v1
|
||||
|
|
|
@ -6,6 +6,8 @@ import (
|
|||
"encoding/json"
|
||||
"math/big"
|
||||
|
||||
d_common "github.com/status-im/status-go/common"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
|
@ -61,6 +63,7 @@ func doMigration(db *sql.DB) error {
|
|||
|
||||
postSteps := []*sqlite.PostStep{
|
||||
{Version: 1662365868, CustomMigration: FixMissingKeyUIDForAccounts},
|
||||
{Version: 1720606449, CustomMigration: OptimizeMobileWakuV2SettingsForMobileV1},
|
||||
}
|
||||
postSteps = append(postSteps, customSteps...)
|
||||
// Run all the new migrations
|
||||
|
@ -87,6 +90,17 @@ func InitializeDB(path, password string, kdfIterationsNumber int) (*sql.DB, erro
|
|||
return db, nil
|
||||
}
|
||||
|
||||
func OptimizeMobileWakuV2SettingsForMobileV1(sqlTx *sql.Tx) error {
|
||||
if d_common.IsMobilePlatform() {
|
||||
_, err := sqlTx.Exec(`UPDATE wakuv2_config SET light_client = ?, enable_store_confirmation_for_messages_sent = ?`, true, false)
|
||||
if err != nil {
|
||||
log.Error("failed to enable light client and disable store confirmation for mobile v1", "err", err.Error())
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func FixMissingKeyUIDForAccounts(sqlTx *sql.Tx) error {
|
||||
rows, err := sqlTx.Query(`SELECT address,pubkey FROM accounts WHERE pubkey IS NOT NULL AND type != '' AND type != 'generated'`)
|
||||
if err != nil {
|
||||
|
|
|
@ -4,9 +4,14 @@ import "runtime"
|
|||
|
||||
const (
|
||||
AndroidPlatform = "android"
|
||||
IOSPlatform = "ios"
|
||||
WindowsPlatform = "windows"
|
||||
)
|
||||
|
||||
var IsMobilePlatform = func() bool {
|
||||
return OperatingSystemIs(AndroidPlatform) || OperatingSystemIs(IOSPlatform)
|
||||
}
|
||||
|
||||
func OperatingSystemIs(targetOS string) bool {
|
||||
return runtime.GOOS == targetOS
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue