From 32570bb6f8118ad6b80784ae2d64a2681c2c5e07 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Mon, 11 Jan 2021 03:36:35 +0530 Subject: [PATCH 1/5] fix signature only --- x/auth/tx/sigs.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/auth/tx/sigs.go b/x/auth/tx/sigs.go index 5916a42c334..e2d5d63a601 100644 --- a/x/auth/tx/sigs.go +++ b/x/auth/tx/sigs.go @@ -118,6 +118,7 @@ func (g config) MarshalSignatureJSON(sigs []signing.SignatureV2) ([]byte, error) descs[i] = &signing.SignatureDescriptor{ PublicKey: any, Data: descData, + Sequence: sig.Sequence, } } From c9297af05b9941b84e786af9df23034d6dd33592 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Tue, 12 Jan 2021 01:14:21 +0530 Subject: [PATCH 2/5] add test, changelog --- CHANGELOG.md | 3 +++ x/auth/client/cli/cli_test.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe247044e3c..5e4cff24404 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,9 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +* __Bug Fixes__ + * (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 diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index 6a6a9b1d559..9d22b174e7e 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -150,6 +150,10 @@ func (s *IntegrationTestSuite) TestCLISign() { 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(uint64(1), sigs[0].Sequence) /**** test full output ****/ res, err = authtest.TxSignExec(val1.ClientCtx, val1.Address, fileUnsigned.Name(), chainFlag) From 97148c41faa7ec00aab820f7ad55d5d91c766cf5 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Tue, 12 Jan 2021 01:44:10 +0530 Subject: [PATCH 3/5] update test --- x/auth/client/cli/cli_test.go | 25 +++++++++++++++---------- x/auth/client/testutil/helpers.go | 6 ++++++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index 9d22b174e7e..6797beb3cfb 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -145,6 +145,14 @@ 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) + /**** test signature-only ****/ res, err := authtest.TxSignExec(val1.ClientCtx, val1.Address, fileUnsigned.Name(), chainFlag, sigOnlyFlag) @@ -153,7 +161,7 @@ func (s *IntegrationTestSuite) TestCLISign() { sigs, err := txCfg.UnmarshalSignatureJSON(res.Bytes()) require.NoError(err) require.Equal(1, len(sigs)) - require.Equal(uint64(1), sigs[0].Sequence) + require.Equal(account.GetSequence(), sigs[0].Sequence) /**** test full output ****/ res, err = authtest.TxSignExec(val1.ClientCtx, val1.Address, fileUnsigned.Name(), chainFlag) @@ -818,19 +826,17 @@ 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, }, } @@ -838,18 +844,17 @@ func (s *IntegrationTestSuite) TestGetAccountCmd() { 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()) } }) diff --git a/x/auth/client/testutil/helpers.go b/x/auth/client/testutil/helpers.go index b46079cc6d9..4b328790398 100644 --- a/x/auth/client/testutil/helpers.go +++ b/x/auth/client/testutil/helpers.go @@ -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) +} + // DONTCOVER From 6ee904a190fc163ae9506ceafee279b30acfe83a Mon Sep 17 00:00:00 2001 From: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Date: Mon, 11 Jan 2021 19:03:05 -0300 Subject: [PATCH 4/5] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e4cff24404..71c88b54540 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,7 +36,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] -* __Bug Fixes__ +### Bug Fixes + * (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 From 524942aece99f700e3b1ce63749c0382cd921435 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Tue, 12 Jan 2021 13:09:15 +0530 Subject: [PATCH 5/5] address suggestions --- x/auth/client/cli/cli_test.go | 11 +++-------- x/auth/client/testutil/helpers.go | 28 ++++++++-------------------- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index 6797beb3cfb..fdd558b7971 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -15,7 +15,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" @@ -147,11 +146,9 @@ func (s *IntegrationTestSuite) TestCLISign() { // 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) + require.NoError(err) var account authtypes.AccountI - err = val1.ClientCtx.InterfaceRegistry.UnpackAny(&any, &account) + require.NoError(val1.ClientCtx.JSONMarshaler.UnmarshalInterfaceJSON(queryResJSON.Bytes(), &account)) /**** test signature-only ****/ res, err := authtest.TxSignExec(val1.ClientCtx, val1.Address, fileUnsigned.Name(), chainFlag, @@ -851,10 +848,8 @@ func (s *IntegrationTestSuite) TestGetAccountCmd() { s.Require().Error(err) s.Require().NotEqual("internal", err.Error()) } else { - var any types.Any - s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), &any)) var acc authtypes.AccountI - s.Require().NoError(clientCtx.InterfaceRegistry.UnpackAny(&any, &acc)) + s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalInterfaceJSON(out.Bytes(), &acc)) s.Require().Equal(val.Address, acc.GetAddress()) } }) diff --git a/x/auth/client/testutil/helpers.go b/x/auth/client/testutil/helpers.go index 4b328790398..e4f31727768 100644 --- a/x/auth/client/testutil/helpers.go +++ b/x/auth/client/testutil/helpers.go @@ -23,12 +23,10 @@ func TxSignExec(clientCtx client.Context, from fmt.Stringer, filename string, ex filename, } - args = append(args, extraArgs...) - cmd := cli.GetSignCommand() tmcli.PrepareBaseCmd(cmd, "", "") - return clitestutil.ExecTestCLICmd(clientCtx, cmd, args) + return clitestutil.ExecTestCLICmd(clientCtx, cmd, append(args, extraArgs...)) } func TxBroadcastExec(clientCtx client.Context, filename string, extraArgs ...string) (testutil.BufferWriter, error) { @@ -36,9 +34,7 @@ func TxBroadcastExec(clientCtx client.Context, filename string, extraArgs ...str filename, } - args = append(args, extraArgs...) - - return clitestutil.ExecTestCLICmd(clientCtx, cli.GetBroadcastCommand(), args) + return clitestutil.ExecTestCLICmd(clientCtx, cli.GetBroadcastCommand(), append(args, extraArgs...)) } 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 filename, } - args = append(args, extraArgs...) - - return clitestutil.ExecTestCLICmd(clientCtx, cli.GetEncodeCommand(), args) + return clitestutil.ExecTestCLICmd(clientCtx, cli.GetEncodeCommand(), append(args, extraArgs...)) } func TxValidateSignaturesExec(clientCtx client.Context, filename string) (testutil.BufferWriter, error) { @@ -70,9 +64,7 @@ func TxMultiSignExec(clientCtx client.Context, from string, filename string, ext from, } - args = append(args, extraArgs...) - - return clitestutil.ExecTestCLICmd(clientCtx, cli.GetMultiSignCommand(), args) + return clitestutil.ExecTestCLICmd(clientCtx, cli.GetMultiSignCommand(), append(args, extraArgs...)) } 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 filename, } - args = append(args, extraArgs...) - - return clitestutil.ExecTestCLICmd(clientCtx, cli.GetSignBatchCommand(), args) + return clitestutil.ExecTestCLICmd(clientCtx, cli.GetSignBatchCommand(), append(args, extraArgs...)) } func TxDecodeExec(clientCtx client.Context, encodedTx string, extraArgs ...string) (testutil.BufferWriter, error) { @@ -93,15 +83,13 @@ func TxDecodeExec(clientCtx client.Context, encodedTx string, extraArgs ...strin encodedTx, } - args = append(args, extraArgs...) - - return clitestutil.ExecTestCLICmd(clientCtx, cli.GetDecodeCommand(), args) + return clitestutil.ExecTestCLICmd(clientCtx, cli.GetDecodeCommand(), append(args, extraArgs...)) } 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) + + return clitestutil.ExecTestCLICmd(clientCtx, cli.GetAccountCmd(), append(args, extraArgs...)) } // DONTCOVER