From 20ed4213b1d914b4069896821502e7c85cf4fa40 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 21 Oct 2022 12:48:42 +0530 Subject: [PATCH 1/6] wip: fix dry run returning key not found error --- client/cmd.go | 2 +- client/context.go | 14 ++++++++++---- x/auth/client/cli/tx_sign.go | 8 ++++---- x/feegrant/client/testutil/suite.go | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/client/cmd.go b/client/cmd.go index 6ea3b3e66fba..5a58a1092d85 100644 --- a/client/cmd.go +++ b/client/cmd.go @@ -235,7 +235,7 @@ func readTxCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, err if clientCtx.From == "" || flagSet.Changed(flags.FlagFrom) { from, _ := flagSet.GetString(flags.FlagFrom) - fromAddr, fromName, keyType, err := GetFromFields(clientCtx.Keyring, from, clientCtx.GenerateOnly) + fromAddr, fromName, keyType, err := GetFromFields(clientCtx.Keyring, from, clientCtx.GenerateOnly, clientCtx.Simulate) if err != nil { return clientCtx, err } diff --git a/client/context.go b/client/context.go index eedbdf6fdb65..b2c83f9ee3c6 100644 --- a/client/context.go +++ b/client/context.go @@ -333,13 +333,19 @@ func (ctx Context) printOutput(out []byte) error { // GetFromFields returns a from account address, account name and keyring type, given either // an address or key name. If genOnly is true, only a valid Bech32 cosmos // address is returned. -func GetFromFields(kr keyring.Keyring, from string, genOnly bool) (sdk.AccAddress, string, keyring.KeyType, error) { +func GetFromFields(kr keyring.Keyring, from string, genOnly bool, simulate bool) (sdk.AccAddress, string, keyring.KeyType, error) { if from == "" { return nil, "", 0, nil } - if genOnly { - addr, err := sdk.AccAddressFromBech32(from) + addr, err := sdk.AccAddressFromBech32(from) + switch { + case simulate: + if err != nil { + return nil, "", 0, errors.Wrap(err, "a valid bech32 address must be provided in simulation mode") + } + return addr, "", 0, nil + case genOnly: if err != nil { return nil, "", 0, errors.Wrap(err, "must provide a valid Bech32 address in generate-only mode") } @@ -365,7 +371,7 @@ func GetFromFields(kr keyring.Keyring, from string, genOnly bool) (sdk.AccAddres // NewKeyringFromBackend gets a Keyring object from a backend func NewKeyringFromBackend(ctx Context, backend string) (keyring.Keyring, error) { - if ctx.GenerateOnly || ctx.Simulate { + if ctx.Simulate { return keyring.New(sdk.KeyringServiceName(), keyring.BackendMemory, ctx.KeyringDir, ctx.Input, ctx.KeyringOptions...) } diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 09be9bbb589d..dd635801cbbd 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -99,7 +99,7 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { } if ms == "" { from, _ := cmd.Flags().GetString(flags.FlagFrom) - _, fromName, _, err := client.GetFromFields(txFactory.Keybase(), from, clientCtx.GenerateOnly) + _, fromName, _, err := client.GetFromFields(txFactory.Keybase(), from, clientCtx.GenerateOnly, clientCtx.Simulate) if err != nil { return fmt.Errorf("error getting account from keybase: %w", err) } @@ -108,7 +108,7 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { return err } } else { - multisigAddr, _, _, err := client.GetFromFields(txFactory.Keybase(), ms, clientCtx.GenerateOnly) + multisigAddr, _, _, err := client.GetFromFields(txFactory.Keybase(), ms, clientCtx.GenerateOnly, clientCtx.Simulate) if err != nil { return fmt.Errorf("error getting account from keybase: %w", err) } @@ -228,7 +228,7 @@ func makeSignCmd() func(cmd *cobra.Command, args []string) error { return err } from, _ := cmd.Flags().GetString(flags.FlagFrom) - _, fromName, _, err := client.GetFromFields(txF.Keybase(), from, clientCtx.GenerateOnly) + _, fromName, _, err := client.GetFromFields(txF.Keybase(), from, clientCtx.GenerateOnly, clientCtx.Simulate) if err != nil { return fmt.Errorf("error getting account from keybase: %w", err) } @@ -238,7 +238,7 @@ func makeSignCmd() func(cmd *cobra.Command, args []string) error { multisigAddr, err := sdk.AccAddressFromBech32(multisig) if err != nil { // Bech32 decode error, maybe it's a name, we try to fetch from keyring - multisigAddr, _, _, err = client.GetFromFields(txFactory.Keybase(), multisig, clientCtx.GenerateOnly) + multisigAddr, _, _, err = client.GetFromFields(txFactory.Keybase(), multisig, clientCtx.GenerateOnly, clientCtx.Simulate) if err != nil { return fmt.Errorf("error getting account from keybase: %w", err) } diff --git a/x/feegrant/client/testutil/suite.go b/x/feegrant/client/testutil/suite.go index 781bc017b043..c90c2a9eb871 100644 --- a/x/feegrant/client/testutil/suite.go +++ b/x/feegrant/client/testutil/suite.go @@ -313,7 +313,7 @@ func (s *IntegrationTestSuite) TestNewCmdFeeGrant() { alreadyExistedGrantee := s.addedGrantee clientCtx := val.ClientCtx - fromAddr, fromName, _, err := client.GetFromFields(clientCtx.Keyring, granter.String(), clientCtx.GenerateOnly) + fromAddr, fromName, _, err := client.GetFromFields(clientCtx.Keyring, granter.String(), clientCtx.GenerateOnly, clientCtx.Simulate) s.Require().Equal(fromAddr, granter) s.Require().NoError(err) From d1e2f58fcc20ba0a11398af0b6c6ec4504470704 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 27 Oct 2022 12:03:25 +0530 Subject: [PATCH 2/6] fix something --- client/tx/factory.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/tx/factory.go b/client/tx/factory.go index ebd43b7480ad..6297d00f65ec 100644 --- a/client/tx/factory.go +++ b/client/tx/factory.go @@ -284,7 +284,7 @@ func (f Factory) BuildSimTx(msgs ...sdk.Msg) ([]byte, error) { var pk cryptotypes.PubKey = &secp256k1.PubKey{} // use default public key type - if f.keybase != nil { + if f.simulateAndExecute && f.keybase != nil { infos, _ := f.keybase.List() if len(infos) == 0 { return nil, errors.New("cannot build signature for simulation, key infos slice is empty") From 12016c3aea161a06b3950279645b57f8f7b923fc Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 27 Oct 2022 14:40:58 +0530 Subject: [PATCH 3/6] add changelog and tests --- CHANGELOG.md | 1 + client/context.go | 2 +- client/context_test.go | 108 ++++++++++++++++++++++++++++++++++++++ client/flags/flags.go | 2 +- crypto/keyring/keyring.go | 4 +- x/bank/client/cli/tx.go | 5 +- 6 files changed, 116 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fb92147a9dc..5d47cb567e20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* [#13673](https://github.com/cosmos/cosmos-sdk/pull/13673) Fix `--dry-run` flag not working when using tx command. * [#13046](https://github.com/cosmos/cosmos-sdk/pull/13046) Fix missing return statement in BaseApp.Query. ## v0.45.7 - 2022-08-04 diff --git a/client/context.go b/client/context.go index b2c83f9ee3c6..9cb5afa46ea7 100644 --- a/client/context.go +++ b/client/context.go @@ -354,7 +354,7 @@ func GetFromFields(kr keyring.Keyring, from string, genOnly bool, simulate bool) } var info keyring.Info - if addr, err := sdk.AccAddressFromBech32(from); err == nil { + if err == nil { info, err = kr.KeyByAddress(addr) if err != nil { return nil, "", 0, err diff --git a/client/context_test.go b/client/context_test.go index 9c2e8d4ab19e..2c073009c8d5 100644 --- a/client/context_test.go +++ b/client/context_test.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "os" + "strings" "testing" "github.com/spf13/viper" @@ -13,6 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil/network" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -113,3 +115,109 @@ func TestCLIQueryConn(t *testing.T) { require.NoError(t, err) require.Equal(t, "hello", res.Message) } + +func TestGetFromFields(t *testing.T) { + ctx := client.Context{} + path := hd.CreateHDPath(118, 0, 0).String() + + testCases := []struct { + clientCtx client.Context + keyring func() keyring.Keyring + from string + expectedErr string + }{ + { + keyring: func() keyring.Keyring { + kb := keyring.NewInMemory() + + _, _, err := kb.NewMnemonic("alice", keyring.English, path, keyring.DefaultBIP39Passphrase, hd.Secp256k1) + require.NoError(t, err) + + return kb + }, + from: "alice", + }, + { + keyring: func() keyring.Keyring { + kb, err := keyring.New(t.Name(), keyring.BackendTest, t.TempDir(), nil, ctx.KeyringOptions...) + require.NoError(t, err) + + _, _, err = kb.NewMnemonic("alice", keyring.English, path, keyring.DefaultBIP39Passphrase, hd.Secp256k1) + require.NoError(t, err) + + return kb + }, + from: "alice", + }, + { + keyring: func() keyring.Keyring { + return keyring.NewInMemory() + }, + from: "cosmos139f7kncmglres2nf3h4hc4tade85ekfr8sulz5", + expectedErr: "key with address 8953EB4F1B47C7982A698DEB7C557D6E4F4CD923 not found: key not found", + }, + { + keyring: func() keyring.Keyring { + kb, err := keyring.New(t.Name(), keyring.BackendTest, t.TempDir(), nil, ctx.KeyringOptions...) + require.NoError(t, err) + return kb + }, + from: "alice", + expectedErr: "alice.info: key not found", + }, + { + keyring: func() keyring.Keyring { + return keyring.NewInMemory() + }, + from: "cosmos139f7kncmglres2nf3h4hc4tade85ekfr8sulz5", + clientCtx: client.Context{}.WithSimulation(true), + }, + { + keyring: func() keyring.Keyring { + return keyring.NewInMemory() + }, + from: "alice", + clientCtx: client.Context{}.WithSimulation(true), + expectedErr: "a valid bech32 address must be provided in simulation mode", + }, + { + keyring: func() keyring.Keyring { + return keyring.NewInMemory() + }, + from: "cosmos139f7kncmglres2nf3h4hc4tade85ekfr8sulz5", + clientCtx: client.Context{}.WithGenerateOnly(true), + }, + { + keyring: func() keyring.Keyring { + return keyring.NewInMemory() + }, + from: "alice", + clientCtx: client.Context{}.WithGenerateOnly(true), + expectedErr: "must provide a valid Bech32 address in generate-only mode", + }, + { + keyring: func() keyring.Keyring { + kb, err := keyring.New(t.Name(), keyring.BackendTest, t.TempDir(), nil, ctx.KeyringOptions...) + require.NoError(t, err) + + _, _, err = kb.NewMnemonic("alice", keyring.English, path, keyring.DefaultBIP39Passphrase, hd.Secp256k1) + require.NoError(t, err) + + return kb + }, + clientCtx: client.Context{}.WithGenerateOnly(true), + from: "alice", + expectedErr: "must provide a valid Bech32 address in generate-only mode", + }, + } + + for _, tc := range testCases { + _, _, _, err := client.GetFromFields(tc.keyring(), tc.from, tc.clientCtx.GenerateOnly, tc.clientCtx.Simulate) + if tc.expectedErr == "" { + require.NoError(t, err) + } else { + require.True(t, strings.HasPrefix(err.Error(), tc.expectedErr)) + } + + } +} diff --git a/client/flags/flags.go b/client/flags/flags.go index cfc0242c1023..d29036f94fc2 100644 --- a/client/flags/flags.go +++ b/client/flags/flags.go @@ -107,7 +107,7 @@ func AddTxFlagsToCmd(cmd *cobra.Command) { cmd.Flags().Bool(FlagUseLedger, false, "Use a connected Ledger device") cmd.Flags().Float64(FlagGasAdjustment, DefaultGasAdjustment, "adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored ") cmd.Flags().StringP(FlagBroadcastMode, "b", BroadcastSync, "Transaction broadcasting mode (sync|async|block)") - cmd.Flags().Bool(FlagDryRun, false, "ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it") + cmd.Flags().Bool(FlagDryRun, false, "ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it (when enabled, the local Keybase is not accessible)") cmd.Flags().Bool(FlagGenerateOnly, false, "Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase is not accessible)") cmd.Flags().Bool(FlagOffline, false, "Offline mode (does not allow any online functionality") cmd.Flags().BoolP(FlagSkipConfirmation, "y", false, "Skip tx broadcasting prompt confirmation") diff --git a/crypto/keyring/keyring.go b/crypto/keyring/keyring.go index 183a9fe9905e..8cd671ea0300 100644 --- a/crypto/keyring/keyring.go +++ b/crypto/keyring/keyring.go @@ -451,11 +451,11 @@ func (ks keystore) Delete(uid string) error { func (ks keystore) KeyByAddress(address sdk.Address) (Info, error) { ik, err := ks.db.Get(addrHexKeyAsString(address)) if err != nil { - return nil, wrapKeyNotFound(err, fmt.Sprint("key with address", address, "not found")) + return nil, wrapKeyNotFound(err, fmt.Sprint("key with address ", address, " not found")) } if len(ik.Data) == 0 { - return nil, wrapKeyNotFound(err, fmt.Sprint("key with address", address, "not found")) + return nil, wrapKeyNotFound(err, fmt.Sprint("key with address ", address, " not found")) } return ks.key(string(ik.Data)) } diff --git a/x/bank/client/cli/tx.go b/x/bank/client/cli/tx.go index 4fee9ffd1e81..6f4e4269c7a4 100644 --- a/x/bank/client/cli/tx.go +++ b/x/bank/client/cli/tx.go @@ -29,8 +29,9 @@ func NewTxCmd() *cobra.Command { func NewSendTxCmd() *cobra.Command { cmd := &cobra.Command{ Use: "send [from_key_or_address] [to_address] [amount]", - Short: `Send funds from one account to another. Note, the'--from' flag is -ignored as it is implied from [from_key_or_address].`, + Short: `Send funds from one account to another. + Note, the'--from' flag is ignored as it is implied from [from_key_or_address]. + When using '--dry-run' a key name cannot be used, only a bech32 address.`, Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { cmd.Flags().Set(flags.FlagFrom, args[0]) From 255042931acc1b5260dc47e462698fa1466403de Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 28 Oct 2022 10:57:06 +0530 Subject: [PATCH 4/6] address review comments --- client/cmd.go | 2 +- client/context.go | 6 +++--- client/context_test.go | 2 +- x/auth/client/cli/tx_sign.go | 8 ++++---- x/feegrant/client/testutil/suite.go | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/client/cmd.go b/client/cmd.go index 5a58a1092d85..af0d2d6a7407 100644 --- a/client/cmd.go +++ b/client/cmd.go @@ -235,7 +235,7 @@ func readTxCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, err if clientCtx.From == "" || flagSet.Changed(flags.FlagFrom) { from, _ := flagSet.GetString(flags.FlagFrom) - fromAddr, fromName, keyType, err := GetFromFields(clientCtx.Keyring, from, clientCtx.GenerateOnly, clientCtx.Simulate) + fromAddr, fromName, keyType, err := GetFromFields(clientCtx, clientCtx.Keyring, from) if err != nil { return clientCtx, err } diff --git a/client/context.go b/client/context.go index 9cb5afa46ea7..ecea496c5490 100644 --- a/client/context.go +++ b/client/context.go @@ -333,19 +333,19 @@ func (ctx Context) printOutput(out []byte) error { // GetFromFields returns a from account address, account name and keyring type, given either // an address or key name. If genOnly is true, only a valid Bech32 cosmos // address is returned. -func GetFromFields(kr keyring.Keyring, from string, genOnly bool, simulate bool) (sdk.AccAddress, string, keyring.KeyType, error) { +func GetFromFields(clientCtx Context, kr keyring.Keyring, from string) (sdk.AccAddress, string, keyring.KeyType, error) { if from == "" { return nil, "", 0, nil } addr, err := sdk.AccAddressFromBech32(from) switch { - case simulate: + case clientCtx.Simulate: if err != nil { return nil, "", 0, errors.Wrap(err, "a valid bech32 address must be provided in simulation mode") } return addr, "", 0, nil - case genOnly: + case clientCtx.GenerateOnly: if err != nil { return nil, "", 0, errors.Wrap(err, "must provide a valid Bech32 address in generate-only mode") } diff --git a/client/context_test.go b/client/context_test.go index 2c073009c8d5..183d7617983a 100644 --- a/client/context_test.go +++ b/client/context_test.go @@ -212,7 +212,7 @@ func TestGetFromFields(t *testing.T) { } for _, tc := range testCases { - _, _, _, err := client.GetFromFields(tc.keyring(), tc.from, tc.clientCtx.GenerateOnly, tc.clientCtx.Simulate) + _, _, _, err := client.GetFromFields(tc.clientCtx, tc.keyring(), tc.from) if tc.expectedErr == "" { require.NoError(t, err) } else { diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index dd635801cbbd..fa5e233d961b 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -99,7 +99,7 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { } if ms == "" { from, _ := cmd.Flags().GetString(flags.FlagFrom) - _, fromName, _, err := client.GetFromFields(txFactory.Keybase(), from, clientCtx.GenerateOnly, clientCtx.Simulate) + _, fromName, _, err := client.GetFromFields(clientCtx, txFactory.Keybase(), from) if err != nil { return fmt.Errorf("error getting account from keybase: %w", err) } @@ -108,7 +108,7 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { return err } } else { - multisigAddr, _, _, err := client.GetFromFields(txFactory.Keybase(), ms, clientCtx.GenerateOnly, clientCtx.Simulate) + multisigAddr, _, _, err := client.GetFromFields(clientCtx, txFactory.Keybase(), ms) if err != nil { return fmt.Errorf("error getting account from keybase: %w", err) } @@ -228,7 +228,7 @@ func makeSignCmd() func(cmd *cobra.Command, args []string) error { return err } from, _ := cmd.Flags().GetString(flags.FlagFrom) - _, fromName, _, err := client.GetFromFields(txF.Keybase(), from, clientCtx.GenerateOnly, clientCtx.Simulate) + _, fromName, _, err := client.GetFromFields(clientCtx, txF.Keybase(), from) if err != nil { return fmt.Errorf("error getting account from keybase: %w", err) } @@ -238,7 +238,7 @@ func makeSignCmd() func(cmd *cobra.Command, args []string) error { multisigAddr, err := sdk.AccAddressFromBech32(multisig) if err != nil { // Bech32 decode error, maybe it's a name, we try to fetch from keyring - multisigAddr, _, _, err = client.GetFromFields(txFactory.Keybase(), multisig, clientCtx.GenerateOnly, clientCtx.Simulate) + multisigAddr, _, _, err = client.GetFromFields(clientCtx, txFactory.Keybase(), multisig) if err != nil { return fmt.Errorf("error getting account from keybase: %w", err) } diff --git a/x/feegrant/client/testutil/suite.go b/x/feegrant/client/testutil/suite.go index c90c2a9eb871..fff5475170dc 100644 --- a/x/feegrant/client/testutil/suite.go +++ b/x/feegrant/client/testutil/suite.go @@ -313,7 +313,7 @@ func (s *IntegrationTestSuite) TestNewCmdFeeGrant() { alreadyExistedGrantee := s.addedGrantee clientCtx := val.ClientCtx - fromAddr, fromName, _, err := client.GetFromFields(clientCtx.Keyring, granter.String(), clientCtx.GenerateOnly, clientCtx.Simulate) + fromAddr, fromName, _, err := client.GetFromFields(clientCtx, clientCtx.Keyring, granter.String()) s.Require().Equal(fromAddr, granter) s.Require().NoError(err) From 24df7ab3bde99e195fb492580bbbdcf9f467e2ad Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 28 Oct 2022 12:57:42 +0530 Subject: [PATCH 5/6] add api breaking changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d47cb567e20..32555f83a786 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#13673](https://github.com/cosmos/cosmos-sdk/pull/13673) Fix `--dry-run` flag not working when using tx command. * [#13046](https://github.com/cosmos/cosmos-sdk/pull/13046) Fix missing return statement in BaseApp.Query. +### API Breaking Changes + +* [#13673](https://github.com/cosmos/cosmos-sdk/pull/13673) The `GetFromFields` function now takes `Context` as an argument and removes `genOnly`. + ## v0.45.7 - 2022-08-04 ### Features From 1a2daf6d292f0c017cef0031cf485112fc2b1b2b Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Mon, 31 Oct 2022 20:07:04 +0530 Subject: [PATCH 6/6] add name field to GetFromFields testcases --- client/context_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/client/context_test.go b/client/context_test.go index 183d7617983a..e94fbff3b563 100644 --- a/client/context_test.go +++ b/client/context_test.go @@ -121,12 +121,14 @@ func TestGetFromFields(t *testing.T) { path := hd.CreateHDPath(118, 0, 0).String() testCases := []struct { + name string clientCtx client.Context keyring func() keyring.Keyring from string expectedErr string }{ { + name: "valid key alice from memory keyring", keyring: func() keyring.Keyring { kb := keyring.NewInMemory() @@ -138,6 +140,7 @@ func TestGetFromFields(t *testing.T) { from: "alice", }, { + name: "valid key alice from test keyring", keyring: func() keyring.Keyring { kb, err := keyring.New(t.Name(), keyring.BackendTest, t.TempDir(), nil, ctx.KeyringOptions...) require.NoError(t, err) @@ -150,6 +153,7 @@ func TestGetFromFields(t *testing.T) { from: "alice", }, { + name: "address not present in memory keyring", keyring: func() keyring.Keyring { return keyring.NewInMemory() }, @@ -157,6 +161,7 @@ func TestGetFromFields(t *testing.T) { expectedErr: "key with address 8953EB4F1B47C7982A698DEB7C557D6E4F4CD923 not found: key not found", }, { + name: "key is not from test keyring", keyring: func() keyring.Keyring { kb, err := keyring.New(t.Name(), keyring.BackendTest, t.TempDir(), nil, ctx.KeyringOptions...) require.NoError(t, err) @@ -166,6 +171,7 @@ func TestGetFromFields(t *testing.T) { expectedErr: "alice.info: key not found", }, { + name: "valid bech32 address is allowed when simulation is true", keyring: func() keyring.Keyring { return keyring.NewInMemory() }, @@ -173,6 +179,7 @@ func TestGetFromFields(t *testing.T) { clientCtx: client.Context{}.WithSimulation(true), }, { + name: "only bech32 address is allowed as from key in simulation mode", keyring: func() keyring.Keyring { return keyring.NewInMemory() }, @@ -181,6 +188,7 @@ func TestGetFromFields(t *testing.T) { expectedErr: "a valid bech32 address must be provided in simulation mode", }, { + name: "valid bech32 address is allowed when generate-only is true", keyring: func() keyring.Keyring { return keyring.NewInMemory() }, @@ -188,6 +196,7 @@ func TestGetFromFields(t *testing.T) { clientCtx: client.Context{}.WithGenerateOnly(true), }, { + name: "only bech32 address is allowed as from key in generate-only mode", keyring: func() keyring.Keyring { return keyring.NewInMemory() }, @@ -196,6 +205,7 @@ func TestGetFromFields(t *testing.T) { expectedErr: "must provide a valid Bech32 address in generate-only mode", }, { + name: "only bech32 address is allowed as from key even when key is present in the keyring", keyring: func() keyring.Keyring { kb, err := keyring.New(t.Name(), keyring.BackendTest, t.TempDir(), nil, ctx.KeyringOptions...) require.NoError(t, err)