Skip to content

Commit

Permalink
lexicographical reorder of functions in config.go of chain package
Browse files Browse the repository at this point in the history
  • Loading branch information
p0mvn committed Apr 19, 2022
1 parent 0bfee3e commit 2bd6a80
Showing 1 changed file with 93 additions and 93 deletions.
186 changes: 93 additions & 93 deletions tests/e2e/chain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,54 +49,75 @@ var (
InitBalanceStrB = fmt.Sprintf("%d%s,%d%s", OsmoBalanceB, OsmoDenom, StakeBalanceB, StakeDenom)
)

func initValidatorConfigs(c *Chain) error {
for i, val := range c.Validators {
tmCfgPath := filepath.Join(val.ConfigDir(), "config", "config.toml")
func addAccount(path, moniker, amountStr string, accAddr sdk.AccAddress) error {
serverCtx := server.NewDefaultContext()
config := serverCtx.Config

vpr := viper.New()
vpr.SetConfigFile(tmCfgPath)
if err := vpr.ReadInConfig(); err != nil {
return err
}
config.SetRoot(path)
config.Moniker = moniker

valConfig := &tmconfig.Config{}
if err := vpr.Unmarshal(valConfig); err != nil {
return err
}
coins, err := sdk.ParseCoinsNormalized(amountStr)
if err != nil {
return fmt.Errorf("failed to parse coins: %w", err)
}

valConfig.P2P.ListenAddress = "tcp://0.0.0.0:26656"
valConfig.P2P.AddrBookStrict = false
valConfig.P2P.ExternalAddress = fmt.Sprintf("%s:%d", val.InstanceName(), 26656)
valConfig.RPC.ListenAddress = "tcp://0.0.0.0:26657"
valConfig.StateSync.Enable = false
valConfig.LogLevel = "info"
balances := banktypes.Balance{Address: accAddr.String(), Coins: coins.Sort()}
genAccount := authtypes.NewBaseAccount(accAddr, nil, 0, 0)

var peers []string
genFile := config.GenesisFile()
appState, genDoc, err := genutiltypes.GenesisStateFromGenFile(genFile)
if err != nil {
return fmt.Errorf("failed to unmarshal genesis state: %w", err)
}

for j := 0; j < len(c.Validators); j++ {
if i == j {
continue
}
authGenState := authtypes.GetGenesisStateFromAppState(util.Cdc, appState)

peer := c.Validators[j]
peerID := fmt.Sprintf("%s@%s%d:26656", peer.getNodeKey().ID(), peer.GetMoniker(), j)
peers = append(peers, peerID)
}
accs, err := authtypes.UnpackAccounts(authGenState.Accounts)
if err != nil {
return fmt.Errorf("failed to get accounts from any: %w", err)
}

valConfig.P2P.PersistentPeers = strings.Join(peers, ",")
if accs.Contains(accAddr) {
return fmt.Errorf("failed to add account to genesis state; account already exists: %s", accAddr)
}

tmconfig.WriteConfigFile(tmCfgPath, valConfig)
// Add the new account to the set of genesis accounts and sanitize the
// accounts afterwards.
accs = append(accs, genAccount)
accs = authtypes.SanitizeGenesisAccounts(accs)

// set application configuration
appCfgPath := filepath.Join(val.ConfigDir(), "config", "app.toml")
genAccs, err := authtypes.PackAccounts(accs)
if err != nil {
return fmt.Errorf("failed to convert accounts into any's: %w", err)
}

appConfig := srvconfig.DefaultConfig()
appConfig.API.Enable = true
appConfig.MinGasPrices = fmt.Sprintf("%s%s", MinGasPrice, OsmoDenom)
authGenState.Accounts = genAccs

srvconfig.WriteConfigFile(appCfgPath, appConfig)
authGenStateBz, err := util.Cdc.MarshalJSON(&authGenState)
if err != nil {
return fmt.Errorf("failed to marshal auth genesis state: %w", err)
}
return nil

appState[authtypes.ModuleName] = authGenStateBz

bankGenState := banktypes.GetGenesisStateFromAppState(util.Cdc, appState)
bankGenState.Balances = append(bankGenState.Balances, balances)
bankGenState.Balances = banktypes.SanitizeGenesisBalances(bankGenState.Balances)

bankGenStateBz, err := util.Cdc.MarshalJSON(bankGenState)
if err != nil {
return fmt.Errorf("failed to marshal bank genesis state: %w", err)
}

appState[banktypes.ModuleName] = bankGenStateBz

appStateJSON, err := json.Marshal(appState)
if err != nil {
return fmt.Errorf("failed to marshal application genesis state: %w", err)
}

genDoc.AppState = appStateJSON
return genutil.ExportGenesisFile(genDoc, genFile)
}

func initGenesis(c *Chain) error {
Expand Down Expand Up @@ -228,73 +249,52 @@ func initNodes(c *Chain) error {
return nil
}

func addAccount(path, moniker, amountStr string, accAddr sdk.AccAddress) error {
serverCtx := server.NewDefaultContext()
config := serverCtx.Config

config.SetRoot(path)
config.Moniker = moniker

coins, err := sdk.ParseCoinsNormalized(amountStr)
if err != nil {
return fmt.Errorf("failed to parse coins: %w", err)
}

balances := banktypes.Balance{Address: accAddr.String(), Coins: coins.Sort()}
genAccount := authtypes.NewBaseAccount(accAddr, nil, 0, 0)

genFile := config.GenesisFile()
appState, genDoc, err := genutiltypes.GenesisStateFromGenFile(genFile)
if err != nil {
return fmt.Errorf("failed to unmarshal genesis state: %w", err)
}

authGenState := authtypes.GetGenesisStateFromAppState(util.Cdc, appState)
func initValidatorConfigs(c *Chain) error {
for i, val := range c.Validators {
tmCfgPath := filepath.Join(val.ConfigDir(), "config", "config.toml")

accs, err := authtypes.UnpackAccounts(authGenState.Accounts)
if err != nil {
return fmt.Errorf("failed to get accounts from any: %w", err)
}
vpr := viper.New()
vpr.SetConfigFile(tmCfgPath)
if err := vpr.ReadInConfig(); err != nil {
return err
}

if accs.Contains(accAddr) {
return fmt.Errorf("failed to add account to genesis state; account already exists: %s", accAddr)
}
valConfig := &tmconfig.Config{}
if err := vpr.Unmarshal(valConfig); err != nil {
return err
}

// Add the new account to the set of genesis accounts and sanitize the
// accounts afterwards.
accs = append(accs, genAccount)
accs = authtypes.SanitizeGenesisAccounts(accs)
valConfig.P2P.ListenAddress = "tcp://0.0.0.0:26656"
valConfig.P2P.AddrBookStrict = false
valConfig.P2P.ExternalAddress = fmt.Sprintf("%s:%d", val.InstanceName(), 26656)
valConfig.RPC.ListenAddress = "tcp://0.0.0.0:26657"
valConfig.StateSync.Enable = false
valConfig.LogLevel = "info"

genAccs, err := authtypes.PackAccounts(accs)
if err != nil {
return fmt.Errorf("failed to convert accounts into any's: %w", err)
}
var peers []string

authGenState.Accounts = genAccs
for j := 0; j < len(c.Validators); j++ {
if i == j {
continue
}

authGenStateBz, err := util.Cdc.MarshalJSON(&authGenState)
if err != nil {
return fmt.Errorf("failed to marshal auth genesis state: %w", err)
}
peer := c.Validators[j]
peerID := fmt.Sprintf("%s@%s%d:26656", peer.getNodeKey().ID(), peer.GetMoniker(), j)
peers = append(peers, peerID)
}

appState[authtypes.ModuleName] = authGenStateBz
valConfig.P2P.PersistentPeers = strings.Join(peers, ",")

bankGenState := banktypes.GetGenesisStateFromAppState(util.Cdc, appState)
bankGenState.Balances = append(bankGenState.Balances, balances)
bankGenState.Balances = banktypes.SanitizeGenesisBalances(bankGenState.Balances)
tmconfig.WriteConfigFile(tmCfgPath, valConfig)

bankGenStateBz, err := util.Cdc.MarshalJSON(bankGenState)
if err != nil {
return fmt.Errorf("failed to marshal bank genesis state: %w", err)
}
// set application configuration
appCfgPath := filepath.Join(val.ConfigDir(), "config", "app.toml")

appState[banktypes.ModuleName] = bankGenStateBz
appConfig := srvconfig.DefaultConfig()
appConfig.API.Enable = true
appConfig.MinGasPrices = fmt.Sprintf("%s%s", MinGasPrice, OsmoDenom)

appStateJSON, err := json.Marshal(appState)
if err != nil {
return fmt.Errorf("failed to marshal application genesis state: %w", err)
srvconfig.WriteConfigFile(appCfgPath, appConfig)
}

genDoc.AppState = appStateJSON
return genutil.ExportGenesisFile(genDoc, genFile)
return nil
}

0 comments on commit 2bd6a80

Please sign in to comment.