diff --git a/CHANGELOG.md b/CHANGELOG.md index 8860d40db1..12e798c236 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/x/genutil/types/genesis_state.go b/x/genutil/types/genesis_state.go index 6c5c555482..453ecdedc9 100644 --- a/x/genutil/types/genesis_state.go +++ b/x/genutil/types/genesis_state.go @@ -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, } diff --git a/x/genutil/types/genesis_state_test.go b/x/genutil/types/genesis_state_test.go index aed7cd7f31..b82a89b98a 100644 --- a/x/genutil/types/genesis_state_test.go +++ b/x/genutil/types/genesis_state_test.go @@ -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" @@ -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", "", "", "", "")