Skip to content

Commit

Permalink
fix: get seq number for non-multisig signing (#754)
Browse files Browse the repository at this point in the history
* fix: get seq number for non-multisig signing

* chore: apply pr review
  • Loading branch information
dudong2 authored Oct 26, 2022
1 parent eb1b5e2 commit 922c126
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (cli) [\#734](https://github.com/line/lbm-sdk/pull/734) add restrictions on the number of args in the CLIs
* (client) [\#737](https://github.com/line/lbm-sdk/pull/737) check multisig key list to prevent unexpected key deletion
* (simapp) [\#752](https://github.com/line/lbm-sdk/pull/752) add x/distribution's module account into blockedAddr
* (x/auth) [\#754](https://github.com/line/lbm-sdk/pull/754) Fix wrong sequences in `sign-batch`

### Breaking Changes
* (proto) [\#564](https://github.com/line/lbm-sdk/pull/564) change gRPC path to original cosmos path
Expand Down
23 changes: 23 additions & 0 deletions x/auth/client/cli/tx_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,29 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error {
}
scanner := authclient.NewBatchScanner(txCfg, infile)

if !clientCtx.Offline {
if ms == "" {
from, err := cmd.Flags().GetString(flags.FlagFrom)
if err != nil {
return err
}

addr, _, _, err := client.GetFromFields(txFactory.Keybase(), from, clientCtx.GenerateOnly)
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)
Expand Down
35 changes: 35 additions & 0 deletions x/auth/client/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,40 @@ func (s *IntegrationTestSuite) TestCLISignBatch() {
// Sign batch malformed tx file signature only.
_, err = TxSignBatchExec(val.ClientCtx, val.Address, malformedFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.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 := 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) TestCLISignAminoJSON() {
Expand Down Expand Up @@ -259,6 +293,7 @@ func (s *IntegrationTestSuite) TestCLIQueryTxCmdByHash() {
sdk.NewCoins(sendTokens),
)
s.Require().NoError(err)

var txRes sdk.TxResponse
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txRes))
s.Require().NoError(s.network.WaitForNextBlock())
Expand Down

0 comments on commit 922c126

Please sign in to comment.