Skip to content

Commit 34f407d

Browse files
authored
test(systemtests): fix export v2 (#22799)
1 parent ecd53f8 commit 34f407d

File tree

10 files changed

+25
-13
lines changed

10 files changed

+25
-13
lines changed

server/v2/store/server.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ func (s *Server[T]) Config() any {
7878
// An empty home directory *is* permitted at this stage, but attempting to build
7979
// the store with an empty home directory will fail.
8080
func UnmarshalConfig(cfg map[string]any) (*root.Config, error) {
81-
config := &root.Config{
82-
Options: root.DefaultStoreOptions(),
83-
}
81+
config := root.DefaultConfig()
8482
if err := serverv2.UnmarshalSubConfig(cfg, ServerName, config); err != nil {
8583
return nil, fmt.Errorf("failed to unmarshal store config: %w", err)
8684
}

simapp/v2/app_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,13 @@ func TestSimAppExportAndBlockedAddrs_WithOneBlockProduced(t *testing.T) {
153153

154154
MoveNextBlock(t, app, ctx)
155155

156-
_, err := app.ExportAppStateAndValidators(nil)
156+
_, err := app.ExportAppStateAndValidators(false, nil)
157157
require.NoError(t, err)
158158
}
159159

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

163-
_, err := app.ExportAppStateAndValidators(nil)
163+
_, err := app.ExportAppStateAndValidators(false, nil)
164164
require.NoError(t, err)
165165
}

simapp/v2/export.go

+6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import (
1313
// file.
1414
// This is a demonstation of how to export a genesis file. Export may need extended at
1515
// the user discretion for cleaning the genesis state at the end provided with jailAllowedAddrs
16+
// Same applies for forZeroHeight preprocessing.
1617
func (app *SimApp[T]) ExportAppStateAndValidators(
18+
forZeroHeight bool,
1719
jailAllowedAddrs []string,
1820
) (v2.ExportedApp, error) {
1921
ctx := context.Background()
@@ -44,5 +46,9 @@ func (app *SimApp[T]) ExportAppStateAndValidators(
4446

4547
exportedApp.AppState = genesis
4648
exportedApp.Height = int64(latestHeight)
49+
if forZeroHeight {
50+
exportedApp.Height = 0
51+
}
52+
4753
return exportedApp, nil
4854
}

store/db/prefixdb_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package db_test
33
import (
44
"testing"
55

6-
"cosmossdk.io/store/db"
7-
"cosmossdk.io/store/mock"
86
"github.com/stretchr/testify/require"
97
"go.uber.org/mock/gomock"
8+
9+
"cosmossdk.io/store/db"
10+
"cosmossdk.io/store/mock"
1011
)
1112

1213
func TestPrefixDB(t *testing.T) {

store/v2/root/builder.go

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ func (sb *builder) Build(
5555
if config.Home == "" {
5656
return nil, fmt.Errorf("home directory is required")
5757
}
58+
59+
if len(config.AppDBBackend) == 0 {
60+
return nil, fmt.Errorf("application db backend is required")
61+
}
62+
5863
scRawDb, err := db.NewDB(
5964
db.DBType(config.AppDBBackend),
6065
"application",

tests/integration/v2/distribution/fixture_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -156,5 +156,4 @@ func (s *fixture) registerMsgRouterService(router *integration.RouterService) {
156156

157157
func (s *fixture) registerQueryRouterService(router *integration.RouterService) {
158158
// register custom router service
159-
160159
}

tests/systemtests/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.23
44

55
require (
66
cosmossdk.io/math v1.4.0
7-
cosmossdk.io/systemtests v1.0.0-rc.2.0.20241205143753-9e94ea87f6e4
7+
cosmossdk.io/systemtests v1.0.0-rc.3
88
github.com/cosmos/cosmos-sdk v0.50.6
99
)
1010

tests/systemtests/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ cosmossdk.io/math v1.4.0 h1:XbgExXFnXmF/CccPPEto40gOO7FpWu9yWNAZPN3nkNQ=
1616
cosmossdk.io/math v1.4.0/go.mod h1:O5PkD4apz2jZs4zqFdTr16e1dcaQCc5z6lkEnrrppuk=
1717
cosmossdk.io/store v1.1.0 h1:LnKwgYMc9BInn9PhpTFEQVbL9UK475G2H911CGGnWHk=
1818
cosmossdk.io/store v1.1.0/go.mod h1:oZfW/4Fc/zYqu3JmQcQdUJ3fqu5vnYTn3LZFFy8P8ng=
19-
cosmossdk.io/systemtests v1.0.0-rc.2.0.20241205143753-9e94ea87f6e4 h1:gt0rrxBW4x9KM3+ES8Gy5BZbKIHI3AspYEuvWZO6fgU=
20-
cosmossdk.io/systemtests v1.0.0-rc.2.0.20241205143753-9e94ea87f6e4/go.mod h1:B3RY1tY/iwLjQ9MUTz+GsiXV9gEdS8mfUvSQtWUwaAo=
19+
cosmossdk.io/systemtests v1.0.0-rc.3 h1:W1ZdfHtWxbzRCiBwcMb1nMKkmUNyAcHapJOrfh1lX20=
20+
cosmossdk.io/systemtests v1.0.0-rc.3/go.mod h1:B3RY1tY/iwLjQ9MUTz+GsiXV9gEdS8mfUvSQtWUwaAo=
2121
cosmossdk.io/x/tx v0.13.3-0.20240419091757-db5906b1e894 h1:kHEvzVqpNv/9pnaEPBsgE/FMc+cVmWjSsInRufkZkpQ=
2222
cosmossdk.io/x/tx v0.13.3-0.20240419091757-db5906b1e894/go.mod h1:Tb6/tpONmtL5qFdOMdv1pdvrtJNxcazZBoz04HB71ss=
2323
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=

x/genutil/v2/cli/commands.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type genesisMM interface {
2020
}
2121

2222
type ExportableApp interface {
23-
ExportAppStateAndValidators([]string) (v2.ExportedApp, error)
23+
ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddrs []string) (v2.ExportedApp, error)
2424
LoadHeight(uint64) error
2525
}
2626

x/genutil/v2/cli/export.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717

1818
const (
1919
flagHeight = "height"
20+
flagForZeroHeight = "for-zero-height"
2021
flagJailAllowedAddrs = "jail-allowed-addrs"
2122
)
2223

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

5859
height, _ := cmd.Flags().GetInt64(flagHeight)
60+
forZeroHeight, _ := cmd.Flags().GetBool(flagForZeroHeight)
5961
jailAllowedAddrs, _ := cmd.Flags().GetStringSlice(flagJailAllowedAddrs)
6062
outputDocument, _ := cmd.Flags().GetString(flags.FlagOutputDocument)
6163
if height != -1 {
6264
if err := app.LoadHeight(uint64(height)); err != nil {
6365
return err
6466
}
6567
}
66-
exported, err := app.ExportAppStateAndValidators(jailAllowedAddrs)
68+
exported, err := app.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs)
6769
if err != nil {
6870
return fmt.Errorf("error exporting state: %w", err)
6971
}
@@ -105,6 +107,7 @@ func ExportCmd(app ExportableApp) *cobra.Command {
105107
StringSlice(flagJailAllowedAddrs, []string{}, "Comma-separated list of operator addresses of jailed validators to unjail")
106108
cmd.Flags().
107109
String(flags.FlagOutputDocument, "", "Exported state is written to the given file instead of STDOUT")
110+
cmd.Flags().Bool(flagForZeroHeight, false, "Export state to start at height zero (perform preproccessing)")
108111

109112
return cmd
110113
}

0 commit comments

Comments
 (0)