Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(evidence): remove bech32 global #15825

Merged
merged 8 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func NewSimApp(

// create evidence keeper with router
evidenceKeeper := evidencekeeper.NewKeeper(
appCodec, keys[evidencetypes.StoreKey], app.StakingKeeper, app.SlashingKeeper,
appCodec, keys[evidencetypes.StoreKey], app.StakingKeeper, app.SlashingKeeper, app.AccountKeeper.GetAddressCodec(),
)
// If evidence needs to be handled for the app, set routes in router here and seal
app.EvidenceKeeper = *evidenceKeeper
Expand Down
4 changes: 4 additions & 0 deletions x/evidence/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

* (x/evidence) [14724](https://github.com/cosmos/cosmos-sdk/pull/14724) The `x/evidence` module is extracted to have a separate go.mod file which allows it be a standalone module.
* (keeper) [#15420](https://github.com/cosmos/cosmos-sdk/pull/15420) Move `BeginBlocker` to the keeper folder & make HandleEquivocation private

### API Breaking Changes

* (keeper) [#15825](https://github.com/cosmos/cosmos-sdk/pull/15825) Evidence constructor now requires an `address.Codec` (`import "cosmossdk.io/core/address"`)
5 changes: 4 additions & 1 deletion x/evidence/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"strings"

"cosmossdk.io/core/address"
"cosmossdk.io/log"
"cosmossdk.io/x/evidence/exported"
"cosmossdk.io/x/evidence/types"
Expand All @@ -26,18 +27,20 @@ type Keeper struct {
router types.Router
stakingKeeper types.StakingKeeper
slashingKeeper types.SlashingKeeper
addressCodec address.Codec
}

// NewKeeper creates a new Keeper object.
func NewKeeper(
cdc codec.BinaryCodec, storeKey storetypes.StoreKey, stakingKeeper types.StakingKeeper,
slashingKeeper types.SlashingKeeper,
slashingKeeper types.SlashingKeeper, ac address.Codec,
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
) *Keeper {
return &Keeper{
cdc: cdc,
storeKey: storeKey,
stakingKeeper: stakingKeeper,
slashingKeeper: slashingKeeper,
addressCodec: ac,
}
}

Expand Down
2 changes: 2 additions & 0 deletions x/evidence/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/testutil"
Expand Down Expand Up @@ -101,6 +102,7 @@ func (suite *KeeperTestSuite) SetupTest() {
key,
stakingKeeper,
slashingKeeper,
address.NewBech32Codec("cosmos"),
)

suite.stakingKeeper = stakingKeeper
Expand Down
2 changes: 1 addition & 1 deletion x/evidence/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var _ types.MsgServer = msgServer{}

// SubmitEvidence implements the MsgServer.SubmitEvidence method.
func (ms msgServer) SubmitEvidence(goCtx context.Context, msg *types.MsgSubmitEvidence) (*types.MsgSubmitEvidenceResponse, error) {
if _, err := sdk.AccAddressFromBech32(msg.Submitter); err != nil {
if _, err := ms.addressCodec.StringToBytes(msg.Submitter); err != nil {
return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid submitter address: %s", err)
}

Expand Down
2 changes: 1 addition & 1 deletion x/evidence/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *KeeperTestSuite) TestSubmitEvidence() {
name: "invalid address",
req: &types.MsgSubmitEvidence{},
expErr: true,
expErrMsg: "invalid submitter address: empty address string is not allowed: invalid address",
expErrMsg: "invalid submitter address: decoding bech32 failed: invalid bech32 string length 0",
},
{
name: "missing evidence",
Expand Down
4 changes: 3 additions & 1 deletion x/evidence/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"google.golang.org/grpc"

modulev1 "cosmossdk.io/api/cosmos/evidence/module/v1"
"cosmossdk.io/core/address"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject"

Expand Down Expand Up @@ -207,6 +208,7 @@ type ModuleInputs struct {

StakingKeeper types.StakingKeeper
SlashingKeeper types.SlashingKeeper
AddressCodec address.Codec
}

type ModuleOutputs struct {
Expand All @@ -217,7 +219,7 @@ type ModuleOutputs struct {
}

func ProvideModule(in ModuleInputs) ModuleOutputs {
k := keeper.NewKeeper(in.Cdc, in.Key, in.StakingKeeper, in.SlashingKeeper)
k := keeper.NewKeeper(in.Cdc, in.Key, in.StakingKeeper, in.SlashingKeeper, in.AddressCodec)
m := NewAppModule(*k)

return ModuleOutputs{EvidenceKeeper: *k, Module: m}
Expand Down