refactor(x): remove Address.String() (#20048)
This commit is contained in:
parent
0f39ba3f09
commit
f499bbf213
@ -49,7 +49,10 @@ func GetTxInitCmd() *cobra.Command {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sender := clientCtx.GetFromAddress()
|
||||
sender, err := clientCtx.AddressCodec.BytesToString(clientCtx.GetFromAddress())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// we need to convert the message from json to a protobuf message
|
||||
// to know which message to use, we need to know the account type
|
||||
@ -67,7 +70,7 @@ func GetTxInitCmd() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
msg := v1.MsgInit{
|
||||
Sender: sender.String(),
|
||||
Sender: sender,
|
||||
AccountType: args[0],
|
||||
Message: msgBytes,
|
||||
}
|
||||
@ -89,7 +92,10 @@ func GetExecuteCmd() *cobra.Command {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sender := clientCtx.GetFromAddress()
|
||||
sender, err := clientCtx.AddressCodec.BytesToString(clientCtx.GetFromAddress())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
schema, err := getSchemaForAccount(clientCtx, args[0])
|
||||
if err != nil {
|
||||
@ -101,7 +107,7 @@ func GetExecuteCmd() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
msg := v1.MsgExecute{
|
||||
Sender: sender.String(),
|
||||
Sender: sender,
|
||||
Target: args[0],
|
||||
Message: msgBytes,
|
||||
}
|
||||
|
||||
@ -220,8 +220,18 @@ func (k Keeper) DeleteGrant(ctx context.Context, grantee, granter sdk.AccAddress
|
||||
skey := grantStoreKey(grantee, granter, msgType)
|
||||
grant, found := k.getGrant(ctx, skey)
|
||||
if !found {
|
||||
granterAddr, err := k.authKeeper.AddressCodec().BytesToString(granter)
|
||||
if err != nil {
|
||||
return errorsmod.Wrapf(authz.ErrNoAuthorizationFound,
|
||||
"could not convert granter address to string")
|
||||
}
|
||||
granteeAddr, err := k.authKeeper.AddressCodec().BytesToString(grantee)
|
||||
if err != nil {
|
||||
return errorsmod.Wrapf(authz.ErrNoAuthorizationFound,
|
||||
"could not convert grantee address to string")
|
||||
}
|
||||
return errorsmod.Wrapf(authz.ErrNoAuthorizationFound,
|
||||
"failed to delete grant with given granter: %s, grantee: %s & msgType: %s ", granter.String(), grantee.String(), msgType)
|
||||
"failed to delete grant with given granter: %s, grantee: %s & msgType: %s ", granterAddr, granteeAddr, msgType)
|
||||
}
|
||||
|
||||
if grant.Expiration != nil {
|
||||
|
||||
@ -51,10 +51,15 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
|
||||
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
|
||||
}
|
||||
|
||||
authorityAddr, err := in.AddressCodec.BytesToString(authority)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
circuitkeeper := keeper.NewKeeper(
|
||||
in.Environment,
|
||||
in.Cdc,
|
||||
authority.String(),
|
||||
authorityAddr,
|
||||
in.AddressCodec,
|
||||
)
|
||||
m := NewAppModule(in.Cdc, circuitkeeper)
|
||||
|
||||
@ -18,7 +18,6 @@ import (
|
||||
codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/runtime"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
||||
)
|
||||
|
||||
@ -43,14 +42,16 @@ func (s *GenesisTestSuite) SetupTest() {
|
||||
sdkCtx := testCtx.Ctx
|
||||
s.ctx = sdkCtx
|
||||
s.cdc = codec.NewProtoCodec(encCfg.InterfaceRegistry)
|
||||
authority := authtypes.NewModuleAddress("gov")
|
||||
ac := addresscodec.NewBech32Codec("cosmos")
|
||||
|
||||
bz, err := ac.StringToBytes(authority.String())
|
||||
authority, err := ac.BytesToString(authtypes.NewModuleAddress("gov"))
|
||||
s.Require().NoError(err)
|
||||
|
||||
bz, err := ac.StringToBytes(authority)
|
||||
s.Require().NoError(err)
|
||||
s.addrBytes = bz
|
||||
|
||||
s.keeper = keeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()), s.cdc, authority.String(), ac)
|
||||
s.keeper = keeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()), s.cdc, authority, ac)
|
||||
}
|
||||
|
||||
func (s *GenesisTestSuite) TestInitExportGenesis() {
|
||||
@ -62,8 +63,10 @@ func (s *GenesisTestSuite) TestInitExportGenesis() {
|
||||
s.Require().NoError(err)
|
||||
|
||||
var accounts []*types.GenesisAccountPermissions
|
||||
addr, err := addresscodec.NewBech32Codec("cosmos").BytesToString(s.addrBytes)
|
||||
s.Require().NoError(err)
|
||||
genAccsPerms := types.GenesisAccountPermissions{
|
||||
Address: sdk.AccAddress(s.addrBytes).String(),
|
||||
Address: addr,
|
||||
Permissions: &perms,
|
||||
}
|
||||
accounts = append(accounts, &genAccsPerms)
|
||||
|
||||
@ -46,9 +46,11 @@ func initFixture(t *testing.T) *fixture {
|
||||
mockStoreKey := storetypes.NewKVStoreKey("test")
|
||||
|
||||
env := runtime.NewEnvironment(runtime.NewKVStoreService(mockStoreKey), log.NewNopLogger())
|
||||
k := keeper.NewKeeper(env, encCfg.Codec, authtypes.NewModuleAddress("gov").String(), ac)
|
||||
authority, err := ac.BytesToString(authtypes.NewModuleAddress("gov"))
|
||||
require.NoError(t, err)
|
||||
k := keeper.NewKeeper(env, encCfg.Codec, authority, ac)
|
||||
|
||||
bz, err := ac.StringToBytes(authtypes.NewModuleAddress("gov").String())
|
||||
bz, err := ac.StringToBytes(authority)
|
||||
require.NoError(t, err)
|
||||
|
||||
return &fixture{
|
||||
|
||||
@ -2,6 +2,7 @@ package consensus
|
||||
|
||||
import (
|
||||
modulev1 "cosmossdk.io/api/cosmos/consensus/module/v1"
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/depinject"
|
||||
"cosmossdk.io/depinject/appconfig"
|
||||
@ -28,9 +29,10 @@ func init() {
|
||||
type ModuleInputs struct {
|
||||
depinject.In
|
||||
|
||||
Config *modulev1.Module
|
||||
Cdc codec.Codec
|
||||
Environment appmodule.Environment
|
||||
Config *modulev1.Module
|
||||
Cdc codec.Codec
|
||||
Environment appmodule.Environment
|
||||
AddressCodec address.Codec
|
||||
}
|
||||
|
||||
type ModuleOutputs struct {
|
||||
@ -48,7 +50,12 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
|
||||
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
|
||||
}
|
||||
|
||||
k := keeper.NewKeeper(in.Cdc, in.Environment, authority.String())
|
||||
authorityAddr, err := in.AddressCodec.BytesToString(authority)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
k := keeper.NewKeeper(in.Cdc, in.Environment, authorityAddr)
|
||||
m := NewAppModule(in.Cdc, k)
|
||||
baseappOpt := func(app *baseapp.BaseApp) {
|
||||
app.SetParamStore(k.ParamsStore)
|
||||
|
||||
@ -36,7 +36,10 @@ func (s *KeeperTestSuite) SetupTest() {
|
||||
encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{})
|
||||
env := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger())
|
||||
|
||||
keeper := consensusparamkeeper.NewKeeper(encCfg.Codec, env, authtypes.NewModuleAddress("gov").String())
|
||||
authority, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(authtypes.NewModuleAddress("gov"))
|
||||
s.Require().NoError(err)
|
||||
|
||||
keeper := consensusparamkeeper.NewKeeper(encCfg.Codec, env, authority)
|
||||
|
||||
s.ctx = ctx
|
||||
s.consensusParamsKeeper = &keeper
|
||||
|
||||
@ -32,10 +32,15 @@ func ProposalMsgs() []simtypes.WeightedProposalMsg {
|
||||
}
|
||||
|
||||
// SimulateMsgUpdateParams returns a random MsgUpdateParams
|
||||
func SimulateMsgUpdateParams(r *rand.Rand, _ []simtypes.Account, _ coreaddress.Codec) (sdk.Msg, error) {
|
||||
func SimulateMsgUpdateParams(r *rand.Rand, _ []simtypes.Account, ac coreaddress.Codec) (sdk.Msg, error) {
|
||||
// use the default gov module account address as authority
|
||||
var authority sdk.AccAddress = address.Module("gov")
|
||||
|
||||
authorityAddr, err := ac.BytesToString(authority)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
params := types.DefaultParams()
|
||||
params.BlocksPerYear = uint64(simtypes.RandIntBetween(r, 1, 1000000))
|
||||
params.GoalBonded = sdkmath.LegacyNewDecWithPrec(int64(simtypes.RandIntBetween(r, 1, 100)), 2)
|
||||
@ -45,7 +50,7 @@ func SimulateMsgUpdateParams(r *rand.Rand, _ []simtypes.Account, _ coreaddress.C
|
||||
params.MintDenom = simtypes.RandStringOfLength(r, 10)
|
||||
|
||||
return &types.MsgUpdateParams{
|
||||
Authority: authority.String(),
|
||||
Authority: authorityAddr,
|
||||
Params: params,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -11,12 +11,12 @@ import (
|
||||
"cosmossdk.io/x/mint/types"
|
||||
|
||||
codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/address"
|
||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
||||
)
|
||||
|
||||
func TestProposalMsgs(t *testing.T) {
|
||||
ac := codectestutil.CodecOptions{}.GetAddressCodec()
|
||||
// initialize parameters
|
||||
s := rand.NewSource(1)
|
||||
r := rand.New(s)
|
||||
@ -33,12 +33,15 @@ func TestProposalMsgs(t *testing.T) {
|
||||
assert.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey())
|
||||
assert.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight())
|
||||
|
||||
msg, err := w0.MsgSimulatorFn()(r, accounts, codectestutil.CodecOptions{}.GetAddressCodec())
|
||||
msg, err := w0.MsgSimulatorFn()(r, accounts, ac)
|
||||
assert.NilError(t, err)
|
||||
msgUpdateParams, ok := msg.(*types.MsgUpdateParams)
|
||||
assert.Assert(t, ok)
|
||||
|
||||
assert.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority)
|
||||
authority, err := ac.BytesToString(address.Module("gov"))
|
||||
assert.NilError(t, err)
|
||||
|
||||
assert.Equal(t, authority, msgUpdateParams.Authority)
|
||||
assert.Equal(t, uint64(122877), msgUpdateParams.Params.BlocksPerYear)
|
||||
assert.DeepEqual(t, sdkmath.LegacyNewDecWithPrec(95, 2), msgUpdateParams.Params.GoalBonded)
|
||||
assert.DeepEqual(t, sdkmath.LegacyNewDecWithPrec(94, 2), msgUpdateParams.Params.InflationMax)
|
||||
|
||||
@ -28,7 +28,11 @@ func (k Keeper) HasValidatorSigningInfo(ctx context.Context, consAddr sdk.ConsAd
|
||||
func (k Keeper) JailUntil(ctx context.Context, consAddr sdk.ConsAddress, jailTime time.Time) error {
|
||||
signInfo, err := k.ValidatorSigningInfo.Get(ctx, consAddr)
|
||||
if err != nil {
|
||||
return errorsmod.Wrap(err, fmt.Sprintf("cannot jail validator with consensus address %s that does not have any signing information", consAddr.String()))
|
||||
addr, err := k.sk.ConsensusAddressCodec().BytesToString(consAddr)
|
||||
if err != nil {
|
||||
return types.ErrNoSigningInfoFound.Wrapf("could not convert consensus address to string. Error: %s", err.Error())
|
||||
}
|
||||
return errorsmod.Wrap(err, fmt.Sprintf("cannot jail validator with consensus address %s that does not have any signing information", addr))
|
||||
}
|
||||
|
||||
signInfo.JailedUntil = jailTime
|
||||
@ -39,7 +43,11 @@ func (k Keeper) JailUntil(ctx context.Context, consAddr sdk.ConsAddress, jailTim
|
||||
func (k Keeper) Tombstone(ctx context.Context, consAddr sdk.ConsAddress) error {
|
||||
signInfo, err := k.ValidatorSigningInfo.Get(ctx, consAddr)
|
||||
if err != nil {
|
||||
return types.ErrNoSigningInfoFound.Wrap(fmt.Sprintf("cannot tombstone validator with consensus address %s that does not have any signing information", consAddr.String()))
|
||||
addr, err := k.sk.ConsensusAddressCodec().BytesToString(consAddr)
|
||||
if err != nil {
|
||||
return types.ErrNoSigningInfoFound.Wrapf("could not convert consensus address to string. Error: %s", err.Error())
|
||||
}
|
||||
return types.ErrNoSigningInfoFound.Wrap(fmt.Sprintf("cannot tombstone validator with consensus address %s that does not have any signing information", addr))
|
||||
}
|
||||
|
||||
if signInfo.Tombstoned {
|
||||
|
||||
@ -121,15 +121,18 @@ func (s *KeeperTestSuite) TestPerformConsensusPubKeyUpdate() {
|
||||
oldConsAddr := sdk.ConsAddress(pks[0].Address())
|
||||
newConsAddr := sdk.ConsAddress(pks[1].Address())
|
||||
|
||||
consAddr, err := s.stakingKeeper.ConsensusAddressCodec().BytesToString(newConsAddr)
|
||||
s.Require().NoError(err)
|
||||
|
||||
newInfo := slashingtypes.NewValidatorSigningInfo(
|
||||
newConsAddr.String(),
|
||||
consAddr,
|
||||
int64(4),
|
||||
time.Unix(2, 0).UTC(),
|
||||
false,
|
||||
int64(10),
|
||||
)
|
||||
|
||||
err := slashingKeeper.ValidatorSigningInfo.Set(ctx, oldConsAddr, newInfo)
|
||||
err = slashingKeeper.ValidatorSigningInfo.Set(ctx, oldConsAddr, newInfo)
|
||||
require.NoError(err)
|
||||
|
||||
s.stakingKeeper.EXPECT().ValidatorIdentifier(gomock.Any(), oldConsAddr).Return(oldConsAddr, nil)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user