Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(systemtests): fix export v2 #22799

Merged
merged 6 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions server/v2/store/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ func (s *Server[T]) Config() any {
// An empty home directory *is* permitted at this stage, but attempting to build
// the store with an empty home directory will fail.
func UnmarshalConfig(cfg map[string]any) (*root.Config, error) {
config := &root.Config{
Options: root.DefaultStoreOptions(),
}
config := root.DefaultConfig()
if err := serverv2.UnmarshalSubConfig(cfg, ServerName, config); err != nil {
return nil, fmt.Errorf("failed to unmarshal store config: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions simapp/v2/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ func TestSimAppExportAndBlockedAddrs_WithOneBlockProduced(t *testing.T) {

MoveNextBlock(t, app, ctx)

_, err := app.ExportAppStateAndValidators(nil)
_, err := app.ExportAppStateAndValidators(false, nil)
require.NoError(t, err)
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
}

func TestSimAppExportAndBlockedAddrs_NoBlocksProduced(t *testing.T) {
app, _ := NewTestApp(t)

_, err := app.ExportAppStateAndValidators(nil)
_, err := app.ExportAppStateAndValidators(false, nil)
require.NoError(t, err)
}
6 changes: 6 additions & 0 deletions simapp/v2/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
// file.
// This is a demonstation of how to export a genesis file. Export may need extended at
// the user discretion for cleaning the genesis state at the end provided with jailAllowedAddrs
// Same applies for forZeroHeight preprocessing.
func (app *SimApp[T]) ExportAppStateAndValidators(
forZeroHeight bool,
jailAllowedAddrs []string,
) (v2.ExportedApp, error) {
ctx := context.Background()
Expand Down Expand Up @@ -44,5 +46,9 @@ func (app *SimApp[T]) ExportAppStateAndValidators(

exportedApp.AppState = genesis
exportedApp.Height = int64(latestHeight)
if forZeroHeight {
exportedApp.Height = 0
}

return exportedApp, nil
}
5 changes: 3 additions & 2 deletions store/db/prefixdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package db_test
import (
"testing"

"cosmossdk.io/store/db"
"cosmossdk.io/store/mock"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"

"cosmossdk.io/store/db"
"cosmossdk.io/store/mock"
)

func TestPrefixDB(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions store/v2/root/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ func (sb *builder) Build(
if config.Home == "" {
return nil, fmt.Errorf("home directory is required")
}

if len(config.AppDBBackend) == 0 {
return nil, fmt.Errorf("application db backend is required")
}

scRawDb, err := db.NewDB(
db.DBType(config.AppDBBackend),
"application",
Expand Down
1 change: 0 additions & 1 deletion tests/integration/v2/distribution/fixture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,4 @@ func (s *fixture) registerMsgRouterService(router *integration.RouterService) {

func (s *fixture) registerQueryRouterService(router *integration.RouterService) {
// register custom router service

}
2 changes: 1 addition & 1 deletion tests/systemtests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.23

require (
cosmossdk.io/math v1.4.0
cosmossdk.io/systemtests v1.0.0-rc.2.0.20241205143753-9e94ea87f6e4
cosmossdk.io/systemtests v1.0.0-rc.3
github.com/cosmos/cosmos-sdk v0.50.6
)

Expand Down
4 changes: 2 additions & 2 deletions tests/systemtests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ cosmossdk.io/math v1.4.0 h1:XbgExXFnXmF/CccPPEto40gOO7FpWu9yWNAZPN3nkNQ=
cosmossdk.io/math v1.4.0/go.mod h1:O5PkD4apz2jZs4zqFdTr16e1dcaQCc5z6lkEnrrppuk=
cosmossdk.io/store v1.1.0 h1:LnKwgYMc9BInn9PhpTFEQVbL9UK475G2H911CGGnWHk=
cosmossdk.io/store v1.1.0/go.mod h1:oZfW/4Fc/zYqu3JmQcQdUJ3fqu5vnYTn3LZFFy8P8ng=
cosmossdk.io/systemtests v1.0.0-rc.2.0.20241205143753-9e94ea87f6e4 h1:gt0rrxBW4x9KM3+ES8Gy5BZbKIHI3AspYEuvWZO6fgU=
cosmossdk.io/systemtests v1.0.0-rc.2.0.20241205143753-9e94ea87f6e4/go.mod h1:B3RY1tY/iwLjQ9MUTz+GsiXV9gEdS8mfUvSQtWUwaAo=
cosmossdk.io/systemtests v1.0.0-rc.3 h1:W1ZdfHtWxbzRCiBwcMb1nMKkmUNyAcHapJOrfh1lX20=
cosmossdk.io/systemtests v1.0.0-rc.3/go.mod h1:B3RY1tY/iwLjQ9MUTz+GsiXV9gEdS8mfUvSQtWUwaAo=
cosmossdk.io/x/tx v0.13.3-0.20240419091757-db5906b1e894 h1:kHEvzVqpNv/9pnaEPBsgE/FMc+cVmWjSsInRufkZkpQ=
cosmossdk.io/x/tx v0.13.3-0.20240419091757-db5906b1e894/go.mod h1:Tb6/tpONmtL5qFdOMdv1pdvrtJNxcazZBoz04HB71ss=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
Expand Down
2 changes: 1 addition & 1 deletion x/genutil/v2/cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type genesisMM interface {
}

type ExportableApp interface {
ExportAppStateAndValidators([]string) (v2.ExportedApp, error)
ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddrs []string) (v2.ExportedApp, error)
LoadHeight(uint64) error
}

Expand Down
5 changes: 4 additions & 1 deletion x/genutil/v2/cli/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

const (
flagHeight = "height"
flagForZeroHeight = "for-zero-height"
flagJailAllowedAddrs = "jail-allowed-addrs"
)

Expand Down Expand Up @@ -56,14 +57,15 @@ func ExportCmd(app ExportableApp) *cobra.Command {
}

height, _ := cmd.Flags().GetInt64(flagHeight)
forZeroHeight, _ := cmd.Flags().GetBool(flagForZeroHeight)
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
jailAllowedAddrs, _ := cmd.Flags().GetStringSlice(flagJailAllowedAddrs)
outputDocument, _ := cmd.Flags().GetString(flags.FlagOutputDocument)
if height != -1 {
if err := app.LoadHeight(uint64(height)); err != nil {
return err
}
}
exported, err := app.ExportAppStateAndValidators(jailAllowedAddrs)
exported, err := app.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs)
if err != nil {
return fmt.Errorf("error exporting state: %w", err)
}
Expand Down Expand Up @@ -105,6 +107,7 @@ func ExportCmd(app ExportableApp) *cobra.Command {
StringSlice(flagJailAllowedAddrs, []string{}, "Comma-separated list of operator addresses of jailed validators to unjail")
cmd.Flags().
String(flags.FlagOutputDocument, "", "Exported state is written to the given file instead of STDOUT")
cmd.Flags().Bool(flagForZeroHeight, false, "Export state to start at height zero (perform preproccessing)")

return cmd
}
Loading