Skip to content

Commit

Permalink
fix: mocha block sync
Browse files Browse the repository at this point in the history
  • Loading branch information
rootulp committed Sep 5, 2024
1 parent 44dea31 commit a5bf569
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ func MakeGenesisState(genDoc *types.GenesisDoc) (State, error) {
if genDoc.ConsensusParams != nil {
appVersion = genDoc.ConsensusParams.Version.AppVersion
}
// The mocha-4 genesis.json file does not have an AppVersion defined so this
// special cases it.
if genDoc.ChainID == "mocha-4" {
appVersion = 1
}

return State{
Version: InitStateVersion(appVersion),
Expand Down
25 changes: 25 additions & 0 deletions state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,31 @@ func TestMakeGenesisStateSetsAppVersion(t *testing.T) {
require.Nil(t, err)
require.Equal(t, appVersion, state.Version.Consensus.App)
require.Equal(t, version.BlockProtocol, state.Version.Consensus.Block)
t.Run("MakeGenesisState does not set app version for random-chain-id", func(t *testing.T) {
cp := types.DefaultConsensusParams()
cp.Version = cmtproto.VersionParams{} // zero value
doc := types.GenesisDoc{
ChainID: "random-chain-id",
ConsensusParams: cp,
}
require.NoError(t, doc.ValidateAndComplete())
state, err := sm.MakeGenesisState(&doc)
require.NoError(t, err)
require.Equal(t, uint64(0), state.Version.Consensus.App)
})

t.Run("MakeGenesisState sets app version to 1 for mocha-4", func(t *testing.T) {
cp := types.DefaultConsensusParams()
cp.Version = cmtproto.VersionParams{} // zero value
doc := types.GenesisDoc{
ChainID: "mocha-4",
ConsensusParams: cp,
}
require.NoError(t, doc.ValidateAndComplete())
state, err := sm.MakeGenesisState(&doc)
require.NoError(t, err)
require.Equal(t, uint64(1), state.Version.Consensus.App)
})
}

// TestStateSaveLoad tests saving and loading State from a db.
Expand Down

0 comments on commit a5bf569

Please sign in to comment.