github.com/cosmos/cosmos-sdk@v0.50.10/x/distribution/client/cli/util_test.go (about) 1 package cli 2 3 import ( 4 "testing" 5 6 "github.com/spf13/pflag" 7 "github.com/stretchr/testify/require" 8 9 "github.com/cosmos/cosmos-sdk/client" 10 "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" 11 "github.com/cosmos/cosmos-sdk/testutil/testdata" 12 sdk "github.com/cosmos/cosmos-sdk/types" 13 ) 14 15 func Test_splitAndCall_NoMessages(t *testing.T) { 16 clientCtx := client.Context{} 17 18 err := newSplitAndApply(nil, clientCtx, nil, nil, 10) 19 require.NoError(t, err, "") 20 } 21 22 func Test_splitAndCall_Splitting(t *testing.T) { 23 clientCtx := client.Context{} 24 25 addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) 26 27 // Add five messages 28 msgs := []sdk.Msg{ 29 testdata.NewTestMsg(addr), 30 testdata.NewTestMsg(addr), 31 testdata.NewTestMsg(addr), 32 testdata.NewTestMsg(addr), 33 testdata.NewTestMsg(addr), 34 } 35 36 // Keep track of number of calls 37 const chunkSize = 2 38 39 callCount := 0 40 err := newSplitAndApply( 41 func(clientCtx client.Context, fs *pflag.FlagSet, msgs ...sdk.Msg) error { 42 callCount++ 43 44 require.NotNil(t, clientCtx) 45 require.NotNil(t, msgs) 46 47 if callCount < 3 { 48 require.Equal(t, len(msgs), 2) 49 } else { 50 require.Equal(t, len(msgs), 1) 51 } 52 53 return nil 54 }, 55 clientCtx, nil, msgs, chunkSize) 56 57 require.NoError(t, err, "") 58 require.Equal(t, 3, callCount) 59 }