From 627e7d4e05067c0e343e24e6312a2d60ef9a1cea Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Thu, 22 Oct 2020 04:02:57 +0530 Subject: [PATCH 01/35] initial commit --- x/auth/client/cli/tx_multisign.go | 130 ++++++++++++++++++++++++++++++ x/auth/client/tx.go | 4 + 2 files changed, 134 insertions(+) diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index fc5e907de0a2..053ee7efcbc2 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -3,6 +3,9 @@ package cli import ( "bufio" "fmt" + "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/gogo/protobuf/codec" + "github.com/spf13/viper" "io/ioutil" "os" "strings" @@ -23,6 +26,12 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/signing" ) +//todo: move to flags +const ( + flagNoAutoIncrement = "no-auto-increment" + FlagMultisig = "multisigaddr" +) + // GetSignCommand returns the sign command func GetMultiSignCommand() *cobra.Command { cmd := &cobra.Command{ @@ -189,6 +198,127 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) error { } } +func GetBatchMultisigCommand(codec *codec.Codec) *cobra.Command { + cmd := &cobra.Command{ + Use: "multisign-batch [file] [name] [[signature-file]...]", + Short: "Assemble multisig transactions", + Long: `Assemble a batch of multisig transactions generated by batch sign command.`, + PreRun: preSignCmd, + RunE: makeBatchMultisigCmd(codec), + Args: cobra.MinimumNArgs(3), + } + + cmd.Flags().Bool(flagNoAutoIncrement, false, "disable sequence auto increment") + cmd.Flags().String( + FlagMultisig, "", + "Address of the multisig account on behalf of which the transaction shall be signed", + ) + + return cmd +} + +func makeBatchMultisigCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) error { + return func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } + + parsedTxs, err := authclient.ReadTxsFromFile(clientCtx, args[0]) + if err != nil { + return err + } + + txFactory := tx.NewFactoryCLI(clientCtx, cmd.Flags()) + if txFactory.SignMode() == signingtypes.SignMode_SIGN_MODE_UNSPECIFIED { + txFactory = txFactory.WithSignMode(signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON) + } + + txCfg := clientCtx.TxConfig + txBldr, err := txCfg.WrapTxBuilder(parsedTxs) + if err != nil { + return err + } + + inBuf := bufio.NewReader(cmd.InOrStdin()) + backend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend) + + kb, err := keyring.New(sdk.KeyringServiceName(), backend, clientCtx.HomeDir, inBuf) + if err != nil { + return err + } + multisigInfo, err := kb.Key(args[1]) + if err != nil { + return errors.Wrap(err, "error getting keybase multisig account") + } + if multisigInfo.GetType() != keyring.TypeMulti { + return fmt.Errorf("%q must be of type %s: %s", args[1], crkeys.TypeMulti, multisigInfo.GetType()) + } + + multisigPub := multisigInfo.GetPubKey().(*kmultisig.LegacyAminoPubKey) + multisigSig := multisig.NewMultisig(len(multisigPub.PubKeys)) + var signatureBatch [][]signingtypes.SignatureV2 + for i := 2; i < len(args); i++ { + signatures, err := utils.ReadSignaturesFromFile(cdc, args[i]) + if err != nil { + return errors.Wrap(err, fmt.Sprintf("error getting signatures from file %s", args[i])) + } + + signatureBatch = append(signatureBatch, signatures) + } + + if !clientCtx.Offline { + accnum, seq, err := clientCtx.AccountRetriever.GetAccountNumberSequence(clientCtx, multisigInfo.GetAddress()) + if err != nil { + return err + } + + txFactory = txFactory.WithAccountNumber(accnum).WithSequence(seq) + } + for i, tx := range parsedTxs { + sigBytes := types.StdSignBytes( + txBldr.ChainID(), txBldr.AccountNumber(), txBldr.Sequence(), + tx.Fee, tx.GetMsgs(), tx.GetMemo(), + ) + + for _, signBatch := range signatureBatch { + if ok := signBatch[i].PubKey.VerifyBytes(sigBytes, signBatch[i].Signature); !ok { + return fmt.Errorf("tx %d: couldn't verify signature for address %q", i, sdk.AccAddress(signBatch[i].PubKey.Address()).String()) + } + if err := multisigSig.AddSignatureFromPubKey(signBatch[i].Signature, signBatch[i].PubKey, multisigPub.PubKeys); err != nil { + return err + } + } + + newStdSig := types.StdSignature{Signature: cdc.MustMarshalBinaryBare(multisigSig), PubKey: multisigPub} + if ok := newStdSig.VerifyBytes(sigBytes, newStdSig.Signature); !ok { + return fmt.Errorf("error verifying multisig signature") + } + + newTx := types.NewStdTx(tx.GetMsgs(), tx.Fee, []types.StdSignature{newStdSig}, tx.GetMemo()) + + json, err := cdc.MarshalJSON(newTx) + if err != nil { + return errors.Wrap(err, "error marshalling tx") + } + + _, err = fmt.Fprintf(out, "%s\n", json) + if err != nil { + return errors.Wrap(err, "error writing to output") + } + + if viper.GetBool(flagNoAutoIncrement) { + continue + } + + sequence++ + } + + return nil + } +} + func unmarshalSignatureJSON(clientCtx client.Context, filename string) (sigs []signingtypes.SignatureV2, err error) { var bytes []byte if bytes, err = ioutil.ReadFile(filename); err != nil { diff --git a/x/auth/client/tx.go b/x/auth/client/tx.go index 79570d519054..8eb9139bb377 100644 --- a/x/auth/client/tx.go +++ b/x/auth/client/tx.go @@ -103,6 +103,10 @@ func ReadTxFromFile(ctx client.Context, filename string) (tx sdk.Tx, err error) return ctx.TxConfig.TxJSONDecoder()(bytes) } +func ReadTxsFromFile(ctx client.Context, filename string) (tx []sdk.Tx, err error) { + return nil, nil +} + // NewBatchScanner returns a new BatchScanner to read newline-delimited StdTx transactions from r. func NewBatchScanner(cfg client.TxConfig, r io.Reader) *BatchScanner { return &BatchScanner{Scanner: bufio.NewScanner(r), cfg: cfg} From 66e34150d3944408a97735b2fd058ca01322cadc Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Fri, 23 Oct 2020 21:25:03 +0530 Subject: [PATCH 02/35] update signing data --- x/auth/client/cli/tx_multisign.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 053ee7efcbc2..90f4f739371d 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -253,19 +253,34 @@ func makeBatchMultisigCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []stri return errors.Wrap(err, "error getting keybase multisig account") } if multisigInfo.GetType() != keyring.TypeMulti { - return fmt.Errorf("%q must be of type %s: %s", args[1], crkeys.TypeMulti, multisigInfo.GetType()) + return fmt.Errorf("%q must be of type %s: %s", args[1], keyring.TypeMulti, multisigInfo.GetType()) } multisigPub := multisigInfo.GetPubKey().(*kmultisig.LegacyAminoPubKey) multisigSig := multisig.NewMultisig(len(multisigPub.PubKeys)) var signatureBatch [][]signingtypes.SignatureV2 for i := 2; i < len(args); i++ { - signatures, err := utils.ReadSignaturesFromFile(cdc, args[i]) + sigs, err := unmarshalSignatureJSON(clientCtx, args[i]) if err != nil { - return errors.Wrap(err, fmt.Sprintf("error getting signatures from file %s", args[i])) + return err + } + + signingData := signing.SignerData{ + ChainID: txFactory.ChainID(), + AccountNumber: txFactory.AccountNumber(), + Sequence: txFactory.Sequence(), } - signatureBatch = append(signatureBatch, signatures) + for _, sig := range sigs { + err = signing.VerifySignature(sig.PubKey, signingData, sig.Data, txCfg.SignModeHandler(), txBuilder.GetTx()) + if err != nil { + return fmt.Errorf("couldn't verify signature: %w", err) + } + + if err := multisig.AddSignatureV2(multisigSig, sig, multisigPub.GetPubKeys()); err != nil { + return err + } + } } if !clientCtx.Offline { From 4d50e323edc43cfacbde8926b6edded79825ae47 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Fri, 30 Oct 2020 01:48:57 +0530 Subject: [PATCH 03/35] Update signature --- x/auth/client/cli/tx_multisign.go | 90 ++++++++++++++++++------------- 1 file changed, 52 insertions(+), 38 deletions(-) diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 90f4f739371d..2a34c7f4345f 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -235,12 +235,6 @@ func makeBatchMultisigCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []stri txFactory = txFactory.WithSignMode(signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON) } - txCfg := clientCtx.TxConfig - txBldr, err := txCfg.WrapTxBuilder(parsedTxs) - if err != nil { - return err - } - inBuf := bufio.NewReader(cmd.InOrStdin()) backend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend) @@ -256,8 +250,6 @@ func makeBatchMultisigCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []stri return fmt.Errorf("%q must be of type %s: %s", args[1], keyring.TypeMulti, multisigInfo.GetType()) } - multisigPub := multisigInfo.GetPubKey().(*kmultisig.LegacyAminoPubKey) - multisigSig := multisig.NewMultisig(len(multisigPub.PubKeys)) var signatureBatch [][]signingtypes.SignatureV2 for i := 2; i < len(args); i++ { sigs, err := unmarshalSignatureJSON(clientCtx, args[i]) @@ -265,62 +257,84 @@ func makeBatchMultisigCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []stri return err } + signatureBatch = append(signatureBatch, sigs) + } + + var sequence uint64 + if !clientCtx.Offline { + accnum, sequence, err := clientCtx.AccountRetriever.GetAccountNumberSequence(clientCtx, multisigInfo.GetAddress()) + if err != nil { + return err + } + + txFactory = txFactory.WithAccountNumber(accnum).WithSequence(sequence) + } + + for i, parsedTx := range parsedTxs { + txCfg := clientCtx.TxConfig + txBldr, err := txCfg.WrapTxBuilder(parsedTx) + if err != nil { + return err + } + signingData := signing.SignerData{ ChainID: txFactory.ChainID(), AccountNumber: txFactory.AccountNumber(), Sequence: txFactory.Sequence(), } - for _, sig := range sigs { - err = signing.VerifySignature(sig.PubKey, signingData, sig.Data, txCfg.SignModeHandler(), txBuilder.GetTx()) + multisigPub := multisigInfo.GetPubKey().(*kmultisig.LegacyAminoPubKey) + multisigSig := multisig.NewMultisig(len(multisigPub.PubKeys)) + for _, sig := range signatureBatch { + err = signing.VerifySignature(sig[i].PubKey, signingData, sig[i].Data, txCfg.SignModeHandler(), txBldr.GetTx()) if err != nil { return fmt.Errorf("couldn't verify signature: %w", err) } - if err := multisig.AddSignatureV2(multisigSig, sig, multisigPub.GetPubKeys()); err != nil { + if err := multisig.AddSignatureV2(multisigSig, sig[i], multisigPub.GetPubKeys()); err != nil { return err } } - } - if !clientCtx.Offline { - accnum, seq, err := clientCtx.AccountRetriever.GetAccountNumberSequence(clientCtx, multisigInfo.GetAddress()) + sigV2 := signingtypes.SignatureV2{ + PubKey: multisigPub, + Data: multisigSig, + Sequence: txFactory.Sequence(), + } + err = txBldr.SetSignatures(sigV2) if err != nil { return err } - txFactory = txFactory.WithAccountNumber(accnum).WithSequence(seq) - } - for i, tx := range parsedTxs { - sigBytes := types.StdSignBytes( - txBldr.ChainID(), txBldr.AccountNumber(), txBldr.Sequence(), - tx.Fee, tx.GetMsgs(), tx.GetMemo(), - ) - - for _, signBatch := range signatureBatch { - if ok := signBatch[i].PubKey.VerifyBytes(sigBytes, signBatch[i].Signature); !ok { - return fmt.Errorf("tx %d: couldn't verify signature for address %q", i, sdk.AccAddress(signBatch[i].PubKey.Address()).String()) - } - if err := multisigSig.AddSignatureFromPubKey(signBatch[i].Signature, signBatch[i].PubKey, multisigPub.PubKeys); err != nil { + sigOnly, _ := cmd.Flags().GetBool(flagSigOnly) + + aminoJSON, _ := cmd.Flags().GetBool(flagAmino) + + var json []byte + + if aminoJSON { + stdTx, err := tx.ConvertTxToStdTx(clientCtx.LegacyAmino, txBldr.GetTx()) + if err != nil { return err } - } - newStdSig := types.StdSignature{Signature: cdc.MustMarshalBinaryBare(multisigSig), PubKey: multisigPub} - if ok := newStdSig.VerifyBytes(sigBytes, newStdSig.Signature); !ok { - return fmt.Errorf("error verifying multisig signature") - } + req := rest.BroadcastReq{ + Tx: stdTx, + Mode: "block|sync|async", + } - newTx := types.NewStdTx(tx.GetMsgs(), tx.Fee, []types.StdSignature{newStdSig}, tx.GetMemo()) + json, _ = clientCtx.LegacyAmino.MarshalJSON(req) - json, err := cdc.MarshalJSON(newTx) - if err != nil { - return errors.Wrap(err, "error marshalling tx") + } else { + json, err = marshalSignatureJSON(txCfg, txBldr, sigOnly) + if err != nil { + return err + } } - _, err = fmt.Fprintf(out, "%s\n", json) + err = clientCtx.PrintString(fmt.Sprintf("%s\n", json)) if err != nil { - return errors.Wrap(err, "error writing to output") + return err } if viper.GetBool(flagNoAutoIncrement) { From 3c5cd6ae2271977d70aff8253f5052961c1d9da9 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Fri, 30 Oct 2020 02:14:33 +0530 Subject: [PATCH 04/35] code cleanup --- x/auth/client/cli/tx_multisign.go | 28 ++++++++++++++++------------ x/auth/client/tx.go | 4 ---- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 2a34c7f4345f..7b268fc81e31 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -225,16 +225,21 @@ func makeBatchMultisigCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []stri return err } - parsedTxs, err := authclient.ReadTxsFromFile(clientCtx, args[0]) - if err != nil { - return err - } - + txCfg := clientCtx.TxConfig txFactory := tx.NewFactoryCLI(clientCtx, cmd.Flags()) if txFactory.SignMode() == signingtypes.SignMode_SIGN_MODE_UNSPECIFIED { txFactory = txFactory.WithSignMode(signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON) } + var infile = os.Stdin + if args[0] != "-" { + infile, err = os.Open(args[0]) + if err != nil { + return err + } + } + scanner := authclient.NewBatchScanner(txCfg, infile) + inBuf := bufio.NewReader(cmd.InOrStdin()) backend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend) @@ -260,19 +265,18 @@ func makeBatchMultisigCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []stri signatureBatch = append(signatureBatch, sigs) } - var sequence uint64 + var seq uint64 if !clientCtx.Offline { - accnum, sequence, err := clientCtx.AccountRetriever.GetAccountNumberSequence(clientCtx, multisigInfo.GetAddress()) + accnum, seq, err := clientCtx.AccountRetriever.GetAccountNumberSequence(clientCtx, multisigInfo.GetAddress()) if err != nil { return err } - txFactory = txFactory.WithAccountNumber(accnum).WithSequence(sequence) + txFactory = txFactory.WithAccountNumber(accnum).WithSequence(seq) } - for i, parsedTx := range parsedTxs { - txCfg := clientCtx.TxConfig - txBldr, err := txCfg.WrapTxBuilder(parsedTx) + for sequence := seq; scanner.Scan(); { + txBldr, err := txCfg.WrapTxBuilder(scanner.Tx()) if err != nil { return err } @@ -285,7 +289,7 @@ func makeBatchMultisigCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []stri multisigPub := multisigInfo.GetPubKey().(*kmultisig.LegacyAminoPubKey) multisigSig := multisig.NewMultisig(len(multisigPub.PubKeys)) - for _, sig := range signatureBatch { + for i, sig := range signatureBatch { err = signing.VerifySignature(sig[i].PubKey, signingData, sig[i].Data, txCfg.SignModeHandler(), txBldr.GetTx()) if err != nil { return fmt.Errorf("couldn't verify signature: %w", err) diff --git a/x/auth/client/tx.go b/x/auth/client/tx.go index 8eb9139bb377..79570d519054 100644 --- a/x/auth/client/tx.go +++ b/x/auth/client/tx.go @@ -103,10 +103,6 @@ func ReadTxFromFile(ctx client.Context, filename string) (tx sdk.Tx, err error) return ctx.TxConfig.TxJSONDecoder()(bytes) } -func ReadTxsFromFile(ctx client.Context, filename string) (tx []sdk.Tx, err error) { - return nil, nil -} - // NewBatchScanner returns a new BatchScanner to read newline-delimited StdTx transactions from r. func NewBatchScanner(cfg client.TxConfig, r io.Reader) *BatchScanner { return &BatchScanner{Scanner: bufio.NewScanner(r), cfg: cfg} From 106e3bcd516fdc7e2e48838279b095ce7c5410b6 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Fri, 30 Oct 2020 02:16:37 +0530 Subject: [PATCH 05/35] code cleanup --- x/auth/client/cli/tx_multisign.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 7b268fc81e31..059d10c62626 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -3,14 +3,12 @@ package cli import ( "bufio" "fmt" - "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/gogo/protobuf/codec" - "github.com/spf13/viper" "io/ioutil" "os" "strings" "github.com/spf13/cobra" + "github.com/spf13/viper" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -19,6 +17,7 @@ import ( kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/errors" signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/version" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" @@ -198,13 +197,13 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) error { } } -func GetBatchMultisigCommand(codec *codec.Codec) *cobra.Command { +func GetBatchMultisigCommand() *cobra.Command { cmd := &cobra.Command{ Use: "multisign-batch [file] [name] [[signature-file]...]", Short: "Assemble multisig transactions", Long: `Assemble a batch of multisig transactions generated by batch sign command.`, PreRun: preSignCmd, - RunE: makeBatchMultisigCmd(codec), + RunE: makeBatchMultisigCmd(), Args: cobra.MinimumNArgs(3), } @@ -217,7 +216,7 @@ func GetBatchMultisigCommand(codec *codec.Codec) *cobra.Command { return cmd } -func makeBatchMultisigCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) error { +func makeBatchMultisigCmd() func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags()) From 7949505c7ec8732782264966d2ed3e9d3d83dc5c Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Tue, 3 Nov 2020 03:45:31 +0530 Subject: [PATCH 06/35] Add test for ms batch --- x/auth/client/cli/cli_test.go | 83 +++++++++++++++++++++++++++++++ x/auth/client/cli/tx.go | 1 + x/auth/client/cli/tx_multisign.go | 12 ++--- x/auth/client/testutil/helpers.go | 14 ++++++ 4 files changed, 102 insertions(+), 8 deletions(-) diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index 4961e91c37fb..8187f30068c8 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -737,6 +737,89 @@ func (s *IntegrationTestSuite) TestCLIMultisign() { s.Require().NoError(s.network.WaitForNextBlock()) } +func (s *IntegrationTestSuite) TestMultiSignBatchCmd() { + val := s.network.Validators[0] + + codec := codec2.NewLegacyAmino() + sdk.RegisterLegacyAminoCodec(codec) + banktypes.RegisterLegacyAminoCodec(codec) + val.ClientCtx.LegacyAmino = codec + + // Fetch 2 accounts and a multisig. + account1, err := val.ClientCtx.Keyring.Key("newAccount1") + s.Require().NoError(err) + + account2, err := val.ClientCtx.Keyring.Key("newAccount2") + s.Require().NoError(err) + + multisigInfo, err := val.ClientCtx.Keyring.Key("multi") + s.Require().NoError(err) + + // Send coins from validator to multisig. + sendTokens := sdk.NewInt64Coin(s.cfg.BondDenom, 10) + _, err = bankcli.MsgSendExec( + val.ClientCtx, + val.Address, + multisigInfo.GetAddress(), + sdk.NewCoins(sendTokens), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + fmt.Sprintf("--gas=%d", flags.DefaultGasLimit), + ) + s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) + + resp, err := bankcli.QueryBalancesExec(val.ClientCtx, multisigInfo.GetAddress()) + s.Require().NoError(err) + + var balRes banktypes.QueryAllBalancesResponse + err = val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &balRes) + s.Require().NoError(err) + s.Require().Equal(sendTokens.Amount, balRes.Balances.AmountOf(s.cfg.BondDenom)) + s.T().Log(balRes.Balances.AmountOf(s.cfg.BondDenom)) + + generatedStd, err := bankcli.MsgSendExec( + val.ClientCtx, + multisigInfo.GetAddress(), + val.Address, + sdk.NewCoins( + sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(1)), + ), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + fmt.Sprintf("--%s=true", flags.FlagGenerateOnly), + ) + + s.Require().NoError(err) + + // Write the output to disk + filename, cleanup1 := testutil.WriteToNewTempFile(s.T(), strings.Repeat(generatedStd.String(), 3)) + defer cleanup1() + + // sign-batch file with account1 + val.ClientCtx.HomeDir = strings.Replace(val.ClientCtx.HomeDir, "simd", "simcli", 1) + res, err := authtest.TxSignBatchExec(val.ClientCtx, account1.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String()) + s.Require().NoError(err) + s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) + + // write sigs to file + file1, cleanup2 := testutil.WriteToNewTempFile(s.T(), res.String()) + defer cleanup2() + + // sign-batch file with account2 + res, err = authtest.TxSignBatchExec(val.ClientCtx, account2.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String()) + s.Require().NoError(err) + s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) + + // write sigs to file2 + file2, cleanup3 := testutil.WriteToNewTempFile(s.T(), res.String()) + defer cleanup3() + res, err = authtest.TxMultiSignBatchExec(val.ClientCtx, filename.Name(), multisigInfo.GetName(), file1.Name(), file2.Name()) + s.Require().NoError(err) +} + func (s *IntegrationTestSuite) TestGetAccountCmd() { val := s.network.Validators[0] _, _, addr1 := testdata.KeyTestPubAddr() diff --git a/x/auth/client/cli/tx.go b/x/auth/client/cli/tx.go index 42b20ae8d5f3..43cb6c8f12de 100644 --- a/x/auth/client/cli/tx.go +++ b/x/auth/client/cli/tx.go @@ -21,6 +21,7 @@ func GetTxCmd() *cobra.Command { GetSignCommand(), GetValidateSignaturesCommand(), GetSignBatchCommand(), + GetMultiSignBatchCmd(), ) return txCmd } diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 059d10c62626..b5d492b2ba84 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -197,7 +197,7 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) error { } } -func GetBatchMultisigCommand() *cobra.Command { +func GetMultiSignBatchCmd() *cobra.Command { cmd := &cobra.Command{ Use: "multisign-batch [file] [name] [[signature-file]...]", Short: "Assemble multisig transactions", @@ -212,6 +212,7 @@ func GetBatchMultisigCommand() *cobra.Command { FlagMultisig, "", "Address of the multisig account on behalf of which the transaction shall be signed", ) + flags.AddTxFlagsToCmd(cmd) return cmd } @@ -239,13 +240,7 @@ func makeBatchMultisigCmd() func(cmd *cobra.Command, args []string) error { } scanner := authclient.NewBatchScanner(txCfg, infile) - inBuf := bufio.NewReader(cmd.InOrStdin()) - backend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend) - - kb, err := keyring.New(sdk.KeyringServiceName(), backend, clientCtx.HomeDir, inBuf) - if err != nil { - return err - } + kb := clientCtx.Keyring multisigInfo, err := kb.Key(args[1]) if err != nil { return errors.Wrap(err, "error getting keybase multisig account") @@ -256,6 +251,7 @@ func makeBatchMultisigCmd() func(cmd *cobra.Command, args []string) error { var signatureBatch [][]signingtypes.SignatureV2 for i := 2; i < len(args); i++ { + // todo:unmarshal sigs from multiple files sigs, err := unmarshalSignatureJSON(clientCtx, args[i]) if err != nil { return err diff --git a/x/auth/client/testutil/helpers.go b/x/auth/client/testutil/helpers.go index b46079cc6d95..994b5dd6b7af 100644 --- a/x/auth/client/testutil/helpers.go +++ b/x/auth/client/testutil/helpers.go @@ -98,4 +98,18 @@ func TxDecodeExec(clientCtx client.Context, encodedTx string, extraArgs ...strin return clitestutil.ExecTestCLICmd(clientCtx, cli.GetDecodeCommand(), args) } +func TxMultiSignBatchExec(clientCtx client.Context, filename string, from string, sigFile1 string, sigFile2 string, extraArgs ...string) (testutil.BufferWriter, error) { + args := []string{ + fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest), + filename, + from, + sigFile1, + sigFile2, + } + + args = append(args, extraArgs...) + + return clitestutil.ExecTestCLICmd(clientCtx, cli.GetMultiSignBatchCmd(), args) +} + // DONTCOVER From 2018ed0f0644a1e66bec6093a4de69166791c6e3 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Tue, 3 Nov 2020 17:15:54 +0530 Subject: [PATCH 07/35] update test --- x/auth/client/cli/cli_test.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index 8187f30068c8..f4a31d336b4b 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -1,5 +1,3 @@ -// +build norace - package cli_test import ( @@ -740,11 +738,6 @@ func (s *IntegrationTestSuite) TestCLIMultisign() { func (s *IntegrationTestSuite) TestMultiSignBatchCmd() { val := s.network.Validators[0] - codec := codec2.NewLegacyAmino() - sdk.RegisterLegacyAminoCodec(codec) - banktypes.RegisterLegacyAminoCodec(codec) - val.ClientCtx.LegacyAmino = codec - // Fetch 2 accounts and a multisig. account1, err := val.ClientCtx.Keyring.Key("newAccount1") s.Require().NoError(err) From 600d184a449d51b407c0082eebeadb44e6f1868a Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Tue, 3 Nov 2020 17:23:46 +0530 Subject: [PATCH 08/35] add build flag --- x/auth/client/cli/cli_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index f4a31d336b4b..8c9a36af6c5a 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -1,3 +1,5 @@ +// +build norace + package cli_test import ( From af681c5c94c818c1cbb96dba55e7efaf946209f7 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Tue, 3 Nov 2020 20:17:40 +0530 Subject: [PATCH 09/35] update flags --- x/auth/client/cli/tx_multisign.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index b5d492b2ba84..77899488a17d 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -25,10 +25,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/signing" ) -//todo: move to flags const ( flagNoAutoIncrement = "no-auto-increment" - FlagMultisig = "multisigaddr" ) // GetSignCommand returns the sign command @@ -209,7 +207,7 @@ func GetMultiSignBatchCmd() *cobra.Command { cmd.Flags().Bool(flagNoAutoIncrement, false, "disable sequence auto increment") cmd.Flags().String( - FlagMultisig, "", + flagMultisig, "", "Address of the multisig account on behalf of which the transaction shall be signed", ) flags.AddTxFlagsToCmd(cmd) @@ -252,7 +250,7 @@ func makeBatchMultisigCmd() func(cmd *cobra.Command, args []string) error { var signatureBatch [][]signingtypes.SignatureV2 for i := 2; i < len(args); i++ { // todo:unmarshal sigs from multiple files - sigs, err := unmarshalSignatureJSON(clientCtx, args[i]) + sigs, err := unmarshalMultiSigsJSON(clientCtx, args[i]) if err != nil { return err } @@ -354,3 +352,11 @@ func unmarshalSignatureJSON(clientCtx client.Context, filename string) (sigs []s } return clientCtx.TxConfig.UnmarshalSignatureJSON(bytes) } + +func unmarshalMultiSigsJSON(clientCtx client.Context, filename string) (sigs []signingtypes.SignatureV2, err error) { + var bytes []byte + if bytes, err = ioutil.ReadFile(filename); err != nil { + return + } + return clientCtx.TxConfig.UnmarshalSignatureJSON(bytes) +} From 2db8ca79d419b429a011d960cec1383aa631b7a1 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Wed, 4 Nov 2020 01:17:34 +0530 Subject: [PATCH 10/35] update tests --- x/auth/client/cli/cli_test.go | 94 +++++++++++++++++++++++++++++-- x/auth/client/cli/tx_multisign.go | 24 +++----- 2 files changed, 97 insertions(+), 21 deletions(-) diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index 8c9a36af6c5a..4c5ce0396724 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -1,5 +1,3 @@ -// +build norace - package cli_test import ( @@ -151,6 +149,8 @@ func (s *IntegrationTestSuite) TestCLISignBatch() { s.Require().NoError(err) s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) + s.T().Log(res.String()) + // sign-batch file res, err = authtest.TxSignBatchExec(val.ClientCtx, val.Address, filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--signature-only") s.Require().NoError(err) @@ -737,15 +737,95 @@ func (s *IntegrationTestSuite) TestCLIMultisign() { s.Require().NoError(s.network.WaitForNextBlock()) } -func (s *IntegrationTestSuite) TestMultiSignBatchCmd() { +func (s *IntegrationTestSuite) TestSignBatchMultisig() { val := s.network.Validators[0] // Fetch 2 accounts and a multisig. account1, err := val.ClientCtx.Keyring.Key("newAccount1") s.Require().NoError(err) + s.T().Log(account1) + account2, err := val.ClientCtx.Keyring.Key("newAccount2") + s.Require().NoError(err) + s.T().Log(account2) + + multisigInfo, err := val.ClientCtx.Keyring.Key("multi") + + // Send coins from validator to multisig. + sendTokens := sdk.NewInt64Coin(s.cfg.BondDenom, 10) + _, err = bankcli.MsgSendExec( + val.ClientCtx, + val.Address, + multisigInfo.GetAddress(), + sdk.NewCoins(sendTokens), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + fmt.Sprintf("--gas=%d", flags.DefaultGasLimit), + ) + s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) + + resp, err := bankcli.QueryBalancesExec(val.ClientCtx, multisigInfo.GetAddress()) + s.Require().NoError(err) + + var balRes banktypes.QueryAllBalancesResponse + err = val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &balRes) + s.Require().NoError(err) + s.Require().Equal(sendTokens.Amount, balRes.Balances.AmountOf(s.cfg.BondDenom)) + s.T().Log(balRes.Balances.AmountOf(s.cfg.BondDenom)) + + generatedStd, err := bankcli.MsgSendExec( + val.ClientCtx, + multisigInfo.GetAddress(), + val.Address, + sdk.NewCoins( + sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(1)), + ), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + fmt.Sprintf("--%s=true", flags.FlagGenerateOnly), + ) + s.Require().NoError(err) + + // Write the output to disk + filename, cleanup1 := testutil.WriteToNewTempFile(s.T(), strings.Repeat(generatedStd.String(), 1)) + defer cleanup1() + + val.ClientCtx.HomeDir = strings.Replace(val.ClientCtx.HomeDir, "simd", "simcli", 1) + + // sign-batch file + res, err := authtest.TxSignExec(val.ClientCtx, account1.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String()) + s.Require().NoError(err) + s.Require().Equal(1, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) + // write sigs to file + file1, cleanup2 := testutil.WriteToNewTempFile(s.T(), res.String()) + defer cleanup2() + s.T().Log("account1 sigs", res) + // sign-batch file with account2 + res, err = authtest.TxSignExec(val.ClientCtx, account2.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String()) + s.Require().NoError(err) + s.Require().Equal(1, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) + s.T().Log("account2 sigs", res) + + // write sigs to file2 + file2, cleanup3 := testutil.WriteToNewTempFile(s.T(), res.String()) + defer cleanup3() + res, err = authtest.TxMultiSignExec(val.ClientCtx, multisigInfo.GetName(), filename.Name(), file1.Name(), file2.Name()) + s.Require().NoError(err) +} + +func (s *IntegrationTestSuite) TestMultiSignBatchCmd() { + val := s.network.Validators[0] + + // Fetch 2 accounts and a multisig. + account1, err := val.ClientCtx.Keyring.Key("newAccount1") + s.Require().NoError(err) + s.T().Log(account1) account2, err := val.ClientCtx.Keyring.Key("newAccount2") s.Require().NoError(err) + s.T().Log(account2) multisigInfo, err := val.ClientCtx.Keyring.Key("multi") s.Require().NoError(err) @@ -790,23 +870,25 @@ func (s *IntegrationTestSuite) TestMultiSignBatchCmd() { s.Require().NoError(err) // Write the output to disk - filename, cleanup1 := testutil.WriteToNewTempFile(s.T(), strings.Repeat(generatedStd.String(), 3)) + filename, cleanup1 := testutil.WriteToNewTempFile(s.T(), strings.Repeat(generatedStd.String(), 1)) defer cleanup1() // sign-batch file with account1 val.ClientCtx.HomeDir = strings.Replace(val.ClientCtx.HomeDir, "simd", "simcli", 1) res, err := authtest.TxSignBatchExec(val.ClientCtx, account1.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String()) s.Require().NoError(err) - s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) + s.Require().Equal(1, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) // write sigs to file file1, cleanup2 := testutil.WriteToNewTempFile(s.T(), res.String()) defer cleanup2() + s.T().Log("account1 sigs", res) // sign-batch file with account2 res, err = authtest.TxSignBatchExec(val.ClientCtx, account2.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String()) s.Require().NoError(err) - s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) + s.Require().Equal(1, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) + s.T().Log("account2 sigs", res) // write sigs to file2 file2, cleanup3 := testutil.WriteToNewTempFile(s.T(), res.String()) diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 77899488a17d..574aab565153 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -247,15 +247,17 @@ func makeBatchMultisigCmd() func(cmd *cobra.Command, args []string) error { return fmt.Errorf("%q must be of type %s: %s", args[1], keyring.TypeMulti, multisigInfo.GetType()) } - var signatureBatch [][]signingtypes.SignatureV2 + var signatureBatch []signingtypes.SignatureV2 for i := 2; i < len(args); i++ { // todo:unmarshal sigs from multiple files - sigs, err := unmarshalMultiSigsJSON(clientCtx, args[i]) + sigs, err := unmarshalSignatureJSON(clientCtx, args[i]) if err != nil { return err } + for _, sig := range sigs { + signatureBatch = append(signatureBatch, sig) - signatureBatch = append(signatureBatch, sigs) + } } var seq uint64 @@ -282,13 +284,13 @@ func makeBatchMultisigCmd() func(cmd *cobra.Command, args []string) error { multisigPub := multisigInfo.GetPubKey().(*kmultisig.LegacyAminoPubKey) multisigSig := multisig.NewMultisig(len(multisigPub.PubKeys)) - for i, sig := range signatureBatch { - err = signing.VerifySignature(sig[i].PubKey, signingData, sig[i].Data, txCfg.SignModeHandler(), txBldr.GetTx()) + for _, sig := range signatureBatch { + err = signing.VerifySignature(sig.PubKey, signingData, sig.Data, txCfg.SignModeHandler(), txBldr.GetTx()) if err != nil { - return fmt.Errorf("couldn't verify signature: %w", err) + return fmt.Errorf("couldn't verify signature: %w %d %d %v", err, txFactory.AccountNumber(), txFactory.Sequence(), sig.Data) } - if err := multisig.AddSignatureV2(multisigSig, sig[i], multisigPub.GetPubKeys()); err != nil { + if err := multisig.AddSignatureV2(multisigSig, sig, multisigPub.GetPubKeys()); err != nil { return err } } @@ -352,11 +354,3 @@ func unmarshalSignatureJSON(clientCtx client.Context, filename string) (sigs []s } return clientCtx.TxConfig.UnmarshalSignatureJSON(bytes) } - -func unmarshalMultiSigsJSON(clientCtx client.Context, filename string) (sigs []signingtypes.SignatureV2, err error) { - var bytes []byte - if bytes, err = ioutil.ReadFile(filename); err != nil { - return - } - return clientCtx.TxConfig.UnmarshalSignatureJSON(bytes) -} From c6e76654cad530f3be8358fb80d2e0ac2a77c470 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Wed, 4 Nov 2020 01:21:26 +0530 Subject: [PATCH 11/35] add test for signbatch multisig --- x/auth/client/cli/cli_test.go | 79 +++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index 4961e91c37fb..d7304ca3b64e 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -737,6 +737,85 @@ func (s *IntegrationTestSuite) TestCLIMultisign() { s.Require().NoError(s.network.WaitForNextBlock()) } +func (s *IntegrationTestSuite) TestSignBatchMultisig() { + val := s.network.Validators[0] + + // Fetch 2 accounts and a multisig. + account1, err := val.ClientCtx.Keyring.Key("newAccount1") + s.Require().NoError(err) + s.T().Log(account1) + account2, err := val.ClientCtx.Keyring.Key("newAccount2") + s.Require().NoError(err) + s.T().Log(account2) + + multisigInfo, err := val.ClientCtx.Keyring.Key("multi") + + // Send coins from validator to multisig. + sendTokens := sdk.NewInt64Coin(s.cfg.BondDenom, 10) + _, err = bankcli.MsgSendExec( + val.ClientCtx, + val.Address, + multisigInfo.GetAddress(), + sdk.NewCoins(sendTokens), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + fmt.Sprintf("--gas=%d", flags.DefaultGasLimit), + ) + s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) + + resp, err := bankcli.QueryBalancesExec(val.ClientCtx, multisigInfo.GetAddress()) + s.Require().NoError(err) + + var balRes banktypes.QueryAllBalancesResponse + err = val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &balRes) + s.Require().NoError(err) + s.Require().Equal(sendTokens.Amount, balRes.Balances.AmountOf(s.cfg.BondDenom)) + s.T().Log(balRes.Balances.AmountOf(s.cfg.BondDenom)) + + generatedStd, err := bankcli.MsgSendExec( + val.ClientCtx, + multisigInfo.GetAddress(), + val.Address, + sdk.NewCoins( + sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(1)), + ), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + fmt.Sprintf("--%s=true", flags.FlagGenerateOnly), + ) + s.Require().NoError(err) + + // Write the output to disk + filename, cleanup1 := testutil.WriteToNewTempFile(s.T(), strings.Repeat(generatedStd.String(), 1)) + defer cleanup1() + + val.ClientCtx.HomeDir = strings.Replace(val.ClientCtx.HomeDir, "simd", "simcli", 1) + + // sign-batch file + res, err := authtest.TxSignBatchExec(val.ClientCtx, account1.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String()) + s.Require().NoError(err) + s.Require().Equal(1, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) + // write sigs to file + file1, cleanup2 := testutil.WriteToNewTempFile(s.T(), res.String()) + defer cleanup2() + s.T().Log("account1 sigs", res) + + // sign-batch file with account2 + res, err = authtest.TxSignBatchExec(val.ClientCtx, account2.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String()) + s.Require().NoError(err) + s.Require().Equal(1, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) + s.T().Log("account2 sigs", res) + + // write sigs to file2 + file2, cleanup3 := testutil.WriteToNewTempFile(s.T(), res.String()) + defer cleanup3() + res, err = authtest.TxMultiSignExec(val.ClientCtx, multisigInfo.GetName(), filename.Name(), file1.Name(), file2.Name()) + s.Require().NoError(err) +} + func (s *IntegrationTestSuite) TestGetAccountCmd() { val := s.network.Validators[0] _, _, addr1 := testdata.KeyTestPubAddr() From df711ac67a5ee6bacebf11da61cc4b9ecf46b7e3 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Wed, 4 Nov 2020 01:51:46 +0530 Subject: [PATCH 12/35] update test --- x/auth/client/cli/cli_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index d7304ca3b64e..2b87a379111e 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -771,7 +771,6 @@ func (s *IntegrationTestSuite) TestSignBatchMultisig() { var balRes banktypes.QueryAllBalancesResponse err = val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &balRes) s.Require().NoError(err) - s.Require().Equal(sendTokens.Amount, balRes.Balances.AmountOf(s.cfg.BondDenom)) s.T().Log(balRes.Balances.AmountOf(s.cfg.BondDenom)) generatedStd, err := bankcli.MsgSendExec( From a3f8641978faa02dabd855d0a35094134ecebde4 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Mon, 23 Nov 2020 16:27:11 +0530 Subject: [PATCH 13/35] fix sign batch multisig --- x/auth/client/cli/cli_test.go | 9 ++------- x/auth/client/cli/tx_sign.go | 3 +++ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index 9c2dc134e0ca..f38ec4713abf 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -741,11 +741,8 @@ func (s *IntegrationTestSuite) TestSignBatchMultisig() { // Fetch 2 accounts and a multisig. account1, err := val.ClientCtx.Keyring.Key("newAccount1") s.Require().NoError(err) - s.T().Log(account1) account2, err := val.ClientCtx.Keyring.Key("newAccount2") s.Require().NoError(err) - s.T().Log(account2) - multisigInfo, err := val.ClientCtx.Keyring.Key("multi") // Send coins from validator to multisig. @@ -769,7 +766,6 @@ func (s *IntegrationTestSuite) TestSignBatchMultisig() { var balRes banktypes.QueryAllBalancesResponse err = val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &balRes) s.Require().NoError(err) - s.T().Log(balRes.Balances.AmountOf(s.cfg.BondDenom)) generatedStd, err := bankcli.MsgSendExec( val.ClientCtx, @@ -792,16 +788,15 @@ func (s *IntegrationTestSuite) TestSignBatchMultisig() { val.ClientCtx.HomeDir = strings.Replace(val.ClientCtx.HomeDir, "simd", "simcli", 1) // sign-batch file - res, err := authtest.TxSignBatchExec(val.ClientCtx, account1.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String()) + res, err := authtest.TxSignExec(val.ClientCtx, account1.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String()) s.Require().NoError(err) s.Require().Equal(1, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) // write sigs to file file1, cleanup2 := testutil.WriteToNewTempFile(s.T(), res.String()) defer cleanup2() - s.T().Log("account1 sigs", res) // sign-batch file with account2 - res, err = authtest.TxSignBatchExec(val.ClientCtx, account2.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String()) + res, err = authtest.TxSignExec(val.ClientCtx, account2.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String()) s.Require().NoError(err) s.Require().Equal(1, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) s.T().Log("account2 sigs", res) diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 7046c495d663..50b12028de25 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -119,6 +119,9 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { return err } } else { + if txFactory.SignMode() == signing.SignMode_SIGN_MODE_UNSPECIFIED { + txFactory = txFactory.WithSignMode(signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON) + } err = authclient.SignTxWithSignerAddress(txFactory, clientCtx, multisigAddr, clientCtx.GetFromName(), txBuilder, true) } From 66e6c3efe85fdf43d9aac1e3a11f3ba287612f53 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Tue, 24 Nov 2020 00:46:14 +0530 Subject: [PATCH 14/35] add test --- x/auth/client/cli/cli_test.go | 81 +++++++++++++++++++++++++++++++++++ x/auth/client/cli/tx.go | 0 2 files changed, 81 insertions(+) delete mode 100644 x/auth/client/cli/tx.go diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index f38ec4713abf..f598a3407476 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -808,6 +808,87 @@ func (s *IntegrationTestSuite) TestSignBatchMultisig() { s.Require().NoError(err) } +func (s *IntegrationTestSuite) TestMultiSignBatchCmd() { + val := s.network.Validators[0] + + // Fetch 2 accounts and a multisig. + account1, err := val.ClientCtx.Keyring.Key("newAccount1") + s.Require().NoError(err) + s.T().Log(account1) + account2, err := val.ClientCtx.Keyring.Key("newAccount2") + s.Require().NoError(err) + s.T().Log(account2) + + multisigInfo, err := val.ClientCtx.Keyring.Key("multi") + s.Require().NoError(err) + + // Send coins from validator to multisig. + sendTokens := sdk.NewInt64Coin(s.cfg.BondDenom, 10) + _, err = bankcli.MsgSendExec( + val.ClientCtx, + val.Address, + multisigInfo.GetAddress(), + sdk.NewCoins(sendTokens), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + fmt.Sprintf("--gas=%d", flags.DefaultGasLimit), + ) + s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) + + resp, err := bankcli.QueryBalancesExec(val.ClientCtx, multisigInfo.GetAddress()) + s.Require().NoError(err) + + var balRes banktypes.QueryAllBalancesResponse + err = val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &balRes) + s.Require().NoError(err) + s.Require().Equal(sendTokens.Amount, balRes.Balances.AmountOf(s.cfg.BondDenom)) + s.T().Log(balRes.Balances.AmountOf(s.cfg.BondDenom)) + + generatedStd, err := bankcli.MsgSendExec( + val.ClientCtx, + multisigInfo.GetAddress(), + val.Address, + sdk.NewCoins( + sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(1)), + ), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + fmt.Sprintf("--%s=true", flags.FlagGenerateOnly), + ) + + s.Require().NoError(err) + + // Write the output to disk + filename, cleanup1 := testutil.WriteToNewTempFile(s.T(), strings.Repeat(generatedStd.String(), 1)) + defer cleanup1() + + // sign-batch file with account1 + val.ClientCtx.HomeDir = strings.Replace(val.ClientCtx.HomeDir, "simd", "simcli", 1) + res, err := authtest.TxSignBatchExec(val.ClientCtx, account1.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String()) + s.Require().NoError(err) + s.Require().Equal(1, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) + + // write sigs to file + file1, cleanup2 := testutil.WriteToNewTempFile(s.T(), res.String()) + defer cleanup2() + s.T().Log("account1 sigs", res) + + // sign-batch file with account2 + res, err = authtest.TxSignBatchExec(val.ClientCtx, account2.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String()) + s.Require().NoError(err) + s.Require().Equal(1, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) + s.T().Log("account2 sigs", res) + + // write sigs to file2 + file2, cleanup3 := testutil.WriteToNewTempFile(s.T(), res.String()) + defer cleanup3() + res, err = authtest.TxMultiSignBatchExec(val.ClientCtx, filename.Name(), multisigInfo.GetName(), file1.Name(), file2.Name()) + s.Require().NoError(err) +} + func (s *IntegrationTestSuite) TestGetAccountCmd() { val := s.network.Validators[0] _, _, addr1 := testdata.KeyTestPubAddr() diff --git a/x/auth/client/cli/tx.go b/x/auth/client/cli/tx.go deleted file mode 100644 index e69de29bb2d1..000000000000 From 21226ec32217dd0e77391b1f28ad2093ad7d5139 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Tue, 24 Nov 2020 15:43:56 +0530 Subject: [PATCH 15/35] update offline usage --- x/auth/client/cli/cli_test.go | 5 ++--- x/auth/client/cli/tx_sign.go | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index f38ec4713abf..a95e9518bfb8 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -788,7 +788,7 @@ func (s *IntegrationTestSuite) TestSignBatchMultisig() { val.ClientCtx.HomeDir = strings.Replace(val.ClientCtx.HomeDir, "simd", "simcli", 1) // sign-batch file - res, err := authtest.TxSignExec(val.ClientCtx, account1.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String()) + res, err := authtest.TxSignBatchExec(val.ClientCtx, account1.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String()) s.Require().NoError(err) s.Require().Equal(1, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) // write sigs to file @@ -796,10 +796,9 @@ func (s *IntegrationTestSuite) TestSignBatchMultisig() { defer cleanup2() // sign-batch file with account2 - res, err = authtest.TxSignExec(val.ClientCtx, account2.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String()) + res, err = authtest.TxSignBatchExec(val.ClientCtx, account2.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String()) s.Require().NoError(err) s.Require().Equal(1, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) - s.T().Log("account2 sigs", res) // write sigs to file2 file2, cleanup3 := testutil.WriteToNewTempFile(s.T(), res.String()) diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 50b12028de25..a9c698078282 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -122,7 +122,7 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { if txFactory.SignMode() == signing.SignMode_SIGN_MODE_UNSPECIFIED { txFactory = txFactory.WithSignMode(signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON) } - err = authclient.SignTxWithSignerAddress(txFactory, clientCtx, multisigAddr, clientCtx.GetFromName(), txBuilder, true) + err = authclient.SignTxWithSignerAddress(txFactory, clientCtx, multisigAddr, clientCtx.GetFromName(), txBuilder, clientCtx.Offline) } if err != nil { From 2c074386bf2e4398b94cd94bd4138653e17fc1b1 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Fri, 11 Dec 2020 02:48:41 +0530 Subject: [PATCH 16/35] update with sign batch fix --- x/auth/client/cli/cli_test.go | 62 +++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index b935d6641258..b3f2a633c517 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -774,6 +774,68 @@ func (s *IntegrationTestSuite) TestSignBatchMultisig() { s.Require().NoError(err) } +func (s *IntegrationTestSuite) TestMultisignBatch() { + val := s.network.Validators[0] + + // Fetch 2 accounts and a multisig. + account1, err := val.ClientCtx.Keyring.Key("newAccount1") + s.Require().NoError(err) + account2, err := val.ClientCtx.Keyring.Key("newAccount2") + s.Require().NoError(err) + multisigInfo, err := val.ClientCtx.Keyring.Key("multi") + + // Send coins from validator to multisig. + sendTokens := sdk.NewInt64Coin(s.cfg.BondDenom, 10) + _, err = bankcli.MsgSendExec( + val.ClientCtx, + val.Address, + multisigInfo.GetAddress(), + sdk.NewCoins(sendTokens), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + fmt.Sprintf("--gas=%d", flags.DefaultGasLimit), + ) + s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) + + generatedStd, err := bankcli.MsgSendExec( + val.ClientCtx, + multisigInfo.GetAddress(), + val.Address, + sdk.NewCoins( + sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(1)), + ), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + fmt.Sprintf("--%s=true", flags.FlagGenerateOnly), + ) + s.Require().NoError(err) + + // Write the output to disk + filename := testutil.WriteToNewTempFile(s.T(), strings.Repeat(generatedStd.String(), 3)) + val.ClientCtx.HomeDir = strings.Replace(val.ClientCtx.HomeDir, "simd", "simcli", 1) + + // sign-batch file + res, err := authtest.TxSignBatchExec(val.ClientCtx, account1.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String()) + s.Require().NoError(err) + s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) + // write sigs to file + file1 := testutil.WriteToNewTempFile(s.T(), res.String()) + + // sign-batch file with account2 + res, err = authtest.TxSignBatchExec(val.ClientCtx, account2.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String()) + s.Require().NoError(err) + s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) + + // write sigs to file2 + file2 := testutil.WriteToNewTempFile(s.T(), res.String()) + res, err = authtest.TxMultiSignBatchExec(val.ClientCtx, filename.Name(), multisigInfo.GetName(), file1.Name(), file2.Name()) + s.T().Log(res) + s.Require().NoError(err) +} + func (s *IntegrationTestSuite) TestGetAccountCmd() { val := s.network.Validators[0] _, _, addr1 := testdata.KeyTestPubAddr() From 190c455cfd9f5af63b307d547bb9812e0a6a2b0a Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Mon, 14 Dec 2020 16:23:45 +0530 Subject: [PATCH 17/35] fix lint --- x/auth/client/cli/tx_multisign.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 574aab565153..792ebafd65d1 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -201,7 +201,7 @@ func GetMultiSignBatchCmd() *cobra.Command { Short: "Assemble multisig transactions", Long: `Assemble a batch of multisig transactions generated by batch sign command.`, PreRun: preSignCmd, - RunE: makeBatchMultisigCmd(), + RunE: makeBatchMultisignCmd(), Args: cobra.MinimumNArgs(3), } @@ -215,7 +215,7 @@ func GetMultiSignBatchCmd() *cobra.Command { return cmd } -func makeBatchMultisigCmd() func(cmd *cobra.Command, args []string) error { +func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags()) @@ -249,15 +249,12 @@ func makeBatchMultisigCmd() func(cmd *cobra.Command, args []string) error { var signatureBatch []signingtypes.SignatureV2 for i := 2; i < len(args); i++ { - // todo:unmarshal sigs from multiple files sigs, err := unmarshalSignatureJSON(clientCtx, args[i]) if err != nil { return err } - for _, sig := range sigs { - signatureBatch = append(signatureBatch, sig) - } + signatureBatch = append(signatureBatch, sigs...) } var seq uint64 @@ -300,13 +297,13 @@ func makeBatchMultisigCmd() func(cmd *cobra.Command, args []string) error { Data: multisigSig, Sequence: txFactory.Sequence(), } + err = txBldr.SetSignatures(sigV2) if err != nil { return err } sigOnly, _ := cmd.Flags().GetBool(flagSigOnly) - aminoJSON, _ := cmd.Flags().GetBool(flagAmino) var json []byte From 45fd7015dc04bce00b586d6b622def8d3d9acbec Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Thu, 17 Dec 2020 17:28:33 +0530 Subject: [PATCH 18/35] update tests --- x/auth/client/cli/cli_test.go | 12 +++++++++++- x/auth/client/cli/tx_multisign.go | 7 +++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index ad01339bba20..b509cb151ee2 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -819,7 +819,7 @@ func (s *IntegrationTestSuite) TestMultisignBatch() { multisigInfo, err := val.ClientCtx.Keyring.Key("multi") // Send coins from validator to multisig. - sendTokens := sdk.NewInt64Coin(s.cfg.BondDenom, 10) + sendTokens := sdk.NewInt64Coin(s.cfg.BondDenom, 1000) _, err = bankcli.MsgSendExec( val.ClientCtx, val.Address, @@ -868,6 +868,16 @@ func (s *IntegrationTestSuite) TestMultisignBatch() { res, err = authtest.TxMultiSignBatchExec(val.ClientCtx, filename.Name(), multisigInfo.GetName(), file1.Name(), file2.Name()) s.T().Log(res) s.Require().NoError(err) + signedTxs := strings.Split(strings.Trim(res.String(), "\n"), "\n") + // Broadcast transactions. + for _, signedTx := range signedTxs { + signedTxFile := testutil.WriteToNewTempFile(s.T(), signedTx) + val.ClientCtx.BroadcastMode = flags.BroadcastBlock + res, err = authtest.TxBroadcastExec(val.ClientCtx, signedTxFile.Name()) + s.T().Log(res) + s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) + } } func (s *IntegrationTestSuite) TestGetAccountCmd() { diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index efb40571be2c..6e991604f4ca 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -223,8 +223,7 @@ func GetMultiSignBatchCmd() *cobra.Command { func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags()) + clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err } @@ -239,7 +238,7 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { if args[0] != "-" { infile, err = os.Open(args[0]) if err != nil { - return err + return fmt.Errorf("couldn't open %s: %w", args[0], err) } } scanner := authclient.NewBatchScanner(txCfg, infile) @@ -343,7 +342,7 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { continue } - sequence++ + txFactory.WithSequence(sequence + 1) } return nil From b33073709ff2e98314dcec9c996f0d681530513e Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Fri, 8 Jan 2021 14:57:10 +0530 Subject: [PATCH 19/35] update test --- x/staking/types/msg_test.go | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/x/staking/types/msg_test.go b/x/staking/types/msg_test.go index 493434527c94..9bed4b2bbc0a 100644 --- a/x/staking/types/msg_test.go +++ b/x/staking/types/msg_test.go @@ -172,29 +172,3 @@ func TestMsgBeginRedelegate(t *testing.T) { } } } - -// test ValidateBasic for MsgUnbond -func TestMsgUndelegate(t *testing.T) { - tests := []struct { - name string - delegatorAddr sdk.AccAddress - validatorAddr sdk.ValAddress - amount sdk.Coin - expectPass bool - }{ - {"regular", sdk.AccAddress(valAddr1), valAddr2, sdk.NewInt64Coin(sdk.DefaultBondDenom, 1), true}, - {"zero amount", sdk.AccAddress(valAddr1), valAddr2, sdk.NewInt64Coin(sdk.DefaultBondDenom, 0), false}, - {"nil amount", sdk.AccAddress(valAddr1), valAddr2, sdk.Coin{}, false}, - {"empty delegator", sdk.AccAddress(emptyAddr), valAddr1, sdk.NewInt64Coin(sdk.DefaultBondDenom, 1), false}, - {"empty validator", sdk.AccAddress(valAddr1), emptyAddr, sdk.NewInt64Coin(sdk.DefaultBondDenom, 1), false}, - } - - for _, tc := range tests { - msg := types.NewMsgUndelegate(tc.delegatorAddr, tc.validatorAddr, tc.amount) - if tc.expectPass { - require.Nil(t, msg.ValidateBasic(), "test: %v", tc.name) - } else { - require.NotNil(t, msg.ValidateBasic(), "test: %v", tc.name) - } - } -} From 11963b43b9ff4f1af95665c59525dc7cf4d16e69 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Mon, 11 Jan 2021 01:31:12 +0530 Subject: [PATCH 20/35] update tests --- x/auth/client/cli/cli_test.go | 15 ++++++++++++--- x/auth/client/cli/tx_multisign.go | 11 ++++++----- x/auth/client/cli/tx_sign.go | 7 ++++--- x/auth/client/testutil/helpers.go | 7 +++++++ 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index b509cb151ee2..59cea6a47380 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -189,7 +189,7 @@ func (s *IntegrationTestSuite) TestCLISign() { sigOnlyFlag, "--overwrite") checkSignatures(require, txCfg, res.Bytes(), valInfo.GetPubKey()) - /**** test flagAmino ****/ + /**** test FlagAmino ****/ res, err = authtest.TxSignExec(val1.ClientCtx, val1.Address, filenameSigned, chainFlag, "--amino=true") require.NoError(err) @@ -851,16 +851,25 @@ func (s *IntegrationTestSuite) TestMultisignBatch() { filename := testutil.WriteToNewTempFile(s.T(), strings.Repeat(generatedStd.String(), 3)) val.ClientCtx.HomeDir = strings.Replace(val.ClientCtx.HomeDir, "simd", "simcli", 1) + queryResJSON, err := authtest.QueryAccountExec(val.ClientCtx, multisigInfo.GetAddress()) + s.Require().NoError(err) + var any types.Any + err = val.ClientCtx.JSONMarshaler.UnmarshalJSON(queryResJSON.Bytes(), &any) + var newAccount1 authtypes.AccountI + err = val.ClientCtx.InterfaceRegistry.UnpackAny(&any, &newAccount1) + // sign-batch file - res, err := authtest.TxSignBatchExec(val.ClientCtx, account1.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String()) + res, err := authtest.TxSignBatchExec(val.ClientCtx, account1.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String(), fmt.Sprintf("--%s", flags.FlagOffline), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, fmt.Sprint(newAccount1.GetAccountNumber())), fmt.Sprintf("--%s=%s", flags.FlagSequence, fmt.Sprint(newAccount1.GetSequence())), fmt.Sprintf("--%s", authcli.FlagAmino)) s.Require().NoError(err) + s.T().Log(res) s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) // write sigs to file file1 := testutil.WriteToNewTempFile(s.T(), res.String()) // sign-batch file with account2 - res, err = authtest.TxSignBatchExec(val.ClientCtx, account2.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String()) + res, err = authtest.TxSignBatchExec(val.ClientCtx, account2.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String(), fmt.Sprintf("--%s", flags.FlagOffline), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, fmt.Sprint(newAccount1.GetAccountNumber())), fmt.Sprintf("--%s=%s", flags.FlagSequence, fmt.Sprint(newAccount1.GetSequence())), fmt.Sprintf("--%s", authcli.FlagAmino)) s.Require().NoError(err) + s.T().Log(res) s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) // write sigs to file2 diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 6e991604f4ca..05483b5869f0 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -59,7 +59,7 @@ recommended to set such parameters manually. cmd.Flags().Bool(flagSigOnly, false, "Print only the generated signature, then exit") cmd.Flags().String(flags.FlagOutputDocument, "", "The document will be written to the given file instead of STDOUT") - cmd.Flags().Bool(flagAmino, false, "Generate Amino encoded JSON suitable for submiting to the txs REST endpoint") + cmd.Flags().Bool(FlagAmino, false, "Generate Amino encoded JSON suitable for submiting to the txs REST endpoint") flags.AddTxFlagsToCmd(cmd) cmd.Flags().String(flags.FlagChainID, "", "network chain ID") @@ -153,7 +153,7 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) { sigOnly, _ := cmd.Flags().GetBool(flagSigOnly) - aminoJSON, _ := cmd.Flags().GetBool(flagAmino) + aminoJSON, _ := cmd.Flags().GetBool(FlagAmino) var json []byte @@ -262,7 +262,7 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { signatureBatch = append(signatureBatch, sigs...) } - var seq uint64 + var seq = txFactory.Sequence() if !clientCtx.Offline { accnum, seq, err := clientCtx.AccountRetriever.GetAccountNumberSequence(clientCtx, multisigInfo.GetAddress()) if err != nil { @@ -309,7 +309,7 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { } sigOnly, _ := cmd.Flags().GetBool(flagSigOnly) - aminoJSON, _ := cmd.Flags().GetBool(flagAmino) + aminoJSON, _ := cmd.Flags().GetBool(FlagAmino) var json []byte @@ -342,7 +342,8 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { continue } - txFactory.WithSequence(sequence + 1) + sequence++ + txFactory = txFactory.WithSequence(sequence) } return nil diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 251282bb8e0c..7f49081e9c45 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -19,7 +19,7 @@ const ( flagMultisig = "multisig" flagOverwrite = "overwrite" flagSigOnly = "signature-only" - flagAmino = "amino" + FlagAmino = "amino" ) // GetSignBatchCommand returns the transaction sign-batch command. @@ -52,6 +52,7 @@ account key. It implies --signature-only. cmd.Flags().String(flags.FlagOutputDocument, "", "The document will be written to the given file instead of STDOUT") cmd.Flags().Bool(flagSigOnly, true, "Print only the generated signature, then exit") cmd.Flags().String(flags.FlagChainID, "", "network chain ID") + cmd.Flags().Bool(FlagAmino, false, "Generate Amino encoded JSON suitable for submiting to the txs REST endpoint") cmd.MarkFlagRequired(flags.FlagFrom) flags.AddTxFlagsToCmd(cmd) @@ -186,7 +187,7 @@ be generated via the 'multisign' command. cmd.Flags().Bool(flagSigOnly, false, "Print only the signatures") cmd.Flags().String(flags.FlagOutputDocument, "", "The document will be written to the given file instead of STDOUT") cmd.Flags().String(flags.FlagChainID, "", "The network chain ID") - cmd.Flags().Bool(flagAmino, false, "Generate Amino encoded JSON suitable for submiting to the txs REST endpoint") + cmd.Flags().Bool(FlagAmino, false, "Generate Amino encoded JSON suitable for submiting to the txs REST endpoint") cmd.MarkFlagRequired(flags.FlagFrom) flags.AddTxFlagsToCmd(cmd) @@ -249,7 +250,7 @@ func makeSignCmd() func(cmd *cobra.Command, args []string) error { return err } - aminoJSON, err := f.GetBool(flagAmino) + aminoJSON, err := f.GetBool(FlagAmino) if err != nil { return err } diff --git a/x/auth/client/testutil/helpers.go b/x/auth/client/testutil/helpers.go index 994b5dd6b7af..4d3a4af0ccaf 100644 --- a/x/auth/client/testutil/helpers.go +++ b/x/auth/client/testutil/helpers.go @@ -112,4 +112,11 @@ func TxMultiSignBatchExec(clientCtx client.Context, filename string, from string return clitestutil.ExecTestCLICmd(clientCtx, cli.GetMultiSignBatchCmd(), 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 92bef3cca816834166ce4bc43789b6ea95c58944 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Mon, 11 Jan 2021 03:02:29 +0530 Subject: [PATCH 21/35] 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 5916a42c3342..e2d5d63a6015 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 5ebd4a86298d0fbb1b94e258d058ec3bc0ac33ba Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Mon, 11 Jan 2021 05:36:22 +0530 Subject: [PATCH 22/35] update seq --- x/auth/client/cli/cli_test.go | 6 +++--- x/auth/client/cli/tx_multisign.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index 59cea6a47380..f823d3cc8d8f 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -859,7 +859,7 @@ func (s *IntegrationTestSuite) TestMultisignBatch() { err = val.ClientCtx.InterfaceRegistry.UnpackAny(&any, &newAccount1) // sign-batch file - res, err := authtest.TxSignBatchExec(val.ClientCtx, account1.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String(), fmt.Sprintf("--%s", flags.FlagOffline), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, fmt.Sprint(newAccount1.GetAccountNumber())), fmt.Sprintf("--%s=%s", flags.FlagSequence, fmt.Sprint(newAccount1.GetSequence())), fmt.Sprintf("--%s", authcli.FlagAmino)) + res, err := authtest.TxSignBatchExec(val.ClientCtx, account1.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String(), fmt.Sprintf("--%s", flags.FlagOffline), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, fmt.Sprint(newAccount1.GetAccountNumber())), fmt.Sprintf("--%s=%s", flags.FlagSequence, fmt.Sprint(newAccount1.GetSequence()))) s.Require().NoError(err) s.T().Log(res) s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) @@ -867,12 +867,12 @@ func (s *IntegrationTestSuite) TestMultisignBatch() { file1 := testutil.WriteToNewTempFile(s.T(), res.String()) // sign-batch file with account2 - res, err = authtest.TxSignBatchExec(val.ClientCtx, account2.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String(), fmt.Sprintf("--%s", flags.FlagOffline), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, fmt.Sprint(newAccount1.GetAccountNumber())), fmt.Sprintf("--%s=%s", flags.FlagSequence, fmt.Sprint(newAccount1.GetSequence())), fmt.Sprintf("--%s", authcli.FlagAmino)) + res, err = authtest.TxSignBatchExec(val.ClientCtx, account2.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String(), fmt.Sprintf("--%s", flags.FlagOffline), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, fmt.Sprint(newAccount1.GetAccountNumber())), fmt.Sprintf("--%s=%s", flags.FlagSequence, fmt.Sprint(newAccount1.GetSequence()))) s.Require().NoError(err) s.T().Log(res) s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) - // write sigs to file2 + // multisign the file file2 := testutil.WriteToNewTempFile(s.T(), res.String()) res, err = authtest.TxMultiSignBatchExec(val.ClientCtx, filename.Name(), multisigInfo.GetName(), file1.Name(), file2.Name()) s.T().Log(res) diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 05483b5869f0..20e1c63da304 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -281,7 +281,7 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { signingData := signing.SignerData{ ChainID: txFactory.ChainID(), AccountNumber: txFactory.AccountNumber(), - Sequence: txFactory.Sequence(), + Sequence: sequence, } multisigPub := multisigInfo.GetPubKey().(*kmultisig.LegacyAminoPubKey) @@ -300,7 +300,7 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { sigV2 := signingtypes.SignatureV2{ PubKey: multisigPub, Data: multisigSig, - Sequence: txFactory.Sequence(), + Sequence: sequence, } err = txBldr.SetSignatures(sigV2) From 7adc5d920591e936fe62022c663e777a491cf2d7 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Tue, 12 Jan 2021 15:40:19 +0530 Subject: [PATCH 23/35] fix conflicts --- x/auth/client/cli/cli_test.go | 10 ++++------ x/auth/client/testutil/helpers.go | 7 ------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index e93a78ae9554..de1d60380beb 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -862,13 +862,11 @@ func (s *IntegrationTestSuite) TestMultisignBatch() { queryResJSON, err := authtest.QueryAccountExec(val.ClientCtx, multisigInfo.GetAddress()) s.Require().NoError(err) - var any types.Any - err = val.ClientCtx.JSONMarshaler.UnmarshalJSON(queryResJSON.Bytes(), &any) - var newAccount1 authtypes.AccountI - err = val.ClientCtx.InterfaceRegistry.UnpackAny(&any, &newAccount1) + var account authtypes.AccountI + s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalInterfaceJSON(queryResJSON.Bytes(), &account)) // sign-batch file - res, err := authtest.TxSignBatchExec(val.ClientCtx, account1.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String(), fmt.Sprintf("--%s", flags.FlagOffline), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, fmt.Sprint(newAccount1.GetAccountNumber())), fmt.Sprintf("--%s=%s", flags.FlagSequence, fmt.Sprint(newAccount1.GetSequence()))) + res, err := authtest.TxSignBatchExec(val.ClientCtx, account1.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String(), fmt.Sprintf("--%s", flags.FlagOffline), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, fmt.Sprint(account.GetAccountNumber())), fmt.Sprintf("--%s=%s", flags.FlagSequence, fmt.Sprint(account.GetSequence()))) s.Require().NoError(err) s.T().Log(res) s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) @@ -876,7 +874,7 @@ func (s *IntegrationTestSuite) TestMultisignBatch() { file1 := testutil.WriteToNewTempFile(s.T(), res.String()) // sign-batch file with account2 - res, err = authtest.TxSignBatchExec(val.ClientCtx, account2.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String(), fmt.Sprintf("--%s", flags.FlagOffline), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, fmt.Sprint(newAccount1.GetAccountNumber())), fmt.Sprintf("--%s=%s", flags.FlagSequence, fmt.Sprint(newAccount1.GetSequence()))) + res, err = authtest.TxSignBatchExec(val.ClientCtx, account2.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String(), fmt.Sprintf("--%s", flags.FlagOffline), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, fmt.Sprint(account.GetAccountNumber())), fmt.Sprintf("--%s=%s", flags.FlagSequence, fmt.Sprint(account.GetSequence()))) s.Require().NoError(err) s.T().Log(res) s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) diff --git a/x/auth/client/testutil/helpers.go b/x/auth/client/testutil/helpers.go index e0b79066b4c7..6d68ef9236f2 100644 --- a/x/auth/client/testutil/helpers.go +++ b/x/auth/client/testutil/helpers.go @@ -106,11 +106,4 @@ func TxMultiSignBatchExec(clientCtx client.Context, filename string, from string return clitestutil.ExecTestCLICmd(clientCtx, cli.GetMultiSignBatchCmd(), 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 fb4d6800593b4f2926a64420ed1c376b76d6b3ea Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Mon, 22 Feb 2021 18:44:42 +0530 Subject: [PATCH 24/35] update multisign --- x/auth/client/cli/cli_test.go | 3 --- x/auth/client/cli/tx_multisign.go | 37 +++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index 6594cd5d602e..d66d45833ece 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -863,7 +863,6 @@ func (s *IntegrationTestSuite) TestMultisignBatch() { // sign-batch file res, err := authtest.TxSignBatchExec(val.ClientCtx, account1.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String(), fmt.Sprintf("--%s", flags.FlagOffline), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, fmt.Sprint(account.GetAccountNumber())), fmt.Sprintf("--%s=%s", flags.FlagSequence, fmt.Sprint(account.GetSequence()))) s.Require().NoError(err) - s.T().Log(res) s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) // write sigs to file file1 := testutil.WriteToNewTempFile(s.T(), res.String()) @@ -871,13 +870,11 @@ func (s *IntegrationTestSuite) TestMultisignBatch() { // sign-batch file with account2 res, err = authtest.TxSignBatchExec(val.ClientCtx, account2.GetAddress(), filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--multisig", multisigInfo.GetAddress().String(), fmt.Sprintf("--%s", flags.FlagOffline), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, fmt.Sprint(account.GetAccountNumber())), fmt.Sprintf("--%s=%s", flags.FlagSequence, fmt.Sprint(account.GetSequence()))) s.Require().NoError(err) - s.T().Log(res) s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) // multisign the file file2 := testutil.WriteToNewTempFile(s.T(), res.String()) res, err = authtest.TxMultiSignBatchExec(val.ClientCtx, filename.Name(), multisigInfo.GetName(), file1.Name(), file2.Name()) - s.T().Log(res) s.Require().NoError(err) signedTxs := strings.Split(strings.Trim(res.String(), "\n"), "\n") // Broadcast transactions. diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index a5dad2de6857..4c49ef8627b6 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -253,17 +253,17 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { return fmt.Errorf("%q must be of type %s: %s", args[1], keyring.TypeMulti, multisigInfo.GetType()) } - var signatureBatch []signingtypes.SignatureV2 + var signatureBatch [][]signingtypes.SignatureV2 for i := 2; i < len(args); i++ { - sigs, err := unmarshalSignatureJSON(clientCtx, args[i]) + sigs, err := readSignaturesFromFile(clientCtx, args[i]) if err != nil { return err } - signatureBatch = append(signatureBatch, sigs...) + signatureBatch = append(signatureBatch, sigs) } - var seq = txFactory.Sequence() + var sequence = txFactory.Sequence() if !clientCtx.Offline { accnum, seq, err := clientCtx.AccountRetriever.GetAccountNumberSequence(clientCtx, multisigInfo.GetAddress()) if err != nil { @@ -273,7 +273,7 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { txFactory = txFactory.WithAccountNumber(accnum).WithSequence(seq) } - for sequence := seq; scanner.Scan(); { + for i := 0; scanner.Scan(); i++ { txBldr, err := txCfg.WrapTxBuilder(scanner.Tx()) if err != nil { return err @@ -288,12 +288,12 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { multisigPub := multisigInfo.GetPubKey().(*kmultisig.LegacyAminoPubKey) multisigSig := multisig.NewMultisig(len(multisigPub.PubKeys)) for _, sig := range signatureBatch { - err = signing.VerifySignature(sig.PubKey, signingData, sig.Data, txCfg.SignModeHandler(), txBldr.GetTx()) + err = signing.VerifySignature(sig[sequence].PubKey, signingData, sig[sequence].Data, txCfg.SignModeHandler(), txBldr.GetTx()) if err != nil { - return fmt.Errorf("couldn't verify signature: %w %d %d %v", err, txFactory.AccountNumber(), txFactory.Sequence(), sig.Data) + return fmt.Errorf("couldn't verify signature: %w", err) } - if err := multisig.AddSignatureV2(multisigSig, sig, multisigPub.GetPubKeys()); err != nil { + if err := multisig.AddSignatureV2(multisigSig, sig[sequence], multisigPub.GetPubKeys()); err != nil { return err } } @@ -342,7 +342,6 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { if viper.GetBool(flagNoAutoIncrement) { continue } - sequence++ txFactory = txFactory.WithSequence(sequence) } @@ -358,3 +357,23 @@ func unmarshalSignatureJSON(clientCtx client.Context, filename string) (sigs []s } return clientCtx.TxConfig.UnmarshalSignatureJSON(bytes) } + +func readSignaturesFromFile(ctx client.Context, filename string) (sigs []signingtypes.SignatureV2, err error) { + bz, err := ioutil.ReadFile(filename) + if err != nil { + return nil, err + } + + newString := strings.TrimSuffix(string(bz), "\n") + lines := strings.Split(newString, "\n") + + for _, bz := range lines { + sig, err := ctx.TxConfig.UnmarshalSignatureJSON([]byte(bz)) + if err != nil { + return nil, err + } + + sigs = append(sigs, sig...) + } + return sigs, nil +} From 4b68f1ae3487bab08ec1cf9fc56b13454eeee18c Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Mon, 22 Feb 2021 20:35:19 +0530 Subject: [PATCH 25/35] revert unintended --- x/staking/types/msg_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/x/staking/types/msg_test.go b/x/staking/types/msg_test.go index 9bed4b2bbc0a..493434527c94 100644 --- a/x/staking/types/msg_test.go +++ b/x/staking/types/msg_test.go @@ -172,3 +172,29 @@ func TestMsgBeginRedelegate(t *testing.T) { } } } + +// test ValidateBasic for MsgUnbond +func TestMsgUndelegate(t *testing.T) { + tests := []struct { + name string + delegatorAddr sdk.AccAddress + validatorAddr sdk.ValAddress + amount sdk.Coin + expectPass bool + }{ + {"regular", sdk.AccAddress(valAddr1), valAddr2, sdk.NewInt64Coin(sdk.DefaultBondDenom, 1), true}, + {"zero amount", sdk.AccAddress(valAddr1), valAddr2, sdk.NewInt64Coin(sdk.DefaultBondDenom, 0), false}, + {"nil amount", sdk.AccAddress(valAddr1), valAddr2, sdk.Coin{}, false}, + {"empty delegator", sdk.AccAddress(emptyAddr), valAddr1, sdk.NewInt64Coin(sdk.DefaultBondDenom, 1), false}, + {"empty validator", sdk.AccAddress(valAddr1), emptyAddr, sdk.NewInt64Coin(sdk.DefaultBondDenom, 1), false}, + } + + for _, tc := range tests { + msg := types.NewMsgUndelegate(tc.delegatorAddr, tc.validatorAddr, tc.amount) + if tc.expectPass { + require.Nil(t, msg.ValidateBasic(), "test: %v", tc.name) + } else { + require.NotNil(t, msg.ValidateBasic(), "test: %v", tc.name) + } + } +} From 5ce860c7c56c200b1d03a5ec972e6ceb106aaeb0 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Tue, 23 Feb 2021 00:18:34 +0530 Subject: [PATCH 26/35] fix tests --- x/auth/client/cli/tx_multisign.go | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 4c49ef8627b6..d3cac9e5f5a0 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -238,6 +238,13 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { var infile = os.Stdin if args[0] != "-" { infile, err = os.Open(args[0]) + defer func() { + err2 := infile.Close() + if err == nil { + err = err2 + } + }() + if err != nil { return fmt.Errorf("couldn't open %s: %w", args[0], err) } @@ -263,7 +270,6 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { signatureBatch = append(signatureBatch, sigs) } - var sequence = txFactory.Sequence() if !clientCtx.Offline { accnum, seq, err := clientCtx.AccountRetriever.GetAccountNumberSequence(clientCtx, multisigInfo.GetAddress()) if err != nil { @@ -279,21 +285,20 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { return err } - signingData := signing.SignerData{ - ChainID: txFactory.ChainID(), - AccountNumber: txFactory.AccountNumber(), - Sequence: sequence, - } - multisigPub := multisigInfo.GetPubKey().(*kmultisig.LegacyAminoPubKey) multisigSig := multisig.NewMultisig(len(multisigPub.PubKeys)) for _, sig := range signatureBatch { - err = signing.VerifySignature(sig[sequence].PubKey, signingData, sig[sequence].Data, txCfg.SignModeHandler(), txBldr.GetTx()) + signingData := signing.SignerData{ + ChainID: txFactory.ChainID(), + AccountNumber: txFactory.AccountNumber(), + Sequence: txFactory.Sequence(), + } + err = signing.VerifySignature(sig[i].PubKey, signingData, sig[i].Data, txCfg.SignModeHandler(), txBldr.GetTx()) if err != nil { - return fmt.Errorf("couldn't verify signature: %w", err) + return fmt.Errorf("couldn't verify signature: %w %v %v", err, signingData, sig) } - if err := multisig.AddSignatureV2(multisigSig, sig[sequence], multisigPub.GetPubKeys()); err != nil { + if err := multisig.AddSignatureV2(multisigSig, sig[i], multisigPub.GetPubKeys()); err != nil { return err } } @@ -301,7 +306,7 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { sigV2 := signingtypes.SignatureV2{ PubKey: multisigPub, Data: multisigSig, - Sequence: sequence, + Sequence: txFactory.Sequence(), } err = txBldr.SetSignatures(sigV2) @@ -342,7 +347,7 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { if viper.GetBool(flagNoAutoIncrement) { continue } - sequence++ + sequence := txFactory.Sequence() + 1 txFactory = txFactory.WithSequence(sequence) } From b3e122d3f1c14d3d70d4bd96b3eab956c66b55cb Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Tue, 23 Feb 2021 00:32:30 +0530 Subject: [PATCH 27/35] rename flags --- x/auth/client/cli/cli_test.go | 2 +- x/auth/client/cli/tx_multisign.go | 10 +++------- x/auth/client/cli/tx_sign.go | 15 ++++++++------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index f9a38febddc2..e2a3b297ac65 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -198,7 +198,7 @@ func (s *IntegrationTestSuite) TestCLISign() { sigOnlyFlag, "--overwrite") checkSignatures(require, txCfg, res.Bytes(), valInfo.GetPubKey()) - /**** test FlagAmino ****/ + /**** test flagAmino ****/ res, err = authtest.TxSignExec(val1.ClientCtx, val1.Address, filenameSigned, chainFlag, "--amino=true") require.NoError(err) diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index d3cac9e5f5a0..da09b582f3fa 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -25,10 +25,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/signing" ) -const ( - flagNoAutoIncrement = "no-auto-increment" -) - // GetSignCommand returns the sign command func GetMultiSignCommand() *cobra.Command { cmd := &cobra.Command{ @@ -59,7 +55,7 @@ recommended to set such parameters manually. cmd.Flags().Bool(flagSigOnly, false, "Print only the generated signature, then exit") cmd.Flags().String(flags.FlagOutputDocument, "", "The document will be written to the given file instead of STDOUT") - cmd.Flags().Bool(FlagAmino, false, "Generate Amino encoded JSON suitable for submiting to the txs REST endpoint") + cmd.Flags().Bool(flagAmino, false, "Generate Amino encoded JSON suitable for submiting to the txs REST endpoint") flags.AddTxFlagsToCmd(cmd) cmd.Flags().String(flags.FlagChainID, "", "network chain ID") @@ -154,7 +150,7 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) { sigOnly, _ := cmd.Flags().GetBool(flagSigOnly) - aminoJSON, _ := cmd.Flags().GetBool(FlagAmino) + aminoJSON, _ := cmd.Flags().GetBool(flagAmino) var json []byte @@ -315,7 +311,7 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { } sigOnly, _ := cmd.Flags().GetBool(flagSigOnly) - aminoJSON, _ := cmd.Flags().GetBool(FlagAmino) + aminoJSON, _ := cmd.Flags().GetBool(flagAmino) var json []byte diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 7f49081e9c45..986db65cdac8 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -16,10 +16,11 @@ import ( ) const ( - flagMultisig = "multisig" - flagOverwrite = "overwrite" - flagSigOnly = "signature-only" - FlagAmino = "amino" + flagMultisig = "multisig" + flagOverwrite = "overwrite" + flagSigOnly = "signature-only" + flagAmino = "amino" + flagNoAutoIncrement = "no-auto-increment" ) // GetSignBatchCommand returns the transaction sign-batch command. @@ -52,7 +53,7 @@ account key. It implies --signature-only. cmd.Flags().String(flags.FlagOutputDocument, "", "The document will be written to the given file instead of STDOUT") cmd.Flags().Bool(flagSigOnly, true, "Print only the generated signature, then exit") cmd.Flags().String(flags.FlagChainID, "", "network chain ID") - cmd.Flags().Bool(FlagAmino, false, "Generate Amino encoded JSON suitable for submiting to the txs REST endpoint") + cmd.Flags().Bool(flagAmino, false, "Generate Amino encoded JSON suitable for submiting to the txs REST endpoint") cmd.MarkFlagRequired(flags.FlagFrom) flags.AddTxFlagsToCmd(cmd) @@ -187,7 +188,7 @@ be generated via the 'multisign' command. cmd.Flags().Bool(flagSigOnly, false, "Print only the signatures") cmd.Flags().String(flags.FlagOutputDocument, "", "The document will be written to the given file instead of STDOUT") cmd.Flags().String(flags.FlagChainID, "", "The network chain ID") - cmd.Flags().Bool(FlagAmino, false, "Generate Amino encoded JSON suitable for submiting to the txs REST endpoint") + cmd.Flags().Bool(flagAmino, false, "Generate Amino encoded JSON suitable for submiting to the txs REST endpoint") cmd.MarkFlagRequired(flags.FlagFrom) flags.AddTxFlagsToCmd(cmd) @@ -250,7 +251,7 @@ func makeSignCmd() func(cmd *cobra.Command, args []string) error { return err } - aminoJSON, err := f.GetBool(FlagAmino) + aminoJSON, err := f.GetBool(flagAmino) if err != nil { return err } From de35defbff46c0b7d3f8f4ea90a6fa4510ba3bae Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Wed, 24 Feb 2021 02:20:03 +0530 Subject: [PATCH 28/35] code refactor --- client/cmd.go | 2 +- x/auth/client/cli/tx_multisign.go | 50 +++++++++++++++---------------- x/auth/client/cli/tx_sign.go | 1 - 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/client/cmd.go b/client/cmd.go index 437022695d47..7bb8d315397d 100644 --- a/client/cmd.go +++ b/client/cmd.go @@ -102,7 +102,7 @@ func ReadPersistentCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Cont if clientCtx.KeyringDir == "" || flagSet.Changed(flags.FlagKeyringDir) { keyringDir, _ := flagSet.GetString(flags.FlagKeyringDir) - // The keyring directory is optional and falls back to the home directory + // The keyring directory is optionakbl and falls back to the home directory // if omitted. if keyringDir == "" { keyringDir = clientCtx.HomeDir diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index da09b582f3fa..3ec6c1957e50 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -1,7 +1,6 @@ package cli import ( - "bufio" "fmt" "io/ioutil" "os" @@ -84,20 +83,9 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) { return err } - backend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend) - - inBuf := bufio.NewReader(cmd.InOrStdin()) - kb, err := keyring.New(sdk.KeyringServiceName(), backend, clientCtx.HomeDir, inBuf) - if err != nil { - return - } - - multisigInfo, err := kb.Key(args[1]) + multisigInfo, err := getMultisigInfo(clientCtx, args[1]) if err != nil { - return - } - if multisigInfo.GetType() != keyring.TypeMulti { - return fmt.Errorf("%q must be of type %s: %s", args[1], keyring.TypeMulti, multisigInfo.GetType()) + return err } multisigPub := multisigInfo.GetPubKey().(*kmultisig.LegacyAminoPubKey) @@ -247,13 +235,9 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { } scanner := authclient.NewBatchScanner(txCfg, infile) - kb := clientCtx.Keyring - multisigInfo, err := kb.Key(args[1]) + multisigInfo, err := getMultisigInfo(clientCtx, args[1]) if err != nil { - return errors.Wrap(err, "error getting keybase multisig account") - } - if multisigInfo.GetType() != keyring.TypeMulti { - return fmt.Errorf("%q must be of type %s: %s", args[1], keyring.TypeMulti, multisigInfo.GetType()) + return err } var signatureBatch [][]signingtypes.SignatureV2 @@ -283,15 +267,16 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { multisigPub := multisigInfo.GetPubKey().(*kmultisig.LegacyAminoPubKey) multisigSig := multisig.NewMultisig(len(multisigPub.PubKeys)) + signingData := signing.SignerData{ + ChainID: txFactory.ChainID(), + AccountNumber: txFactory.AccountNumber(), + Sequence: txFactory.Sequence(), + } + for _, sig := range signatureBatch { - signingData := signing.SignerData{ - ChainID: txFactory.ChainID(), - AccountNumber: txFactory.AccountNumber(), - Sequence: txFactory.Sequence(), - } err = signing.VerifySignature(sig[i].PubKey, signingData, sig[i].Data, txCfg.SignModeHandler(), txBldr.GetTx()) if err != nil { - return fmt.Errorf("couldn't verify signature: %w %v %v", err, signingData, sig) + return fmt.Errorf("couldn't verify signature: %w %v", err, sig) } if err := multisig.AddSignatureV2(multisigSig, sig[i], multisigPub.GetPubKeys()); err != nil { @@ -378,3 +363,16 @@ func readSignaturesFromFile(ctx client.Context, filename string) (sigs []signing } return sigs, nil } + +func getMultisigInfo(clientCtx client.Context, name string) (keyring.Info, error) { + kb := clientCtx.Keyring + multisigInfo, err := kb.Key(name) + if err != nil { + return nil, errors.Wrap(err, "error getting keybase multisig account") + } + if multisigInfo.GetType() != keyring.TypeMulti { + return nil, fmt.Errorf("%q must be of type %s: %s", name, keyring.TypeMulti, multisigInfo.GetType()) + } + + return multisigInfo, nil +} diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 986db65cdac8..74173f6b08cb 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -53,7 +53,6 @@ account key. It implies --signature-only. cmd.Flags().String(flags.FlagOutputDocument, "", "The document will be written to the given file instead of STDOUT") cmd.Flags().Bool(flagSigOnly, true, "Print only the generated signature, then exit") cmd.Flags().String(flags.FlagChainID, "", "network chain ID") - cmd.Flags().Bool(flagAmino, false, "Generate Amino encoded JSON suitable for submiting to the txs REST endpoint") cmd.MarkFlagRequired(flags.FlagFrom) flags.AddTxFlagsToCmd(cmd) From c622dac90fb1fa27999f5b818c79259c59431df8 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Wed, 24 Feb 2021 02:21:50 +0530 Subject: [PATCH 29/35] fix typo --- client/cmd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/cmd.go b/client/cmd.go index 7bb8d315397d..437022695d47 100644 --- a/client/cmd.go +++ b/client/cmd.go @@ -102,7 +102,7 @@ func ReadPersistentCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Cont if clientCtx.KeyringDir == "" || flagSet.Changed(flags.FlagKeyringDir) { keyringDir, _ := flagSet.GetString(flags.FlagKeyringDir) - // The keyring directory is optionakbl and falls back to the home directory + // The keyring directory is optional and falls back to the home directory // if omitted. if keyringDir == "" { keyringDir = clientCtx.HomeDir From e18022daa3b858806dddb73301e82a5ab2dc826c Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Wed, 24 Feb 2021 02:38:26 +0530 Subject: [PATCH 30/35] update docs --- simapp/simd/cmd/root.go | 1 + x/auth/client/cli/tx_multisign.go | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index f76948d59cd5..836036bcf08c 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -136,6 +136,7 @@ func txCommand() *cobra.Command { authcmd.GetSignCommand(), authcmd.GetSignBatchCommand(), authcmd.GetMultiSignCommand(), + authcmd.GetMultiSignBatchCmd(), authcmd.GetValidateSignaturesCommand(), flags.LineBreak, authcmd.GetBroadcastCommand(), diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 3ec6c1957e50..d0db2d101a56 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -36,7 +36,7 @@ Read signature(s) from [signature] file(s), generate a multisig signature compli multisig key [name], and attach it to the transaction read from [file]. Example: -$ %s multisign transaction.json k1k2k3 k1sig.json k2sig.json k3sig.json +$ %s tx multisign transaction.json k1k2k3 k1sig.json k2sig.json k3sig.json If the flag --signature-only flag is on, it outputs a JSON representation of the generated signature only. @@ -44,6 +44,9 @@ of the generated signature only. The --offline flag makes sure that the client will not reach out to an external node. Thus account number or sequence number lookups will not be performed and it is recommended to set such parameters manually. + +The current multisig implementation doesn't support sign_mode_direct and defaults +to amino-json sign mode.' `, version.AppName, ), @@ -188,9 +191,22 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) { func GetMultiSignBatchCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "multisign-batch [file] [name] [[signature-file]...]", - Short: "Assemble multisig transactions", - Long: `Assemble a batch of multisig transactions generated by batch sign command.`, + Use: "multisign-batch [file] [name] [[signature-file]...]", + Short: "Assemble multisig transactions in batch from batch signatures", + Long: strings.TrimSpace( + fmt.Sprintf(`SAssemble a batch of multisig transactions generated by batch sign command. + +Read signature(s) from [signature] file(s), generates multisig signatures compliant to the +multisig key [name], and attach it to the transactions read from [file]. + +Example: +$ %s tx multisign-batch transactions.json k1k2k3 k1sigs.json k2sigs.json k3sig.json + +The current multisig implementation doesn't support sign_mode_direct and defaults +to amino-json sign mode.' +`, version.AppName, + ), + ), PreRun: preSignCmd, RunE: makeBatchMultisignCmd(), Args: cobra.MinimumNArgs(3), From b6661d1fd0f9bb6070efb5a9c9c31207d07bdbb1 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Wed, 24 Feb 2021 02:41:29 +0530 Subject: [PATCH 31/35] update test --- x/auth/client/cli/cli_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index 90392318688d..6cd102cade97 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -877,6 +877,7 @@ func (s *IntegrationTestSuite) TestMultisignBatch() { res, err = authtest.TxMultiSignBatchExec(val.ClientCtx, filename.Name(), multisigInfo.GetName(), file1.Name(), file2.Name()) s.Require().NoError(err) signedTxs := strings.Split(strings.Trim(res.String(), "\n"), "\n") + // Broadcast transactions. for _, signedTx := range signedTxs { signedTxFile := testutil.WriteToNewTempFile(s.T(), signedTx) From 1397f47da0c0a8e7fb05d8b9ccc4507ea475295e Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Wed, 24 Feb 2021 12:53:55 +0000 Subject: [PATCH 32/35] Update x/auth/client/cli/tx_multisign.go --- x/auth/client/cli/tx_multisign.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index d0db2d101a56..a09c4f0ca947 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -45,7 +45,7 @@ The --offline flag makes sure that the client will not reach out to an external Thus account number or sequence number lookups will not be performed and it is recommended to set such parameters manually. -The current multisig implementation doesn't support sign_mode_direct and defaults +The current multisig implementation doesn't support SIGN_MORE_DIRECT and defaults to amino-json sign mode.' `, version.AppName, From 0580c12f8b5de731eada8e0c13044e640bdfbedd Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Wed, 24 Feb 2021 15:57:32 +0000 Subject: [PATCH 33/35] use named return values and explicit return --- x/auth/client/cli/tx_multisign.go | 6 ++++-- x/auth/client/cli/tx_sign.go | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index a09c4f0ca947..c52d97335e5a 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -223,8 +223,10 @@ to amino-json sign mode.' } func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { - return func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) + return func(cmd *cobra.Command, args []string) (err error) { + var clientCtx client.Context + + clientCtx, err = client.GetClientTxContext(cmd) if err != nil { return err } diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 74173f6b08cb..955554512125 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -204,8 +204,10 @@ func preSignCmd(cmd *cobra.Command, _ []string) { } func makeSignCmd() func(cmd *cobra.Command, args []string) error { - return func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) + return func(cmd *cobra.Command, args []string) (err error) { + var clientCtx client.Context + + clientCtx, err = client.GetClientTxContext(cmd) if err != nil { return err } From ba5f3b1a6b419aa4c885215ee1805c4500d989fa Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Wed, 24 Feb 2021 19:31:44 +0000 Subject: [PATCH 34/35] Update x/auth/client/cli/tx_multisign.go Co-authored-by: Robert Zaremba --- x/auth/client/cli/tx_multisign.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index c52d97335e5a..13292a6dcf28 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -194,7 +194,7 @@ func GetMultiSignBatchCmd() *cobra.Command { Use: "multisign-batch [file] [name] [[signature-file]...]", Short: "Assemble multisig transactions in batch from batch signatures", Long: strings.TrimSpace( - fmt.Sprintf(`SAssemble a batch of multisig transactions generated by batch sign command. + fmt.Sprintf(`Assemble a batch of multisig transactions generated by batch sign command. Read signature(s) from [signature] file(s), generates multisig signatures compliant to the multisig key [name], and attach it to the transactions read from [file]. From 98dce412cae92592c863ffa3ecc5cb7fc3cf486f Mon Sep 17 00:00:00 2001 From: SaReN Date: Thu, 25 Feb 2021 01:14:31 +0530 Subject: [PATCH 35/35] Update x/auth/client/cli/tx_multisign.go Co-authored-by: Robert Zaremba --- x/auth/client/cli/tx_multisign.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 13292a6dcf28..61ec84bdc219 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -200,7 +200,7 @@ Read signature(s) from [signature] file(s), generates multisig signatures compli multisig key [name], and attach it to the transactions read from [file]. Example: -$ %s tx multisign-batch transactions.json k1k2k3 k1sigs.json k2sigs.json k3sig.json +$ %s tx multisign-batch transactions.json multisigk1k2k3 k1sigs.json k2sigs.json k3sig.json The current multisig implementation doesn't support sign_mode_direct and defaults to amino-json sign mode.'