diff --git a/x/distribution/client/cli/tx.go b/x/distribution/client/cli/tx.go index ccbf5d8c6dbb..e54ee4cf76c8 100644 --- a/x/distribution/client/cli/tx.go +++ b/x/distribution/client/cli/tx.go @@ -52,13 +52,12 @@ func newSplitAndApply( genOrBroadcastFn newGenerateOrBroadcastFunc, clientCtx client.Context, fs *pflag.FlagSet, msgs []sdk.Msg, chunkSize int, ) error { - - if chunkSize == 0 { + totalMessages := len(msgs) + if chunkSize == 0 || totalMessages == 0 { return genOrBroadcastFn(clientCtx, fs, msgs...) } // split messages into slices of length chunkSize - totalMessages := len(msgs) for i := 0; i < len(msgs); i += chunkSize { sliceEnd := i + chunkSize diff --git a/x/distribution/client/cli/tx_test.go b/x/distribution/client/cli/tx_test.go index 7176c6bf9578..27f41392cb34 100644 --- a/x/distribution/client/cli/tx_test.go +++ b/x/distribution/client/cli/tx_test.go @@ -21,8 +21,19 @@ import ( func Test_splitAndCall_NoMessages(t *testing.T) { clientCtx := client.Context{} - err := newSplitAndApply(nil, clientCtx, nil, nil, 10) - assert.NoError(t, err, "") + // empty tx will always trigger genOrBroadcastFn + maxMsgsCases := []int{0, 1, 10} + calledCounter := 0 + for _, maxMsgs := range maxMsgsCases { + err := newSplitAndApply( + func(clientCtx client.Context, fs *pflag.FlagSet, msgs ...sdk.Msg) error { + // dummy genOrBroadcastFn called once for each case + calledCounter++ + return nil + }, clientCtx, nil, nil, maxMsgs) + assert.NoError(t, err, "") + } + assert.Equal(t, calledCounter, len(maxMsgsCases)) } func Test_splitAndCall_Splitting(t *testing.T) {