Skip to content

Commit

Permalink
Register evm (and other missing) module grpc routes endpoints (sei-pr…
Browse files Browse the repository at this point in the history
…otocol#1717)

* - Register evm module endpoints
- Register epoch module endpoints

* - Tests for adding routes

* - Update test
  • Loading branch information
dssei authored Jun 10, 2024
1 parent 3ea043e commit 1c7253b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
5 changes: 4 additions & 1 deletion x/epoch/module.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package epoch

import (
"context"
"encoding/json"
"fmt"

Expand Down Expand Up @@ -77,7 +78,9 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingCo
func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {}

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) {}
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
_ = types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
}

// GetTxCmd returns the capability module's root tx command.
func (a AppModuleBasic) GetTxCmd() *cobra.Command {
Expand Down
18 changes: 18 additions & 0 deletions x/epoch/module_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package epoch_test

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"testing"
"time"

Expand Down Expand Up @@ -35,6 +37,22 @@ func TestBasic(t *testing.T) {
require.Equal(t, appModule.EndBlock(ctx, abci.RequestEndBlock{}), []abci.ValidatorUpdate{})
}

// This test is just to make sure that the routes can be added without crashing
func TestRoutesAddition(t *testing.T) {
testApp := app.Setup(false, false)
appModule := epoch.NewAppModule(
testApp.AppCodec(),
testApp.EpochKeeper,
testApp.AccountKeeper,
testApp.BankKeeper,
)

mux := runtime.NewServeMux()
appModule.RegisterGRPCGatewayRoutes(client.Context{}, mux)

require.NotNil(t, appModule)
}

func TestExportGenesis(t *testing.T) {
t.Parallel()
// Create a mock context and keeper
Expand Down
5 changes: 4 additions & 1 deletion x/evm/module.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package evm

import (
"context"
"encoding/json"
"fmt"
"math"
Expand Down Expand Up @@ -75,7 +76,9 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingCo
func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {}

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) {}
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
_ = types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
}

// GetTxCmd returns the capability module's root tx command.
func (a AppModuleBasic) GetTxCmd() *cobra.Command {
Expand Down
12 changes: 12 additions & 0 deletions x/evm/module_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package evm_test

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"math"
"math/big"
"testing"
Expand Down Expand Up @@ -150,3 +152,13 @@ func TestAnteSurplus(t *testing.T) {
// ante surplus should be cleared
require.Equal(t, uint64(0), k.GetAnteSurplusSum(ctx).Uint64())
}

// This test is just to make sure that the routes can be added without crashing
func TestRoutesAddition(t *testing.T) {
k, _ := testkeeper.MockEVMKeeper()
appModule := evm.NewAppModule(nil, k)
mux := runtime.NewServeMux()
appModule.RegisterGRPCGatewayRoutes(client.Context{}, mux)

require.NotNil(t, appModule)
}

0 comments on commit 1c7253b

Please sign in to comment.