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

[Testing, Tooling] Expose integration app via gRPC/HTTP/WS #1017

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
wip
bryanchriswhite committed Jan 10, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 1714822a1646658e9333fec1645646762337fc6e
40 changes: 28 additions & 12 deletions testutil/e2e/app.go
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@ import (
"sync"
"testing"

"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/gorilla/websocket"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
@@ -20,7 +19,6 @@ import (
coretypes "github.com/cometbft/cometbft/rpc/core/types"

"github.com/pokt-network/poktroll/testutil/integration"
"github.com/pokt-network/poktroll/testutil/testclient"
)

// E2EApp wraps an integration.App and provides both gRPC and WebSocket servers for end-to-end testing
@@ -50,20 +48,32 @@ func NewE2EApp(t *testing.T, opts ...integration.IntegrationAppOptionFn) *E2EApp
app.RegisterGRPCServer(grpcServer)
//app.RegisterGRPCServer(e2eApp.grpcServer)

flagSet := testclient.NewFlagSet(t, "tcp://127.0.0.1:42069")
keyRing := keyring.NewInMemory(app.GetCodec())
clientCtx := testclient.NewLocalnetClientCtx(t, flagSet).WithKeyring(keyRing)
//flagSet := testclient.NewFlagSet(t, "127.0.0.1:42069")
//keyRing := keyring.NewInMemory(app.GetCodec())
//clientCtx := testclient.NewLocalnetClientCtx(t, flagSet).WithKeyring(keyRing)

//authtx.RegisterTxService(
// //app.GRPCQueryRouter(),
// grpcServer,
// clientCtx,
// app.Simulate,
// app.GetRegistry(),
//)
//authtx.RegisterGRPCGatewayRoutes(clientCtx, mux)

configurator := module.NewConfigurator(app.GetCodec(), app.MsgServiceRouter(), app.GRPCQueryRouter())
for moduleName, mod := range app.GetModuleManager().Modules {
fmt.Printf(">>> %s\n", moduleName)
mod.(module.AppModuleBasic).RegisterGRPCGatewayRoutes(clientCtx, mux)
fmt.Printf(">>> start: %s\n", moduleName)
//mod.(module.AppModuleBasic).RegisterGRPCGatewayRoutes(clientCtx, mux)
mod.(module.HasServices).RegisterServices(configurator)
fmt.Printf(">>> done: %s\n", moduleName)
}

// Create listeners for gRPC, WebSocket, and HTTP
grpcListener, err := net.Listen("tcp", "localhost:42069")
grpcListener, err := net.Listen("tcp", "127.0.0.1:42069")
require.NoError(t, err, "failed to create gRPC listener")

wsListener, err := net.Listen("tcp", "localhost:6969")
wsListener, err := net.Listen("tcp", "127.0.0.1:6969")
require.NoError(t, err, "failed to create WebSocket listener")

e2eApp := &E2EApp{
@@ -78,22 +88,28 @@ func NewE2EApp(t *testing.T, opts ...integration.IntegrationAppOptionFn) *E2EApp

go func() {
if err := e2eApp.grpcServer.Serve(grpcListener); err != nil {
panic(err)
if !errors.Is(err, http.ErrServerClosed) {
panic(err)
}
}
}()

// Initialize and start WebSocket server
e2eApp.wsServer = newWebSocketServer(e2eApp)
go func() {
if err := e2eApp.wsServer.Serve(wsListener); err != nil && errors.Is(err, http.ErrServerClosed) {
panic(err)
if !errors.Is(err, http.ErrServerClosed) {
panic(err)
}
}
}()

// Initialize and start HTTP server
go func() {
if err := http.ListenAndServe("localhost:42070", mux); err != nil {
panic(err)
if !errors.Is(err, http.ErrServerClosed) {
panic(err)
}
}
}()

62 changes: 53 additions & 9 deletions testutil/e2e/app_test.go
Original file line number Diff line number Diff line change
@@ -2,16 +2,17 @@ package e2e

import (
"context"
"encoding/hex"
"net/http"
"testing"
"time"

"cosmossdk.io/depinject"
"cosmossdk.io/math"
abci "github.com/cometbft/cometbft/abci/types"
cometrpctypes "github.com/cometbft/cometbft/rpc/core/types"
"github.com/cometbft/cometbft/types"
cosmostx "github.com/cosmos/cosmos-sdk/client/tx"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
cosmostypes "github.com/cosmos/cosmos-sdk/types"
@@ -148,7 +149,10 @@ func TestNewE2EApp(t *testing.T) {
//blockQueryClient, err := sdkclient.NewClientFromNode("tcp://127.0.0.1:26657")
//require.NoError(t, err)

deps := depinject.Supply(app.QueryHelper(), blockQueryClient)
creds := insecure.NewCredentials()
grpcConn, err := grpc.NewClient("127.0.0.1:42069", grpc.WithTransportCredentials(creds))
require.NoError(t, err)
deps := depinject.Supply(grpcConn, blockQueryClient)

sharedQueryClient, err := query.NewSharedQuerier(deps)
require.NoError(t, err)
@@ -213,18 +217,58 @@ func TestGRPCServer(t *testing.T) {
//dataHex, err := hex.DecodeString("0A2B706F6B74313577336668667963306C747476377235383565326E6370663674326B6C3975683872736E797A")
require.NoError(t, err)

req := gatewaytypes.QueryGetGatewayRequest{
Address: "pokt15w3fhfyc0lttv7r585e2ncpf6t2kl9uh8rsnyz",
}
//req := gatewaytypes.QueryGetGatewayRequest{
// Address: "pokt15w3fhfyc0lttv7r585e2ncpf6t2kl9uh8rsnyz",
//}
res := &abci.ResponseQuery{}

//grpcConn.Invoke(context.Background(), "abci_query", req, res)

ctrl := gomock.NewController(t)
blockQueryClient := mockclient.NewMockBlockQueryClient(ctrl)
blockQueryClient.EXPECT().
Block(gomock.Any(), gomock.Any()).
DoAndReturn(
func(ctx context.Context, height *int64) (*cometrpctypes.ResultBlock, error) {
//time.Sleep(time.Second * 100)
blockResultMock := &cometrpctypes.ResultBlock{
Block: &types.Block{
Header: types.Header{
Height: 1,
},
},
}
return blockResultMock, nil
},
).AnyTimes()

deps := depinject.Supply(grpcConn, blockQueryClient)

sharedQueryClient, err := query.NewSharedQuerier(deps)
require.NoError(t, err)

// convert the request to a proto message
anyReq, err := codectypes.NewAnyWithValue(&req)
//res := new(gatewaytypes.QueryGetGatewayResponse)
//
//err = grpcConn.Invoke(context.Background(), "/poktroll.gateway.Query/Gateway", anyReq, res)
dataHex, err := hex.DecodeString("0A2B706F6B74313577336668667963306C747476377235383565326E6370663674326B6C3975683872736E797A")
require.NoError(t, err)

res := new(gatewaytypes.QueryGetGatewayResponse)
req := &abci.RequestQuery{
Data: dataHex,
Path: "/cosmos.auth.v1beta1.Query/Account",
Height: 0,
Prove: false,
}

err = grpcConn.Invoke(context.Background(), "abci_query", req, res)
//err = grpcConn.Invoke(context.Background(), "abci_query", req, res)
require.NoError(t, err)

err = grpcConn.Invoke(context.Background(), "/poktroll.gateway.Query/Gateway", anyReq, res)
require.NoError(t, err)
sharedParams, err := sharedQueryClient.GetParams(app.GetSdkCtx())
require.NoError(t, err)

t.Logf("shared params: %+v", sharedParams)

//"method" : "abci_query",
//"params" : {

Unchanged files with check annotations Beta

"github.com/pokt-network/poktroll/app/volatile"
"github.com/pokt-network/poktroll/testutil/events"
"github.com/pokt-network/poktroll/testutil/integration/suites"

Check failure on line 13 in tests/integration/application/application_transfer_test.go

GitHub Actions / go-test

could not import github.com/pokt-network/poktroll/testutil/integration/suites (-: # github.com/pokt-network/poktroll/testutil/integration/suites
"github.com/pokt-network/poktroll/testutil/testkeyring"
apptypes "github.com/pokt-network/poktroll/x/application/types"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
// TestAppTransferSuite runs the application transfer test suite.
func TestAppTransferSuite(t *testing.T) {
suite.Run(t, new(appTransferTestSuite))

Check failure on line 45 in tests/integration/application/application_transfer_test.go

GitHub Actions / go-test

cannot use new(appTransferTestSuite) (value of type *appTransferTestSuite) as suite.TestingSuite value in argument to suite.Run: *appTransferTestSuite does not implement suite.TestingSuite (missing method SetS) (typecheck)
}
func (s *appTransferTestSuite) SetupTest() {
// Construct a new integration app for each test.
s.NewApp(s.T())

Check failure on line 50 in tests/integration/application/application_transfer_test.go

GitHub Actions / go-test

s.NewApp undefined (type *appTransferTestSuite has no field or method NewApp) (typecheck)
s.gatewaySuite.SetApp(s.GetApp())

Check failure on line 51 in tests/integration/application/application_transfer_test.go

GitHub Actions / go-test

s.GetApp undefined (type *appTransferTestSuite has no field or method GetApp) (typecheck)
s.paramsSuite.SetApp(s.GetApp())

Check failure on line 52 in tests/integration/application/application_transfer_test.go

GitHub Actions / go-test

s.GetApp undefined (type *appTransferTestSuite has no field or method GetApp) (typecheck)
// Setup authz accounts and grants to enable updating params.
s.paramsSuite.SetupTestAuthzAccounts(s.T())

Check failure on line 55 in tests/integration/application/application_transfer_test.go

GitHub Actions / go-test

s.T undefined (type *appTransferTestSuite has no field or method T) (typecheck)
s.paramsSuite.SetupTestAuthzGrants(s.T())

Check failure on line 56 in tests/integration/application/application_transfer_test.go

GitHub Actions / go-test

s.T undefined (type *appTransferTestSuite has no field or method T) (typecheck)
// Ensure gateways and apps have bank balances.
s.setupTestAddresses()
})
// Assert the on-chain state shows the application 3 as NOT staked.
_, queryErr := s.GetAppQueryClient().GetApplication(s.SdkCtx(), s.app3)

Check failure on line 84 in tests/integration/application/application_transfer_test.go

GitHub Actions / go-test

s.GetAppQueryClient undefined (type *appTransferTestSuite has no field or method GetAppQueryClient) (typecheck)
require.ErrorContains(s.T(), queryErr, "application not found")
require.ErrorContains(s.T(), queryErr, s.app3)
}
// GetBankQueryClient constructs and returns a query client for the bank module
// of the integration app.
func (s *BaseIntegrationSuite) GetBankQueryClient() banktypes.QueryClient {
return banktypes.NewQueryClient(s.GetApp().QueryHelper())

Check failure on line 101 in testutil/integration/suites/base.go

GitHub Actions / go-test

cannot use s.GetApp().QueryHelper() (value of type *baseapp.GRPCQueryRouter) as "github.com/cosmos/gogoproto/grpc".ClientConn value in argument to banktypes.NewQueryClient: *baseapp.GRPCQueryRouter does not implement "github.com/cosmos/gogoproto/grpc".ClientConn (missing method Invoke)
}
// FilterEvents returns the events from the event manager which match the given
s.RunAuthzGrantMsg(t, granterAddr, granteeAddr, authorization)
// Query for the created grant to assert that they were created.
authzQueryClient := authz.NewQueryClient(s.app.QueryHelper())

Check failure on line 46 in testutil/integration/suites/authz.go

GitHub Actions / go-test

cannot use s.app.QueryHelper() (value of type *baseapp.GRPCQueryRouter) as "github.com/cosmos/gogoproto/grpc".ClientConn value in argument to authz.NewQueryClient: *baseapp.GRPCQueryRouter does not implement "github.com/cosmos/gogoproto/grpc".ClientConn (missing method Invoke)) (typecheck)
queryGrantsReq := &authz.QueryGrantsRequest{
Granter: granterAddr.String(),
Grantee: granteeAddr.String(),