Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sequence value in auth sign signature only #8287

Merged
merged 11 commits into from
Jan 12, 2021
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

* __Bug Fixes__
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
* (x/auth) [\#8287](https://github.com/cosmos/cosmos-sdk/pull/8287) Fix `tx sign --signature-only` to return correct sequence value in signature.

## [v0.40.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.40.0) - 2021-01-08

v0.40.0, known as the Stargate release of the Cosmos SDK, is one of the largest releases
Expand Down
27 changes: 18 additions & 9 deletions x/auth/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,23 @@ func (s *IntegrationTestSuite) TestCLISign() {
valInfo, err := val1.ClientCtx.Keyring.Key(val1.Moniker)
require.NoError(err)

// query account info
queryResJSON, err := authtest.QueryAccountExec(val1.ClientCtx, val1.Address)
s.Require().NoError(err)
var any types.Any
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(queryResJSON.Bytes(), &any)
var account authtypes.AccountI
err = val1.ClientCtx.InterfaceRegistry.UnpackAny(&any, &account)
sahith-narahari marked this conversation as resolved.
Show resolved Hide resolved

/**** test signature-only ****/
res, err := authtest.TxSignExec(val1.ClientCtx, val1.Address, fileUnsigned.Name(), chainFlag,
sigOnlyFlag)
require.NoError(err)
checkSignatures(require, txCfg, res.Bytes(), valInfo.GetPubKey())
sigs, err := txCfg.UnmarshalSignatureJSON(res.Bytes())
require.NoError(err)
require.Equal(1, len(sigs))
require.Equal(account.GetSequence(), sigs[0].Sequence)

/**** test full output ****/
res, err = authtest.TxSignExec(val1.ClientCtx, val1.Address, fileUnsigned.Name(), chainFlag)
Expand Down Expand Up @@ -814,38 +826,35 @@ func (s *IntegrationTestSuite) TestGetAccountCmd() {

testCases := []struct {
name string
args []string
address sdk.AccAddress
expectErr bool
}{
{
"invalid address",
[]string{addr1.String(),
fmt.Sprintf("--%s=json", tmcli.OutputFlag)},
addr1,
true,
},
{
"valid address",
[]string{val.Address.String(),
fmt.Sprintf("--%s=json", tmcli.OutputFlag)},
val.Address,
false,
},
}

for _, tc := range testCases {
tc := tc
s.Run(tc.name, func() {
cmd := authcli.GetAccountCmd()
clientCtx := val.ClientCtx

out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
out, err := authtest.QueryAccountExec(clientCtx, tc.address)
if tc.expectErr {
s.Require().Error(err)
s.Require().NotEqual("internal", err.Error())
} else {
var any types.Any
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), &any))
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), &any))
var acc authtypes.AccountI
s.Require().NoError(val.ClientCtx.InterfaceRegistry.UnpackAny(&any, &acc))
s.Require().NoError(clientCtx.InterfaceRegistry.UnpackAny(&any, &acc))
s.Require().Equal(val.Address, acc.GetAddress())
}
})
Expand Down
6 changes: 6 additions & 0 deletions x/auth/client/testutil/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,10 @@ func TxDecodeExec(clientCtx client.Context, encodedTx string, extraArgs ...strin
return clitestutil.ExecTestCLICmd(clientCtx, cli.GetDecodeCommand(), args)
}

func QueryAccountExec(clientCtx client.Context, address fmt.Stringer, extraArgs ...string) (testutil.BufferWriter, error) {
args := []string{address.String(), fmt.Sprintf("--%s=json", tmcli.OutputFlag)}
args = append(args, extraArgs...)
return clitestutil.ExecTestCLICmd(clientCtx, cli.GetAccountCmd(), args)
sahith-narahari marked this conversation as resolved.
Show resolved Hide resolved
}

// DONTCOVER
1 change: 1 addition & 0 deletions x/auth/tx/sigs.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func (g config) MarshalSignatureJSON(sigs []signing.SignatureV2) ([]byte, error)
descs[i] = &signing.SignatureDescriptor{
PublicKey: any,
Data: descData,
Sequence: sig.Sequence,
}
}

Expand Down