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 Feb 10, 2020
1 parent 7edd414 commit e2d4b9d
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 @@ -65,6 +65,7 @@ is the latest height, we'll use the store's `lastCommitInfo`. Otherwise, we fetc
* (x/bank) [\#5531](https://github.com/cosmos/cosmos-sdk/issues/5531) Added missing amount event to MsgMultiSend, emitted for each output.
* (client) [\#5618](https://github.com/cosmos/cosmos-sdk/pull/5618) Fix crash on the client when the verifier is not set.
* (x/distribution) [\#5620](https://github.com/cosmos/cosmos-sdk/pull/5620) Fix nil pointer deref in distribution tax/rewward validation helpers.
* (genesis) [\#5086](https://github.com/cosmos/cosmos-sdk/issues/5086) Ensure `gentxs` are always an empty array instead of `nil`

### State Machine Breaking

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 e2d4b9d

Please sign in to comment.