Skip to content

Commit 9d67526

Browse files
sahith-narahariAlessio Tregliafedekunze
authored
Fix sequence value in auth sign signature only (#8287)
* fix signature only * add test, changelog * update test * Update CHANGELOG.md * address suggestions Co-authored-by: Alessio Treglia <[email protected]> Co-authored-by: Federico Kunze <[email protected]>
1 parent 4fa9e98 commit 9d67526

File tree

4 files changed

+31
-28
lines changed

4 files changed

+31
-28
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
3636

3737
## [Unreleased]
3838

39+
### Bug Fixes
40+
41+
* (x/auth) [\#8287](https://github.com/cosmos/cosmos-sdk/pull/8287) Fix `tx sign --signature-only` to return correct sequence value in signature.
42+
3943
## [v0.40.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.40.0) - 2021-01-08
4044

4145
v0.40.0, known as the Stargate release of the Cosmos SDK, is one of the largest releases

x/auth/client/cli/cli_test.go

+15-11
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515

1616
"github.com/cosmos/cosmos-sdk/client"
1717
"github.com/cosmos/cosmos-sdk/client/flags"
18-
"github.com/cosmos/cosmos-sdk/codec/types"
1918
"github.com/cosmos/cosmos-sdk/crypto/hd"
2019
"github.com/cosmos/cosmos-sdk/crypto/keyring"
2120
kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
@@ -145,11 +144,21 @@ func (s *IntegrationTestSuite) TestCLISign() {
145144
valInfo, err := val1.ClientCtx.Keyring.Key(val1.Moniker)
146145
require.NoError(err)
147146

147+
// query account info
148+
queryResJSON, err := authtest.QueryAccountExec(val1.ClientCtx, val1.Address)
149+
require.NoError(err)
150+
var account authtypes.AccountI
151+
require.NoError(val1.ClientCtx.JSONMarshaler.UnmarshalInterfaceJSON(queryResJSON.Bytes(), &account))
152+
148153
/**** test signature-only ****/
149154
res, err := authtest.TxSignExec(val1.ClientCtx, val1.Address, fileUnsigned.Name(), chainFlag,
150155
sigOnlyFlag)
151156
require.NoError(err)
152157
checkSignatures(require, txCfg, res.Bytes(), valInfo.GetPubKey())
158+
sigs, err := txCfg.UnmarshalSignatureJSON(res.Bytes())
159+
require.NoError(err)
160+
require.Equal(1, len(sigs))
161+
require.Equal(account.GetSequence(), sigs[0].Sequence)
153162

154163
/**** test full output ****/
155164
res, err = authtest.TxSignExec(val1.ClientCtx, val1.Address, fileUnsigned.Name(), chainFlag)
@@ -814,38 +823,33 @@ func (s *IntegrationTestSuite) TestGetAccountCmd() {
814823

815824
testCases := []struct {
816825
name string
817-
args []string
826+
address sdk.AccAddress
818827
expectErr bool
819828
}{
820829
{
821830
"invalid address",
822-
[]string{addr1.String(),
823-
fmt.Sprintf("--%s=json", tmcli.OutputFlag)},
831+
addr1,
824832
true,
825833
},
826834
{
827835
"valid address",
828-
[]string{val.Address.String(),
829-
fmt.Sprintf("--%s=json", tmcli.OutputFlag)},
836+
val.Address,
830837
false,
831838
},
832839
}
833840

834841
for _, tc := range testCases {
835842
tc := tc
836843
s.Run(tc.name, func() {
837-
cmd := authcli.GetAccountCmd()
838844
clientCtx := val.ClientCtx
839845

840-
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
846+
out, err := authtest.QueryAccountExec(clientCtx, tc.address)
841847
if tc.expectErr {
842848
s.Require().Error(err)
843849
s.Require().NotEqual("internal", err.Error())
844850
} else {
845-
var any types.Any
846-
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), &any))
847851
var acc authtypes.AccountI
848-
s.Require().NoError(val.ClientCtx.InterfaceRegistry.UnpackAny(&any, &acc))
852+
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalInterfaceJSON(out.Bytes(), &acc))
849853
s.Require().Equal(val.Address, acc.GetAddress())
850854
}
851855
})

x/auth/client/testutil/helpers.go

+11-17
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,18 @@ func TxSignExec(clientCtx client.Context, from fmt.Stringer, filename string, ex
2323
filename,
2424
}
2525

26-
args = append(args, extraArgs...)
27-
2826
cmd := cli.GetSignCommand()
2927
tmcli.PrepareBaseCmd(cmd, "", "")
3028

31-
return clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
29+
return clitestutil.ExecTestCLICmd(clientCtx, cmd, append(args, extraArgs...))
3230
}
3331

