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

fix: solve proposal handler route conflict #122

Merged
merged 2 commits into from
Apr 7, 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
35 changes: 0 additions & 35 deletions modules/tibc/core/02-client/proposal_handler.go

This file was deleted.

6 changes: 3 additions & 3 deletions modules/tibc/core/02-client/types/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (cup *CreateClientProposal) GetTitle() string { return cup.Title }
func (cup *CreateClientProposal) GetDescription() string { return cup.Description }

// ProposalRoute returns the routing key of a client update proposal.
func (cup *CreateClientProposal) ProposalRoute() string { return RouterKey }
func (cup *CreateClientProposal) ProposalRoute() string { return host.RouterKey }

// ProposalType returns the type of a client update proposal.
func (cup *CreateClientProposal) ProposalType() string { return ProposalTypeClientCreate }
Expand Down Expand Up @@ -128,7 +128,7 @@ func (cup *UpgradeClientProposal) GetTitle() string { return cup.Title }
func (cup *UpgradeClientProposal) GetDescription() string { return cup.Description }

// ProposalRoute returns the routing key of a client upgrade proposal.
func (cup *UpgradeClientProposal) ProposalRoute() string { return RouterKey }
func (cup *UpgradeClientProposal) ProposalRoute() string { return host.RouterKey }

// ProposalType returns the type of a client upgrade proposal.
func (cup *UpgradeClientProposal) ProposalType() string { return ProposalTypeClientUpgrade }
Expand Down Expand Up @@ -180,7 +180,7 @@ func (rrp *RegisterRelayerProposal) GetTitle() string { return rrp.Title }
func (rrp *RegisterRelayerProposal) GetDescription() string { return rrp.Description }

// ProposalRoute returns the routing key of a registering relayer proposal.
func (rrp *RegisterRelayerProposal) ProposalRoute() string { return RouterKey }
func (rrp *RegisterRelayerProposal) ProposalRoute() string { return host.RouterKey }

// ProposalType returns the type of a client registering relayer proposal.
func (rrp *RegisterRelayerProposal) ProposalType() string { return ProposalTypeRelayerRegister }
Expand Down
28 changes: 0 additions & 28 deletions modules/tibc/core/26-routing/proposal_handler.go

This file was deleted.

87 changes: 0 additions & 87 deletions modules/tibc/core/26-routing/proposal_handler_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion modules/tibc/core/26-routing/types/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (cup *SetRoutingRulesProposal) GetTitle() string { return cup.Title }
func (cup *SetRoutingRulesProposal) GetDescription() string { return cup.Description }

// ProposalRoute returns the routing key of a setting rules proposal.
func (cup *SetRoutingRulesProposal) ProposalRoute() string { return RouterKey }
func (cup *SetRoutingRulesProposal) ProposalRoute() string { return host.RouterKey }

// ProposalType returns the type of a setting rules proposal.
func (cup *SetRoutingRulesProposal) ProposalType() string { return ProposalTypeSetRoutingRules }
Expand Down
39 changes: 39 additions & 0 deletions modules/tibc/core/client/cli/proposal_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package cli

import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"

clientcli "github.com/bianjieai/tibc-go/modules/tibc/core/02-client/client/cli"
clienttypes "github.com/bianjieai/tibc-go/modules/tibc/core/02-client/types"
routingcli "github.com/bianjieai/tibc-go/modules/tibc/core/26-routing/client/cli"
routingtypes "github.com/bianjieai/tibc-go/modules/tibc/core/26-routing/types"
"github.com/bianjieai/tibc-go/modules/tibc/core/keeper"
)

var GovHandlers = []govclient.ProposalHandler{
govclient.NewProposalHandler(clientcli.NewCreateClientProposalCmd),
govclient.NewProposalHandler(clientcli.NewUpgradeClientProposalCmd),
govclient.NewProposalHandler(clientcli.NewRegisterRelayerProposalCmd),
govclient.NewProposalHandler(routingcli.NewSetRoutingRulesProposalCmd),
}

