Skip to content

Commit

Permalink
fix: multisig works with only multisig name as argument, not its addr…
Browse files Browse the repository at this point in the history
…ess (backport cosmos#11197) (cosmos#11348)

* fix: multisig works with only multisig name as argument, not its address (cosmos#11197)

## Description

Closes: cosmos#11196
ref: https://github.com/terra-money/core/issues/570

multisig flag now works with both address and name as arguments for signing

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)

(cherry picked from commit efdedf3)

# Conflicts:
#	CHANGELOG.md

* fix tests

* fix conflicts

Co-authored-by: likhita-809 <78951027+likhita-809@users.noreply.github.com>
Co-authored-by: likhita-809 <likhita@vitwit.com>
Co-authored-by: marbar3778 <marbar3778@yahoo.com>
  • Loading branch information
4 people authored and randy75828 committed Aug 10, 2022
1 parent 7b7afcb commit 2e200ce
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* [\#11197](https://github.com/cosmos/cosmos-sdk/pull/11197) Signing with multisig now works with multisig address which is not in the keyring.
* (client) [\#11283](https://github.com/cosmos/cosmos-sdk/issues/11283) Support multiple keys for tx simulation and setting automatic gas for txs.
* (store) [\#11177](https://github.com/cosmos/cosmos-sdk/pull/11177) Update the prune `everything` strategy to store the last two heights.
* (store) [\#11117](https://github.com/cosmos/cosmos-sdk/pull/11117) Fix data race in store trace component
Expand Down
9 changes: 7 additions & 2 deletions x/auth/client/cli/tx_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
)

Expand Down Expand Up @@ -234,9 +235,13 @@ func makeSignCmd() func(cmd *cobra.Command, args []string) error {

overwrite, _ := f.GetBool(flagOverwrite)
if multisig != "" {
multisigAddr, _, _, err := client.GetFromFields(txFactory.Keybase(), multisig, clientCtx.GenerateOnly)
multisigAddr, err := sdk.AccAddressFromBech32(multisig)
if err != nil {
return fmt.Errorf("error getting account from keybase: %w", err)
// Bech32 decode error, maybe it's a name, we try to fetch from keyring
multisigAddr, _, _, err = client.GetFromFields(txFactory.Keybase(), multisig, clientCtx.GenerateOnly)
if err != nil {
return fmt.Errorf("error getting account from keybase: %w", err)
}
}
err = authclient.SignTxWithSignerAddress(
txF, clientCtx, multisigAddr, fromName, txBuilder, clientCtx.Offline, overwrite)
Expand Down
41 changes: 41 additions & 0 deletions x/auth/client/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,47 @@ func (s *IntegrationTestSuite) TestCLIMultisignSortSignatures() {
s.Require().NoError(s.network.WaitForNextBlock())
}

func (s *IntegrationTestSuite) TestSignWithMultisig() {
val1 := s.network.Validators[0]

// Generate a account for signing.
account1, err := val1.ClientCtx.Keyring.Key("newAccount1")
s.Require().NoError(err)

addr1 := account1.GetAddress()
s.Require().NoError(err)

// Create an address that is not in the keyring, will be used to simulate `--multisig`
multisig := "cosmos1hd6fsrvnz6qkp87s3u86ludegq97agxsdkwzyh"
multisigAddr, err := sdk.AccAddressFromBech32(multisig)
s.Require().NoError(err)

// Generate a transaction for testing --multisig with an address not in the keyring.
multisigTx, err := bankcli.MsgSendExec(
val1.ClientCtx,
val1.Address,
val1.Address,
sdk.NewCoins(
sdk.NewInt64Coin(s.cfg.BondDenom, 5),
),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
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)

// Save multi tx to file
multiGeneratedTx2File := testutil.WriteToNewTempFile(s.T(), multisigTx.String())

// Sign using multisig. We're signing a tx on behalf of the multisig address,
// even though the tx signer is NOT the multisig address. This is fine though,
// as the main point of this test is to test the `--multisig` flag with an address
// that is not in the keyring.
_, err = TxSignExec(val1.ClientCtx, addr1, multiGeneratedTx2File.Name(), "--multisig", multisigAddr.String())
s.Require().Contains(err.Error(), "tx intended signer does not match the given signer")
}

func (s *IntegrationTestSuite) TestCLIMultisign() {
val1 := s.network.Validators[0]

Expand Down

0 comments on commit 2e200ce

Please sign in to comment.