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

x/evidence: remove alias.go usage #6435

Merged
merged 2 commits into from
Jun 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 9 additions & 7 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/crisis"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/evidence"
evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/cosmos/cosmos-sdk/x/gov"
Expand Down Expand Up @@ -135,7 +137,7 @@ type SimApp struct {
UpgradeKeeper upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
IBCKeeper *ibc.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
EvidenceKeeper evidence.Keeper
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper transfer.Keeper

// make scoped keepers public for test purposes
Expand Down Expand Up @@ -166,7 +168,7 @@ func NewSimApp(
auth.StoreKey, bank.StoreKey, stakingtypes.StoreKey,
minttypes.StoreKey, distr.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, ibc.StoreKey, upgradetypes.StoreKey,
evidence.StoreKey, transfer.StoreKey, capability.StoreKey,
evidencetypes.StoreKey, transfer.StoreKey, capability.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capability.MemStoreKey)
Expand Down Expand Up @@ -265,10 +267,10 @@ func NewSimApp(
app.IBCKeeper.SetRouter(ibcRouter)

// create evidence keeper with router
evidenceKeeper := evidence.NewKeeper(
appCodec, keys[evidence.StoreKey], &app.StakingKeeper, app.SlashingKeeper,
evidenceKeeper := evidencekeeper.NewKeeper(
appCodec, keys[evidencetypes.StoreKey], &app.StakingKeeper, app.SlashingKeeper,
)
evidenceRouter := evidence.NewRouter().
evidenceRouter := evidencetypes.NewRouter().
AddRoute(ibcclient.RouterKey, ibcclient.HandlerClientMisbehaviour(app.IBCKeeper.ClientKeeper))

evidenceKeeper.SetRouter(evidenceRouter)
Expand Down Expand Up @@ -300,7 +302,7 @@ func NewSimApp(
// NOTE: staking module is required if HistoricalEntries param > 0
app.mm.SetOrderBeginBlockers(
upgradetypes.ModuleName, minttypes.ModuleName, distr.ModuleName, slashingtypes.ModuleName,
evidence.ModuleName, stakingtypes.ModuleName, ibc.ModuleName,
evidencetypes.ModuleName, stakingtypes.ModuleName, ibc.ModuleName,
)
app.mm.SetOrderEndBlockers(crisis.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName)

Expand All @@ -312,7 +314,7 @@ func NewSimApp(
app.mm.SetOrderInitGenesis(
capability.ModuleName, auth.ModuleName, distr.ModuleName, stakingtypes.ModuleName, bank.ModuleName,
slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisis.ModuleName,
ibc.ModuleName, genutiltypes.ModuleName, evidence.ModuleName, transfer.ModuleName,
ibc.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, transfer.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
Expand Down
4 changes: 2 additions & 2 deletions simapp/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/capability"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/evidence"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/ibc"
transfer "github.com/cosmos/cosmos-sdk/x/ibc-transfer"
Expand Down Expand Up @@ -160,7 +160,7 @@ func TestAppImportExport(t *testing.T) {
{app.keys[bank.StoreKey], newApp.keys[bank.StoreKey], [][]byte{bank.BalancesPrefix}},
{app.keys[paramtypes.StoreKey], newApp.keys[paramtypes.StoreKey], [][]byte{}},
{app.keys[govtypes.StoreKey], newApp.keys[govtypes.StoreKey], [][]byte{}},
{app.keys[evidence.StoreKey], newApp.keys[evidence.StoreKey], [][]byte{}},
{app.keys[evidencetypes.StoreKey], newApp.keys[evidencetypes.StoreKey], [][]byte{}},
{app.keys[capability.StoreKey], newApp.keys[capability.StoreKey], [][]byte{}},
{app.keys[ibc.StoreKey], newApp.keys[ibc.StoreKey], [][]byte{}},
{app.keys[transfer.StoreKey], newApp.keys[transfer.StoreKey], [][]byte{}},
Expand Down
9 changes: 6 additions & 3 deletions x/evidence/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ import (

abci "github.com/tendermint/tendermint/abci/types"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/x/evidence/keeper"
"github.com/cosmos/cosmos-sdk/x/evidence/types"
)

// BeginBlocker iterates through and handles any newly discovered evidence of
// misbehavior submitted by Tendermint. Currently, only equivocation is handled.
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k Keeper) {
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) {
for _, tmEvidence := range req.ByzantineValidators {
switch tmEvidence.Type {
case tmtypes.ABCIEvidenceTypeDuplicateVote:
evidence := ConvertDuplicateVoteEvidence(tmEvidence)
k.HandleDoubleSign(ctx, evidence.(*Equivocation))
evidence := types.ConvertDuplicateVoteEvidence(tmEvidence)
k.HandleDoubleSign(ctx, evidence.(*types.Equivocation))

default:
k.Logger(ctx).Error(fmt.Sprintf("ignored unknown evidence type: %s", tmEvidence.Type))
Expand Down
50 changes: 0 additions & 50 deletions x/evidence/alias.go

This file was deleted.

10 changes: 6 additions & 4 deletions x/evidence/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/evidence/keeper"
"github.com/cosmos/cosmos-sdk/x/evidence/types"
)

// InitGenesis initializes the evidence module's state from a provided genesis
// state.
func InitGenesis(ctx sdk.Context, k Keeper, gs GenesisState) {
func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) {
if err := gs.Validate(); err != nil {
panic(fmt.Sprintf("failed to validate %s genesis state: %s", ModuleName, err))
panic(fmt.Sprintf("failed to validate %s genesis state: %s", types.ModuleName, err))
}

for _, e := range gs.Evidence {
Expand All @@ -23,8 +25,8 @@ func InitGenesis(ctx sdk.Context, k Keeper, gs GenesisState) {
}

// ExportGenesis returns the evidence module's exported genesis.
func ExportGenesis(ctx sdk.Context, k Keeper) GenesisState {
return GenesisState{
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState {
return types.GenesisState{
Evidence: k.GetAllEvidence(ctx),
}
}
7 changes: 4 additions & 3 deletions x/evidence/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/evidence"
"github.com/cosmos/cosmos-sdk/x/evidence/exported"
"github.com/cosmos/cosmos-sdk/x/evidence/keeper"
"github.com/cosmos/cosmos-sdk/x/evidence/types"
)

type GenesisTestSuite struct {
suite.Suite

ctx sdk.Context
keeper evidence.Keeper
keeper keeper.Keeper
}

func (suite *GenesisTestSuite) SetupTest() {
Expand All @@ -44,7 +45,7 @@ func (suite *GenesisTestSuite) TestInitGenesis_Valid() {
}

suite.NotPanics(func() {
evidence.InitGenesis(suite.ctx, suite.keeper, evidence.NewGenesisState(testEvidence))
evidence.InitGenesis(suite.ctx, suite.keeper, types.NewGenesisState(testEvidence))
})

for _, e := range testEvidence {
Expand All @@ -66,7 +67,7 @@ func (suite *GenesisTestSuite) TestInitGenesis_Invalid() {
}

suite.Panics(func() {
evidence.InitGenesis(suite.ctx, suite.keeper, evidence.NewGenesisState(testEvidence))
evidence.InitGenesis(suite.ctx, suite.keeper, types.NewGenesisState(testEvidence))
})

suite.Empty(suite.keeper.GetAllEvidence(suite.ctx))
Expand Down
10 changes: 6 additions & 4 deletions x/evidence/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/evidence/exported"
"github.com/cosmos/cosmos-sdk/x/evidence/keeper"
"github.com/cosmos/cosmos-sdk/x/evidence/types"
)

func NewHandler(k Keeper) sdk.Handler {
func NewHandler(k keeper.Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
ctx = ctx.WithEventManager(sdk.NewEventManager())

Expand All @@ -16,12 +18,12 @@ func NewHandler(k Keeper) sdk.Handler {

default:

return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", ModuleName, msg)
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg)
}
}
}

func handleMsgSubmitEvidence(ctx sdk.Context, k Keeper, msg exported.MsgSubmitEvidence) (*sdk.Result, error) {
func handleMsgSubmitEvidence(ctx sdk.Context, k keeper.Keeper, msg exported.MsgSubmitEvidence) (*sdk.Result, error) {
evidence := msg.GetEvidence()
if err := k.SubmitEvidence(ctx, evidence); err != nil {
return nil, err
Expand All @@ -30,7 +32,7 @@ func handleMsgSubmitEvidence(ctx sdk.Context, k Keeper, msg exported.MsgSubmitEv
ctx.EventManager().EmitEvent(
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, msg.GetSubmitter().String()),
),
)
Expand Down
9 changes: 5 additions & 4 deletions x/evidence/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/evidence"
"github.com/cosmos/cosmos-sdk/x/evidence/exported"
"github.com/cosmos/cosmos-sdk/x/evidence/keeper"
"github.com/cosmos/cosmos-sdk/x/evidence/types"
)

Expand All @@ -25,7 +26,7 @@ type HandlerTestSuite struct {
}

func testMsgSubmitEvidence(r *require.Assertions, e exported.Evidence, s sdk.AccAddress) exported.MsgSubmitEvidence {
msg, err := evidence.NewMsgSubmitEvidence(s, e)
msg, err := types.NewMsgSubmitEvidence(s, e)
r.NoError(err)
return msg
}
Expand Down Expand Up @@ -53,10 +54,10 @@ func (suite *HandlerTestSuite) SetupTest() {
app := simapp.Setup(checkTx)

// recreate keeper in order to use custom testing types
evidenceKeeper := evidence.NewKeeper(
app.AppCodec(), app.GetKey(evidence.StoreKey), app.StakingKeeper, app.SlashingKeeper,
evidenceKeeper := keeper.NewKeeper(
app.AppCodec(), app.GetKey(types.StoreKey), app.StakingKeeper, app.SlashingKeeper,
)
router := evidence.NewRouter()
router := types.NewRouter()
router = router.AddRoute(types.RouteEquivocation, testEquivocationHandler(*evidenceKeeper))
evidenceKeeper.SetRouter(router)

Expand Down
7 changes: 3 additions & 4 deletions x/evidence/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/evidence"
"github.com/cosmos/cosmos-sdk/x/evidence/exported"
"github.com/cosmos/cosmos-sdk/x/evidence/keeper"
"github.com/cosmos/cosmos-sdk/x/evidence/types"
Expand Down Expand Up @@ -81,10 +80,10 @@ func (suite *KeeperTestSuite) SetupTest() {
app := simapp.Setup(checkTx)

// recreate keeper in order to use custom testing types
evidenceKeeper := evidence.NewKeeper(
app.AppCodec(), app.GetKey(evidence.StoreKey), app.StakingKeeper, app.SlashingKeeper,
evidenceKeeper := keeper.NewKeeper(
app.AppCodec(), app.GetKey(types.StoreKey), app.StakingKeeper, app.SlashingKeeper,
)
router := evidence.NewRouter()
router := types.NewRouter()
router = router.AddRoute(types.RouteEquivocation, testEquivocationHandler(*evidenceKeeper))
evidenceKeeper.SetRouter(router)

Expand Down
Loading