Skip to content

Commit

Permalink
test: precedence of flag vs toml for abci client type (merge #419)
Browse files Browse the repository at this point in the history
  • Loading branch information
gibson042 authored Apr 19, 2024
2 parents 5733916 + 2fa6403 commit c03a8b7
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 3 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG-Agoric.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Improvements

* (auth) [#407](https://github.com/agoric-labs/cosmos-sdk/pull/407) Configurable fee collector module account in DeductFeeDecorator.
* (baseapp) [#415](https://github.com/agoric-labs/cosmos-sdk/pull/415) Unit tests and documentation for event history.
* (deps) [#412](https://github.com/agoric-labs/cosmos-sdk/pull/412) Bump iavl to v0.19.7
* (server) [#409](https://github.com/agoric-labs/cosmos-sdk/pull/409) Flag to select ABCI client type.
* (server) [#416](https://github.com/agoric-labs/cosmos-sdk/pull/416) Config entry to select ABCI client type.
* (deps) [#412](https://github.com/agoric-labs/cosmos-sdk/pull/412) Bump iavl to v0.19.7
* (baseapp) [#415](https://github.com/agoric-labs/cosmos-sdk/pull/415) Unit tests and documentation for event history.
* (server) [#419](https://github.com/agoric-labs/cosmos-sdk/pull/419) More unit tests for flag vs toml precedence for ABCI client type.

### Bug Fixes

Expand Down
3 changes: 3 additions & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ type BaseConfig struct {
IAVLLazyLoading bool `mapstructure:"iavl-lazy-loading"`

// ABCIClientType selects the type of ABCI client.
// Valid settings are "committing" (default) or "local".
// The committing client allows greater query parallelism,
// but the local client is more defensive.
ABCIClientType string `mapstructure:"abci-client-type"`

// AppDBBackend defines the type of Database to use for the application and snapshots databases.
Expand Down
4 changes: 3 additions & 1 deletion server/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ iavl-disable-fastnode = {{ .BaseConfig.IAVLDisableFastNode }}
iavl-lazy-loading = {{ .BaseConfig.IAVLLazyLoading }}
# ABCIClientType selects the type of ABCI client.
# Default is "committing".
# Valid settings are "committing" (default) or "local".
# The committing client allows greater query parallelism,
# but the local client is more defensive.
abci-client-type = "{{ .BaseConfig.ABCIClientType }}"
# AppDBBackend defines the database backend type to use for the application and snapshots DBs.
Expand Down
88 changes: 88 additions & 0 deletions server/start_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package server

import (
"context"
"errors"
"fmt"
"os"
"path"
"reflect"
"runtime"
"testing"

"github.com/spf13/cobra"
tmcfg "github.com/tendermint/tendermint/config"
)

func TestAbciClientType(t *testing.T) {
Expand Down Expand Up @@ -44,3 +52,83 @@ func TestAbciClientType(t *testing.T) {
})
}
}

var errCancelledInPreRun = errors.New("cancelled in prerun")

func TestAbciClientPrecedence(t *testing.T) {
for i, tt := range []struct {
flag, toml, want string
}{
{
want: "committing",
},
{
flag: "foo",
want: "foo",
},
{
toml: "foo",
want: "foo",
},
{
flag: "foo",
toml: "bar",
want: "foo",
},
} {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
tempDir := t.TempDir()
err := os.Mkdir(path.Join(tempDir, "config"), os.ModePerm)
if err != nil {
t.Fatalf("creating config dir failed: %v", err)
}
appTomlPath := path.Join(tempDir, "config", "app.toml")

cmd := StartCmd(nil, tempDir)

if tt.flag != "" {
err = cmd.Flags().Set(FlagAbciClientType, tt.flag)
if err != nil {
t.Fatalf(`failed setting flag to "%s": %v`, tt.flag, err)
}
}

if tt.toml != "" {
writer, err := os.Create(appTomlPath)
if err != nil {
t.Fatalf(`failed creating "%s": %v`, appTomlPath, err)
}
_, err = writer.WriteString(fmt.Sprintf("%s = \"%s\"\n", FlagAbciClientType, tt.toml))
if err != nil {
t.Fatalf(`failed writing to app.toml: %v`, err)
}
err = writer.Close()
if err != nil {
t.Fatalf(`failed closing app.toml: %v`, err)
}
}

// Compare to tests in util_test.go
cmd.PreRunE = func(cmd *cobra.Command, args []string) error {
err := InterceptConfigsPreRunHandler(cmd, "", nil, tmcfg.DefaultConfig())
if err != nil {
return err
}
return errCancelledInPreRun
}

serverCtx := NewDefaultContext()
ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx)
err = cmd.ExecuteContext(ctx)
if err != errCancelledInPreRun {
t.Fatal(err)
}

gotClientType := serverCtx.Viper.GetString(FlagAbciClientType)

if gotClientType != tt.want {
t.Errorf(`want client type "%s", got "%s"`, tt.want, gotClientType)
}
})
}
}

0 comments on commit c03a8b7

Please sign in to comment.