Skip to content

Commit

Permalink
Add E2ETestSuite Type (E2E #3) (#1650)
Browse files Browse the repository at this point in the history
  • Loading branch information
chatton committed Jul 14, 2022
1 parent b0b1810 commit 81d10d4
Show file tree
Hide file tree
Showing 9 changed files with 503 additions and 38 deletions.
26 changes: 9 additions & 17 deletions .github/scripts/determine_simd_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,24 @@ package main
import (
"flag"
"fmt"
"os"
)

var prNum int
var ref string
var prNum string

func init() {
flag.IntVar(&prNum, "pr", 0, "the number of the pr")
flag.StringVar(&ref, "ref", "", "the github ref")
flag.StringVar(&prNum, "pr", "", "the number of the pr")
flag.Parse()
}

// in the context of a GithubAction workflow, the PR is the event number. So if the ref is not specified
// but the event number is, that means we are running for a PR. If the ref is specified, this means
// we have merged the PR, so we want to use the ref as a tag instead of the PR number.
// in the context of a GithubAction workflow, the PR is non empty if it is a pr. When
// code is merged to main, it will be empty. In this case we just use the "main" tag.
func main() {
if prNum == 0 && ref == "" {
fmt.Printf("must specify one or bot of [pr, ref]")
os.Exit(1)
}
fmt.Printf(getSimdTag(prNum, ref))
fmt.Printf(getSimdTag(prNum))
}

func getSimdTag(prNum int, ref string) string {
if ref != "" {
return ref
func getSimdTag(prNum string) string {
if prNum == "" {
return "main"
}
return fmt.Sprintf("pr-%d", prNum)
return fmt.Sprintf("pr-%s", prNum)
}
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ jobs:
go-version: 1.18
- id: get-tag
run: |
tag=$(go run .github/scripts/determine_simd_tag.go -ref "${{ github.event.push.ref }}" -pr "${{ github.event.pull_request.number }}" )
tag=$(go run .github/scripts/determine_simd_tag.go -pr "${{ github.event.pull_request.number }}" )
echo "Using tag $tag"
echo "::set-output name=simd-tag::$tag"
Expand All @@ -233,6 +233,9 @@ jobs:
matrix: ${{ fromJSON(needs.build-test-matrix.outputs.matrix) }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.18
- name: Log in to the Container registry
uses: docker/login-action@49ed152c8eca782a232dede0303416e8f356c37b
with:
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ FROM ubuntu:20.04

COPY --from=builder /go/build/simd /bin/simd

ENTRYPOINT ["simd"]
# TODO(chatton): uncomment once https://github.com/strangelove-ventures/ibctest/issues/183 is resolved.
#ENTRYPOINT ["simd"]
28 changes: 18 additions & 10 deletions e2e/fee_middleware_test.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
package e2e

import (
"os"
"context"
"testing"

"github.com/strangelove-ventures/ibctest/ibc"
"github.com/stretchr/testify/suite"

"github.com/cosmos/ibc-go/v4/e2e/testsuite"
)

func TestFeeMiddlewareTestSuite(t *testing.T) {
suite.Run(t, new(FeeMiddlewareTestSuite))
}

type FeeMiddlewareTestSuite struct {
suite.Suite
testsuite.E2ETestSuite
}

func (s *FeeMiddlewareTestSuite) TestPlaceholder() {
tag, ok := os.LookupEnv("SIMD_TAG")
s.Require().True(ok)
s.T().Logf("SIMD_TAG=%s", tag)
ctx := context.Background()
r := s.SetupChainsRelayerAndChannel(ctx, feeMiddlewareChannelOptions())
s.T().Run("start relayer", func(t *testing.T) {
s.StartRelayer(r)
})

image, ok := os.LookupEnv("SIMD_IMAGE")
s.Require().True(ok)
s.T().Logf("SIMD_IMAGE=%s", image)
}

s.T().Logf("Placeholder test")
s.Require().True(true)
// feeMiddlewareChannelOptions configures both of the chains to have fee middleware enabled.
func feeMiddlewareChannelOptions() func(options *ibc.CreateChannelOptions) {
return func(opts *ibc.CreateChannelOptions) {
opts.Version = "{\"fee_version\":\"ics29-1\",\"app_version\":\"ics20-1\"}"
opts.DestPortName = "transfer"
opts.SourcePortName = "transfer"
}
}
83 changes: 83 additions & 0 deletions e2e/testconfig/testconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package testconfig

import (
"fmt"
"os"

"github.com/strangelove-ventures/ibctest/ibc"
)

const (
DefaultSimdImage = "ghcr.io/cosmos/ibc-go-simd-e2e"
SimdImageEnv = "SIMD_IMAGE"
SimdTagEnv = "SIMD_TAG"
)

// TestConfig holds various fields used in the E2E tests.
type TestConfig struct {
SimdImage string
SimdTag string
}

// FromEnv returns a TestConfig constructed from environment variables.
func FromEnv() TestConfig {
simdImage, ok := os.LookupEnv(SimdImageEnv)
if !ok {
simdImage = DefaultSimdImage
}

simdTag, ok := os.LookupEnv(SimdTagEnv)
if !ok {
panic(fmt.Sprintf("must specify simd version for test with environment variable [%s]", SimdTagEnv))
}

return TestConfig{
SimdImage: simdImage,
SimdTag: simdTag,
}
}

// ChainOptions stores chain configurations for the chains that will be
// created for the tests. They can be modified by passing ChainOptionConfiguration
// to E2ETestSuite.GetChains.
type ChainOptions struct {
ChainAConfig *ibc.ChainConfig
ChainBConfig *ibc.ChainConfig
}

// ChainOptionConfiguration enables arbitrary configuration of ChainOptions.
type ChainOptionConfiguration func(options *ChainOptions)

// DefaultChainOptions returns the default configuration for the chains.
// These options can be configured by passing configuration functions to E2ETestSuite.GetChains.
func DefaultChainOptions() ChainOptions {
tc := FromEnv()
chainACfg := newDefaultSimappConfig(tc, "simapp-a", "chain-a", "atoma")
chainBCfg := newDefaultSimappConfig(tc, "simapp-b", "chain-b", "atomb")
return ChainOptions{
ChainAConfig: &chainACfg,
ChainBConfig: &chainBCfg,
}
}

// newDefaultSimappConfig creates an ibc configuration for simd.
func newDefaultSimappConfig(tc TestConfig, name, chainID, denom string) ibc.ChainConfig {
return ibc.ChainConfig{
Type: "cosmos",
Name: name,
ChainID: chainID,
Images: []ibc.DockerImage{
{
Repository: tc.SimdImage,
Version: tc.SimdTag,
},
},
Bin: "simd",
Bech32Prefix: "cosmos",
Denom: denom,
GasPrices: fmt.Sprintf("0.01%s", denom),
GasAdjustment: 1.3,
TrustingPeriod: "508h",
NoHostMount: false,
}
}
22 changes: 22 additions & 0 deletions e2e/testsuite/relayer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package testsuite

import (
"testing"

dockerclient "github.com/docker/docker/client"
"github.com/strangelove-ventures/ibctest"
"github.com/strangelove-ventures/ibctest/ibc"
"github.com/strangelove-ventures/ibctest/relayer"
"go.uber.org/zap"
)

const (
cosmosRelayerRepository = "ghcr.io/cosmos/relayer"
)

// newCosmosRelayer returns an instance of the go relayer.
func newCosmosRelayer(t *testing.T, logger *zap.Logger, dockerClient *dockerclient.Client, network string, home string) ibc.Relayer {
return ibctest.NewBuiltinRelayerFactory(ibc.CosmosRly, logger, relayer.CustomDockerImage(cosmosRelayerRepository, "main")).Build(
t, dockerClient, network, home,
)
}
Loading

0 comments on commit 81d10d4

Please sign in to comment.