// NewProposalHandler defines the client manager proposal handler
func NewProposalHandler(k *keeper.Keeper) govv1beta1.Handler {
return func(ctx sdk.Context, content govv1beta1.Content) error {
switch c := content.(type) {
case *clienttypes.CreateClientProposal:
return k.ClientKeeper.HandleCreateClientProposal(ctx, c)
case *clienttypes.UpgradeClientProposal:
return k.ClientKeeper.HandleUpgradeClientProposal(ctx, c)
case *clienttypes.RegisterRelayerProposal:
return k.ClientKeeper.HandleRegisterRelayerProposal(ctx, c)
case *routingtypes.SetRoutingRulesProposal:
return k.RoutingKeeper.HandleSetRoutingRulesProposal(ctx, c)
default:
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized tibc proposal content type: %T", c)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package client_test
package cli_test

import (
"testing"
Expand All @@ -9,8 +9,9 @@ import (
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"

client "github.com/bianjieai/tibc-go/modules/tibc/core/02-client"
clienttypes "github.com/bianjieai/tibc-go/modules/tibc/core/02-client/types"
routingtypes "github.com/bianjieai/tibc-go/modules/tibc/core/26-routing/types"
clientcli "github.com/bianjieai/tibc-go/modules/tibc/core/client/cli"
ibctesting "github.com/bianjieai/tibc-go/modules/tibc/testing"
)

Expand Down Expand Up @@ -107,7 +108,7 @@ func (suite *ClientTestSuite) TestNewClientUpdateProposalHandler() {

tc.malleate()

proposalHandler := client.NewClientProposalHandler(suite.chainA.App.TIBCKeeper.ClientKeeper)
proposalHandler := clientcli.NewProposalHandler(suite.chainA.App.TIBCKeeper)

err = proposalHandler(suite.chainA.GetContext(), content)

Expand All @@ -119,3 +120,57 @@ func (suite *ClientTestSuite) TestNewClientUpdateProposalHandler() {
})
}
}

func (suite *ClientTestSuite) TestNewSetRoutingRulesProposalHandler() {
var (
content govv1beta1.Content
err error
)

testCases := []struct {
name string
malleate func()
expPass bool
}{
{
"valid routing rules proposal",
func() {
content, err = routingtypes.NewSetRoutingRulesProposal(ibctesting.Title, ibctesting.Description, []string{"source,dest,dgsbl"})
suite.Require().NoError(err)
}, true,
},
{
"nil proposal",
func() {
content = nil
}, false,
},
{
"unsupported proposal type",
func() {
content = distributiontypes.NewCommunityPoolSpendProposal(ibctesting.Title, ibctesting.Description, suite.chainA.SenderAccount.GetAddress(), sdk.NewCoins(sdk.NewCoin("communityfunds", sdk.NewInt(10))))
}, false,
},
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
suite.SetupTest() // reset

tc.malleate()

proposalHandler := clientcli.NewProposalHandler(suite.chainA.App.TIBCKeeper)

err = proposalHandler(suite.chainA.GetContext(), content)

if tc.expPass {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
}
})
}

}
25 changes: 10 additions & 15 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,9 @@ import (
mttypes "github.com/irisnet/irismod/modules/mt/types"

tibc "github.com/bianjieai/tibc-go/modules/tibc/core"
tibcclient "github.com/bianjieai/tibc-go/modules/tibc/core/02-client"
tibcclienttypes "github.com/bianjieai/tibc-go/modules/tibc/core/02-client/types"
tibchost "github.com/bianjieai/tibc-go/modules/tibc/core/24-host"
tibcrouting "github.com/bianjieai/tibc-go/modules/tibc/core/26-routing"
tibcroutingtypes "github.com/bianjieai/tibc-go/modules/tibc/core/26-routing/types"
corecli "github.com/bianjieai/tibc-go/modules/tibc/core/client/cli"
tibckeeper "github.com/bianjieai/tibc-go/modules/tibc/core/keeper"
tibcmock "github.com/bianjieai/tibc-go/modules/tibc/testing/mock"
simappparams "github.com/bianjieai/tibc-go/simapp/params"
Expand All @@ -117,6 +115,13 @@ var (
// DefaultNodeHome default home directories for the application daemon
DefaultNodeHome string

legacyProposalHandlers = []govclient.ProposalHandler{
paramsclient.ProposalHandler,
distrclient.ProposalHandler,
upgradeclient.LegacyProposalHandler,
upgradeclient.LegacyCancelProposalHandler,
}

// ModuleBasics defines the module BasicManager is in charge of setting up basic,
// non-dependant module elements, such as codec registration
// and genesis verification.
Expand All @@ -129,16 +134,7 @@ var (
mint.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic(
[]govclient.ProposalHandler{
paramsclient.ProposalHandler,
distrclient.ProposalHandler,
upgradeclient.LegacyProposalHandler,
upgradeclient.LegacyCancelProposalHandler,
tibcclient.CreateClientProposalHandler,
tibcclient.UpgradeClientProposalHandler,
tibcclient.RegisterRelayerProposalHandler,
tibcrouting.SetRoutingRulesProposalHandler,
},
append(legacyProposalHandlers, corecli.GovHandlers...),
),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
Expand Down Expand Up @@ -345,8 +341,7 @@ func NewSimApp(
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(tibcclienttypes.RouterKey, tibcclient.NewClientProposalHandler(app.TIBCKeeper.ClientKeeper)).
AddRoute(tibcroutingtypes.RouterKey, tibcrouting.NewSetRoutingProposalHandler(app.TIBCKeeper.RoutingKeeper))
AddRoute(tibchost.RouterKey, corecli.NewProposalHandler(app.TIBCKeeper))
govConfig := govtypes.DefaultConfig()
app.GovKeeper = govkeeper.NewKeeper(
appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
Expand Down