refactor(client): use address codec (#17503)
This commit is contained in:
parent
029f9ed71e
commit
c6b0bb62ac
@ -44,6 +44,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
### Improvements
|
||||
|
||||
* (client) [#17503](https://github.com/cosmos/cosmos-sdk/pull/17503) Add `client.Context{}.WithAddressCodec`, `WithValidatorAddressCodec`, `WithConsensusAddressCodec` to provide address codecs to the client context. See the [UPGRADING.md](./UPGRADING.md) for more details.
|
||||
* (crypto/keyring) [#17503](https://github.com/cosmos/cosmos-sdk/pull/17503) Simplify keyring interfaces to use `[]byte` instead of `sdk.Address` for addresses.
|
||||
* (all) [#16537](https://github.com/cosmos/cosmos-sdk/pull/16537) Properly propagated `fmt.Errorf` errors and using `errors.New` where appropriate.
|
||||
|
||||
### Bug Fixes
|
||||
@ -52,6 +54,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
### API Breaking Changes
|
||||
|
||||
* (client/keys) [#17503](https://github.com/cosmos/cosmos-sdk/pull/17503) `clientkeys.NewKeyOutput`, `MkConsKeyOutput`, `MkValKeyOutput`, `MkAccKeyOutput`, `MkAccKeysOutput` now take their corresponding address codec instead of using the global SDK config.
|
||||
* (x/staking) [#17336](https://github.com/cosmos/cosmos-sdk/pull/17336) Use collections for `RedelegationByValDstIndexKey`:
|
||||
* remove from `types`: `GetREDByValDstIndexKey`, `GetREDsToValDstIndexKey`
|
||||
* (x/staking) [#17332](https://github.com/cosmos/cosmos-sdk/pull/17332) Use collections for `RedelegationByValSrcIndexKey`:
|
||||
|
||||
31
UPGRADING.md
31
UPGRADING.md
@ -5,7 +5,34 @@ Note, always read the **SimApp** section for more information on application wir
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Migration to Collections
|
||||
### SimApp
|
||||
|
||||
In this section we describe the changes made in Cosmos SDK' SimApp.
|
||||
**These changes are directly applicable to your application wiring.**
|
||||
|
||||
#### Client (`root.go`)
|
||||
|
||||
The `client` package has been refactored to make use of the address codecs (address, validator address, consensus address, etc.).
|
||||
This is part of the work of abstracting the SDK from the global bech32 config.
|
||||
|
||||
This means the address codecs must be provided in the `client.Context` in the application client (usually `root.go`).
|
||||
|
||||
```diff
|
||||
clientCtx = clientCtx.
|
||||
+ WithAddressCodec(addressCodec).
|
||||
+ WithValidatorAddressCodec(validatorAddressCodec).
|
||||
+ WithConsensusAddressCodec(consensusAddressCodec)
|
||||
```
|
||||
|
||||
**When using `depinject` / `app v2`, the client codecs can be provided directly from application config.**
|
||||
|
||||
Refer to SimApp `root_v2.go` and `root.go` for an example with an app v2 and a legacy app.
|
||||
|
||||
### Modules
|
||||
|
||||
#### `**all**`
|
||||
|
||||
##### Migration to Collections
|
||||
|
||||
Most of Cosmos SDK modules have migrated to [collections](https://docs.cosmos.network/main/packages/collections).
|
||||
Many functions have been removed due to this changes as the API can be smaller thanks to collections.
|
||||
@ -78,9 +105,11 @@ for more info.
|
||||
#### Upgrade
|
||||
|
||||
**Users using `depinject` / app v2 do not need any changes, this is abstracted for them.**
|
||||
|
||||
```diff
|
||||
+ app.BaseApp.SetMigrationModuleManager(app.ModuleManager)
|
||||
```
|
||||
|
||||
BaseApp added `SetMigrationModuleManager` for apps to set their ModuleManager which implements `RunMigrationBeginBlock`. This is essential for BaseApp to run `BeginBlock` of upgrade module and inject `ConsensusParams` to context for `beginBlocker` during `beginBlock`.
|
||||
|
||||
#### Events
|
||||
|
||||
@ -251,7 +251,7 @@ func readTxCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, err
|
||||
payer, _ := flagSet.GetString(flags.FlagFeePayer)
|
||||
|
||||
if payer != "" {
|
||||
payerAcc, err := sdk.AccAddressFromBech32(payer)
|
||||
payerAcc, err := clientCtx.AddressCodec.StringToBytes(payer)
|
||||
if err != nil {
|
||||
return clientCtx, err
|
||||
}
|
||||
@ -264,7 +264,7 @@ func readTxCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, err
|
||||
granter, _ := flagSet.GetString(flags.FlagFeeGranter)
|
||||
|
||||
if granter != "" {
|
||||
granterAcc, err := sdk.AccAddressFromBech32(granter)
|
||||
granterAcc, err := clientCtx.AddressCodec.StringToBytes(granter)
|
||||
if err != nil {
|
||||
return clientCtx, err
|
||||
}
|
||||
|
||||
@ -13,6 +13,8 @@ import (
|
||||
"google.golang.org/grpc"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
@ -65,6 +67,11 @@ type Context struct {
|
||||
|
||||
// CmdContext is the context.Context from the Cobra command.
|
||||
CmdContext context.Context
|
||||
|
||||
// Address codecs
|
||||
AddressCodec address.Codec
|
||||
ValidatorAddressCodec address.Codec
|
||||
ConsensusAddressCodec address.Codec
|
||||
}
|
||||
|
||||
// WithCmdContext returns a copy of the context with an updated context.Context,
|
||||
@ -292,6 +299,24 @@ func (ctx Context) WithPreprocessTxHook(preprocessFn PreprocessTxFn) Context {
|
||||
return ctx
|
||||
}
|
||||
|
||||
// WithAddressCodec returns the context with the provided address codec.
|
||||
func (ctx Context) WithAddressCodec(addressCodec address.Codec) Context {
|
||||
ctx.AddressCodec = addressCodec
|
||||
return ctx
|
||||
}
|
||||
|
||||
// WithValidatorAddressCodec returns the context with the provided validator address codec.
|
||||
func (ctx Context) WithValidatorAddressCodec(validatorAddressCodec address.Codec) Context {
|
||||
ctx.ValidatorAddressCodec = validatorAddressCodec
|
||||
return ctx
|
||||
}
|
||||
|
||||
// WithConsensusAddressCodec returns the context with the provided consensus address codec.
|
||||
func (ctx Context) WithConsensusAddressCodec(consensusAddressCodec address.Codec) Context {
|
||||
ctx.ConsensusAddressCodec = consensusAddressCodec
|
||||
return ctx
|
||||
}
|
||||
|
||||
// PrintString prints the raw string to ctx.Output if it's defined, otherwise to os.Stdout
|
||||
func (ctx Context) PrintString(str string) error {
|
||||
return ctx.PrintBytes([]byte(str))
|
||||
@ -365,11 +390,11 @@ func GetFromFields(clientCtx Context, kr keyring.Keyring, from string) (sdk.AccA
|
||||
return nil, "", 0, nil
|
||||
}
|
||||
|
||||
addr, err := sdk.AccAddressFromBech32(from)
|
||||
addr, err := clientCtx.AddressCodec.StringToBytes(from)
|
||||
switch {
|
||||
case clientCtx.Simulate:
|
||||
if err != nil {
|
||||
return nil, "", 0, fmt.Errorf("a valid bech32 address must be provided in simulation mode: %w", err)
|
||||
return nil, "", 0, fmt.Errorf("a valid address must be provided in simulation mode: %w", err)
|
||||
}
|
||||
|
||||
return addr, "", 0, nil
|
||||
|
||||
@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
@ -13,6 +12,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
@ -108,6 +108,7 @@ func TestGetFromFields(t *testing.T) {
|
||||
expectedErr string
|
||||
}{
|
||||
{
|
||||
clientCtx: client.Context{}.WithAddressCodec(addresscodec.NewBech32Codec("cosmos")),
|
||||
keyring: func() keyring.Keyring {
|
||||
kb := keyring.NewInMemory(cfg.Codec)
|
||||
|
||||
@ -119,6 +120,7 @@ func TestGetFromFields(t *testing.T) {
|
||||
from: "alice",
|
||||
},
|
||||
{
|
||||
clientCtx: client.Context{}.WithAddressCodec(addresscodec.NewBech32Codec("cosmos")),
|
||||
keyring: func() keyring.Keyring {
|
||||
kb, err := keyring.New(t.Name(), keyring.BackendTest, t.TempDir(), nil, cfg.Codec)
|
||||
require.NoError(t, err)
|
||||
@ -131,13 +133,15 @@ func TestGetFromFields(t *testing.T) {
|
||||
from: "alice",
|
||||
},
|
||||
{
|
||||
clientCtx: client.Context{}.WithAddressCodec(addresscodec.NewBech32Codec("cosmos")),
|
||||
keyring: func() keyring.Keyring {
|
||||
return keyring.NewInMemory(cfg.Codec)
|
||||
},
|
||||
from: "cosmos139f7kncmglres2nf3h4hc4tade85ekfr8sulz5",
|
||||
expectedErr: "key with address cosmos139f7kncmglres2nf3h4hc4tade85ekfr8sulz5 not found: key not found",
|
||||
expectedErr: "key with given address not found: key not found",
|
||||
},
|
||||
{
|
||||
clientCtx: client.Context{}.WithAddressCodec(addresscodec.NewBech32Codec("cosmos")),
|
||||
keyring: func() keyring.Keyring {
|
||||
kb, err := keyring.New(t.Name(), keyring.BackendTest, t.TempDir(), nil, cfg.Codec)
|
||||
require.NoError(t, err)
|
||||
@ -147,36 +151,37 @@ func TestGetFromFields(t *testing.T) {
|
||||
expectedErr: "alice.info: key not found",
|
||||
},
|
||||
{
|
||||
clientCtx: client.Context{}.WithSimulation(true).WithAddressCodec(addresscodec.NewBech32Codec("cosmos")),
|
||||
keyring: func() keyring.Keyring {
|
||||
return keyring.NewInMemory(cfg.Codec)
|
||||
},
|
||||
from: "cosmos139f7kncmglres2nf3h4hc4tade85ekfr8sulz5",
|
||||
clientCtx: client.Context{}.WithSimulation(true),
|
||||
from: "cosmos139f7kncmglres2nf3h4hc4tade85ekfr8sulz5",
|
||||
},
|
||||
{
|
||||
clientCtx: client.Context{}.WithSimulation(true).WithAddressCodec(addresscodec.NewBech32Codec("cosmos")),
|
||||
keyring: func() keyring.Keyring {
|
||||
return keyring.NewInMemory(cfg.Codec)
|
||||
},
|
||||
from: "alice",
|
||||
clientCtx: client.Context{}.WithSimulation(true),
|
||||
expectedErr: "a valid bech32 address must be provided in simulation mode",
|
||||
expectedErr: "a valid address must be provided in simulation mode",
|
||||
},
|
||||
{
|
||||
clientCtx: client.Context{}.WithGenerateOnly(true).WithAddressCodec(addresscodec.NewBech32Codec("cosmos")),
|
||||
keyring: func() keyring.Keyring {
|
||||
return keyring.NewInMemory(cfg.Codec)
|
||||
},
|
||||
from: "cosmos139f7kncmglres2nf3h4hc4tade85ekfr8sulz5",
|
||||
clientCtx: client.Context{}.WithGenerateOnly(true),
|
||||
from: "cosmos139f7kncmglres2nf3h4hc4tade85ekfr8sulz5",
|
||||
},
|
||||
{
|
||||
clientCtx: client.Context{}.WithGenerateOnly(true).WithAddressCodec(addresscodec.NewBech32Codec("cosmos")),
|
||||
keyring: func() keyring.Keyring {
|
||||
return keyring.NewInMemory(cfg.Codec)
|
||||
},
|
||||
from: "alice",
|
||||
clientCtx: client.Context{}.WithGenerateOnly(true),
|
||||
expectedErr: "alice.info: key not found",
|
||||
},
|
||||
{
|
||||
clientCtx: client.Context{}.WithGenerateOnly(true).WithAddressCodec(addresscodec.NewBech32Codec("cosmos")),
|
||||
keyring: func() keyring.Keyring {
|
||||
kb, err := keyring.New(t.Name(), keyring.BackendTest, t.TempDir(), nil, cfg.Codec)
|
||||
require.NoError(t, err)
|
||||
@ -186,8 +191,7 @@ func TestGetFromFields(t *testing.T) {
|
||||
|
||||
return kb
|
||||
},
|
||||
clientCtx: client.Context{}.WithGenerateOnly(true),
|
||||
from: "alice",
|
||||
from: "alice",
|
||||
},
|
||||
}
|
||||
|
||||
@ -196,7 +200,7 @@ func TestGetFromFields(t *testing.T) {
|
||||
if tc.expectedErr == "" {
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
require.True(t, strings.HasPrefix(err.Error(), tc.expectedErr))
|
||||
require.ErrorContains(t, err, tc.expectedErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -193,27 +193,26 @@ $ %s debug pubkey-raw cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg
|
||||
|
||||
func AddrCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "addr [address]",
|
||||
Short: "Convert an address between hex and bech32",
|
||||
Long: fmt.Sprintf(`Convert an address between hex encoding and bech32.
|
||||
|
||||
Example:
|
||||
$ %s debug addr cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg
|
||||
`, version.AppName),
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "addr [address]",
|
||||
Short: "Convert an address between hex and bech32",
|
||||
Example: fmt.Sprintf("%s debug addr cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg", version.AppName),
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
addrString := args[0]
|
||||
var addr []byte
|
||||
clientCtx := client.GetClientContextFromCmd(cmd)
|
||||
|
||||
addrString := args[0]
|
||||
// try hex, then bech32
|
||||
var err error
|
||||
var (
|
||||
addr []byte
|
||||
err error
|
||||
)
|
||||
addr, err = hex.DecodeString(addrString)
|
||||
if err != nil {
|
||||
var err2 error
|
||||
addr, err2 = sdk.AccAddressFromBech32(addrString)
|
||||
addr, err2 = clientCtx.AddressCodec.StringToBytes(addrString)
|
||||
if err2 != nil {
|
||||
var err3 error
|
||||
addr, err3 = sdk.ValAddressFromBech32(addrString)
|
||||
addr, err3 = clientCtx.ValidatorAddressCodec.StringToBytes(addrString)
|
||||
|
||||
if err3 != nil {
|
||||
return fmt.Errorf("expected hex or bech32. Got errors: hex: %v, bech32 acc: %v, bech32 val: %v", err, err2, err3)
|
||||
@ -264,7 +263,7 @@ func PrefixesCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "prefixes",
|
||||
Short: "List prefixes used for Human-Readable Part (HRP) in Bech32",
|
||||
Long: "List prefixes used in Bech32 addresses.",
|
||||
Long: "List prefixes used in Bech32 addresses. NOTE, if the chain does not use the Cosmos SDK global config, this will not be accurate.",
|
||||
Example: fmt.Sprintf("$ %s debug prefixes", version.AppName),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cmd.Printf("Bech32 Acc: %s\n", sdk.GetConfig().GetBech32AccountAddrPrefix())
|
||||
|
||||
@ -184,7 +184,7 @@ func runAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf
|
||||
return err
|
||||
}
|
||||
|
||||
return printCreate(cmd, k, false, "", outputFormat)
|
||||
return printCreate(ctx, cmd, k, false, "", outputFormat)
|
||||
}
|
||||
}
|
||||
|
||||
@ -200,7 +200,7 @@ func runAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf
|
||||
return err
|
||||
}
|
||||
|
||||
return printCreate(cmd, k, false, "", outputFormat)
|
||||
return printCreate(ctx, cmd, k, false, "", outputFormat)
|
||||
}
|
||||
|
||||
coinType, _ := cmd.Flags().GetUint32(flagCoinType)
|
||||
@ -223,7 +223,7 @@ func runAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf
|
||||
return err
|
||||
}
|
||||
|
||||
return printCreate(cmd, k, false, "", outputFormat)
|
||||
return printCreate(ctx, cmd, k, false, "", outputFormat)
|
||||
}
|
||||
|
||||
// Get bip39 mnemonic
|
||||
@ -297,14 +297,19 @@ func runAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf
|
||||
mnemonic = ""
|
||||
}
|
||||
|
||||
return printCreate(cmd, k, showMnemonic, mnemonic, outputFormat)
|
||||
return printCreate(ctx, cmd, k, showMnemonic, mnemonic, outputFormat)
|
||||
}
|
||||
|
||||
func printCreate(cmd *cobra.Command, k *keyring.Record, showMnemonic bool, mnemonic, outputFormat string) error {
|
||||
func printCreate(ctx client.Context, cmd *cobra.Command, k *keyring.Record, showMnemonic bool, mnemonic, outputFormat string) error {
|
||||
switch outputFormat {
|
||||
case flags.OutputFormatText:
|
||||
cmd.PrintErrln()
|
||||
if err := printKeyringRecord(cmd.OutOrStdout(), k, MkAccKeyOutput, outputFormat); err != nil {
|
||||
ko, err := MkAccKeyOutput(k, ctx.AddressCodec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := printKeyringRecord(cmd.OutOrStdout(), ko, outputFormat); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -315,7 +320,7 @@ func printCreate(cmd *cobra.Command, k *keyring.Record, showMnemonic bool, mnemo
|
||||
}
|
||||
}
|
||||
case flags.OutputFormatJSON:
|
||||
out, err := MkAccKeyOutput(k)
|
||||
out, err := MkAccKeyOutput(k, ctx.AddressCodec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
@ -44,7 +45,13 @@ func Test_runAddCmdLedgerWithCustomCoinType(t *testing.T) {
|
||||
kbHome := t.TempDir()
|
||||
|
||||
cdc := moduletestutil.MakeTestEncodingConfig().Codec
|
||||
clientCtx := client.Context{}.WithKeyringDir(kbHome).WithCodec(cdc)
|
||||
clientCtx := client.Context{}.
|
||||
WithKeyringDir(kbHome).
|
||||
WithCodec(cdc).
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons"))
|
||||
|
||||
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)
|
||||
|
||||
cmd.SetArgs([]string{
|
||||
@ -97,7 +104,13 @@ func Test_runAddCmdLedger(t *testing.T) {
|
||||
kbHome := t.TempDir()
|
||||
cdc := moduletestutil.MakeTestEncodingConfig().Codec
|
||||
|
||||
clientCtx := client.Context{}.WithKeyringDir(kbHome).WithCodec(cdc)
|
||||
clientCtx := client.Context{}.
|
||||
WithKeyringDir(kbHome).
|
||||
WithCodec(cdc).
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons"))
|
||||
|
||||
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)
|
||||
|
||||
cmd.SetArgs([]string{
|
||||
@ -176,7 +189,10 @@ func Test_runAddCmdLedgerDryRun(t *testing.T) {
|
||||
clientCtx := client.Context{}.
|
||||
WithKeyringDir(kbHome).
|
||||
WithKeyring(kb).
|
||||
WithCodec(cdc)
|
||||
WithCodec(cdc).
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons"))
|
||||
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)
|
||||
b := bytes.NewBufferString("")
|
||||
cmd.SetOut(b)
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
@ -31,7 +32,14 @@ func Test_runAddCmdBasic(t *testing.T) {
|
||||
kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn, cdc)
|
||||
require.NoError(t, err)
|
||||
|
||||
clientCtx := client.Context{}.WithKeyringDir(kbHome).WithInput(mockIn).WithCodec(cdc)
|
||||
clientCtx := client.Context{}.
|
||||
WithKeyringDir(kbHome).
|
||||
WithInput(mockIn).
|
||||
WithCodec(cdc).
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons"))
|
||||
|
||||
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)
|
||||
|
||||
t.Cleanup(func() {
|
||||
@ -197,7 +205,10 @@ func Test_runAddCmdDryRun(t *testing.T) {
|
||||
clientCtx := client.Context{}.
|
||||
WithCodec(cdc).
|
||||
WithKeyringDir(kbHome).
|
||||
WithKeyring(kb)
|
||||
WithKeyring(kb).
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons"))
|
||||
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)
|
||||
|
||||
path := sdk.GetConfig().GetFullBIP44Path()
|
||||
@ -238,7 +249,14 @@ func TestAddRecoverFileBackend(t *testing.T) {
|
||||
mockIn := testutil.ApplyMockIODiscardOutErr(cmd)
|
||||
kbHome := t.TempDir()
|
||||
|
||||
clientCtx := client.Context{}.WithKeyringDir(kbHome).WithInput(mockIn).WithCodec(cdc)
|
||||
clientCtx := client.Context{}.
|
||||
WithKeyringDir(kbHome).
|
||||
WithInput(mockIn).
|
||||
WithCodec(cdc).
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons"))
|
||||
|
||||
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)
|
||||
|
||||
cmd.SetArgs([]string{
|
||||
|
||||
@ -40,7 +40,7 @@ func runListCmd(cmd *cobra.Command, _ []string) error {
|
||||
}
|
||||
|
||||
if ok, _ := cmd.Flags().GetBool(flagListNames); !ok {
|
||||
return printKeyringRecords(cmd.OutOrStdout(), records, clientCtx.OutputFormat)
|
||||
return printKeyringRecords(clientCtx, cmd.OutOrStdout(), records, clientCtx.OutputFormat)
|
||||
}
|
||||
|
||||
for _, k := range records {
|
||||
|
||||
@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
@ -42,7 +43,12 @@ func Test_runListCmd(t *testing.T) {
|
||||
kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome2, mockIn, cdc)
|
||||
assert.NilError(t, err)
|
||||
|
||||
clientCtx := client.Context{}.WithKeyring(kb)
|
||||
clientCtx := client.Context{}.
|
||||
WithKeyring(kb).
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons"))
|
||||
|
||||
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)
|
||||
|
||||
path := "" // sdk.GetConfig().GetFullBIP44Path()
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
@ -34,6 +35,10 @@ type MigrateTestSuite struct {
|
||||
pub cryptotypes.PubKey
|
||||
}
|
||||
|
||||
func TestMigrateTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(MigrateTestSuite))
|
||||
}
|
||||
|
||||
func (s *MigrateTestSuite) SetupSuite() {
|
||||
s.dir = s.T().TempDir()
|
||||
s.cdc = moduletestutil.MakeTestEncodingConfig().Codec
|
||||
@ -71,7 +76,12 @@ func (s *MigrateTestSuite) Test_runListAndShowCmd() {
|
||||
s.Require().True(ok)
|
||||
s.Require().NoError(setter.SetItem(item))
|
||||
|
||||
clientCtx := client.Context{}.WithKeyring(kb)
|
||||
clientCtx := client.Context{}.
|
||||
WithKeyring(kb).
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons"))
|
||||
|
||||
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)
|
||||
|
||||
cmd.SetArgs([]string{
|
||||
@ -147,7 +157,3 @@ func (s *MigrateTestSuite) Test_runMigrateCmdLegacyMultiInfo() {
|
||||
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)
|
||||
s.Require().NoError(cmd.ExecuteContext(ctx))
|
||||
}
|
||||
|
||||
func TestMigrateTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(MigrateTestSuite))
|
||||
}
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
package keys
|
||||
|
||||
import (
|
||||
"cosmossdk.io/core/address"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// Use protobuf interface marshaler rather then generic JSON
|
||||
@ -21,65 +22,68 @@ type KeyOutput struct {
|
||||
}
|
||||
|
||||
// NewKeyOutput creates a default KeyOutput instance without Mnemonic, Threshold and PubKeys
|
||||
func NewKeyOutput(name string, keyType keyring.KeyType, a sdk.Address, pk cryptotypes.PubKey) (KeyOutput, error) {
|
||||
func NewKeyOutput(name string, keyType keyring.KeyType, addr []byte, pk cryptotypes.PubKey, addressCodec address.Codec) (KeyOutput, error) {
|
||||
apk, err := codectypes.NewAnyWithValue(pk)
|
||||
if err != nil {
|
||||
return KeyOutput{}, err
|
||||
}
|
||||
|
||||
bz, err := codec.ProtoMarshalJSON(apk, nil)
|
||||
if err != nil {
|
||||
return KeyOutput{}, err
|
||||
}
|
||||
|
||||
addrStr, err := addressCodec.BytesToString(addr)
|
||||
if err != nil {
|
||||
return KeyOutput{}, err
|
||||
}
|
||||
|
||||
return KeyOutput{
|
||||
Name: name,
|
||||
Type: keyType.String(),
|
||||
Address: a.String(),
|
||||
Address: addrStr,
|
||||
PubKey: string(bz),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// MkConsKeyOutput create a KeyOutput in with "cons" Bech32 prefixes.
|
||||
func MkConsKeyOutput(k *keyring.Record) (KeyOutput, error) {
|
||||
// MkConsKeyOutput create a KeyOutput for consensus addresses.
|
||||
func MkConsKeyOutput(k *keyring.Record, consensusAddressCodec address.Codec) (KeyOutput, error) {
|
||||
pk, err := k.GetPubKey()
|
||||
if err != nil {
|
||||
return KeyOutput{}, err
|
||||
}
|
||||
addr := sdk.ConsAddress(pk.Address())
|
||||
return NewKeyOutput(k.Name, k.GetType(), addr, pk)
|
||||
return NewKeyOutput(k.Name, k.GetType(), pk.Address(), pk, consensusAddressCodec)
|
||||
}
|
||||
|
||||
// MkValKeyOutput create a KeyOutput in with "val" Bech32 prefixes.
|
||||
func MkValKeyOutput(k *keyring.Record) (KeyOutput, error) {
|
||||
// MkValKeyOutput create a KeyOutput for validator addresses.
|
||||
func MkValKeyOutput(k *keyring.Record, validatorAddressCodec address.Codec) (KeyOutput, error) {
|
||||
pk, err := k.GetPubKey()
|
||||
if err != nil {
|
||||
return KeyOutput{}, err
|
||||
}
|
||||
|
||||
addr := sdk.ValAddress(pk.Address())
|
||||
|
||||
return NewKeyOutput(k.Name, k.GetType(), addr, pk)
|
||||
return NewKeyOutput(k.Name, k.GetType(), pk.Address(), pk, validatorAddressCodec)
|
||||
}
|
||||
|
||||
// MkAccKeyOutput create a KeyOutput in with "acc" Bech32 prefixes. If the
|
||||
// public key is a multisig public key, then the threshold and constituent
|
||||
// public keys will be added.
|
||||
func MkAccKeyOutput(k *keyring.Record) (KeyOutput, error) {
|
||||
func MkAccKeyOutput(k *keyring.Record, addressCodec address.Codec) (KeyOutput, error) {
|
||||
pk, err := k.GetPubKey()
|
||||
if err != nil {
|
||||
return KeyOutput{}, err
|
||||
}
|
||||
addr := sdk.AccAddress(pk.Address())
|
||||
return NewKeyOutput(k.Name, k.GetType(), addr, pk)
|
||||
return NewKeyOutput(k.Name, k.GetType(), pk.Address(), pk, addressCodec)
|
||||
}
|
||||
|
||||
// MkAccKeysOutput returns a slice of KeyOutput objects, each with the "acc"
|
||||
// Bech32 prefixes, given a slice of Record objects. It returns an error if any
|
||||
// call to MkKeyOutput fails.
|
||||
func MkAccKeysOutput(records []*keyring.Record) ([]KeyOutput, error) {
|
||||
func MkAccKeysOutput(records []*keyring.Record, addressCodec address.Codec) ([]KeyOutput, error) {
|
||||
kos := make([]KeyOutput, len(records))
|
||||
var err error
|
||||
for i, r := range records {
|
||||
kos[i], err = MkAccKeyOutput(r)
|
||||
kos[i], err = MkAccKeyOutput(r, addressCodec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
@ -35,10 +36,10 @@ func TestBech32KeysOutput(t *testing.T) {
|
||||
pubKey, err := k.GetPubKey()
|
||||
require.NoError(t, err)
|
||||
accAddr := sdk.AccAddress(pubKey.Address())
|
||||
expectedOutput, err := NewKeyOutput(k.Name, k.GetType(), accAddr, multisigPk)
|
||||
expectedOutput, err := NewKeyOutput(k.Name, k.GetType(), accAddr, multisigPk, addresscodec.NewBech32Codec("cosmos"))
|
||||
require.NoError(t, err)
|
||||
|
||||
out, err := MkAccKeyOutput(k)
|
||||
out, err := MkAccKeyOutput(k, addresscodec.NewBech32Codec("cosmos"))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expectedOutput, out)
|
||||
require.Equal(t, "{Name:multisig Type:multi Address:cosmos1nf8lf6n4wa43rzmdzwe6hkrnw5guekhqt595cw PubKey:{\"@type\":\"/cosmos.crypto.multisig.LegacyAminoPubKey\",\"threshold\":1,\"public_keys\":[{\"@type\":\"/cosmos.crypto.secp256k1.PubKey\",\"key\":\"AurroA7jvfPd1AadmmOvWM2rJSwipXfRf8yD6pLbA2DJ\"}]} Mnemonic:}", fmt.Sprintf("%+v", out))
|
||||
@ -61,11 +62,17 @@ func TestProtoMarshalJSON(t *testing.T) {
|
||||
require.NoError(err)
|
||||
require.True(pk2.Equals(msig))
|
||||
|
||||
addressCodec := addresscodec.NewBech32Codec("cosmos")
|
||||
|
||||
// Test that we can correctly unmarshal key from output
|
||||
k, err := keyring.NewMultiRecord("my multisig", msig)
|
||||
require.NoError(err)
|
||||
ko, err := MkAccKeyOutput(k)
|
||||
ko, err := MkAccKeyOutput(k, addressCodec)
|
||||
require.NoError(err)
|
||||
require.Equal(ko.Address, sdk.AccAddress(pk2.Address()).String())
|
||||
|
||||
expectedOutput, err := addressCodec.BytesToString(pk2.Address())
|
||||
require.NoError(err)
|
||||
|
||||
require.Equal(ko.Address, expectedOutput)
|
||||
require.Equal(ko.PubKey, string(bz))
|
||||
}
|
||||
|
||||
@ -79,17 +79,15 @@ func ParseKeyStringCommand() *cobra.Command {
|
||||
hexadecimal into bech32 cosmos prefixed format and vice versa.
|
||||
`,
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: parseKey,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
config, _ := sdk.GetSealedConfig(cmd.Context())
|
||||
return doParseKey(cmd, config, args)
|
||||
},
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func parseKey(cmd *cobra.Command, args []string) error {
|
||||
config, _ := sdk.GetSealedConfig(cmd.Context())
|
||||
return doParseKey(cmd, config, args)
|
||||
}
|
||||
|
||||
func doParseKey(cmd *cobra.Command, config *sdk.Config, args []string) error {
|
||||
addr := strings.TrimSpace(args[0])
|
||||
outstream := cmd.OutOrStdout()
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
@ -61,14 +62,14 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
|
||||
outputFormat := clientCtx.OutputFormat
|
||||
|
||||
if len(args) == 1 {
|
||||
k, err = fetchKey(clientCtx.Keyring, args[0])
|
||||
k, err = fetchKey(clientCtx.Keyring, args[0], clientCtx.AddressCodec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s is not a valid name or address: %w", args[0], err)
|
||||
}
|
||||
} else {
|
||||
pks := make([]cryptotypes.PubKey, len(args))
|
||||
for i, keyref := range args {
|
||||
k, err := fetchKey(clientCtx.Keyring, keyref)
|
||||
k, err := fetchKey(clientCtx.Keyring, keyref, clientCtx.AddressCodec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s is not a valid name or address: %w", keyref, err)
|
||||
}
|
||||
@ -111,7 +112,7 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
|
||||
}
|
||||
|
||||
bechPrefix, _ := cmd.Flags().GetString(FlagBechPrefix)
|
||||
bechKeyOut, err := getBechKeyOut(bechPrefix)
|
||||
ko, err := getKeyOutput(clientCtx, bechPrefix, k)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -122,10 +123,6 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
|
||||
|
||||
switch {
|
||||
case isShowAddr, isShowPubKey:
|
||||
ko, err := bechKeyOut(k)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
out := ko.Address
|
||||
if isShowPubKey {
|
||||
out = ko.PubKey
|
||||
@ -135,7 +132,7 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
if err := printKeyringRecord(cmd.OutOrStdout(), k, bechKeyOut, outputFormat); err != nil {
|
||||
if err := printKeyringRecord(cmd.OutOrStdout(), ko, outputFormat); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -169,7 +166,7 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func fetchKey(kb keyring.Keyring, keyref string) (*keyring.Record, error) {
|
||||
func fetchKey(kb keyring.Keyring, keyref string, addressCodec address.Codec) (*keyring.Record, error) {
|
||||
// firstly check if the keyref is a key name of a key registered in a keyring.
|
||||
k, err := kb.Key(keyref)
|
||||
// if the key is not there or if we have a problem with a keyring itself then we move to a
|
||||
@ -179,7 +176,7 @@ func fetchKey(kb keyring.Keyring, keyref string) (*keyring.Record, error) {
|
||||
return k, err
|
||||
}
|
||||
|
||||
accAddr, err := sdk.AccAddressFromBech32(keyref)
|
||||
accAddr, err := addressCodec.StringToBytes(keyref)
|
||||
if err != nil {
|
||||
return k, err
|
||||
}
|
||||
@ -199,15 +196,15 @@ func validateMultisigThreshold(k, nKeys int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getBechKeyOut(bechPrefix string) (bechKeyOutFn, error) {
|
||||
func getKeyOutput(clientCtx client.Context, bechPrefix string, k *keyring.Record) (KeyOutput, error) {
|
||||
switch bechPrefix {
|
||||
case sdk.PrefixAccount:
|
||||
return MkAccKeyOutput, nil
|
||||
return MkAccKeyOutput(k, clientCtx.AddressCodec)
|
||||
case sdk.PrefixValidator:
|
||||
return MkValKeyOutput, nil
|
||||
return MkValKeyOutput(k, clientCtx.ValidatorAddressCodec)
|
||||
case sdk.PrefixConsensus:
|
||||
return MkConsKeyOutput, nil
|
||||
return MkConsKeyOutput(k, clientCtx.ConsensusAddressCodec)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("invalid Bech32 prefix encoding provided: %s", bechPrefix)
|
||||
return KeyOutput{}, fmt.Errorf("invalid Bech32 prefix encoding provided: %s", bechPrefix)
|
||||
}
|
||||
|
||||
@ -7,8 +7,11 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
|
||||
@ -59,7 +62,11 @@ func Test_runShowCmd(t *testing.T) {
|
||||
|
||||
clientCtx := client.Context{}.
|
||||
WithKeyringDir(kbHome).
|
||||
WithCodec(cdc)
|
||||
WithCodec(cdc).
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons"))
|
||||
|
||||
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)
|
||||
|
||||
cmd.SetArgs([]string{"invalid"})
|
||||
@ -196,13 +203,22 @@ func Test_validateMultisigThreshold(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_getBechKeyOut(t *testing.T) {
|
||||
ctx := client.Context{}.
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons"))
|
||||
|
||||
tmpKey1 := secp256k1.GenPrivKeyFromSecret([]byte("mySecret"))
|
||||
k, err := keyring.NewLocalRecord("foo", tmpKey1, tmpKey1.PubKey())
|
||||
require.NoError(t, err)
|
||||
|
||||
type args struct {
|
||||
bechPrefix string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want bechKeyOutFn
|
||||
want func(k *keyring.Record, addressCodec address.Codec) (KeyOutput, error)
|
||||
wantErr bool
|
||||
}{
|
||||
{"empty", args{""}, nil, true},
|
||||
@ -214,12 +230,12 @@ func Test_getBechKeyOut(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := getBechKeyOut(tt.args.bechPrefix)
|
||||
output, err := getKeyOutput(ctx, tt.args.bechPrefix, k)
|
||||
if tt.wantErr {
|
||||
require.Error(t, err)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, got)
|
||||
require.NotNil(t, output)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@ -7,18 +7,12 @@ import (
|
||||
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
cryptokeyring "github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
)
|
||||
|
||||
type bechKeyOutFn func(k *cryptokeyring.Record) (KeyOutput, error)
|
||||
|
||||
func printKeyringRecord(w io.Writer, k *cryptokeyring.Record, bechKeyOut bechKeyOutFn, output string) error {
|
||||
ko, err := bechKeyOut(k)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
func printKeyringRecord(w io.Writer, ko KeyOutput, output string) error {
|
||||
switch output {
|
||||
case flags.OutputFormatText:
|
||||
if err := printTextRecords(w, []KeyOutput{ko}); err != nil {
|
||||
@ -39,8 +33,8 @@ func printKeyringRecord(w io.Writer, k *cryptokeyring.Record, bechKeyOut bechKey
|
||||
return nil
|
||||
}
|
||||
|
||||
func printKeyringRecords(w io.Writer, records []*cryptokeyring.Record, output string) error {
|
||||
kos, err := MkAccKeysOutput(records)
|
||||
func printKeyringRecords(clientCtx client.Context, w io.Writer, records []*cryptokeyring.Record, output string) error {
|
||||
kos, err := MkAccKeysOutput(records, clientCtx.AddressCodec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ func ValidatePromptURL(input string) error {
|
||||
}
|
||||
|
||||
// ValidatePromptAddress validates that the input is a valid Bech32 address.
|
||||
func ValidatePromptAddress(input string) error {
|
||||
func ValidatePromptAddress(input string) error { // TODO(@julienrbrt) remove and add prompts in AutoCLI
|
||||
_, err := sdk.AccAddressFromBech32(input)
|
||||
if err == nil {
|
||||
return nil
|
||||
|
||||
@ -394,8 +394,8 @@ func makeAuxSignerData(clientCtx client.Context, f Factory, msgs ...sdk.Msg) (tx
|
||||
}
|
||||
|
||||
if f.tip != nil {
|
||||
if _, err := sdk.AccAddressFromBech32(f.tip.Tipper); err != nil {
|
||||
return tx.AuxSignerData{}, sdkerrors.ErrInvalidAddress.Wrap("tipper must be a bech32 address")
|
||||
if _, err := clientCtx.AddressCodec.StringToBytes(f.tip.Tipper); err != nil {
|
||||
return tx.AuxSignerData{}, sdkerrors.ErrInvalidAddress.Wrap("tipper must be a valid address")
|
||||
}
|
||||
b.SetTip(f.tip)
|
||||
}
|
||||
|
||||
@ -66,11 +66,11 @@ type Keyring interface {
|
||||
|
||||
// Key and KeyByAddress return keys by uid and address respectively.
|
||||
Key(uid string) (*Record, error)
|
||||
KeyByAddress(address sdk.Address) (*Record, error)
|
||||
KeyByAddress(address []byte) (*Record, error)
|
||||
|
||||
// Delete and DeleteByAddress remove keys from the keyring.
|
||||
Delete(uid string) error
|
||||
DeleteByAddress(address sdk.Address) error
|
||||
DeleteByAddress(address []byte) error
|
||||
|
||||
// Rename an existing key from the Keyring
|
||||
Rename(from, to string) error
|
||||
@ -113,7 +113,7 @@ type Signer interface {
|
||||
Sign(uid string, msg []byte, signMode signing.SignMode) ([]byte, types.PubKey, error)
|
||||
|
||||
// SignByAddress sign byte messages with a user key providing the address.
|
||||
SignByAddress(address sdk.Address, msg []byte, signMode signing.SignMode) ([]byte, types.PubKey, error)
|
||||
SignByAddress(address, msg []byte, signMode signing.SignMode) ([]byte, types.PubKey, error)
|
||||
}
|
||||
|
||||
// Importer is implemented by key stores that support import of public and private keys.
|
||||
@ -135,12 +135,12 @@ type Migrator interface {
|
||||
type Exporter interface {
|
||||
// Export public key
|
||||
ExportPubKeyArmor(uid string) (string, error)
|
||||
ExportPubKeyArmorByAddress(address sdk.Address) (string, error)
|
||||
ExportPubKeyArmorByAddress(address []byte) (string, error)
|
||||
|
||||
// ExportPrivKeyArmor returns a private key in ASCII armored format.
|
||||
// It returns an error if the key does not exist or a wrong encryption passphrase is supplied.
|
||||
ExportPrivKeyArmor(uid, encryptPassphrase string) (armor string, err error)
|
||||
ExportPrivKeyArmorByAddress(address sdk.Address, encryptPassphrase string) (armor string, err error)
|
||||
ExportPrivKeyArmorByAddress(address []byte, encryptPassphrase string) (armor string, err error)
|
||||
}
|
||||
|
||||
// Option overrides keyring configuration options.
|
||||
@ -278,7 +278,7 @@ func (ks keystore) ExportPubKeyArmor(uid string) (string, error) {
|
||||
return crypto.ArmorPubKeyBytes(bz, key.Type()), nil
|
||||
}
|
||||
|
||||
func (ks keystore) ExportPubKeyArmorByAddress(address sdk.Address) (string, error) {
|
||||
func (ks keystore) ExportPubKeyArmorByAddress(address []byte) (string, error) {
|
||||
k, err := ks.KeyByAddress(address)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@ -312,7 +312,7 @@ func (ks keystore) ExportPrivateKeyObject(uid string) (types.PrivKey, error) {
|
||||
return priv, err
|
||||
}
|
||||
|
||||
func (ks keystore) ExportPrivKeyArmorByAddress(address sdk.Address, encryptPassphrase string) (armor string, err error) {
|
||||
func (ks keystore) ExportPrivKeyArmorByAddress(address []byte, encryptPassphrase string) (armor string, err error) {
|
||||
k, err := ks.KeyByAddress(address)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@ -420,7 +420,7 @@ func (ks keystore) Sign(uid string, msg []byte, signMode signing.SignMode) ([]by
|
||||
}
|
||||
}
|
||||
|
||||
func (ks keystore) SignByAddress(address sdk.Address, msg []byte, signMode signing.SignMode) ([]byte, types.PubKey, error) {
|
||||
func (ks keystore) SignByAddress(address, msg []byte, signMode signing.SignMode) ([]byte, types.PubKey, error) {
|
||||
k, err := ks.KeyByAddress(address)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@ -461,7 +461,7 @@ func (ks keystore) SaveOfflineKey(uid string, pubkey types.PubKey) (*Record, err
|
||||
return ks.writeOfflineKey(uid, pubkey)
|
||||
}
|
||||
|
||||
func (ks keystore) DeleteByAddress(address sdk.Address) error {
|
||||
func (ks keystore) DeleteByAddress(address []byte) error {
|
||||
k, err := ks.KeyByAddress(address)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -523,14 +523,14 @@ func (ks keystore) Delete(uid string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ks keystore) KeyByAddress(address sdk.Address) (*Record, error) {
|
||||
func (ks keystore) KeyByAddress(address []byte) (*Record, error) {
|
||||
ik, err := ks.db.Get(addrHexKeyAsString(address))
|
||||
if err != nil {
|
||||
return nil, wrapKeyNotFound(err, fmt.Sprintf("key with address %s not found", address.String()))
|
||||
return nil, wrapKeyNotFound(err, "key with given address not found") // we do not print the address for not needing an address codec
|
||||
}
|
||||
|
||||
if len(ik.Data) == 0 {
|
||||
return nil, wrapKeyNotFound(err, fmt.Sprintf("key with address %s not found", address.String()))
|
||||
return nil, wrapKeyNotFound(err, "key with given address not found") // we do not print the address for not needing an address codec
|
||||
}
|
||||
|
||||
return ks.Key(string(ik.Data))
|
||||
@ -867,7 +867,7 @@ func (ks keystore) writeRecord(k *Record) error {
|
||||
// existsInDb returns (true, nil) if either addr or name exist is in keystore DB.
|
||||
// On the other hand, it returns (false, error) if Get method returns error different from keyring.ErrKeyNotFound
|
||||
// In case of inconsistent keyring, it recovers it automatically.
|
||||
func (ks keystore) existsInDb(addr sdk.Address, name string) (bool, error) {
|
||||
func (ks keystore) existsInDb(addr []byte, name string) (bool, error) {
|
||||
_, errAddr := ks.db.Get(addrHexKeyAsString(addr))
|
||||
if errAddr != nil && !errors.Is(errAddr, keyring.ErrKeyNotFound) {
|
||||
return false, errAddr
|
||||
@ -882,7 +882,7 @@ func (ks keystore) existsInDb(addr sdk.Address, name string) (bool, error) {
|
||||
|
||||
// looking for an issue, record with meta (getByAddress) exists, but record with public key itself does not
|
||||
if errAddr == nil && errors.Is(errInfo, keyring.ErrKeyNotFound) {
|
||||
fmt.Fprintf(os.Stderr, "address \"%s\" exists but pubkey itself does not\n", hex.EncodeToString(addr.Bytes()))
|
||||
fmt.Fprintf(os.Stderr, "address \"%s\" exists but pubkey itself does not\n", hex.EncodeToString(addr))
|
||||
fmt.Fprintln(os.Stderr, "recreating pubkey record")
|
||||
err := ks.db.Remove(addrHexKeyAsString(addr))
|
||||
if err != nil {
|
||||
@ -1055,6 +1055,6 @@ func (ks keystore) convertFromLegacyInfo(info LegacyInfo) (*Record, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func addrHexKeyAsString(address sdk.Address) string {
|
||||
return fmt.Sprintf("%s.%s", hex.EncodeToString(address.Bytes()), addressSuffix)
|
||||
func addrHexKeyAsString(address []byte) string {
|
||||
return fmt.Sprintf("%s.%s", hex.EncodeToString(address), addressSuffix)
|
||||
}
|
||||
|
||||
@ -647,11 +647,8 @@ func (app *SimApp) AutoCliOpts() autocli.AppOptions {
|
||||
}
|
||||
|
||||
return autocli.AppOptions{
|
||||
Modules: modules,
|
||||
ModuleOptions: runtimeservices.ExtractAutoCLIOptions(app.ModuleManager.Modules),
|
||||
AddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()),
|
||||
ValidatorAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()),
|
||||
ConsensusAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()),
|
||||
Modules: modules,
|
||||
ModuleOptions: runtimeservices.ExtractAutoCLIOptions(app.ModuleManager.Modules),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -14,8 +14,10 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/config"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/server"
|
||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/tx/signing"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/tx"
|
||||
txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
|
||||
@ -41,6 +43,9 @@ func NewRootCmd() *cobra.Command {
|
||||
WithLegacyAmino(encodingConfig.Amino).
|
||||
WithInput(os.Stdin).
|
||||
WithAccountRetriever(types.AccountRetriever{}).
|
||||
WithAddressCodec(addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix())).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix())).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix())).
|
||||
WithHomeDir(simapp.DefaultNodeHome).
|
||||
WithViper("") // In simapp, we don't use any prefix for env variables.
|
||||
|
||||
@ -93,10 +98,14 @@ func NewRootCmd() *cobra.Command {
|
||||
|
||||
initRootCmd(rootCmd, encodingConfig.TxConfig, encodingConfig.InterfaceRegistry, encodingConfig.Codec, tempApp.BasicModuleManager)
|
||||
|
||||
// add keyring to autocli opts
|
||||
autoCliOpts := tempApp.AutoCliOpts()
|
||||
// autocli opts
|
||||
initClientCtx, _ = config.ReadFromClientConfig(initClientCtx)
|
||||
|
||||
autoCliOpts := tempApp.AutoCliOpts()
|
||||
autoCliOpts.Keyring = initClientCtx.Keyring
|
||||
autoCliOpts.AddressCodec = initClientCtx.AddressCodec
|
||||
autoCliOpts.ValidatorAddressCodec = initClientCtx.ValidatorAddressCodec
|
||||
autoCliOpts.ConsensusAddressCodec = initClientCtx.ConsensusAddressCodec
|
||||
|
||||
if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil {
|
||||
panic(err)
|
||||
|
||||
@ -18,6 +18,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client/config"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/runtime"
|
||||
"github.com/cosmos/cosmos-sdk/server"
|
||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
@ -114,13 +115,23 @@ func NewRootCmd() *cobra.Command {
|
||||
return rootCmd
|
||||
}
|
||||
|
||||
func ProvideClientContext(appCodec codec.Codec, interfaceRegistry codectypes.InterfaceRegistry, legacyAmino *codec.LegacyAmino) client.Context {
|
||||
func ProvideClientContext(
|
||||
appCodec codec.Codec,
|
||||
interfaceRegistry codectypes.InterfaceRegistry,
|
||||
legacyAmino *codec.LegacyAmino,
|
||||
addressCodec address.Codec,
|
||||
validatorAddressCodec runtime.ValidatorAddressCodec,
|
||||
consensusAddressCodec runtime.ConsensusAddressCodec,
|
||||
) client.Context {
|
||||
initClientCtx := client.Context{}.
|
||||
WithCodec(appCodec).
|
||||
WithInterfaceRegistry(interfaceRegistry).
|
||||
WithLegacyAmino(legacyAmino).
|
||||
WithInput(os.Stdin).
|
||||
WithAccountRetriever(types.AccountRetriever{}).
|
||||
WithAddressCodec(addressCodec).
|
||||
WithValidatorAddressCodec(validatorAddressCodec).
|
||||
WithConsensusAddressCodec(consensusAddressCodec).
|
||||
WithHomeDir(simapp.DefaultNodeHome).
|
||||
WithViper("") // In simapp, we don't use any prefix for env variables.
|
||||
|
||||
|
||||
@ -65,7 +65,10 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}).
|
||||
WithAccountRetriever(client.MockAccountRetriever{}).
|
||||
WithOutput(io.Discard).
|
||||
WithChainID("test-chain")
|
||||
WithChainID("test-chain").
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons"))
|
||||
|
||||
ctxGen := func() client.Context {
|
||||
bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{})
|
||||
|
||||
@ -24,6 +24,7 @@ import (
|
||||
"golang.org/x/sync/errgroup"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/depinject"
|
||||
"cosmossdk.io/log"
|
||||
sdkmath "cosmossdk.io/math"
|
||||
@ -36,6 +37,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client/grpc/cmtservice"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
@ -130,6 +132,11 @@ type Config struct {
|
||||
APIAddress string // REST API listen address (including port)
|
||||
GRPCAddress string // GRPC server listen address (including port)
|
||||
PrintMnemonic bool // print the mnemonic of first validator as log output for testing
|
||||
|
||||
// Address codecs
|
||||
AddressCodec address.Codec // address codec
|
||||
ValidatorAddressCodec runtime.ValidatorAddressCodec // validator address codec
|
||||
ConsensusAddressCodec runtime.ConsensusAddressCodec // consensus address codec
|
||||
}
|
||||
|
||||
// DefaultConfig returns a sane default configuration suitable for nearly all
|
||||
@ -138,26 +145,29 @@ func DefaultConfig(factory TestFixtureFactory) Config {
|
||||
fixture := factory()
|
||||
|
||||
return Config{
|
||||
Codec: fixture.EncodingConfig.Codec,
|
||||
TxConfig: fixture.EncodingConfig.TxConfig,
|
||||
LegacyAmino: fixture.EncodingConfig.Amino,
|
||||
InterfaceRegistry: fixture.EncodingConfig.InterfaceRegistry,
|
||||
AccountRetriever: authtypes.AccountRetriever{},
|
||||
AppConstructor: fixture.AppConstructor,
|
||||
GenesisState: fixture.GenesisState,
|
||||
TimeoutCommit: 2 * time.Second,
|
||||
ChainID: "chain-" + unsafe.Str(6),
|
||||
NumValidators: 4,
|
||||
BondDenom: sdk.DefaultBondDenom,
|
||||
MinGasPrices: fmt.Sprintf("0.000006%s", sdk.DefaultBondDenom),
|
||||
AccountTokens: sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction),
|
||||
StakingTokens: sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction),
|
||||
BondedTokens: sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction),
|
||||
PruningStrategy: pruningtypes.PruningOptionNothing,
|
||||
CleanupDir: true,
|
||||
SigningAlgo: string(hd.Secp256k1Type),
|
||||
KeyringOptions: []keyring.Option{},
|
||||
PrintMnemonic: false,
|
||||
Codec: fixture.EncodingConfig.Codec,
|
||||
TxConfig: fixture.EncodingConfig.TxConfig,
|
||||
LegacyAmino: fixture.EncodingConfig.Amino,
|
||||
InterfaceRegistry: fixture.EncodingConfig.InterfaceRegistry,
|
||||
AccountRetriever: authtypes.AccountRetriever{},
|
||||
AppConstructor: fixture.AppConstructor,
|
||||
GenesisState: fixture.GenesisState,
|
||||
TimeoutCommit: 2 * time.Second,
|
||||
ChainID: "chain-" + unsafe.Str(6),
|
||||
NumValidators: 4,
|
||||
BondDenom: sdk.DefaultBondDenom,
|
||||
MinGasPrices: fmt.Sprintf("0.000006%s", sdk.DefaultBondDenom),
|
||||
AccountTokens: sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction),
|
||||
StakingTokens: sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction),
|
||||
BondedTokens: sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction),
|
||||
PruningStrategy: pruningtypes.PruningOptionNothing,
|
||||
CleanupDir: true,
|
||||
SigningAlgo: string(hd.Secp256k1Type),
|
||||
KeyringOptions: []keyring.Option{},
|
||||
PrintMnemonic: false,
|
||||
AddressCodec: addresscodec.NewBech32Codec("cosmos"),
|
||||
ValidatorAddressCodec: addresscodec.NewBech32Codec("cosmosvaloper"),
|
||||
ConsensusAddressCodec: addresscodec.NewBech32Codec("cosmosvalcons"),
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,11 +186,14 @@ func MinimumAppConfig() depinject.Config {
|
||||
|
||||
func DefaultConfigWithAppConfig(appConfig depinject.Config) (Config, error) {
|
||||
var (
|
||||
appBuilder *runtime.AppBuilder
|
||||
txConfig client.TxConfig
|
||||
legacyAmino *codec.LegacyAmino
|
||||
cdc codec.Codec
|
||||
interfaceRegistry codectypes.InterfaceRegistry
|
||||
appBuilder *runtime.AppBuilder
|
||||
txConfig client.TxConfig
|
||||
legacyAmino *codec.LegacyAmino
|
||||
cdc codec.Codec
|
||||
interfaceRegistry codectypes.InterfaceRegistry
|
||||
addressCodec address.Codec
|
||||
validatorAddressCodec runtime.ValidatorAddressCodec
|
||||
consensusAddressCodec runtime.ConsensusAddressCodec
|
||||
)
|
||||
|
||||
if err := depinject.Inject(
|
||||
@ -193,6 +206,9 @@ func DefaultConfigWithAppConfig(appConfig depinject.Config) (Config, error) {
|
||||
&cdc,
|
||||
&legacyAmino,
|
||||
&interfaceRegistry,
|
||||
&addressCodec,
|
||||
&validatorAddressCodec,
|
||||
&consensusAddressCodec,
|
||||
); err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
@ -233,6 +249,10 @@ func DefaultConfigWithAppConfig(appConfig depinject.Config) (Config, error) {
|
||||
return app
|
||||
}
|
||||
|
||||
cfg.AddressCodec = addressCodec
|
||||
cfg.ValidatorAddressCodec = validatorAddressCodec
|
||||
cfg.ConsensusAddressCodec = consensusAddressCodec
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
@ -579,7 +599,10 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
|
||||
WithCodec(cfg.Codec).
|
||||
WithLegacyAmino(cfg.LegacyAmino).
|
||||
WithTxConfig(cfg.TxConfig).
|
||||
WithAccountRetriever(cfg.AccountRetriever)
|
||||
WithAccountRetriever(cfg.AccountRetriever).
|
||||
WithAddressCodec(cfg.AddressCodec).
|
||||
WithValidatorAddressCodec(cfg.ValidatorAddressCodec).
|
||||
WithConsensusAddressCodec(cfg.ValidatorAddressCodec)
|
||||
|
||||
// Provide ChainID here since we can't modify it in the Comet config.
|
||||
ctx.Viper.Set(flags.FlagChainID, cfg.ChainID)
|
||||
|
||||
@ -14,7 +14,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec/address"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
@ -46,12 +46,15 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
WithCodec(s.encCfg.Codec).
|
||||
WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}).
|
||||
WithAccountRetriever(client.MockAccountRetriever{}).
|
||||
WithOutput(io.Discard)
|
||||
WithOutput(io.Discard).
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons"))
|
||||
}
|
||||
|
||||
func (s *CLITestSuite) TestNewMsgCreateVestingAccountCmd() {
|
||||
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
||||
cmd := cli.NewMsgCreateVestingAccountCmd(address.NewBech32Codec("cosmos"))
|
||||
cmd := cli.NewMsgCreateVestingAccountCmd(addresscodec.NewBech32Codec("cosmos"))
|
||||
cmd.SetOutput(io.Discard)
|
||||
|
||||
extraArgs := []string{
|
||||
@ -140,7 +143,7 @@ func (s *CLITestSuite) TestNewMsgCreateVestingAccountCmd() {
|
||||
|
||||
func (s *CLITestSuite) TestNewMsgCreatePermanentLockedAccountCmd() {
|
||||
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
||||
cmd := cli.NewMsgCreatePermanentLockedAccountCmd(address.NewBech32Codec("cosmos"))
|
||||
cmd := cli.NewMsgCreatePermanentLockedAccountCmd(addresscodec.NewBech32Codec("cosmos"))
|
||||
cmd.SetOutput(io.Discard)
|
||||
|
||||
extraArgs := []string{
|
||||
@ -219,7 +222,7 @@ func (s *CLITestSuite) TestNewMsgCreatePermanentLockedAccountCmd() {
|
||||
|
||||
func (s *CLITestSuite) TestNewMsgCreatePeriodicVestingAccountCmd() {
|
||||
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
||||
cmd := cli.NewMsgCreatePeriodicVestingAccountCmd(address.NewBech32Codec("cosmos"))
|
||||
cmd := cli.NewMsgCreatePeriodicVestingAccountCmd(addresscodec.NewBech32Codec("cosmos"))
|
||||
cmd.SetOutput(io.Discard)
|
||||
|
||||
extraArgs := []string{
|
||||
|
||||
@ -68,7 +68,10 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}).
|
||||
WithAccountRetriever(client.MockAccountRetriever{}).
|
||||
WithOutput(io.Discard).
|
||||
WithChainID("test-chain")
|
||||
WithChainID("test-chain").
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons"))
|
||||
|
||||
s.ac = addresscodec.NewBech32Codec("cosmos")
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec/address"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
@ -45,12 +45,15 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
WithCodec(s.encCfg.Codec).
|
||||
WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}).
|
||||
WithAccountRetriever(client.MockAccountRetriever{}).
|
||||
WithOutput(io.Discard)
|
||||
WithOutput(io.Discard).
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons"))
|
||||
}
|
||||
|
||||
func (s *CLITestSuite) TestSendTxCmd() {
|
||||
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
||||
cmd := cli.NewSendTxCmd(address.NewBech32Codec("cosmos"))
|
||||
cmd := cli.NewSendTxCmd(addresscodec.NewBech32Codec("cosmos"))
|
||||
cmd.SetOutput(io.Discard)
|
||||
|
||||
extraArgs := []string{
|
||||
@ -136,7 +139,7 @@ func (s *CLITestSuite) TestSendTxCmd() {
|
||||
func (s *CLITestSuite) TestMultiSendTxCmd() {
|
||||
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 3)
|
||||
|
||||
cmd := cli.NewMultiSendTxCmd(address.NewBech32Codec("cosmos"))
|
||||
cmd := cli.NewMultiSendTxCmd(addresscodec.NewBech32Codec("cosmos"))
|
||||
cmd.SetOutput(io.Discard)
|
||||
|
||||
extraArgs := []string{
|
||||
|
||||
@ -13,6 +13,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
@ -33,7 +34,10 @@ func TestNewMsgVerifyInvariantTxCmd(t *testing.T) {
|
||||
WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}).
|
||||
WithAccountRetriever(client.MockAccountRetriever{}).
|
||||
WithOutput(io.Discard).
|
||||
WithChainID("test-chain")
|
||||
WithChainID("test-chain").
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons"))
|
||||
|
||||
accounts := testutil.CreateKeyringAccounts(t, kr, 1)
|
||||
testCases := []struct {
|
||||
|
||||
@ -15,7 +15,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec/address"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
@ -52,7 +52,10 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}).
|
||||
WithAccountRetriever(client.MockAccountRetriever{}).
|
||||
WithOutput(io.Discard).
|
||||
WithChainID("test-chain")
|
||||
WithChainID("test-chain").
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons"))
|
||||
|
||||
ctxGen := func() client.Context {
|
||||
bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{})
|
||||
@ -133,7 +136,7 @@ func (s *CLITestSuite) TestTxWithdrawRewardsCmd() {
|
||||
args := append([]string{tc.valAddr.String()}, tc.args...)
|
||||
|
||||
ctx := svrcmd.CreateExecuteContext(context.Background())
|
||||
cmd := cli.NewWithdrawRewardsCmd(address.NewBech32Codec("cosmosvaloper"), address.NewBech32Codec("cosmos"))
|
||||
cmd := cli.NewWithdrawRewardsCmd(addresscodec.NewBech32Codec("cosmosvaloper"), addresscodec.NewBech32Codec("cosmos"))
|
||||
cmd.SetContext(ctx)
|
||||
cmd.SetArgs(args)
|
||||
s.Require().NoError(client.SetCmdClientContextHandler(s.clientCtx, cmd))
|
||||
@ -185,7 +188,7 @@ func (s *CLITestSuite) TestTxWithdrawAllRewardsCmd() {
|
||||
tc := tc
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.NewWithdrawAllRewardsCmd(address.NewBech32Codec("cosmosvaloper"), address.NewBech32Codec("cosmos"))
|
||||
cmd := cli.NewWithdrawAllRewardsCmd(addresscodec.NewBech32Codec("cosmosvaloper"), addresscodec.NewBech32Codec("cosmos"))
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(s.clientCtx, cmd, tc.args)
|
||||
if tc.expectErrMsg != "" {
|
||||
@ -237,7 +240,7 @@ func (s *CLITestSuite) TestTxSetWithdrawAddrCmd() {
|
||||
tc := tc
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.NewSetWithdrawAddrCmd(address.NewBech32Codec("cosmos"))
|
||||
cmd := cli.NewSetWithdrawAddrCmd(addresscodec.NewBech32Codec("cosmos"))
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(s.clientCtx, cmd, tc.args)
|
||||
if tc.expectErr {
|
||||
@ -287,7 +290,7 @@ func (s *CLITestSuite) TestTxFundCommunityPoolCmd() {
|
||||
tc := tc
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.NewFundCommunityPoolCmd(address.NewBech32Codec("cosmos"))
|
||||
cmd := cli.NewFundCommunityPoolCmd(addresscodec.NewBech32Codec("cosmos"))
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(s.clientCtx, cmd, tc.args)
|
||||
if tc.expectErr {
|
||||
|
||||
@ -21,7 +21,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
codecaddress "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
@ -70,7 +70,10 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}).
|
||||
WithAccountRetriever(client.MockAccountRetriever{}).
|
||||
WithOutput(io.Discard).
|
||||
WithChainID("test-chain")
|
||||
WithChainID("test-chain").
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons"))
|
||||
|
||||
ctxGen := func() client.Context {
|
||||
bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{})
|
||||
@ -128,7 +131,7 @@ func (s *CLITestSuite) createGrant(granter, grantee sdk.Address) {
|
||||
commonFlags...,
|
||||
)
|
||||
|
||||
cmd := cli.NewCmdFeeGrant(codecaddress.NewBech32Codec("cosmos"))
|
||||
cmd := cli.NewCmdFeeGrant(addresscodec.NewBech32Codec("cosmos"))
|
||||
out, err := clitestutil.ExecTestCLICmd(s.clientCtx, cmd, args)
|
||||
s.Require().NoError(err)
|
||||
|
||||
@ -415,7 +418,7 @@ func (s *CLITestSuite) TestNewCmdFeeGrant() {
|
||||
tc := tc
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.NewCmdFeeGrant(codecaddress.NewBech32Codec("cosmos"))
|
||||
cmd := cli.NewCmdFeeGrant(addresscodec.NewBech32Codec("cosmos"))
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
|
||||
if tc.expectErr {
|
||||
@ -439,7 +442,7 @@ func (s *CLITestSuite) TestNewCmdRevokeFeegrant() {
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()),
|
||||
}
|
||||
|
||||
addressCodec := codecaddress.NewBech32Codec("cosmos")
|
||||
addressCodec := addresscodec.NewBech32Codec("cosmos")
|
||||
// Create new fee grant specifically to test amino.
|
||||
encodedGrantee := "cosmos16ydaqh0fcnh4qt7a3jme4mmztm2qel5axcpw00"
|
||||
aminoGrantee, err := addressCodec.StringToBytes(encodedGrantee)
|
||||
@ -508,7 +511,7 @@ func (s *CLITestSuite) TestNewCmdRevokeFeegrant() {
|
||||
tc := tc
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.NewCmdRevokeFeegrant(codecaddress.NewBech32Codec("cosmos"))
|
||||
cmd := cli.NewCmdRevokeFeegrant(addresscodec.NewBech32Codec("cosmos"))
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
|
||||
if tc.expectErr {
|
||||
@ -551,7 +554,7 @@ func (s *CLITestSuite) TestTxWithFeeGrant() {
|
||||
commonFlags...,
|
||||
)
|
||||
|
||||
cmd := cli.NewCmdFeeGrant(codecaddress.NewBech32Codec("cosmos"))
|
||||
cmd := cli.NewCmdFeeGrant(addresscodec.NewBech32Codec("cosmos"))
|
||||
|
||||
var res sdk.TxResponse
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
|
||||
@ -704,7 +707,7 @@ func (s *CLITestSuite) TestFilteredFeeAllowance() {
|
||||
tc := tc
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.NewCmdFeeGrant(codecaddress.NewBech32Codec("cosmos"))
|
||||
cmd := cli.NewCmdFeeGrant(addresscodec.NewBech32Codec("cosmos"))
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
if tc.expectErrMsg != "" {
|
||||
s.Require().Error(err)
|
||||
@ -754,7 +757,7 @@ func (s *CLITestSuite) TestFilteredFeeAllowance() {
|
||||
commonFlags...,
|
||||
)
|
||||
|
||||
cmd := cli.NewCmdFeeGrant(codecaddress.NewBech32Codec("cosmos"))
|
||||
cmd := cli.NewCmdFeeGrant(addresscodec.NewBech32Codec("cosmos"))
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
|
||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &sdk.TxResponse{}), out.String())
|
||||
|
||||
|
||||
@ -10,10 +10,10 @@ require (
|
||||
cosmossdk.io/errors v1.0.0
|
||||
cosmossdk.io/log v1.2.0
|
||||
cosmossdk.io/math v1.1.2
|
||||
cosmossdk.io/store v1.0.0-alpha.1
|
||||
cosmossdk.io/store v1.0.0-alpha.1.0.20230728080422-54ed7dab3982
|
||||
github.com/cometbft/cometbft v0.38.0-rc3
|
||||
github.com/cosmos/cosmos-proto v1.0.0-beta.3
|
||||
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230727092431-f0f777fa3cb7
|
||||
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230822164746-64b2fc6ff80e
|
||||
github.com/cosmos/gogoproto v1.4.11
|
||||
github.com/golang/mock v1.6.0
|
||||
github.com/golang/protobuf v1.5.3
|
||||
|
||||
@ -49,8 +49,8 @@ cosmossdk.io/log v1.2.0 h1:BbykkDsutXPSy8RojFB3KZEWyvMsToLy0ykb/ZhsLqQ=
|
||||
cosmossdk.io/log v1.2.0/go.mod h1:GNSCc/6+DhFIj1aLn/j7Id7PaO8DzNylUZoOYBL9+I4=
|
||||
cosmossdk.io/math v1.1.2 h1:ORZetZCTyWkI5GlZ6CZS28fMHi83ZYf+A2vVnHNzZBM=
|
||||
cosmossdk.io/math v1.1.2/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0=
|
||||
cosmossdk.io/store v1.0.0-alpha.1 h1:/151XxAgm0tiKuYrtJzMG61lf6enpPuP+D/hIN8cRjQ=
|
||||
cosmossdk.io/store v1.0.0-alpha.1/go.mod h1:ejgU9GhRGMNBduVnDwC3RyhOmu4uKlNQlTiJgPmbDkI=
|
||||
cosmossdk.io/store v1.0.0-alpha.1.0.20230728080422-54ed7dab3982 h1:61YFeW2AhwwPfoJWzNJWvVubCj32sm5jZkJfraS9pDQ=
|
||||
cosmossdk.io/store v1.0.0-alpha.1.0.20230728080422-54ed7dab3982/go.mod h1:QAF9zeRa/9ghuv7E8NS9SzWqRbgVNwH/dZwGhYDHUjI=
|
||||
cosmossdk.io/x/tx v0.9.1 h1:9pmmXA9Vs4qdouOFnzhsdsff2mif0f0kylMq5xTGhRI=
|
||||
cosmossdk.io/x/tx v0.9.1/go.mod h1:/YFGTXG6+kyihd8YbfuJiXHV4R/mIMm2uvVzo80CIhA=
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
@ -182,8 +182,8 @@ github.com/cosmos/cosmos-db v1.0.0 h1:EVcQZ+qYag7W6uorBKFPvX6gRjw6Uq2hIh4hCWjuQ0
|
||||
github.com/cosmos/cosmos-db v1.0.0/go.mod h1:iBvi1TtqaedwLdcrZVYRSSCb6eSy61NLj4UNmdIgs0U=
|
||||
github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o=
|
||||
github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I=
|
||||
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230727092431-f0f777fa3cb7 h1:ZbRIti9b4rTLuLB9ZM5XAMev1AYi9eOoo0ide5vIstM=
|
||||
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230727092431-f0f777fa3cb7/go.mod h1:fKr/+xe4ZSzj38HwFBvxz/+LZ6v4e9bknD7vq6AJXzY=
|
||||
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230822164746-64b2fc6ff80e h1:uLglmtUZiCVxxlFOrfg7epXEW8blaQcraQlp9wGtftk=
|
||||
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230822164746-64b2fc6ff80e/go.mod h1:lUps0DsgRmykXPyjoEBIkJa0Ybq666DFdubg6AB+WCg=
|
||||
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
|
||||
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
|
||||
github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE=
|
||||
|
||||
@ -14,6 +14,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
@ -51,7 +52,10 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}).
|
||||
WithAccountRetriever(client.MockAccountRetriever{}).
|
||||
WithOutput(io.Discard).
|
||||
WithChainID("test-chain")
|
||||
WithChainID("test-chain").
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons"))
|
||||
|
||||
ctxGen := func() client.Context {
|
||||
bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{})
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
//nolint:staticcheck // legacy types used for migration
|
||||
package v3
|
||||
|
||||
import (
|
||||
@ -162,8 +161,8 @@ func convertToNewVotes(oldVotes v1beta1.Votes) (v1.Votes, error) {
|
||||
newWVOs[j] = v1.NewWeightedVoteOption(v1.VoteOption(oldWVO.Option), oldWVO.Weight)
|
||||
}
|
||||
|
||||
case oldVote.Option != v1beta1.OptionEmpty:
|
||||
newWVOs = v1.NewNonSplitVoteOption(v1.VoteOption(oldVote.Option))
|
||||
case oldVote.Option != v1beta1.OptionEmpty: //nolint:staticcheck // Depcrecated but required for migrations
|
||||
newWVOs = v1.NewNonSplitVoteOption(v1.VoteOption(oldVote.Option)) //nolint:staticcheck // Depcrecated but required for migrations
|
||||
default:
|
||||
return nil, fmt.Errorf("vote does not have neither InterfaceRegistryOptions nor Option")
|
||||
}
|
||||
@ -178,21 +177,21 @@ func convertToNewVotes(oldVotes v1beta1.Votes) (v1.Votes, error) {
|
||||
return newVotes, nil
|
||||
}
|
||||
|
||||
func convertToNewDepParams(oldDepParams v1beta1.DepositParams) v1.DepositParams {
|
||||
return v1.DepositParams{
|
||||
func convertToNewDepParams(oldDepParams v1beta1.DepositParams) v1.DepositParams { //nolint:staticcheck // Depcrecated but required for migrations
|
||||
return v1.DepositParams{ //nolint:staticcheck // Depcrecated but required for migrations
|
||||
MinDeposit: oldDepParams.MinDeposit,
|
||||
MaxDepositPeriod: &oldDepParams.MaxDepositPeriod,
|
||||
}
|
||||
}
|
||||
|
||||
func convertToNewVotingParams(oldVoteParams v1beta1.VotingParams) v1.VotingParams {
|
||||
return v1.VotingParams{
|
||||
func convertToNewVotingParams(oldVoteParams v1beta1.VotingParams) v1.VotingParams { //nolint:staticcheck // Depcrecated but required for migrations
|
||||
return v1.VotingParams{ //nolint:staticcheck // Depcrecated but required for migrations
|
||||
VotingPeriod: &oldVoteParams.VotingPeriod,
|
||||
}
|
||||
}
|
||||
|
||||
func convertToNewTallyParams(oldTallyParams v1beta1.TallyParams) v1.TallyParams {
|
||||
return v1.TallyParams{
|
||||
func convertToNewTallyParams(oldTallyParams v1beta1.TallyParams) v1.TallyParams { //nolint:staticcheck // Depcrecated but required for migrations
|
||||
return v1.TallyParams{ //nolint:staticcheck // Depcrecated but required for migrations
|
||||
Quorum: oldTallyParams.Quorum.String(),
|
||||
Threshold: oldTallyParams.Threshold.String(),
|
||||
VetoThreshold: oldTallyParams.VetoThreshold.String(),
|
||||
|
||||
@ -17,7 +17,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec/address"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
|
||||
@ -57,7 +57,10 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}).
|
||||
WithAccountRetriever(client.MockAccountRetriever{}).
|
||||
WithOutput(io.Discard).
|
||||
WithChainID("test-chain")
|
||||
WithChainID("test-chain").
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons"))
|
||||
|
||||
s.commonFlags = []string{
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
@ -89,7 +92,7 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
s.clientCtx,
|
||||
val.Address,
|
||||
account,
|
||||
sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(2000))), address.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(2000))), addresscodec.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()),
|
||||
)
|
||||
@ -942,7 +945,7 @@ func (s *CLITestSuite) TestTxUpdateGroupPolicyDecisionPolicy() {
|
||||
thresholdDecisionPolicy := testutil.WriteToNewTempFile(s.T(), `{"@type":"/cosmos.group.v1.ThresholdDecisionPolicy", "threshold":"1", "windows":{"voting_period":"40000s"}}`)
|
||||
percentageDecisionPolicy := testutil.WriteToNewTempFile(s.T(), `{"@type":"/cosmos.group.v1.PercentageDecisionPolicy", "percentage":"0.5", "windows":{"voting_period":"40000s"}}`)
|
||||
|
||||
cmd := groupcli.MsgUpdateGroupPolicyDecisionPolicyCmd(address.NewBech32Codec("cosmos"))
|
||||
cmd := groupcli.MsgUpdateGroupPolicyDecisionPolicyCmd(addresscodec.NewBech32Codec("cosmos"))
|
||||
cmd.SetOutput(io.Discard)
|
||||
|
||||
testCases := []struct {
|
||||
|
||||
@ -19,7 +19,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
codecaddress "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
@ -95,7 +95,10 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}).
|
||||
WithAccountRetriever(client.MockAccountRetriever{}).
|
||||
WithOutput(io.Discard).
|
||||
WithChainID("test-chain")
|
||||
WithChainID("test-chain").
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons"))
|
||||
|
||||
s.ctx = svrcmd.CreateExecuteContext(context.Background())
|
||||
ctxGen := func() client.Context {
|
||||
@ -123,7 +126,7 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
s.Require().NoError(err)
|
||||
genesisState[nft.ModuleName] = nftDataBz
|
||||
|
||||
s.ac = codecaddress.NewBech32Codec("cosmos")
|
||||
s.ac = addresscodec.NewBech32Codec("cosmos")
|
||||
|
||||
s.initAccount()
|
||||
}
|
||||
|
||||
@ -9,10 +9,10 @@ require (
|
||||
cosmossdk.io/errors v1.0.0
|
||||
cosmossdk.io/log v1.2.0
|
||||
cosmossdk.io/math v1.1.2
|
||||
cosmossdk.io/store v1.0.0-alpha.1
|
||||
cosmossdk.io/store v1.0.0-alpha.1.0.20230728080422-54ed7dab3982
|
||||
github.com/cometbft/cometbft v0.38.0-rc3
|
||||
github.com/cosmos/cosmos-proto v1.0.0-beta.3
|
||||
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230713093628-90d9a75d4125
|
||||
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230822164746-64b2fc6ff80e
|
||||
github.com/cosmos/gogoproto v1.4.11
|
||||
github.com/golang/mock v1.6.0
|
||||
github.com/golang/protobuf v1.5.3
|
||||
|
||||
@ -49,8 +49,8 @@ cosmossdk.io/log v1.2.0 h1:BbykkDsutXPSy8RojFB3KZEWyvMsToLy0ykb/ZhsLqQ=
|
||||
cosmossdk.io/log v1.2.0/go.mod h1:GNSCc/6+DhFIj1aLn/j7Id7PaO8DzNylUZoOYBL9+I4=
|
||||
cosmossdk.io/math v1.1.2 h1:ORZetZCTyWkI5GlZ6CZS28fMHi83ZYf+A2vVnHNzZBM=
|
||||
cosmossdk.io/math v1.1.2/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0=
|
||||
cosmossdk.io/store v1.0.0-alpha.1 h1:/151XxAgm0tiKuYrtJzMG61lf6enpPuP+D/hIN8cRjQ=
|
||||
cosmossdk.io/store v1.0.0-alpha.1/go.mod h1:ejgU9GhRGMNBduVnDwC3RyhOmu4uKlNQlTiJgPmbDkI=
|
||||
cosmossdk.io/store v1.0.0-alpha.1.0.20230728080422-54ed7dab3982 h1:61YFeW2AhwwPfoJWzNJWvVubCj32sm5jZkJfraS9pDQ=
|
||||
cosmossdk.io/store v1.0.0-alpha.1.0.20230728080422-54ed7dab3982/go.mod h1:QAF9zeRa/9ghuv7E8NS9SzWqRbgVNwH/dZwGhYDHUjI=
|
||||
cosmossdk.io/x/tx v0.9.1 h1:9pmmXA9Vs4qdouOFnzhsdsff2mif0f0kylMq5xTGhRI=
|
||||
cosmossdk.io/x/tx v0.9.1/go.mod h1:/YFGTXG6+kyihd8YbfuJiXHV4R/mIMm2uvVzo80CIhA=
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
@ -184,8 +184,8 @@ github.com/cosmos/cosmos-db v1.0.0 h1:EVcQZ+qYag7W6uorBKFPvX6gRjw6Uq2hIh4hCWjuQ0
|
||||
github.com/cosmos/cosmos-db v1.0.0/go.mod h1:iBvi1TtqaedwLdcrZVYRSSCb6eSy61NLj4UNmdIgs0U=
|
||||
github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o=
|
||||
github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I=
|
||||
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230713093628-90d9a75d4125 h1:2aGCqfxWf2AAvLOUHaRiByle6n0FPRdeOF/62JTldh0=
|
||||
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230713093628-90d9a75d4125/go.mod h1:LME6v5XztqVK7/1uTQj/G6ZJdosJEz24rKaPYk+WbqI=
|
||||
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230822164746-64b2fc6ff80e h1:uLglmtUZiCVxxlFOrfg7epXEW8blaQcraQlp9wGtftk=
|
||||
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230822164746-64b2fc6ff80e/go.mod h1:lUps0DsgRmykXPyjoEBIkJa0Ybq666DFdubg6AB+WCg=
|
||||
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
|
||||
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
|
||||
github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE=
|
||||
|
||||
@ -13,7 +13,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec/address"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
@ -52,7 +52,10 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}).
|
||||
WithAccountRetriever(client.MockAccountRetriever{}).
|
||||
WithOutput(io.Discard).
|
||||
WithChainID("test-chain")
|
||||
WithChainID("test-chain").
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons"))
|
||||
|
||||
ctxGen := func() client.Context {
|
||||
bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{})
|
||||
@ -97,7 +100,7 @@ func (s *CLITestSuite) TestNewUnjailTxCmd() {
|
||||
tc := tc
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.NewUnjailTxCmd(address.NewBech32Codec("cosmosvaloper"))
|
||||
cmd := cli.NewUnjailTxCmd(addresscodec.NewBech32Codec("cosmosvaloper"))
|
||||
clientCtx := s.clientCtx
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
|
||||
@ -39,6 +39,10 @@ type CLITestSuite struct {
|
||||
addrs []sdk.AccAddress
|
||||
}
|
||||
|
||||
func TestCLITestSuite(t *testing.T) {
|
||||
suite.Run(t, new(CLITestSuite))
|
||||
}
|
||||
|
||||
func (s *CLITestSuite) SetupSuite() {
|
||||
s.encCfg = testutilmod.MakeTestEncodingConfig(staking.AppModuleBasic{})
|
||||
s.kr = keyring.NewInMemory(s.encCfg.Codec)
|
||||
@ -49,7 +53,10 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}).
|
||||
WithAccountRetriever(client.MockAccountRetriever{}).
|
||||
WithOutput(io.Discard).
|
||||
WithChainID("test-chain")
|
||||
WithChainID("test-chain").
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons"))
|
||||
|
||||
ctxGen := func() client.Context {
|
||||
bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{})
|
||||
@ -717,7 +724,3 @@ func (s *CLITestSuite) TestNewCancelUnbondingDelegationCmd() {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCLITestSuite(t *testing.T) {
|
||||
suite.Run(t, new(CLITestSuite))
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user