diff --git a/CHANGELOG.md b/CHANGELOG.md index 6625b5d70604..e36daa18e0ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* (x/auth) [#13200](https://github.com/cosmos/cosmos-sdk/pull/13200) Fix wrong sequences in `sign-batch`. * (export) [#13029](https://github.com/cosmos/cosmos-sdk/pull/13029) Fix exporting the blockParams regression. * [#13046](https://github.com/cosmos/cosmos-sdk/pull/13046) Fix missing return statement in BaseApp.Query. diff --git a/tests/e2e/auth/suite.go b/tests/e2e/auth/suite.go index 204782e34818..4b199b143f49 100644 --- a/tests/e2e/auth/suite.go +++ b/tests/e2e/auth/suite.go @@ -270,6 +270,41 @@ func (s *E2ETestSuite) TestCLISignBatch() { _, err = authclitestutil.TxSignBatchExec(clientCtx, val.GetAddress(), malformedFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID), "--signature-only") s.Require().Error(err) + // make a txn to increase the sequence of sender + _, seq, err := val.ClientCtx.AccountRetriever.GetAccountNumberSequence(val.ClientCtx, val.Address) + s.Require().NoError(err) + + account1, err := val.ClientCtx.Keyring.Key("newAccount1") + s.Require().NoError(err) + + addr, err := account1.GetAddress() + s.Require().NoError(err) + + // Send coins from validator to multisig. + _, err = s.createBankMsg( + val, + addr, + sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 1000)), + ) + s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) + + // fetch the sequence after a tx, should be incremented. + _, seq1, err := val.ClientCtx.AccountRetriever.GetAccountNumberSequence(val.ClientCtx, val.Address) + s.Require().NoError(err) + s.Require().Equal(seq+1, seq1) + + // signing sign-batch should start from the last sequence. + signed, err := TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--signature-only") + s.Require().NoError(err) + signedTxs := strings.Split(strings.Trim(signed.String(), "\n"), "\n") + s.Require().GreaterOrEqual(len(signedTxs), 1) + + sigs, err := s.cfg.TxConfig.UnmarshalSignatureJSON([]byte(signedTxs[0])) + s.Require().NoError(err) + s.Require().Equal(sigs[0].Sequence, seq1) +} + func (s *IntegrationTestSuite) TestCliGetAccountAddressByID() { require := s.Require() val1 := s.network.Validators[0] @@ -428,6 +463,9 @@ func (s *E2ETestSuite) TestCLIQueryTxCmdByHash() { s.Require().NoError(err) s.Require().NoError(s.network.WaitForNextBlock()) + var txRes sdk.TxResponse + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txRes)) + var txRes sdk.TxResponse s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(res.Bytes(), &txRes)) diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index c9d359a1e7b3..bb206f5d7f35 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -101,7 +101,33 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { return err } - fromAddr, _, _, err := client.GetFromFields(clientCtx, txFactory.Keybase(), from) + if !clientCtx.Offline { + if ms == "" { + from, err := cmd.Flags().GetString(flags.FlagFrom) + if err != nil { + return err + } + + addr, _, _, err := client.GetFromFields(clientCtx, txFactory.Keybase(), from) + if err != nil { + return err + } + + acc, err := txFactory.AccountRetriever().GetAccount(clientCtx, addr) + if err != nil { + return err + } + + txFactory = txFactory.WithAccountNumber(acc.GetAccountNumber()).WithSequence(acc.GetSequence()) + } else { + txFactory = txFactory.WithAccountNumber(0).WithSequence(0) + } + } + + for sequence := txFactory.Sequence(); scanner.Scan(); sequence++ { + unsignedStdTx := scanner.Tx() + txFactory = txFactory.WithSequence(sequence) + txBuilder, err := txCfg.WrapTxBuilder(unsignedStdTx) if err != nil { return err }