Skip to content

Commit

Permalink
Merge PR #5497: ensure non-nil gentxs
Browse files Browse the repository at this point in the history
  • Loading branch information
cbarraford authored and alexanderbez committed Mar 10, 2020
1 parent 9c64b02 commit 9da1fb5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Bug Fixes

* (x/genutil) [\#5499](https://github.com/cosmos/cosmos-sdk/pull/) Ensure `DefaultGenesis` returns valid and non-nil default genesis state.
* (genesis) [\#5086](https://github.com/cosmos/cosmos-sdk/issues/5086) Ensure `gentxs` are always an empty array instead of `nil`.

## [v0.37.7] - 2020-02-10

Expand Down
4 changes: 4 additions & 0 deletions x/genutil/types/genesis_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ type GenesisState struct {

// NewGenesisState creates a new GenesisState object
func NewGenesisState(genTxs []json.RawMessage) GenesisState {
// Ensure genTxs is never nil, https://github.com/cosmos/cosmos-sdk/issues/5086
if len(genTxs) == 0 {
genTxs = make([]json.RawMessage, 0)
}
return GenesisState{
GenTxs: genTxs,
}
Expand Down
14 changes: 14 additions & 0 deletions x/genutil/types/genesis_state_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package types

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/ed25519"

Expand All @@ -16,6 +18,18 @@ var (
pk2 = ed25519.GenPrivKey().PubKey()
)

func TestNetGenesisState(t *testing.T) {
gen := NewGenesisState(nil)
assert.NotNil(t, gen.GenTxs) // https://github.com/cosmos/cosmos-sdk/issues/5086

gen = NewGenesisState(
[]json.RawMessage{
[]byte(`{"foo":"bar"}`),
},
)
assert.Equal(t, string(gen.GenTxs[0]), `{"foo":"bar"}`)
}

func TestValidateGenesisMultipleMessages(t *testing.T) {

desc := stakingtypes.NewDescription("testname", "", "", "")
Expand Down

0 comments on commit 9da1fb5

Please sign in to comment.