Skip to content

Commit

Permalink
refactor(e2e): improved the e2esuite (#97)
Browse files Browse the repository at this point in the history
* refactor: moved chainconfig

* imp: improved types

* refactor: more code

* refactor: tests

* style: ran golangci-lint

* docs: changed godocs

* refactor: removed useless line

* imp: fix errors

* fix: wasm test

* test: better grpc queries

* deps: ran 'go mod tidy'

* fix: wasm test

* style: ran golangci-lint

* deps: ran 'go mod tidy'

* fix: attempt 1

* fix: attempt 3

* fix: wasm test

* style: added wasmd to linter

* imp: use custom encoding everywhere

* refactor: renamed testsuite to e2esuite

* style: ran golangci-lint

* imp: remove uneeded log
  • Loading branch information
srdtrk committed Apr 2, 2024
1 parent 124f9dd commit d4ef6df
Show file tree
Hide file tree
Showing 25 changed files with 910 additions and 499 deletions.
1 change: 1 addition & 0 deletions e2e/interchaintest/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ linters-settings:
- prefix(github.com/cosmos/cosmos-sdk)
- prefix(github.com/cometbft/cometbft)
- prefix(github.com/cosmos/ibc-go)
- prefix(github.com/CosmWasm/wasmd)
- prefix(github.com/strangelove-ventures/interchaintest)
- prefix(github.com/srdtrk/cw-ica-controller/interchaintest)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package main
package chainconfig

import (
interchaintest "github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos/wasm"
"github.com/strangelove-ventures/interchaintest/v8/ibc"

mysuite "github.com/srdtrk/cw-ica-controller/interchaintest/v2/testsuite"
"github.com/srdtrk/cw-ica-controller/interchaintest/v2/e2esuite"
)

var chainSpecs = []*interchaintest.ChainSpec{
var DefaultChainSpecs = []*interchaintest.ChainSpec{
// -- WASMD --
{
ChainConfig: ibc.ChainConfig{
Expand All @@ -22,13 +21,12 @@ var chainSpecs = []*interchaintest.ChainSpec{
UidGid: "1025:1025",
},
},
Bin: "wasmd",
Bech32Prefix: "wasm",
Denom: "stake",
GasPrices: "0.00stake",
GasAdjustment: 1.3,
// cannot run wasmd commands without wasm encoding
EncodingConfig: wasm.WasmEncoding(),
Bin: "wasmd",
Bech32Prefix: "wasm",
Denom: "stake",
GasPrices: "0.00stake",
GasAdjustment: 1.3,
EncodingConfig: e2esuite.EncodingConfig(),
TrustingPeriod: "508h",
NoHostMount: false,
},
Expand All @@ -51,7 +49,7 @@ var chainSpecs = []*interchaintest.ChainSpec{
Denom: "stake",
GasPrices: "0.00stake",
GasAdjustment: 1.3,
EncodingConfig: mysuite.SDKEncodingConfig(),
EncodingConfig: e2esuite.EncodingConfig(),
TrustingPeriod: "508h",
NoHostMount: false,
},
Expand Down
351 changes: 182 additions & 169 deletions e2e/interchaintest/contract_test.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package testsuite
package e2esuite

const (
// hermesRelayerImage = "ghcr.io/informalsystems/hermes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package testsuite
package e2esuite

import (
"archive/tar"
Expand Down
92 changes: 92 additions & 0 deletions e2e/interchaintest/e2esuite/grpc_query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package e2esuite

import (
"context"
"fmt"

"github.com/cosmos/gogoproto/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
pb "google.golang.org/protobuf/proto"

msgv1 "cosmossdk.io/api/cosmos/msg/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"

"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
)

var queryReqToPath = make(map[string]string)

func populateQueryReqToPath(ctx context.Context, chain *cosmos.CosmosChain) error {
resp, err := queryFileDescriptors(ctx, chain)
if err != nil {
return err
}

for _, fileDescriptor := range resp.Files {
for _, service := range fileDescriptor.GetService() {
// Skip services that are annotated with the "cosmos.msg.v1.service" option.
if ext := pb.GetExtension(service.GetOptions(), msgv1.E_Service); ext != nil && ext.(bool) {
continue
}

for _, method := range service.GetMethod() {
// trim the first character from input which is a dot
queryReqToPath[method.GetInputType()[1:]] = fileDescriptor.GetPackage() + "." + service.GetName() + "/" + method.GetName()
}
}
}

return nil
}

// Queries the chain with a query request and deserializes the response to T
func GRPCQuery[T any](ctx context.Context, chain *cosmos.CosmosChain, req proto.Message, opts ...grpc.CallOption) (*T, error) {
path, ok := queryReqToPath[proto.MessageName(req)]
if !ok {
return nil, fmt.Errorf("no path found for %s", proto.MessageName(req))
}

// Create a connection to the gRPC server.
grpcConn, err := grpc.Dial(
chain.GetHostGRPCAddress(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
return nil, err
}

defer grpcConn.Close()

resp := new(T)
err = grpcConn.Invoke(ctx, path, req, resp, opts...)
if err != nil {
return nil, err
}

return resp, nil
}

func queryFileDescriptors(ctx context.Context, chain *cosmos.CosmosChain) (*reflectionv1.FileDescriptorsResponse, error) {
// Create a connection to the gRPC server.
grpcConn, err := grpc.Dial(
chain.GetHostGRPCAddress(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
return nil, err
}

defer grpcConn.Close()

resp := new(reflectionv1.FileDescriptorsResponse)
err = grpcConn.Invoke(
ctx, reflectionv1.ReflectionService_FileDescriptors_FullMethodName,
&reflectionv1.FileDescriptorsRequest{}, resp,
)
if err != nil {
return nil, err
}

return resp, nil
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package testsuite
package e2esuite

import (
"context"
Expand All @@ -16,6 +16,7 @@ import (
"github.com/strangelove-ventures/interchaintest/v8/testutil"
)

// TestSuite is a suite of tests that require two chains and a relayer
type TestSuite struct {
suite.Suite

Expand Down Expand Up @@ -82,6 +83,9 @@ func (s *TestSuite) SetupSuite(ctx context.Context, chainSpecs []*interchaintest
SkipPathCreation: true,
}))

s.Require().NoError(populateQueryReqToPath(ctx, s.ChainA))
s.Require().NoError(populateQueryReqToPath(ctx, s.ChainB))

// Fund a user account on ChainA and ChainB
const userFunds = int64(10_000_000_000)
users := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), userFunds, s.ChainA, s.ChainB)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package testsuite
package e2esuite

import (
"context"
Expand All @@ -10,13 +10,19 @@ import (
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdktestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/authz"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
grouptypes "github.com/cosmos/cosmos-sdk/x/group"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
proposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
Expand All @@ -31,6 +37,8 @@ import (
localhost "github.com/cosmos/ibc-go/v8/modules/light-clients/09-localhost"
simappparams "github.com/cosmos/ibc-go/v8/testing/simapp/params"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"

"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
Expand Down Expand Up @@ -82,8 +90,9 @@ func (s *TestSuite) fundAddress(ctx context.Context, chain *cosmos.CosmosChain,
s.Require().NoError(err)
}

// SDKEncodingConfig returns the global E2E encoding config.
func SDKEncodingConfig() *sdktestutil.TestEncodingConfig {
// EncodingConfig returns the global E2E encoding config.
// It includes CosmosSDK, IBC, and Wasm messages
func EncodingConfig() *sdktestutil.TestEncodingConfig {
_, cfg := codecAndEncodingConfig()
return &sdktestutil.TestEncodingConfig{
InterfaceRegistry: cfg.InterfaceRegistry,
Expand All @@ -109,7 +118,7 @@ func codecAndEncodingConfig() (*codec.ProtoCodec, simappparams.EncodingConfig) {
ibctmtypes.RegisterInterfaces(cfg.InterfaceRegistry)
localhost.RegisterInterfaces(cfg.InterfaceRegistry)

// all other types
// sdk types
upgradetypes.RegisterInterfaces(cfg.InterfaceRegistry)
banktypes.RegisterInterfaces(cfg.InterfaceRegistry)
govv1beta1.RegisterInterfaces(cfg.InterfaceRegistry)
Expand All @@ -119,6 +128,15 @@ func codecAndEncodingConfig() (*codec.ProtoCodec, simappparams.EncodingConfig) {
grouptypes.RegisterInterfaces(cfg.InterfaceRegistry)
proposaltypes.RegisterInterfaces(cfg.InterfaceRegistry)
authz.RegisterInterfaces(cfg.InterfaceRegistry)
txtypes.RegisterInterfaces(cfg.InterfaceRegistry)
stakingtypes.RegisterInterfaces(cfg.InterfaceRegistry)
minttypes.RegisterInterfaces(cfg.InterfaceRegistry)
distrtypes.RegisterInterfaces(cfg.InterfaceRegistry)
slashingtypes.RegisterInterfaces(cfg.InterfaceRegistry)
consensustypes.RegisterInterfaces(cfg.InterfaceRegistry)

// custom module types
wasmtypes.RegisterInterfaces(cfg.InterfaceRegistry)

cdc := codec.NewProtoCodec(cfg.InterfaceRegistry)
return cdc, cfg
Expand Down
4 changes: 2 additions & 2 deletions e2e/interchaintest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.21
toolchain go1.21.5

require (
cosmossdk.io/api v0.7.2
cosmossdk.io/math v1.2.0
cosmossdk.io/x/upgrade v0.1.0
github.com/CosmWasm/wasmd v0.50.0
Expand All @@ -16,6 +17,7 @@ require (
github.com/stretchr/testify v1.8.4
go.uber.org/zap v1.26.0
google.golang.org/grpc v1.60.1
google.golang.org/protobuf v1.32.0
)

require (
Expand All @@ -24,7 +26,6 @@ require (
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.5 // indirect
cloud.google.com/go/storage v1.30.1 // indirect
cosmossdk.io/api v0.7.2 // indirect
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/core v0.11.0 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
Expand Down Expand Up @@ -232,7 +233,6 @@ require (
google.golang.org/genproto v0.0.0-20231211222908-989df2bf70f3 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading

0 comments on commit d4ef6df

Please sign in to comment.