Skip to content

Commit

Permalink
draft TestStartCmdwithEmptyandNonEmptyMinGasPrices
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberbono3 committed Jun 9, 2021
1 parent 345e531 commit 1c6ea9c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
5 changes: 4 additions & 1 deletion server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"fmt"
"strings"
"errors"

"github.com/spf13/viper"

Expand All @@ -21,6 +22,8 @@ const (
DefaultGRPCWebAddress = "0.0.0.0:9091"
)

var ErrMinGasPrices = errors.New("please set min gas price in app.toml or flag or env var")

// BaseConfig defines the server's basic configuration
type BaseConfig struct {
// The minimum gas prices a validator is willing to accept for processing a
Expand Down Expand Up @@ -309,7 +312,7 @@ func GetConfig(v *viper.Viper) Config {

func (c Config) ValidateBasic() error {
if c.BaseConfig.MinGasPrices == "" {
return fmt.Errorf("please set min gas price in app.toml or flag or env var")
return ErrMinGasPrices
}

return nil
Expand Down
24 changes: 24 additions & 0 deletions server/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/server/config"
)

var CancelledInPreRun = errors.New("Canelled in prerun")
Expand Down Expand Up @@ -399,3 +400,26 @@ func TestInterceptConfigsWithBadPermissions(t *testing.T) {
t.Fatalf("Failed to catch permissions error, got: [%T] %v", err, err)
}
}

func TestStartCmdwithEmptyandNonEmptyMinGasPrices(t *testing.T){

// first case - raise an error
tempDir := t.TempDir()
cmd := StartCmd(nil, tempDir)


// MinGasPrices ="0.22 -> no error raised
cfg := config.DefaultConfig()
cfg.BaseConfig.MinGasPrices ="0.22"

cmd.PreRunE = preRunETestImpl

serverCtx := &Context{}
ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx)

if err := cmd.ExecuteContext(ctx); err != CancelledInPreRun {
t.Fatalf("function failed with [%T] %v", err, err)
}

}

0 comments on commit 1c6ea9c

Please sign in to comment.