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
f45dbb3067
commit
f325e95bf1
|
@ -6,6 +6,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
d_common "github.com/status-im/status-go/common"
|
||||||
|
|
||||||
"github.com/status-im/status-go/appdatabase"
|
"github.com/status-im/status-go/appdatabase"
|
||||||
"github.com/status-im/status-go/common/dbsetup"
|
"github.com/status-im/status-go/common/dbsetup"
|
||||||
"github.com/status-im/status-go/sqlite"
|
"github.com/status-im/status-go/sqlite"
|
||||||
|
@ -46,6 +48,8 @@ type OldMobileUserUpgradingFromV1ToV2Test struct {
|
||||||
tmpdir string
|
tmpdir string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PostLoginCheckCallback func(b *GethStatusBackend)
|
||||||
|
|
||||||
func (s *OldMobileUserUpgradingFromV1ToV2Test) SetupTest() {
|
func (s *OldMobileUserUpgradingFromV1ToV2Test) SetupTest() {
|
||||||
utils.Init()
|
utils.Init()
|
||||||
s.tmpdir = s.T().TempDir()
|
s.tmpdir = s.T().TempDir()
|
||||||
|
@ -56,72 +60,95 @@ func TestOldMobileUserUpgradingFromV1ToV2(t *testing.T) {
|
||||||
suite.Run(t, new(OldMobileUserUpgradingFromV1ToV2Test))
|
suite.Run(t, new(OldMobileUserUpgradingFromV1ToV2Test))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *OldMobileUserUpgradingFromV1ToV2Test) loginMobileUser() {
|
func (s *OldMobileUserUpgradingFromV1ToV2Test) loginMobileUser(check PostLoginCheckCallback) {
|
||||||
b := NewGethStatusBackend()
|
b := NewGethStatusBackend()
|
||||||
b.UpdateRootDataDir(s.tmpdir)
|
b.UpdateRootDataDir(s.tmpdir)
|
||||||
s.Require().NoError(b.OpenAccounts())
|
s.Require().NoError(b.OpenAccounts())
|
||||||
s.Require().NoError(b.Login(oldMobileUserKeyUID, oldMobileUserPasswd))
|
s.Require().NoError(b.Login(oldMobileUserKeyUID, oldMobileUserPasswd))
|
||||||
db, err := accounts.NewDB(b.appDB)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
accs, err := db.GetAllAccounts()
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.Require().True(len(accs) == 6)
|
|
||||||
kps, err := db.GetAllKeypairs()
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.Require().True(len(kps) == 3)
|
|
||||||
|
|
||||||
// Create a map to categorize keypairs by their type
|
check(b)
|
||||||
keypairMap := make(map[accounts.KeypairType][]*accounts.Keypair)
|
|
||||||
for _, kp := range kps {
|
|
||||||
keypairMap[kp.Type] = append(keypairMap[kp.Type], kp)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check profile keypair
|
|
||||||
profileKps, ok := keypairMap[accounts.KeypairTypeProfile]
|
|
||||||
s.Require().True(ok, "Profile keypair not found")
|
|
||||||
s.Require().True(len(profileKps) == 1, "Unexpected number of profile keypairs")
|
|
||||||
s.Require().True(len(profileKps[0].Accounts) == 3)
|
|
||||||
for _, a := range profileKps[0].Accounts {
|
|
||||||
s.Require().Equal(a.KeyUID, oldMobileUserKeyUID)
|
|
||||||
}
|
|
||||||
|
|
||||||
generator := b.AccountManager().AccountsGenerator()
|
|
||||||
// Check seed keypair
|
|
||||||
seedKps, ok := keypairMap[accounts.KeypairTypeSeed]
|
|
||||||
s.Require().True(ok, "Seed keypair not found")
|
|
||||||
s.Require().True(len(seedKps) == 1, "Unexpected number of seed keypairs")
|
|
||||||
s.Require().True(len(seedKps[0].Accounts) == 1)
|
|
||||||
info, err := generator.LoadAccount(seedKps[0].Accounts[0].Address.Hex(), oldMobileUserPasswd)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.Require().Equal(seedKps[0].KeyUID, info.KeyUID)
|
|
||||||
s.Require().Equal(seedKps[0].Accounts[0].KeyUID, info.KeyUID)
|
|
||||||
mnemonicNoExtraSpaces := strings.Join(strings.Fields("vocal blouse script census island armor seek catch wool narrow peasant attract"), " ")
|
|
||||||
importedSeedAccountInfo, err := generator.ImportMnemonic(mnemonicNoExtraSpaces, "")
|
|
||||||
s.Require().NoError(err)
|
|
||||||
derivedAddresses, err := generator.DeriveAddresses(importedSeedAccountInfo.ID, paths)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.Require().Equal(derivedAddresses[pathDefaultWallet].PublicKey, "0x04fde3e58a7379161da2adf033fbee076e2ba11fca8b07c4d06610b399911a60017e4c108eae243487d19e273f99c2d6af13ff5e330783f4389212092b01cc616c")
|
|
||||||
//following line shows: we're unable to calculate the right KeyUID with the wrong public key from existing records for the imported seed account
|
|
||||||
s.Require().False(importedSeedAccountInfo.KeyUID == seedKps[0].KeyUID)
|
|
||||||
|
|
||||||
// Check key keypair
|
|
||||||
keyKps, ok := keypairMap[accounts.KeypairTypeKey]
|
|
||||||
s.Require().True(ok, "Key keypair not found")
|
|
||||||
s.Require().True(len(keyKps) == 1, "Unexpected number of key keypairs")
|
|
||||||
s.Require().True(len(keyKps[0].Accounts) == 1)
|
|
||||||
info, err = generator.LoadAccount(keyKps[0].Accounts[0].Address.Hex(), oldMobileUserPasswd)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.Require().Equal(keyKps[0].KeyUID, info.KeyUID)
|
|
||||||
s.Require().Equal(keyKps[0].Accounts[0].KeyUID, info.KeyUID)
|
|
||||||
info, err = generator.ImportPrivateKey("c3ad0b50652318f845565c13761e5369ce75dcbc2a94616e15b829d4b07410fe")
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.Require().Equal(info.KeyUID, keyKps[0].KeyUID)
|
|
||||||
s.Require().NoError(b.Logout())
|
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() {
|
func (s *OldMobileUserUpgradingFromV1ToV2Test) TestLoginAndMigrationsStillWorkWithExistingMobileUser() {
|
||||||
s.loginMobileUser()
|
checkAfterLogin := func(b *GethStatusBackend) {
|
||||||
s.loginMobileUser() // Login twice to catch weird errors that only appear after logout
|
db, err := accounts.NewDB(b.appDB)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
accs, err := db.GetAllAccounts()
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().True(len(accs) == 6)
|
||||||
|
kps, err := db.GetAllKeypairs()
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().True(len(kps) == 3)
|
||||||
|
|
||||||
|
// Create a map to categorize keypairs by their type
|
||||||
|
keypairMap := make(map[accounts.KeypairType][]*accounts.Keypair)
|
||||||
|
for _, kp := range kps {
|
||||||
|
keypairMap[kp.Type] = append(keypairMap[kp.Type], kp)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check profile keypair
|
||||||
|
profileKps, ok := keypairMap[accounts.KeypairTypeProfile]
|
||||||
|
s.Require().True(ok, "Profile keypair not found")
|
||||||
|
s.Require().True(len(profileKps) == 1, "Unexpected number of profile keypairs")
|
||||||
|
s.Require().True(len(profileKps[0].Accounts) == 3)
|
||||||
|
for _, a := range profileKps[0].Accounts {
|
||||||
|
s.Require().Equal(a.KeyUID, oldMobileUserKeyUID)
|
||||||
|
}
|
||||||
|
|
||||||
|
generator := b.AccountManager().AccountsGenerator()
|
||||||
|
// Check seed keypair
|
||||||
|
seedKps, ok := keypairMap[accounts.KeypairTypeSeed]
|
||||||
|
s.Require().True(ok, "Seed keypair not found")
|
||||||
|
s.Require().True(len(seedKps) == 1, "Unexpected number of seed keypairs")
|
||||||
|
s.Require().True(len(seedKps[0].Accounts) == 1)
|
||||||
|
info, err := generator.LoadAccount(seedKps[0].Accounts[0].Address.Hex(), oldMobileUserPasswd)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().Equal(seedKps[0].KeyUID, info.KeyUID)
|
||||||
|
s.Require().Equal(seedKps[0].Accounts[0].KeyUID, info.KeyUID)
|
||||||
|
mnemonicNoExtraSpaces := strings.Join(strings.Fields("vocal blouse script census island armor seek catch wool narrow peasant attract"), " ")
|
||||||
|
importedSeedAccountInfo, err := generator.ImportMnemonic(mnemonicNoExtraSpaces, "")
|
||||||
|
s.Require().NoError(err)
|
||||||
|
derivedAddresses, err := generator.DeriveAddresses(importedSeedAccountInfo.ID, paths)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().Equal(derivedAddresses[pathDefaultWallet].PublicKey, "0x04fde3e58a7379161da2adf033fbee076e2ba11fca8b07c4d06610b399911a60017e4c108eae243487d19e273f99c2d6af13ff5e330783f4389212092b01cc616c")
|
||||||
|
//following line shows: we're unable to calculate the right KeyUID with the wrong public key from existing records for the imported seed account
|
||||||
|
s.Require().False(importedSeedAccountInfo.KeyUID == seedKps[0].KeyUID)
|
||||||
|
|
||||||
|
// Check key keypair
|
||||||
|
keyKps, ok := keypairMap[accounts.KeypairTypeKey]
|
||||||
|
s.Require().True(ok, "Key keypair not found")
|
||||||
|
s.Require().True(len(keyKps) == 1, "Unexpected number of key keypairs")
|
||||||
|
s.Require().True(len(keyKps[0].Accounts) == 1)
|
||||||
|
info, err = generator.LoadAccount(keyKps[0].Accounts[0].Address.Hex(), oldMobileUserPasswd)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().Equal(keyKps[0].KeyUID, info.KeyUID)
|
||||||
|
s.Require().Equal(keyKps[0].Accounts[0].KeyUID, info.KeyUID)
|
||||||
|
info, err = generator.ImportPrivateKey("c3ad0b50652318f845565c13761e5369ce75dcbc2a94616e15b829d4b07410fe")
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().Equal(info.KeyUID, keyKps[0].KeyUID)
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
// TestAddWalletAccount we should be able to add a wallet account after upgrading from mobile v1
|
||||||
|
|
|
@ -6,6 +6,8 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
|
d_common "github.com/status-im/status-go/common"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
@ -61,6 +63,7 @@ func doMigration(db *sql.DB) error {
|
||||||
|
|
||||||
postSteps := []*sqlite.PostStep{
|
postSteps := []*sqlite.PostStep{
|
||||||
{Version: 1662365868, CustomMigration: FixMissingKeyUIDForAccounts},
|
{Version: 1662365868, CustomMigration: FixMissingKeyUIDForAccounts},
|
||||||
|
{Version: 1720606449, CustomMigration: OptimizeMobileWakuV2SettingsForMobileV1},
|
||||||
}
|
}
|
||||||
postSteps = append(postSteps, customSteps...)
|
postSteps = append(postSteps, customSteps...)
|
||||||
// Run all the new migrations
|
// Run all the new migrations
|
||||||
|
@ -87,6 +90,17 @@ func InitializeDB(path, password string, kdfIterationsNumber int) (*sql.DB, erro
|
||||||
return db, nil
|
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 {
|
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'`)
|
rows, err := sqlTx.Query(`SELECT address,pubkey FROM accounts WHERE pubkey IS NOT NULL AND type != '' AND type != 'generated'`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -4,9 +4,14 @@ import "runtime"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AndroidPlatform = "android"
|
AndroidPlatform = "android"
|
||||||
|
IOSPlatform = "ios"
|
||||||
WindowsPlatform = "windows"
|
WindowsPlatform = "windows"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var IsMobilePlatform = func() bool {
|
||||||
|
return OperatingSystemIs(AndroidPlatform) || OperatingSystemIs(IOSPlatform)
|
||||||
|
}
|
||||||
|
|
||||||
func OperatingSystemIs(targetOS string) bool {
|
func OperatingSystemIs(targetOS string) bool {
|
||||||
return runtime.GOOS == targetOS
|
return runtime.GOOS == targetOS
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue