Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
amaury1093 committed Jul 27, 2021
1 parent 4e19f3d commit 91314fe
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
2 changes: 1 addition & 1 deletion x/auth/ante/sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,6 @@ func signatureDataToBz(data signing.SignatureData) ([][]byte, error) {

return sigs, nil
default:
return nil, fmt.Errorf("unexpected signature data type %T", data)
return nil, sdkerrors.ErrInvalidType.Wrapf("unexpected signature data type %T", data)
}
}
24 changes: 17 additions & 7 deletions x/auth/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/version"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
Expand Down Expand Up @@ -222,9 +223,10 @@ Example:
$ %s query tx <hash>
$ %s query tx --%s=%s <addr>:<sequence>
$ %s query tx --%s=%s <sig1_base64,sig2_base64...>
`, version.AppName,
version.AppName, flagType, typeAccSeq,
version.AppName, flagType, typeSig)),
`,
version.AppName,
version.AppName, flagType, typeAccSeq,
version.AppName, flagType, typeSig)),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
Expand Down Expand Up @@ -255,11 +257,10 @@ version.AppName, flagType, typeSig)),
}
case typeSig:
{
if len(args) != 1 || args[0] == "" {
return fmt.Errorf("argument should be comma-separated signatures")
sigParts, err := parseSigArgs(args)
if err != nil {
return err
}

sigParts := strings.Split(args[0], ",")
tmEvents := make([]string, len(sigParts))
for i, sig := range sigParts {
tmEvents[i] = fmt.Sprintf("%s.%s='%s'", sdk.EventTypeTx, sdk.AttributeKeySignature, sig)
Expand Down Expand Up @@ -313,3 +314,12 @@ version.AppName, flagType, typeSig)),

return cmd
}

// parseSigArgs parses comma-separated signatures from the CLI arguments.
func parseSigArgs(args []string) ([]string, error) {
if len(args) != 1 || args[0] == "" {
return nil, fmt.Errorf("argument should be comma-separated signatures")
}

return strings.Split(args[0], ","), nil
}
32 changes: 32 additions & 0 deletions x/auth/client/cli/query_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cli

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestParseSigs(t *testing.T) {
cases := []struct {
name string
args []string
expErr bool
expNumSigs int
}{
{"no args", []string{}, true, 0},
{"empty args", []string{""}, true, 0},
{"too many args", []string{"foo", "bar"}, true, 0},
{"1 sig", []string{"foo"}, false, 1},
{"3 sigs", []string{"foo,bar,baz"}, false, 3},
}

for _, tc := range cases {
sigs, err := parseSigArgs(tc.args)
if tc.expErr {
require.Error(t, err)
} else {
require.NoError(t, err)
require.Equal(t, tc.expNumSigs, len(sigs))
}
}
}

0 comments on commit 91314fe

Please sign in to comment.