3432
func TxBroadcastExec(clientCtx client.Context, filename string, extraArgs ...string) (testutil.BufferWriter, error) {
3533
args := []string{
3634
filename,
3735
}
3836

39-
args = append(args, extraArgs...)
40-
41-
return clitestutil.ExecTestCLICmd(clientCtx, cli.GetBroadcastCommand(), args)
37+
return clitestutil.ExecTestCLICmd(clientCtx, cli.GetBroadcastCommand(), append(args, extraArgs...))
4238
}
4339

4440
func TxEncodeExec(clientCtx client.Context, filename string, extraArgs ...string) (testutil.BufferWriter, error) {
@@ -47,9 +43,7 @@ func TxEncodeExec(clientCtx client.Context, filename string, extraArgs ...string
4743
filename,
4844
}
4945

50-
args = append(args, extraArgs...)
51-
52-
return clitestutil.ExecTestCLICmd(clientCtx, cli.GetEncodeCommand(), args)
46+
return clitestutil.ExecTestCLICmd(clientCtx, cli.GetEncodeCommand(), append(args, extraArgs...))
5347
}
5448

5549
func TxValidateSignaturesExec(clientCtx client.Context, filename string) (testutil.BufferWriter, error) {
@@ -70,9 +64,7 @@ func TxMultiSignExec(clientCtx client.Context, from string, filename string, ext
7064
from,
7165
}
7266

73-
args = append(args, extraArgs...)
74-
75-
return clitestutil.ExecTestCLICmd(clientCtx, cli.GetMultiSignCommand(), args)
67+
return clitestutil.ExecTestCLICmd(clientCtx, cli.GetMultiSignCommand(), append(args, extraArgs...))
7668
}
7769

7870
func TxSignBatchExec(clientCtx client.Context, from fmt.Stringer, filename string, extraArgs ...string) (testutil.BufferWriter, error) {
@@ -82,9 +74,7 @@ func TxSignBatchExec(clientCtx client.Context, from fmt.Stringer, filename strin
8274
filename,
8375
}
8476

85-
args = append(args, extraArgs...)
86-
87-
return clitestutil.ExecTestCLICmd(clientCtx, cli.GetSignBatchCommand(), args)
77+
return clitestutil.ExecTestCLICmd(clientCtx, cli.GetSignBatchCommand(), append(args, extraArgs...))
8878
}
8979

9080
func TxDecodeExec(clientCtx client.Context, encodedTx string, extraArgs ...string) (testutil.BufferWriter, error) {
@@ -93,9 +83,13 @@ func TxDecodeExec(clientCtx client.Context, encodedTx string, extraArgs ...strin
9383
encodedTx,
9484
}
9585

96-
args = append(args, extraArgs...)
86+
return clitestutil.ExecTestCLICmd(clientCtx, cli.GetDecodeCommand(), append(args, extraArgs...))
87+
}
88+
89+
func QueryAccountExec(clientCtx client.Context, address fmt.Stringer, extraArgs ...string) (testutil.BufferWriter, error) {
90+
args := []string{address.String(), fmt.Sprintf("--%s=json", tmcli.OutputFlag)}
9791

98-
return clitestutil.ExecTestCLICmd(clientCtx, cli.GetDecodeCommand(), args)
92+
return clitestutil.ExecTestCLICmd(clientCtx, cli.GetAccountCmd(), append(args, extraArgs...))
9993
}
10094

10195
// DONTCOVER

x/auth/tx/sigs.go

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ func (g config) MarshalSignatureJSON(sigs []signing.SignatureV2) ([]byte, error)
118118
descs[i] = &signing.SignatureDescriptor{
119119
PublicKey: any,
120120
Data: descData,
121+
Sequence: sig.Sequence,
121122
}
122123
}
123124

0 commit comments

Comments
 (0)