Skip to content

Commit

Permalink
Merge pull request #1489 from mesg-foundation/feature/config-acc-mnem…
Browse files Browse the repository at this point in the history
…onic

Add account.mnemonic in config
  • Loading branch information
Nicolas Mahé authored Nov 8, 2019
2 parents 4badb52 + 38a66f0 commit c260499
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"
"time"

"github.com/cosmos/go-bip39"
homedir "github.com/mitchellh/go-homedir"
"github.com/sirupsen/logrus"
tmconfig "github.com/tendermint/tendermint/config"
Expand Down Expand Up @@ -63,6 +64,7 @@ type Config struct {
Account struct {
Name string `validate:"required"`
Password string `validate:"required"`
Mnemonic string
}
}

Expand Down Expand Up @@ -170,8 +172,12 @@ func (c *Config) validate() error {
if _, err := logrus.ParseLevel(c.Log.Level); err != nil {
return fmt.Errorf("config.Log.Level error: %w", err)
}
if c.Account.Mnemonic != "" && !bip39.IsMnemonicValid(c.Account.Mnemonic) {
return fmt.Errorf("config.Account.Mnemonic error: mnemonic is not valid")
}
if err := c.Tendermint.Config.ValidateBasic(); err != nil {
return fmt.Errorf("config.Tendermint error: %w", err)
}

return validator.New().Struct(c)
}
5 changes: 5 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ func TestDefaultConfig(t *testing.T) {
require.Equal(t, filepath.Join(home, ".mesg"), c.Path)
require.Equal(t, filepath.Join("database", "executions", executionDBVersion), c.Database.ExecutionRelativePath)
require.Equal(t, "engine", c.Name)
require.Equal(t, "engine", c.Account.Name)
require.Equal(t, "pass", c.Account.Password)
}

func TestEnv(t *testing.T) {
os.Setenv(envPathKey, "tempPath")
defer os.Unsetenv(envPathKey)
Expand Down Expand Up @@ -56,6 +59,8 @@ func TestLoadFromFile(t *testing.T) {
address: :50050
log:
forcecolors: true
account:
mnemonic: glimpse upon body vast economy give taxi yellow rabbit come click ranch chronic hammer sport near rotate charge lumber chicken cloud base thing forum
tendermint:
config:
consensus:
Expand Down
5 changes: 5 additions & 0 deletions core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ func stopRunningServices(sdk *enginesdk.SDK, cfg *config.Config, address string)
}

func loadOrGenConfigAccount(kb *cosmos.Keybase, cfg *config.Config) (keys.Info, error) {
if cfg.Account.Mnemonic != "" {
logrus.WithField("module", "main").Warn("Config account mnemonic presents. Generating account with it...")
return kb.CreateAccount(cfg.Account.Name, cfg.Account.Mnemonic, "", cfg.Account.Password, 0, 0)
}

exist, err := kb.Exist(cfg.Account.Name)
if err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions e2e/testdata/e2e.config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
log:
level: fatal

account:
mnemonic: glimpse upon body vast economy give taxi yellow rabbit come click ranch chronic hammer sport near rotate charge lumber chicken cloud base thing forum


tendermint:
config:
consensus:
Expand Down

0 comments on commit c260499

Please sign in to comment.