diff --git a/x/rollapp/client/cli/cli_test.go b/x/rollapp/client/cli/cli_test.go index b08162449..2f65273b4 100644 --- a/x/rollapp/client/cli/cli_test.go +++ b/x/rollapp/client/cli/cli_test.go @@ -1,9 +1,11 @@ package cli_test import ( + "encoding/json" "os" "strings" "testing" + "time" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" @@ -46,7 +48,7 @@ func TestGetTxCmd(t *testing.T) { assert.True(t, cmd.Flags().HasFlags()) } -func TestCmdCreateIRO(t *testing.T) { +func TestCmdCreateRollapp(t *testing.T) { addr := sdk.AccAddress("testAddress").String() // Create a temporary file for metadata @@ -98,3 +100,55 @@ func TestCmdCreateIRO(t *testing.T) { }) } } + +func TestCmdUpdateState(t *testing.T) { + addr := sdk.AccAddress("testAddress").String() + + bds := types.BlockDescriptors{ + BD: []types.BlockDescriptor{ + { + Height: 12345, + StateRoot: []byte("helloworld"), + Timestamp: time.Date(2023, 10, 1, 12, 34, 56, 0, time.UTC), + }, + { + Height: 12346, + StateRoot: []byte("worldhello"), + Timestamp: time.Date(2023, 10, 1, 12, 35, 56, 0, time.UTC), + }, + }, + } + + bdsStr, err := json.Marshal(bds) + assert.NoError(t, err) + + testCases := []struct { + name string + args []string + errMsg string + }{ + { + "valid minimal args", + []string{"testRollappId", "10", "10", "dat-path", string(bdsStr), "--from", addr}, + "", + }, + { + "missing args", + []string{"testRollappId", "10", "10", "dat-path", "--from", addr}, + "accepts", + }, + } + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + cmd := cli.CmdUpdateState() + cmd.SetArgs(tc.args) + err := cmd.Execute() + if tc.errMsg != "" { + require.Error(t, err) + assert.Contains(t, err.Error(), tc.errMsg) + } else { + require.Contains(t, err.Error(), "key not found") // we expect this error because we are not setting the key. anyway it means we passed validation + } + }) + } +} diff --git a/x/rollapp/client/cli/tx_update_state.go b/x/rollapp/client/cli/tx_update_state.go index 77bea1ae1..115b54ef8 100644 --- a/x/rollapp/client/cli/tx_update_state.go +++ b/x/rollapp/client/cli/tx_update_state.go @@ -19,7 +19,7 @@ func CmdUpdateState() *cobra.Command { cmd := &cobra.Command{ Use: "update-state [rollapp-id] [start-height] [num-blocks] [da-path] [bds]", Short: "Update rollapp state", - Args: cobra.ExactArgs(6), + Args: cobra.ExactArgs(5), RunE: func(cmd *cobra.Command, args []string) (err error) { argRollappId := args[0] argStartHeight, err := cast.ToUint64E(args[1]) @@ -32,7 +32,7 @@ func CmdUpdateState() *cobra.Command { } argDAPath := args[3] argBDs := new(types.BlockDescriptors) - err = json.Unmarshal([]byte(args[5]), argBDs) + err = json.Unmarshal([]byte(args[4]), argBDs) if err != nil { return err }