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

Add height in exported genesis #7089

Merged
merged 70 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
7b56ee3
Add height in exported genesis
amaury1093 Aug 18, 2020
167cc8b
+1
amaury1093 Aug 18, 2020
e17275c
Add test
amaury1093 Aug 19, 2020
ef1e6f0
Merge branch 'master' into am-7018-export-height
amaury1093 Aug 19, 2020
64e828b
Refactor ctx in setupApp
amaury1093 Aug 19, 2020
a04a42c
Use amino in export
amaury1093 Aug 20, 2020
a619220
Merge branch 'master' into am-7018-export-height
amaury1093 Aug 20, 2020
2c7ef98
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Aug 21, 2020
1749ca8
Use tmjson
amaury1093 Aug 21, 2020
2b1cec3
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Aug 24, 2020
facab0e
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Aug 24, 2020
a4ac0fc
Add custom initialVersion (set to 0 for now)
amaury1093 Aug 24, 2020
6a9e6bc
Add comment
amaury1093 Aug 24, 2020
a04b438
Add mount in initChainer
amaury1093 Aug 25, 2020
bf549ec
app.LastBlockheight
amaury1093 Aug 25, 2020
86162b3
Merge branch 'master' into am-7018-export-height
amaury1093 Aug 25, 2020
fb99bb3
InitializeAndSeal in InitChain?
amaury1093 Aug 25, 2020
bf9d606
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Aug 25, 2020
405c921
Merge branch 'master' into am-7018-export-height
alexanderbez Aug 26, 2020
270c323
Revert create store with initial version
amaury1093 Aug 26, 2020
5df1626
Update to latest iavl
amaury1093 Aug 26, 2020
9d16e9e
Check height in test
amaury1093 Aug 26, 2020
af9e5dc
Merge branch 'master' into am-7018-export-height
amaury1093 Aug 26, 2020
9274552
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Aug 27, 2020
5dfa955
Make it work
amaury1093 Aug 27, 2020
4aa9bcc
Add more tests
amaury1093 Aug 27, 2020
bcbb243
Rename interface
amaury1093 Aug 27, 2020
7fdab5d
Use struct isntead of 6 args
amaury1093 Aug 27, 2020
6839081
Fix lint
amaury1093 Aug 27, 2020
0b82fec
Remove stray fmt
amaury1093 Aug 27, 2020
ca6b7c1
Revert go mod/sum
amaury1093 Aug 27, 2020
7f0b573
Install iavl rc3
amaury1093 Aug 27, 2020
4c858a5
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Aug 28, 2020
76c7a12
Update comments
amaury1093 Aug 28, 2020
b80e01b
Merge branch 'master' into am-7018-export-height
jackzampolin Aug 28, 2020
eb65bd1
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Aug 31, 2020
10bc9e6
Add fee in network
amaury1093 Aug 31, 2020
314f0a3
Merge branch 'am-7018-export-height' of ssh://github.com/cosmos/cosmo…
amaury1093 Aug 31, 2020
255aaa7
Typo
amaury1093 Aug 31, 2020
f6216f6
Fix logic in commit
amaury1093 Aug 31, 2020
1f1b602
Fix tests
amaury1093 Aug 31, 2020
789842a
Only set initial version on > 1
amaury1093 Aug 31, 2020
fac4d5e
Genesis block num = 1
amaury1093 Aug 31, 2020
b532d0d
Fresh chain, genesis block = 0
amaury1093 Aug 31, 2020
6ab3cf9
Merge branch 'master' into am-7018-export-height
amaury1093 Aug 31, 2020
54b0a97
Add comments
amaury1093 Aug 31, 2020
e62a650
Merge branch 'master' into am-7018-export-height
amaury1093 Sep 1, 2020
c95c075
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Sep 1, 2020
dbc92b7
Revert Mutable/ImmutableTree
amaury1093 Sep 1, 2020
e238ebe
Allow for zero height
amaury1093 Sep 1, 2020
b8ba3e2
Fix restart
amaury1093 Sep 1, 2020
57485ee
Add comments
amaury1093 Sep 1, 2020
7c6ba4d
Add comments, fix test
amaury1093 Sep 1, 2020
ecd6d7a
Merge branch 'master' into am-7018-export-height
amaury1093 Sep 1, 2020
66a0dc8
Fix remaining one test
amaury1093 Sep 1, 2020
f7cd6d2
Add panic test
amaury1093 Sep 1, 2020
af26c5b
Update comment
amaury1093 Sep 1, 2020
5c5b3eb
Merge branch 'master' into am-7018-export-height
alexanderbez Sep 1, 2020
31d2986
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Sep 2, 2020
57c1f9f
Add test for --height
amaury1093 Sep 2, 2020
2b28235
Merge branch 'am-7018-export-height' of ssh://github.com/cosmos/cosmo…
amaury1093 Sep 2, 2020
aeec99f
No cast
amaury1093 Sep 2, 2020
c2d41b5
Add check that genesis file exists
amaury1093 Sep 2, 2020
d7f4353
Remove duplicate imports
amaury1093 Sep 2, 2020
5940b66
Merge branch 'master' into am-7018-export-height
alexanderbez Sep 2, 2020
95365dc
Merge branch 'master' into am-7018-export-height
alexanderbez Sep 2, 2020
788fb8b
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Sep 2, 2020
6bf735c
Fail early
amaury1093 Sep 2, 2020
8712d04
Merge branch 'am-7018-export-height' of ssh://github.com/cosmos/cosmo…
amaury1093 Sep 2, 2020
abdfb85
Merge branch 'master' into am-7018-export-height
clevinson Sep 2, 2020
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
22 changes: 11 additions & 11 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,12 @@ import (
// InitChain implements the ABCI interface. It runs the initialization logic
// directly on the CommitMultiStore.
func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitChain) {
initHeader := tmproto.Header{ChainID: req.ChainId, Time: req.Time}
initHeader := tmproto.Header{ChainID: req.ChainId, Height: req.InitialHeight, Time: req.Time}

// initialize the deliver state and check state with a correct header
app.setDeliverState(initHeader)
app.setCheckState(initHeader)

// Store the consensus params in the BaseApp's paramstore. Note, this must be
// done after the deliver state and context have been set as it's persisted
// to state.
if req.ConsensusParams != nil {
app.StoreConsensusParams(app.deliverState.ctx, req.ConsensusParams)
}

if app.initChainer == nil {
return
}
Expand All @@ -45,6 +38,13 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC

res = app.initChainer(app.deliverState.ctx, req)

// Store the consensus params in the BaseApp's paramstore. Note, this must be
// done after the deliver state and context have been set as it's persisted
// to state.
if req.ConsensusParams != nil {
app.StoreConsensusParams(app.deliverState.ctx, req.ConsensusParams)
}

amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
// sanity check
if len(req.Validators) > 0 {
if len(req.Validators) != len(res.Validators) {
Expand All @@ -60,13 +60,13 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC
sort.Sort(abci.ValidatorUpdates(res.Validators))

for i := range res.Validators {
if proto.Equal(&res.Validators[i], &req.Validators[i]) {
if !proto.Equal(&res.Validators[i], &req.Validators[i]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this not correctly implemented before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah seems so

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol wow.....

panic(fmt.Errorf("genesisValidators[%d] != req.Validators[%d] ", i, i))
}
}
}

// NOTE: We don't commit, but BeginBlock for block 1 starts from this
// NOTE: We don't commit, but BeginBlock for block `initial_height` starts from this
// deliverState.
return res
}
Expand Down Expand Up @@ -97,7 +97,7 @@ func (app *BaseApp) FilterPeerByAddrPort(info string) abci.ResponseQuery {
return abci.ResponseQuery{}
}

// FilterPeerByIDfilters peers by node ID.
// FilterPeerByID filters peers by node ID.
func (app *BaseApp) FilterPeerByID(info string) abci.ResponseQuery {
if app.idPeerFilter != nil {
return app.idPeerFilter(info)
Expand Down
28 changes: 11 additions & 17 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,20 @@ func (app *BaseApp) Logger() log.Logger {

// MountStores mounts all IAVL or DB stores to the provided keys in the BaseApp
// multistore.
func (app *BaseApp) MountStores(keys ...sdk.StoreKey) {
func (app *BaseApp) MountStores(initialVersion int64, keys ...sdk.StoreKey) {
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
for _, key := range keys {
switch key.(type) {
case *sdk.KVStoreKey:
if !app.fauxMerkleMode {
app.MountStore(key, sdk.StoreTypeIAVL)
app.MountStore(key, sdk.StoreTypeIAVL, initialVersion)
} else {
// StoreTypeDB doesn't do anything upon commit, and it doesn't
// retain history, but it's useful for faster simulation.
app.MountStore(key, sdk.StoreTypeDB)
app.MountStore(key, sdk.StoreTypeDB, 0)
}

case *sdk.TransientStoreKey:
app.MountStore(key, sdk.StoreTypeTransient)
app.MountStore(key, sdk.StoreTypeTransient, 0)

default:
panic("Unrecognized store key type " + reflect.TypeOf(key).Name())
Expand All @@ -178,14 +178,14 @@ func (app *BaseApp) MountStores(keys ...sdk.StoreKey) {

// MountKVStores mounts all IAVL or DB stores to the provided keys in the
// BaseApp multistore.
func (app *BaseApp) MountKVStores(keys map[string]*sdk.KVStoreKey) {
func (app *BaseApp) MountKVStores(keys map[string]*sdk.KVStoreKey, initialVersion int64) {
for _, key := range keys {
if !app.fauxMerkleMode {
app.MountStore(key, sdk.StoreTypeIAVL)
app.MountStore(key, sdk.StoreTypeIAVL, initialVersion)
} else {
// StoreTypeDB doesn't do anything upon commit, and it doesn't
// retain history, but it's useful for faster simulation.
app.MountStore(key, sdk.StoreTypeDB)
app.MountStore(key, sdk.StoreTypeDB, 0)
}
}
}
Expand All @@ -194,28 +194,22 @@ func (app *BaseApp) MountKVStores(keys map[string]*sdk.KVStoreKey) {
// the BaseApp multistore.
func (app *BaseApp) MountTransientStores(keys map[string]*sdk.TransientStoreKey) {
for _, key := range keys {
app.MountStore(key, sdk.StoreTypeTransient)
app.MountStore(key, sdk.StoreTypeTransient, 0)
}
}

// MountMemoryStores mounts all in-memory KVStores with the BaseApp's internal
// commit multi-store.
func (app *BaseApp) MountMemoryStores(keys map[string]*sdk.MemoryStoreKey) {
for _, memKey := range keys {
app.MountStore(memKey, sdk.StoreTypeMemory)
app.MountStore(memKey, sdk.StoreTypeMemory, 0)
}
}

// MountStoreWithDB mounts a store to the provided key in the BaseApp
// multistore, using a specified DB.
func (app *BaseApp) MountStoreWithDB(key sdk.StoreKey, typ sdk.StoreType, db dbm.DB) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this dead code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a shortcut for app.cms.MountStoreWithDB, but in the code we always use app.cms.MountStoreWithDB directly. This function was never.called.

app.cms.MountStoreWithDB(key, typ, db)
}

// MountStore mounts a store to the provided key in the BaseApp multistore,
// using the default DB.
func (app *BaseApp) MountStore(key sdk.StoreKey, typ sdk.StoreType) {
app.cms.MountStoreWithDB(key, typ, nil)
func (app *BaseApp) MountStore(key sdk.StoreKey, typ sdk.StoreType, initialVersion int64) {
app.cms.MountStoreWithDB(key, typ, nil, initialVersion)
}

// LoadLatestVersion loads the latest application version. It will panic if
Expand Down
18 changes: 9 additions & 9 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func setupBaseApp(t *testing.T, options ...func(*BaseApp)) *BaseApp {
app := newBaseApp(t.Name(), options...)
require.Equal(t, t.Name(), app.Name())

app.MountStores(capKey1, capKey2)
app.MountStores(0, capKey1, capKey2)
app.SetParamStore(&paramStore{db: dbm.NewMemDB()})

// stores are mounted
Expand Down Expand Up @@ -150,7 +150,7 @@ func TestLoadVersion(t *testing.T) {

// reload with LoadLatestVersion
app = NewBaseApp(name, logger, db, nil, pruningOpt)
app.MountStores()
app.MountStores(0)
err = app.LoadLatestVersion()
require.Nil(t, err)
testLoadVersionHelper(t, app, int64(2), commitID2)
Expand All @@ -174,7 +174,7 @@ func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) {
rs := rootmulti.NewStore(db)
rs.SetPruning(store.PruneNothing)
key := sdk.NewKVStoreKey(storeKey)
rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil)
rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil, 0)
err := rs.LoadLatestVersion()
require.Nil(t, err)
require.Equal(t, int64(0), rs.LastCommitID().Version)
Expand All @@ -191,7 +191,7 @@ func checkStore(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte
rs := rootmulti.NewStore(db)
rs.SetPruning(store.PruneDefault)
key := sdk.NewKVStoreKey(storeKey)
rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil)
rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil, 0)
err := rs.LoadLatestVersion()
require.Nil(t, err)
require.Equal(t, ver, rs.LastCommitID().Version)
Expand Down Expand Up @@ -237,7 +237,7 @@ func TestSetLoader(t *testing.T) {
opts = append(opts, tc.setLoader)
}
app := NewBaseApp(t.Name(), defaultLogger(), db, nil, opts...)
app.MountStores(sdk.NewKVStoreKey(tc.loadStoreKey))
app.MountStores(0, sdk.NewKVStoreKey(tc.loadStoreKey))
err := app.LoadLatestVersion()
require.Nil(t, err)

Expand Down Expand Up @@ -319,7 +319,7 @@ func TestLoadVersionPruning(t *testing.T) {

// make a cap key and mount the store
capKey := sdk.NewKVStoreKey("key1")
app.MountStores(capKey)
app.MountStores(0, capKey)

err := app.LoadLatestVersion() // needed to make stores non-nil
require.Nil(t, err)
Expand Down Expand Up @@ -354,7 +354,7 @@ func TestLoadVersionPruning(t *testing.T) {

// reload with LoadLatestVersion, check it loads last version
app = NewBaseApp(name, logger, db, nil, pruningOpt)
app.MountStores(capKey)
app.MountStores(0, capKey)

err = app.LoadLatestVersion()
require.Nil(t, err)
Expand Down Expand Up @@ -472,7 +472,7 @@ func TestInitChainer(t *testing.T) {
app := NewBaseApp(name, logger, db, nil)
capKey := sdk.NewKVStoreKey("main")
capKey2 := sdk.NewKVStoreKey("key2")
app.MountStores(capKey, capKey2)
app.MountStores(0, capKey, capKey2)

// set a value in the store on init chain
key, value := []byte("hello"), []byte("goodbye")
Expand Down Expand Up @@ -517,7 +517,7 @@ func TestInitChainer(t *testing.T) {
// reload app
app = NewBaseApp(name, logger, db, nil)
app.SetInitChainer(initChainer)
app.MountStores(capKey, capKey2)
app.MountStores(0, capKey, capKey2)
err = app.LoadLatestVersion() // needed to make stores non-nil
require.Nil(t, err)
require.Equal(t, int64(1), app.LastBlockHeight())
Expand Down
13 changes: 7 additions & 6 deletions server/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package server
// DONTCOVER

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"

"github.com/spf13/cobra"
tmjson "github.com/tendermint/tendermint/libs/json"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"

Expand Down Expand Up @@ -64,7 +64,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com
forZeroHeight, _ := cmd.Flags().GetBool(FlagForZeroHeight)
jailAllowedAddrs, _ := cmd.Flags().GetStringSlice(FlagJailAllowedAddrs)

appState, validators, cp, err := appExporter(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailAllowedAddrs)
appState, validators, appHeight, cp, err := appExporter(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailAllowedAddrs)
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return fmt.Errorf("error exporting state: %v", err)
}
Expand All @@ -76,6 +76,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com

doc.AppState = appState
doc.Validators = validators
doc.InitialHeight = appHeight + 1
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
doc.ConsensusParams = &tmproto.ConsensusParams{
Block: tmproto.BlockParams{
MaxBytes: cp.Block.MaxBytes,
Expand All @@ -93,10 +94,10 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com
},
}

// NOTE: for now we're just using standard JSON marshaling for the root GenesisDoc.
// These types are in Tendermint, don't support proto and as far as we know, don't need it.
// All of the protobuf/amino state is inside AppState
encoded, err := json.MarshalIndent(doc, "", " ")
// NOTE: Tendermint uses a custom JSON decoder for GenesisDoc
// (except for stuff inside AppState). Inside AppState, we're free
// to encode as protobuf or amino.
encoded, err := tmjson.Marshal(doc)
if err != nil {
return err
}
Expand Down
76 changes: 56 additions & 20 deletions server/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import (
"path"
"testing"

"github.com/spf13/cobra"
"github.com/stretchr/testify/require"

abci "github.com/tendermint/tendermint/abci/types"
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tm-db"

Expand All @@ -29,6 +32,56 @@ func TestExportCmd_ConsensusParams(t *testing.T) {
tempDir, clean := testutil.NewTestCaseDir(t)
defer clean()

_, ctx, genDoc, cmd := setupApp(t, tempDir)

output := &bytes.Buffer{}
cmd.SetOut(output)
cmd.SetArgs([]string{fmt.Sprintf("--%s=%s", flags.FlagHome, tempDir)})
require.NoError(t, cmd.ExecuteContext(ctx))

var exportedGenDoc tmtypes.GenesisDoc
err := tmjson.Unmarshal(output.Bytes(), &exportedGenDoc)
if err != nil {
t.Fatalf("error unmarshaling exported genesis doc: %s", err)
}

require.Equal(t, genDoc.ConsensusParams.Block.TimeIotaMs, exportedGenDoc.ConsensusParams.Block.TimeIotaMs)
require.Equal(t, simapp.DefaultConsensusParams.Block.MaxBytes, exportedGenDoc.ConsensusParams.Block.MaxBytes)
require.Equal(t, simapp.DefaultConsensusParams.Block.MaxGas, exportedGenDoc.ConsensusParams.Block.MaxGas)

require.Equal(t, simapp.DefaultConsensusParams.Evidence.MaxAgeDuration, exportedGenDoc.ConsensusParams.Evidence.MaxAgeDuration)
require.Equal(t, simapp.DefaultConsensusParams.Evidence.MaxAgeNumBlocks, exportedGenDoc.ConsensusParams.Evidence.MaxAgeNumBlocks)
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved

require.Equal(t, simapp.DefaultConsensusParams.Validator.PubKeyTypes, exportedGenDoc.ConsensusParams.Validator.PubKeyTypes)
}

func TestExportCmd_Height(t *testing.T) {
tempDir, clean := testutil.NewTestCaseDir(t)
defer clean()

app, ctx, _, cmd := setupApp(t, tempDir)

// Fast forward to block 3.
app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 2}})
app.Commit()
app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 3}})
app.Commit()

output := &bytes.Buffer{}
cmd.SetOut(output)
cmd.SetArgs([]string{fmt.Sprintf("--%s=%s", flags.FlagHome, tempDir)})
require.NoError(t, cmd.ExecuteContext(ctx))

var exportedGenDoc tmtypes.GenesisDoc
err := tmjson.Unmarshal(output.Bytes(), &exportedGenDoc)
if err != nil {
t.Fatalf("error unmarshaling exported genesis doc: %s", err)
}

require.Equal(t, int64(4), exportedGenDoc.InitialHeight)
}

func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *tmtypes.GenesisDoc, *cobra.Command) {
err := createConfigFolder(tempDir)
if err != nil {
t.Fatalf("error creating config folder: %s", err)
Expand All @@ -44,6 +97,7 @@ func TestExportCmd_ConsensusParams(t *testing.T) {

genDoc := newDefaultGenesisDoc()
err = saveGenesisFile(genDoc, serverCtx.Config.GenesisFile())
require.NoError(t, err)

app.InitChain(
abci.RequestInitChain{
Expand All @@ -56,33 +110,15 @@ func TestExportCmd_ConsensusParams(t *testing.T) {
app.Commit()

cmd := ExportCmd(
func(logger log.Logger, db dbm.DB, writer io.Writer, i int64, b bool, strings []string) (json.RawMessage, []tmtypes.GenesisValidator, *abci.ConsensusParams, error) {
func(logger log.Logger, db dbm.DB, writer io.Writer, i int64, b bool, strings []string) (json.RawMessage, []tmtypes.GenesisValidator, int64, *abci.ConsensusParams, error) {
return app.ExportAppStateAndValidators(true, []string{})
}, tempDir)

ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
ctx = context.WithValue(ctx, ServerContextKey, serverCtx)

output := &bytes.Buffer{}
cmd.SetOut(output)
cmd.SetArgs([]string{fmt.Sprintf("--%s=%s", flags.FlagHome, tempDir)})
require.NoError(t, cmd.ExecuteContext(ctx))

var exportedGenDoc tmtypes.GenesisDoc
err = json.Unmarshal(output.Bytes(), &exportedGenDoc)
if err != nil {
t.Fatalf("error unmarshaling exported genesis doc: %s", err)
}

require.Equal(t, genDoc.ConsensusParams.Block.TimeIotaMs, exportedGenDoc.ConsensusParams.Block.TimeIotaMs)
require.Equal(t, simapp.DefaultConsensusParams.Block.MaxBytes, exportedGenDoc.ConsensusParams.Block.MaxBytes)
require.Equal(t, simapp.DefaultConsensusParams.Block.MaxGas, exportedGenDoc.ConsensusParams.Block.MaxGas)

require.Equal(t, simapp.DefaultConsensusParams.Evidence.MaxAgeDuration, exportedGenDoc.ConsensusParams.Evidence.MaxAgeDuration)
require.Equal(t, simapp.DefaultConsensusParams.Evidence.MaxAgeNumBlocks, exportedGenDoc.ConsensusParams.Evidence.MaxAgeNumBlocks)

require.Equal(t, simapp.DefaultConsensusParams.Validator.PubKeyTypes, exportedGenDoc.ConsensusParams.Validator.PubKeyTypes)
return app, ctx, genDoc, cmd
}

func createConfigFolder(dir string) error {
Expand Down
2 changes: 1 addition & 1 deletion server/mock/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewApp(rootDir string, logger log.Logger) (abci.Application, error) {
baseApp := bam.NewBaseApp("kvstore", logger, db, decodeTx)

// Set mounts for BaseApp's MultiStore.
baseApp.MountStores(capKeyMainStore)
baseApp.MountStores(0, capKeyMainStore)

baseApp.SetInitChainer(InitChainer(capKeyMainStore))

Expand Down
2 changes: 1 addition & 1 deletion server/mock/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (ms multiStore) GetCommitStore(key sdk.StoreKey) sdk.CommitStore {
panic("not implemented")
}

func (ms multiStore) MountStoreWithDB(key sdk.StoreKey, typ sdk.StoreType, db dbm.DB) {
func (ms multiStore) MountStoreWithDB(key sdk.StoreKey, typ sdk.StoreType, db dbm.DB, initialVersion int64) {
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
ms.kv[key] = kvStore{store: make(map[string][]byte)}
}

Expand Down
Loading