-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 TimeIotaMs to export GenesisFile #6510
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
194e95c
Add TimeIotaMs to export GenesisFile.
jgimeno 0ecc1cf
include changelog entry
jgimeno 92daaea
Fix changelog.
jgimeno 47fe6b3
Merge branch 'master' into jonathan/export-time-genesis
alexanderbez b1cfe5a
Merge branch 'jonathan/export-time-genesis' of github.com:cosmos/cosm…
jgimeno 7e82788
add test for exporting consensus params
jgimeno 9bd01f2
Merge branch 'master' into jonathan/export-time-genesis
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package server | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"io" | ||
"os" | ||
"path" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/spf13/viper" | ||
|
||
abci "github.com/tendermint/tendermint/abci/types" | ||
"github.com/tendermint/tendermint/libs/log" | ||
tmtypes "github.com/tendermint/tendermint/types" | ||
dbm "github.com/tendermint/tm-db" | ||
|
||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/simapp" | ||
"github.com/cosmos/cosmos-sdk/tests" | ||
"github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/cosmos/cosmos-sdk/x/genutil" | ||
) | ||
|
||
func TestExportCmd_ConsensusParams(t *testing.T) { | ||
tempDir, clean := tests.NewTestCaseDir(t) | ||
defer clean() | ||
|
||
err := createConfigFolder(tempDir) | ||
if err != nil { | ||
t.Fatalf("error creating config folder: %s", err) | ||
} | ||
|
||
db := dbm.NewMemDB() | ||
app := simapp.NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, tempDir, 0) | ||
|
||
ctx := NewDefaultContext() | ||
ctx.Config.RootDir = tempDir | ||
|
||
genDoc := newDefaultGenesisDoc(app.Codec()) | ||
err = saveGenesisFile(genDoc, ctx.Config.GenesisFile()) | ||
|
||
app.InitChain( | ||
abci.RequestInitChain{ | ||
Validators: []abci.ValidatorUpdate{}, | ||
ConsensusParams: simapp.DefaultConsensusParams, | ||
AppStateBytes: genDoc.AppState, | ||
}, | ||
) | ||
|
||
app.Commit() | ||
|
||
cmd := ExportCmd( | ||
ctx, | ||
app.Codec(), | ||
func(logger log.Logger, db dbm.DB, writer io.Writer, i int64, b bool, strings []string) (json.RawMessage, []tmtypes.GenesisValidator, *abci.ConsensusParams, error) { | ||
return app.ExportAppStateAndValidators(true, []string{}) | ||
}) | ||
|
||
output := &bytes.Buffer{} | ||
cmd.SetOut(output) | ||
|
||
viper.Set(flags.FlagHome, tempDir) | ||
err = cmd.RunE(cmd, []string{}) | ||
if err != nil { | ||
t.Errorf("error: %s", err) | ||
} | ||
|
||
var exportedGenDoc tmtypes.GenesisDoc | ||
err = app.Codec().UnmarshalJSON(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) | ||
} | ||
|
||
func createConfigFolder(dir string) error { | ||
return os.Mkdir(path.Join(dir, "config"), 0700) | ||
} | ||
|
||
func newDefaultGenesisDoc(cdc *codec.Codec) *tmtypes.GenesisDoc { | ||
genesisState := simapp.NewDefaultGenesisState() | ||
|
||
stateBytes, err := codec.MarshalJSONIndent(cdc, genesisState) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
genDoc := &tmtypes.GenesisDoc{} | ||
genDoc.ChainID = "theChainId" | ||
genDoc.Validators = nil | ||
genDoc.AppState = stateBytes | ||
|
||
return genDoc | ||
} | ||
|
||
func saveGenesisFile(genDoc *tmtypes.GenesisDoc, dir string) error { | ||
err := genutil.ExportGenesisFile(genDoc, dir) | ||
if err != nil { | ||
return errors.Wrap(err, "error creating file") | ||
} | ||
|
||
return nil | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should try find a way to automatically call Set{Err,Out} for all commands at some point.