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

test: ensure msg is registered in MsgServiceRouter #628

Merged
merged 1 commit into from
Aug 6, 2024
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 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ lint-install:
lint: lint-install
echo "--> Running linter"
@golangci-lint run --build-tags=$(GO_BUILD) --out-format=tab
@if [ $$(find . -name '*.go' -type f | xargs grep 'nolint\|#nosec' | wc -l) -ne 44 ]; then \
@if [ $$(find . -name '*.go' -type f | xargs grep 'nolint\|#nosec' | wc -l) -ne 43 ]; then \
echo "\033[91m--> increase or decrease nolint, please recheck them\033[0m"; \
echo "\033[91m--> list nolint: \`find . -name '*.go' -type f | xargs grep 'nolint\|#nosec'\`\033[0m"; exit 1;\
fi
Expand Down
44 changes: 44 additions & 0 deletions app/app_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package app_test

import (
"os"
"testing"

dbm "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/assert"

"github.com/functionx/fx-core/v7/app"
fxtypes "github.com/functionx/fx-core/v7/types"
crosschaintypes "github.com/functionx/fx-core/v7/x/crosschain/types"
govlegacy "github.com/functionx/fx-core/v7/x/gov/legacy"
gravitytypes "github.com/functionx/fx-core/v7/x/gravity/types"
)

func Test_MsgServiceRouter(t *testing.T) {
home := t.TempDir()
chainId := fxtypes.TestnetChainId
encodingConfig := app.MakeEncodingConfig()

myApp := app.New(log.NewFilter(log.NewTMLogger(os.Stdout), log.AllowAll()),
dbm.NewMemDB(), nil, true, map[int64]bool{}, home, 0,
encodingConfig, app.EmptyAppOptions{}, baseapp.SetChainID(chainId))

msgServiceRouter := myApp.MsgServiceRouter()
// nolint:staticcheck
deprecated := map[string]struct{}{
sdk.MsgTypeURL(&crosschaintypes.MsgSetOrchestratorAddress{}): {},
sdk.MsgTypeURL(&crosschaintypes.MsgAddOracleDeposit{}): {},
sdk.MsgTypeURL(&gravitytypes.MsgSetOrchestratorAddress{}): {},
sdk.MsgTypeURL(&gravitytypes.MsgFxOriginatedTokenClaim{}): {},
sdk.MsgTypeURL(&govlegacy.MsgUpdateParams{}): {},
}
for _, msg := range encodingConfig.InterfaceRegistry.ListImplementations(sdk.MsgInterfaceProtoName) {
if _, ok := deprecated[msg]; ok {
continue
}
assert.NotNil(t, msgServiceRouter.HandlerByTypeURL(msg), msg)
}
}
2 changes: 1 addition & 1 deletion x/crosschain/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (suite *KeeperTestSuite) TestBatchAndTxImportExport() {
denom, err := suite.Keeper().SetIbcDenomTrace(suite.ctx, bridgeToken.Token, "")
suite.Require().NoError(err)
suite.Require().Equal(denom, bridgeToken.Denom)
suite.Keeper().AddBridgeToken(suite.ctx, bridgeToken.Token, denom) // nolint:staticcheck
suite.Keeper().AddBridgeToken(suite.ctx, bridgeToken.Token, denom)

for _, bridger := range suite.bridgerAddrs {
voucher := sdk.NewCoin(bridgeToken.Denom, sdkmath.NewInt(9990))
Expand Down
4 changes: 2 additions & 2 deletions x/crosschain/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func (suite *KeeperTestSuite) TestMsgEditBridger() {

token := fmt.Sprintf("0x%s", tmrand.Str(40))
denom := types.NewBridgeDenom(suite.chainName, token)
suite.Keeper().AddBridgeToken(suite.ctx, token, denom) // nolint:staticcheck
suite.Keeper().AddBridgeToken(suite.ctx, token, denom)

privateKey, err := crypto.GenerateKey()
suite.Require().NoError(err)
Expand Down Expand Up @@ -671,7 +671,7 @@ func (suite *KeeperTestSuite) TestClaimMsgGasConsumed() {
execute: func(claimMsg types.ExternalClaim) (minGas, maxGas, avgGas uint64) {
msg, ok := claimMsg.(*types.MsgSendToFxClaim)
suite.True(ok)
suite.Keeper().AddBridgeToken(suite.ctx, msg.TokenContract, types.NewBridgeDenom(suite.chainName, msg.TokenContract)) // nolint:staticcheck
suite.Keeper().AddBridgeToken(suite.ctx, msg.TokenContract, types.NewBridgeDenom(suite.chainName, msg.TokenContract))
for i, oracle := range suite.oracleAddrs {
eventNonce := suite.Keeper().GetLastEventNonceByOracle(suite.ctx, oracle)
msg.EventNonce = eventNonce + 1
Expand Down
9 changes: 7 additions & 2 deletions x/gov/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,18 @@ func NewAppModule(cdc codec.Codec, keeper *keeper.Keeper, ak govtypes.AccountKee

// RegisterServices registers module services.
func (am AppModule) RegisterServices(cfg module.Configurator) {
msgServer := keeper.NewMsgServerImpl(govkeeper.NewMsgServerImpl(am.keeper.Keeper), am.keeper)
govv1betal.RegisterMsgServer(cfg.MsgServer(), govkeeper.NewLegacyMsgServerImpl(am.ak.GetModuleAddress(govtypes.ModuleName).String(), msgServer))
govMsgServer := govkeeper.NewMsgServerImpl(am.keeper.Keeper)
msgServer := keeper.NewMsgServerImpl(govMsgServer, am.keeper)

legacyMsgServer := govkeeper.NewLegacyMsgServerImpl(am.ak.GetModuleAddress(govtypes.ModuleName).String(), msgServer)
govv1betal.RegisterMsgServer(cfg.MsgServer(), legacyMsgServer)
govv1.RegisterMsgServer(cfg.MsgServer(), msgServer)
types.RegisterMsgServer(cfg.MsgServer(), msgServer)

legacyQueryServer := govkeeper.NewLegacyQueryServer(am.keeper.Keeper)
govv1betal.RegisterQueryServer(cfg.QueryServer(), legacyQueryServer)
govv1.RegisterQueryServer(cfg.QueryServer(), am.keeper.Keeper)
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)

m := keeper.NewMigrator(am.keeper, am.legacySubspace)
err := cfg.RegisterMigration(govtypes.ModuleName, 3, m.Migrate3to4)
Expand Down