refactor_: set default node config values for frontend when doing local pair sync
This commit is contained in:
parent
0ef4fb8cc7
commit
90b18d4f88
|
@ -253,6 +253,6 @@ func setRPCs(networks []params.Network, request *requests.WalletSecretsConfig) [
|
|||
return networksWithRPC
|
||||
}
|
||||
|
||||
func BuildDefaultNetworks(request *requests.CreateAccount) []params.Network {
|
||||
return setRPCs(defaultNetworks, &request.WalletSecretsConfig)
|
||||
func BuildDefaultNetworks(walletSecretsConfig *requests.WalletSecretsConfig) []params.Network {
|
||||
return setRPCs(defaultNetworks, walletSecretsConfig)
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ func TestBuildDefaultNetworks(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
actualNetworks := BuildDefaultNetworks(request)
|
||||
actualNetworks := BuildDefaultNetworks(&request.WalletSecretsConfig)
|
||||
|
||||
require.Len(t, actualNetworks, 9)
|
||||
|
||||
|
@ -75,7 +75,7 @@ func TestBuildDefaultNetworksGanache(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
actualNetworks := BuildDefaultNetworks(request)
|
||||
actualNetworks := BuildDefaultNetworks(&request.WalletSecretsConfig)
|
||||
|
||||
require.Len(t, actualNetworks, 9)
|
||||
|
||||
|
|
|
@ -31,6 +31,8 @@ const defaultKeycardPairingDataFile = "/ethereum/mainnet_rpc/keycard/pairings.js
|
|||
const defaultArchivesRelativePath = "data/archivedata"
|
||||
const defaultTorrentTorrentsRelativePath = "data/torrents"
|
||||
|
||||
const DefaultDataDir = "/ethereum/mainnet_rpc"
|
||||
|
||||
var paths = []string{pathWalletRoot, pathEIP1581, pathDefaultChat, pathDefaultWallet}
|
||||
|
||||
var DefaultFleet = params.FleetShardsTest
|
||||
|
@ -212,7 +214,7 @@ func defaultNodeConfig(installationID string, request *requests.CreateAccount) (
|
|||
nodeConfig.LogFile = "geth.log"
|
||||
nodeConfig.LogDir = request.LogFilePath
|
||||
nodeConfig.LogLevel = "ERROR"
|
||||
nodeConfig.DataDir = "/ethereum/mainnet_rpc"
|
||||
nodeConfig.DataDir = DefaultDataDir
|
||||
nodeConfig.KeycardPairingDataFile = defaultKeycardPairingDataFile
|
||||
nodeConfig.ProcessBackedupMessages = false
|
||||
|
||||
|
@ -223,7 +225,7 @@ func defaultNodeConfig(installationID string, request *requests.CreateAccount) (
|
|||
nodeConfig.LogEnabled = false
|
||||
}
|
||||
|
||||
nodeConfig.Networks = BuildDefaultNetworks(request)
|
||||
nodeConfig.Networks = BuildDefaultNetworks(&request.WalletSecretsConfig)
|
||||
|
||||
if request.NetworkID != nil {
|
||||
nodeConfig.NetworkID = *request.NetworkID
|
||||
|
|
|
@ -344,7 +344,7 @@ func defaultNodeConfig(installationID string) (*params.NodeConfig, error) {
|
|||
nodeConfig := ¶ms.NodeConfig{}
|
||||
nodeConfig.NetworkID = 1
|
||||
nodeConfig.LogLevel = "ERROR"
|
||||
nodeConfig.DataDir = "/ethereum/mainnet_rpc"
|
||||
nodeConfig.DataDir = api.DefaultDataDir
|
||||
nodeConfig.UpstreamConfig = params.UpstreamRPCConfig{
|
||||
Enabled: true,
|
||||
URL: "https://mainnet.infura.io/v3/800c641949d64d768a5070a1b0511938",
|
||||
|
|
|
@ -392,7 +392,7 @@ func defaultNodeConfig(installationID string) (*params.NodeConfig, error) {
|
|||
nodeConfig := ¶ms.NodeConfig{}
|
||||
nodeConfig.NetworkID = 1
|
||||
nodeConfig.LogLevel = "ERROR"
|
||||
nodeConfig.DataDir = "/ethereum/mainnet_rpc"
|
||||
nodeConfig.DataDir = api.DefaultDataDir
|
||||
nodeConfig.UpstreamConfig = params.UpstreamRPCConfig{
|
||||
Enabled: true,
|
||||
URL: "https://mainnet.infura.io/v3/800c641949d64d768a5070a1b0511938",
|
||||
|
|
|
@ -269,7 +269,7 @@ func defaultNodeConfig(installationID string) (*params.NodeConfig, error) {
|
|||
nodeConfig := ¶ms.NodeConfig{}
|
||||
nodeConfig.NetworkID = 1
|
||||
nodeConfig.LogLevel = "DEBUG"
|
||||
nodeConfig.DataDir = "/ethereum/mainnet_rpc"
|
||||
nodeConfig.DataDir = api.DefaultDataDir
|
||||
nodeConfig.HTTPEnabled = true
|
||||
nodeConfig.HTTPPort = 8545
|
||||
// FIXME: This should be taken from CLI flags.
|
||||
|
|
|
@ -523,7 +523,11 @@ func setupReceivingClient(backend *api.GethStatusBackend, cs, configJSON string)
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = validateAndVerifyNodeConfig(conf, conf.ReceiverConfig)
|
||||
receiverConf := conf.ReceiverConfig
|
||||
if err = setDefaultNodeConfig(receiverConf.NodeConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = validateAndVerifyNodeConfig(conf, receiverConf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -10,6 +10,9 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/protocol/requests"
|
||||
|
||||
"gopkg.in/go-playground/validator.v9"
|
||||
|
||||
"github.com/status-im/status-go/account/generator"
|
||||
|
@ -116,14 +119,6 @@ func validateAndVerifyPassword(s interface{}, senderConfig *SenderConfig) error
|
|||
}
|
||||
|
||||
func validateAndVerifyNodeConfig(s interface{}, receiverConfig *ReceiverConfig) error {
|
||||
if receiverConfig.NodeConfig != nil {
|
||||
// we should update with defaults before validation
|
||||
err := receiverConfig.NodeConfig.UpdateWithDefaults()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
err := validate(s)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -250,3 +245,34 @@ func validateKeystoreFilesConfig(backend *api.GethStatusBackend, conf interface{
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func setDefaultNodeConfig(c *params.NodeConfig) error {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
err := c.UpdateWithDefaults()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(c.Networks) == 0 {
|
||||
c.Networks = api.BuildDefaultNetworks(&requests.WalletSecretsConfig{})
|
||||
}
|
||||
|
||||
if c.NetworkID == 0 {
|
||||
// because PR https://github.com/status-im/status-mobile/pull/19467/files removed :networks/networks,
|
||||
// we need to set the networkID and RPCURL here to make local pairing work again
|
||||
c.NetworkID = c.Networks[0].ChainID
|
||||
c.UpstreamConfig = params.UpstreamRPCConfig{
|
||||
URL: c.Networks[0].RPCURL,
|
||||
Enabled: true,
|
||||
}
|
||||
}
|
||||
|
||||
if c.DataDir == "" {
|
||||
c.DataDir = api.DefaultDataDir
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -75,9 +75,9 @@ func (s *ConfigTestSuite) TestValidationKeyUID() {
|
|||
}
|
||||
|
||||
func (s *ConfigTestSuite) TestValidationNotEndKeyUID() {
|
||||
nodeConfig, err := defaultNodeConfig(uuid.New().String(), "")
|
||||
nodeConfig, err := nodeConfigForLocalPairSync(uuid.New().String(), "", "/dummy/path")
|
||||
nodeConfig.RootDataDir = "/tmp"
|
||||
require.NoError(s.T(), err, "defaultNodeConfig should not return error")
|
||||
require.NoError(s.T(), err, "nodeConfigForLocalPairSync should not return error")
|
||||
s.T().Run("Valid keystore path without keyUID", func(t *testing.T) {
|
||||
r := &ReceiverConfig{
|
||||
NodeConfig: nodeConfig,
|
||||
|
@ -86,7 +86,7 @@ func (s *ConfigTestSuite) TestValidationNotEndKeyUID() {
|
|||
KDFIterations: 1,
|
||||
SettingCurrentNetwork: "mainnet",
|
||||
}
|
||||
|
||||
assert.NoError(t, setDefaultNodeConfig(r.NodeConfig))
|
||||
assert.NoError(t, validateAndVerifyNodeConfig(r, r), "ReceiverConfig validation should pass")
|
||||
})
|
||||
|
||||
|
@ -98,6 +98,7 @@ func (s *ConfigTestSuite) TestValidationNotEndKeyUID() {
|
|||
KDFIterations: 1,
|
||||
SettingCurrentNetwork: "mainnet",
|
||||
}
|
||||
assert.NoError(t, setDefaultNodeConfig(r.NodeConfig))
|
||||
assert.Error(t, validateAndVerifyNodeConfig(r, r), "ReceiverConfig validation should fail")
|
||||
})
|
||||
}
|
||||
|
|
|
@ -291,7 +291,11 @@ func StartUpReceiverServer(backend *api.GethStatusBackend, configJSON string) (s
|
|||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
err = validateAndVerifyNodeConfig(conf, conf.ReceiverConfig)
|
||||
receiverConf := conf.ReceiverConfig
|
||||
if err = setDefaultNodeConfig(receiverConf.NodeConfig); err != nil {
|
||||
return "", err
|
||||
}
|
||||
err = validateAndVerifyNodeConfig(conf, receiverConf)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -114,8 +114,14 @@ func (s *SyncDeviceSuite) prepareBackendWithAccount(mnemonic, tmpdir string) *ap
|
|||
|
||||
account.Name = settings.Name
|
||||
|
||||
nodeConfig, err := defaultNodeConfig(settings.InstallationID, account.KeyUID)
|
||||
nodeConfig, err := nodeConfigForLocalPairSync(settings.InstallationID, account.KeyUID, tmpdir)
|
||||
require.NoError(s.T(), err)
|
||||
nodeConfig.NetworkID = 1
|
||||
nodeConfig.UpstreamConfig = params.UpstreamRPCConfig{
|
||||
Enabled: true,
|
||||
URL: "https://mainnet.infura.io/v3/800c641949d64d768a5070a1b0511938",
|
||||
}
|
||||
nodeConfig.DataDir = api.DefaultDataDir
|
||||
|
||||
walletDerivedAccount := derivedAddresses[pathDefaultWallet]
|
||||
walletAccount := &accounts.Account{
|
||||
|
@ -187,7 +193,7 @@ func (s *SyncDeviceSuite) pairAccounts(serverBackend *api.GethStatusBackend, ser
|
|||
err = clientBackend.OpenAccounts()
|
||||
require.NoError(s.T(), err)
|
||||
|
||||
clientNodeConfig, err := defaultNodeConfig(uuid.New().String(), "")
|
||||
clientNodeConfig, err := nodeConfigForLocalPairSync(uuid.New().String(), "", clientDir)
|
||||
require.NoError(s.T(), err)
|
||||
|
||||
clientKeystoreDir := filepath.Join(clientDir, keystoreDir)
|
||||
|
@ -290,7 +296,7 @@ func (s *SyncDeviceSuite) TestPairingSyncDeviceClientAsSender() {
|
|||
require.NoError(s.T(), err)
|
||||
err = serverBackend.OpenAccounts()
|
||||
require.NoError(s.T(), err)
|
||||
serverNodeConfig, err := defaultNodeConfig(uuid.New().String(), "")
|
||||
serverNodeConfig, err := nodeConfigForLocalPairSync(uuid.New().String(), "", serverTmpDir)
|
||||
require.NoError(s.T(), err)
|
||||
serverKeystoreDir := filepath.Join(serverTmpDir, keystoreDir)
|
||||
serverPayloadSourceConfig := &ReceiverServerConfig{
|
||||
|
@ -471,7 +477,7 @@ func (s *SyncDeviceSuite) TestPairingSyncDeviceClientAsReceiver() {
|
|||
require.NoError(s.T(), err)
|
||||
err = clientBackend.OpenAccounts()
|
||||
require.NoError(s.T(), err)
|
||||
clientNodeConfig, err := defaultNodeConfig(uuid.New().String(), "")
|
||||
clientNodeConfig, err := nodeConfigForLocalPairSync(uuid.New().String(), "", clientTmpDir)
|
||||
require.NoError(s.T(), err)
|
||||
clientKeystoreDir := filepath.Join(clientTmpDir, keystoreDir)
|
||||
clientPayloadSourceConfig := ReceiverClientConfig{
|
||||
|
@ -724,19 +730,12 @@ func defaultSettings(generatedAccountInfo generator.GeneratedAccountInfo, derive
|
|||
return syncSettings, nil
|
||||
}
|
||||
|
||||
func defaultNodeConfig(installationID, keyUID string) (*params.NodeConfig, error) {
|
||||
func nodeConfigForLocalPairSync(installationID, keyUID, tmpDir string) (*params.NodeConfig, error) {
|
||||
// Set mainnet
|
||||
nodeConfig := ¶ms.NodeConfig{}
|
||||
nodeConfig.NetworkID = 1
|
||||
nodeConfig.LogLevel = "DEBUG"
|
||||
nodeConfig.DataDir = filepath.Join("ethereum/mainnet_rpc")
|
||||
nodeConfig.KeyStoreDir = filepath.Join(keystoreDir, keyUID)
|
||||
nodeConfig.KeycardPairingDataFile = filepath.Join("keycard", "pairings.json")
|
||||
nodeConfig.UpstreamConfig = params.UpstreamRPCConfig{
|
||||
Enabled: true,
|
||||
URL: "https://mainnet.infura.io/v3/800c641949d64d768a5070a1b0511938",
|
||||
}
|
||||
|
||||
nodeConfig.Name = "StatusIM"
|
||||
clusterConfig, err := params.LoadClusterConfigFromFleet("eth.prod")
|
||||
if err != nil {
|
||||
|
@ -756,7 +755,7 @@ func defaultNodeConfig(installationID, keyUID string) (*params.NodeConfig, error
|
|||
}
|
||||
|
||||
nodeConfig.ShhextConfig = params.ShhextConfig{
|
||||
BackupDisabledDataDir: nodeConfig.DataDir,
|
||||
BackupDisabledDataDir: tmpDir,
|
||||
InstallationID: installationID,
|
||||
MaxMessageDeliveryAttempts: 6,
|
||||
MailServerConfirmations: true,
|
||||
|
@ -1283,7 +1282,7 @@ func (s *SyncDeviceSuite) TestPreventLoggedInAccountLocalPairingClientAsReceiver
|
|||
s.NoError(err)
|
||||
|
||||
clientKeystoreDir := filepath.Join(clientTmpDir, keystoreDir)
|
||||
clientNodeConfig, err := defaultNodeConfig(uuid.New().String(), "")
|
||||
clientNodeConfig, err := nodeConfigForLocalPairSync(uuid.New().String(), "", clientTmpDir)
|
||||
s.NoError(err)
|
||||
clientPayloadSourceConfig := ReceiverClientConfig{
|
||||
ReceiverConfig: &ReceiverConfig{
|
||||
|
@ -1312,7 +1311,7 @@ func (s *SyncDeviceSuite) TestPreventLoggedInAccountLocalPairingClientAsSender()
|
|||
s.NoError(clientBackend.Logout())
|
||||
}()
|
||||
|
||||
serverNodeConfig, err := defaultNodeConfig(uuid.New().String(), "")
|
||||
serverNodeConfig, err := nodeConfigForLocalPairSync(uuid.New().String(), "", serverTmpDir)
|
||||
s.NoError(err)
|
||||
serverKeystoreDir := filepath.Join(serverTmpDir, keystoreDir)
|
||||
serverPayloadSourceConfig := &ReceiverServerConfig{
|
||||
|
|
Loading…
Reference in New Issue