Skip to content

Commit

Permalink
fixed command
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsitrin committed Oct 7, 2024
1 parent ada3fa2 commit 6bedbd9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
56 changes: 55 additions & 1 deletion x/rollapp/client/cli/cli_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
})
}
}
4 changes: 2 additions & 2 deletions x/rollapp/client/cli/tx_update_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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
}
Expand Down

0 comments on commit 6bedbd9

Please sign in to comment.