Skip to content

Commit 2bd397b

Browse files
authored
feat(test): adding support for backwards compatibility testing (#1912)
1 parent f054208 commit 2bd397b

8 files changed

Lines changed: 180 additions & 38 deletions

File tree

.github/workflows/e2e-fork.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ jobs:
2424

2525
e2e:
2626
env:
27-
SIMD_TAG: latest
28-
SIMD_IMAGE: ibc-go-simd-e2e
27+
CHAIN_A_SIMD_TAG: latest
28+
CHAIN_A_SIMD_IMAGE: ibc-go-simd-e2e
2929
if: ${{ github.event.pull_request.head.repo.fork || github.actor == 'dependabot[bot]' || github.event_name == 'workflow_dispatch' }}
3030
needs:
3131
- build-test-matrix
@@ -36,7 +36,7 @@ jobs:
3636
steps:
3737
- uses: actions/checkout@v3
3838
- name: Docker Build
39-
run: docker build . -t "${SIMD_IMAGE}:${SIMD_TAG}"
39+
run: docker build . -t "${CHAIN_A_SIMD_IMAGE}:${CHAIN_A_SIMD_TAG}"
4040
- name: Setup Go
4141
uses: actions/setup-go@v3
4242
with:

.github/workflows/e2e-manual.yaml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Manual E2E
2+
on:
3+
# when https://github.com/community/community/discussions/11795 is resolved
4+
# we will be able to dynamically build up the list of valid inputs.
5+
# for now this needs to be manual.
6+
workflow_dispatch:
7+
inputs:
8+
test-entry-point:
9+
description: 'Test entry point'
10+
required: true
11+
type: choice
12+
options:
13+
- TestFeeMiddlewareTestSuite
14+
chain-a-image:
15+
description: 'The image to use for chain A'
16+
required: true
17+
type: string
18+
default: "ghcr.io/cosmos/ibc-go-simd-e2e"
19+
chain-a-tag:
20+
description: 'The tag to use for chain A'
21+
required: true
22+
type: choice
23+
default: main
24+
options:
25+
- main
26+
- v4.0.0-rc3
27+
- v3.0.0
28+
- v2.2.0
29+
- v2.1.0
30+
- v2.0.0
31+
chain-b-image:
32+
description: 'The image to use for chain B'
33+
required: true
34+
type: string
35+
default: "ghcr.io/cosmos/ibc-go-simd"
36+
chain-b-tag:
37+
default: v4.0.0-rc3
38+
description: 'The tag to use for chain B'
39+
required: true
40+
type: choice
41+
options:
42+
- v4.0.0-rc3
43+
- v3.0.0
44+
- v2.2.0
45+
- v2.1.0
46+
- v2.0.0
47+
relayer-tag:
48+
description: 'The tag to use for the relayer'
49+
required: true
50+
default: "v2.0.0-rc2"
51+
type: string
52+
53+
54+
jobs:
55+
# dynamically build a matrix of test/test suite pairs to run
56+
build-test-matrix:
57+
runs-on: ubuntu-latest
58+
outputs:
59+
matrix: ${{ steps.set-matrix.outputs.matrix }}
60+
steps:
61+
- uses: actions/checkout@v3
62+
- uses: actions/setup-go@v3
63+
with:
64+
go-version: 1.18
65+
- id: set-matrix
66+
run: echo "::set-output name=matrix::$(go run cmd/build_test_matrix/main.go)"
67+
env:
68+
TEST_ENTRYPOINT: "${{ github.event.inputs.test-entry-point }}"
69+
70+
71+
72+
e2e-manual:
73+
runs-on: ubuntu-latest
74+
needs:
75+
- build-test-matrix
76+
env:
77+
CHAIN_A_SIMD_TAG: "${{ github.event.inputs.chain-a-tag }}"
78+
CHAIN_A_SIMD_IMAGE: "${{ github.event.inputs.chain-a-image }}"
79+
CHAIN_B_SIMD_TAG: "${{ github.event.inputs.chain-b-tag }}"
80+
CHAIN_B_SIMD_IMAGE: "${{ github.event.inputs.chain-b-image }}"
81+
# see images here https://github.com/cosmos/relayer/pkgs/container/relayer/versions
82+
RLY_TAG: "${{ github.event.inputs.relayer-tag }}"
83+
strategy:
84+
fail-fast: false
85+
matrix: ${{ fromJSON(needs.build-test-matrix.outputs.matrix) }}
86+
steps:
87+
- uses: actions/checkout@v3
88+
- uses: actions/setup-go@v3
89+
with:
90+
go-version: 1.18
91+
- name: Run e2e Test
92+
run: |
93+
cd e2e
94+
make e2e-test suite=${{ matrix.suite }} test=${{ matrix.test }}

.github/workflows/e2e.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ jobs:
8181
- determine-image-tag
8282
- docker-build
8383
env:
84-
SIMD_TAG: ${{ needs.determine-image-tag.outputs.simd-tag }}
85-
SIMD_IMAGE: ghcr.io/cosmos/ibc-go-simd-e2e
84+
CHAIN_A_SIMD_TAG: ${{ needs.determine-image-tag.outputs.simd-tag }}
85+
CHAIN_A_SIMD_IMAGE: ghcr.io/cosmos/ibc-go-simd-e2e
8686
# see images here https://github.com/cosmos/relayer/pkgs/container/relayer/versions
8787
RLY_TAG: "v2.0.0-rc2"
8888
strategy:

cmd/build_test_matrix/main.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const (
1616
testNamePrefix = "Test"
1717
testFileNameSuffix = "_test.go"
1818
e2eTestDirectory = "e2e"
19+
testEntryPointEnv = "TEST_ENTRYPOINT"
1920
)
2021

2122
// GithubActionTestMatrix represents
@@ -29,7 +30,7 @@ type TestSuitePair struct {
2930
}
3031

3132
func main() {
32-
githubActionMatrix, err := getGithubActionMatrixForTests(e2eTestDirectory)
33+
githubActionMatrix, err := getGithubActionMatrixForTests(e2eTestDirectory, getTestFunctionToRun())
3334
if err != nil {
3435
fmt.Printf("error generating github action json: %s", err)
3536
os.Exit(1)
@@ -43,10 +44,20 @@ func main() {
4344
fmt.Println(string(ghBytes))
4445
}
4546

47+
// getTestFunctionToRun returns the specified test function to run if present, otherwise
48+
// it returns an empty string which will result in running all test suites.
49+
func getTestFunctionToRun() string {
50+
testSuite, ok := os.LookupEnv(testEntryPointEnv)
51+
if !ok {
52+
return ""
53+
}
54+
return testSuite
55+
}
56+
4657
// getGithubActionMatrixForTests returns a json string representing the contents that should go in the matrix
4758
// field in a github action workflow. This string can be used with `fromJSON(str)` to dynamically build
4859
// the workflow matrix to include all E2E tests under the e2eRootDirectory directory.
49-
func getGithubActionMatrixForTests(e2eRootDirectory string) (GithubActionTestMatrix, error) {
60+
func getGithubActionMatrixForTests(e2eRootDirectory, suite string) (GithubActionTestMatrix, error) {
5061
testSuiteMapping := map[string][]string{}
5162
fset := token.NewFileSet()
5263
err := filepath.Walk(e2eRootDirectory, func(path string, info fs.FileInfo, err error) error {
@@ -69,7 +80,9 @@ func getGithubActionMatrixForTests(e2eRootDirectory string) (GithubActionTestMat
6980
return fmt.Errorf("failed extracting test suite name and test cases: %s", err)
7081
}
7182

72-
testSuiteMapping[suiteNameForFile] = testCases
83+
if suite == "" || suiteNameForFile == suite {
84+
testSuiteMapping[suiteNameForFile] = testCases
85+
}
7386

7487
return nil
7588
})

cmd/build_test_matrix/main_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ const (
1919
func TestGetGithubActionMatrixForTests(t *testing.T) {
2020
t.Run("empty dir does not fail", func(t *testing.T) {
2121
testingDir := t.TempDir()
22-
_, err := getGithubActionMatrixForTests(testingDir)
22+
_, err := getGithubActionMatrixForTests(testingDir, "")
2323
assert.NoError(t, err)
2424
})
2525

2626
t.Run("only test functions are picked up", func(t *testing.T) {
2727
testingDir := t.TempDir()
2828
createFileWithTestSuiteAndTests(t, "FeeMiddlewareTestSuite", "TestA", "TestB", testingDir, goTestFileNameOne)
2929

30-
gh, err := getGithubActionMatrixForTests(testingDir)
30+
gh, err := getGithubActionMatrixForTests(testingDir, "")
3131
assert.NoError(t, err)
3232

3333
expected := GithubActionTestMatrix{
@@ -50,7 +50,7 @@ func TestGetGithubActionMatrixForTests(t *testing.T) {
5050
createFileWithTestSuiteAndTests(t, "FeeMiddlewareTestSuite", "TestA", "TestB", testingDir, goTestFileNameOne)
5151
createFileWithTestSuiteAndTests(t, "TransferTestSuite", "TestC", "TestD", testingDir, goTestFileNameTwo)
5252

53-
gh, err := getGithubActionMatrixForTests(testingDir)
53+
gh, err := getGithubActionMatrixForTests(testingDir, "")
5454
assert.NoError(t, err)
5555

5656
expected := GithubActionTestMatrix{
@@ -81,7 +81,7 @@ func TestGetGithubActionMatrixForTests(t *testing.T) {
8181
testingDir := t.TempDir()
8282
createFileWithTestSuiteAndTests(t, "FeeMiddlewareTestSuite", "TestA", "TestB", testingDir, nonTestFile)
8383

84-
gh, err := getGithubActionMatrixForTests(testingDir)
84+
gh, err := getGithubActionMatrixForTests(testingDir, "")
8585
assert.NoError(t, err)
8686
assert.Empty(t, gh.Include)
8787
})
@@ -105,7 +105,7 @@ type FeeMiddlewareTestSuite struct {}
105105
err := os.WriteFile(path.Join(testingDir, goTestFileNameOne), []byte(fileWithTwoSuites), os.FileMode(777))
106106
assert.NoError(t, err)
107107

108-
_, err = getGithubActionMatrixForTests(testingDir)
108+
_, err = getGithubActionMatrixForTests(testingDir, "")
109109
assert.Error(t, err)
110110
})
111111
}

e2e/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,14 @@ Every time changes are pushed to a branch or to `main`, a new `simd` image is bu
5757
#### Example Command:
5858

5959
```sh
60-
export SIMD_IMAGE="ghcr.io/cosmos/ibc-go-simd-e2e"
61-
export SIMD_TAG="pr-1650"
60+
export CHAIN_A_SIMD_IMAGE="ghcr.io/cosmos/ibc-go-simd-e2e"
61+
export CHAIN_A_SIMD_TAG="pr-1650"
62+
63+
# We can also specify different values for the chains if needed.
64+
# they will default to the same as chain a.
65+
# export CHAIN_B_SIMD_IMAGE="ghcr.io/cosmos/ibc-go-simd-e2e"
66+
# export CHAIN_B_SIMD_TAG="pr-1650"
67+
6268
export RLY_TAG="v2.0.0-rc2"
6369
make e2e-test suite=FeeMiddlewareTestSuite test=TestMultiMsg_MsgPayPacketFeeSingleSender
6470
```

e2e/scripts/run-e2e.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ set -euo pipefail
44

55
SUITE="${1}"
66
TEST="${2}"
7-
export SIMD_TAG="${SIMD_TAG:-latest}"
8-
export SIMD_IMAGE="${SIMD_IMAGE:-ibc-go-simd-e2e}"
7+
export SIMD_TAG="${CHAIN_A_SIMD_TAG:-latest}"
8+
export SIMD_IMAGE="${CHAIN_A_SIMD_IMAGE:-ibc-go-simd-e2e}"
99

1010
# In CI, the docker images will be built separately.
1111
# context for building the image is one directory up.

e2e/testconfig/testconfig.go

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,71 @@ import (
88
)
99

1010
const (
11-
DefaultSimdImage = "ghcr.io/cosmos/ibc-go-simd-e2e"
12-
SimdImageEnv = "SIMD_IMAGE"
13-
SimdTagEnv = "SIMD_TAG"
14-
GoRelayerTag = "RLY_TAG"
11+
// ChainASimdImageEnv specifies the image that Chain A will use.
12+
ChainASimdImageEnv = "CHAIN_A_SIMD_IMAGE"
13+
// ChainASimdTagEnv specifies the tag that Chain A will use.
14+
ChainASimdTagEnv = "CHAIN_A_SIMD_TAG"
15+
// ChainBSimdImageEnv specifies the image that Chain B will use. If unspecified
16+
// the value will default to the same value as Chain A.
17+
ChainBSimdImageEnv = "CHAIN_B_SIMD_IMAGE"
18+
// ChainBSimdTagEnv specifies the tag that Chain B will use. If unspecified
19+
// the value will default to the same value as Chain A.
20+
ChainBSimdTagEnv = "CHAIN_B_SIMD_TAG"
21+
GoRelayerTagEnv = "RLY_TAG"
1522

16-
defaultRlyTag = "main"
23+
defaultSimdImage = "ghcr.io/cosmos/ibc-go-simd-e2e"
24+
defaultRlyTag = "main"
1725
)
1826

1927
// TestConfig holds various fields used in the E2E tests.
2028
type TestConfig struct {
21-
SimdImage string
22-
SimdTag string
23-
RlyTag string
29+
ChainAConfig ChainConfig
30+
ChainBConfig ChainConfig
31+
RlyTag string
32+
}
33+
34+
type ChainConfig struct {
35+
Image string
36+
Tag string
2437
}
2538

2639
// FromEnv returns a TestConfig constructed from environment variables.
2740
func FromEnv() TestConfig {
28-
simdImage, ok := os.LookupEnv(SimdImageEnv)
41+
chainASimdImage, ok := os.LookupEnv(ChainASimdImageEnv)
42+
if !ok {
43+
chainASimdImage = defaultSimdImage
44+
}
45+
46+
chainASimdTag, ok := os.LookupEnv(ChainASimdTagEnv)
2947
if !ok {
30-
simdImage = DefaultSimdImage
48+
panic(fmt.Sprintf("must specify simd version for test with environment variable [%s]", ChainASimdTagEnv))
3149
}
3250

33-
simdTag, ok := os.LookupEnv(SimdTagEnv)
51+
chainBSimdImage, ok := os.LookupEnv(ChainBSimdImageEnv)
3452
if !ok {
35-
panic(fmt.Sprintf("must specify simd version for test with environment variable [%s]", SimdTagEnv))
53+
chainBSimdImage = chainASimdImage
3654
}
3755

38-
rlyTag, ok := os.LookupEnv(GoRelayerTag)
56+
chainBSimdTag, ok := os.LookupEnv(ChainBSimdTagEnv)
57+
if !ok {
58+
chainBSimdTag = chainASimdTag
59+
}
60+
61+
rlyTag, ok := os.LookupEnv(GoRelayerTagEnv)
3962
if !ok {
4063
rlyTag = defaultRlyTag
4164
}
4265

4366
return TestConfig{
44-
SimdImage: simdImage,
45-
SimdTag: simdTag,
46-
RlyTag: rlyTag,
67+
ChainAConfig: ChainConfig{
68+
Image: chainASimdImage,
69+
Tag: chainASimdTag,
70+
},
71+
ChainBConfig: ChainConfig{
72+
Image: chainBSimdImage,
73+
Tag: chainBSimdTag,
74+
},
75+
RlyTag: rlyTag,
4776
}
4877
}
4978

@@ -62,24 +91,24 @@ type ChainOptionConfiguration func(options *ChainOptions)
6291
// These options can be configured by passing configuration functions to E2ETestSuite.GetChains.
6392
func DefaultChainOptions() ChainOptions {
6493
tc := FromEnv()
65-
chainACfg := newDefaultSimappConfig(tc, "simapp-a", "chain-a", "atoma")
66-
chainBCfg := newDefaultSimappConfig(tc, "simapp-b", "chain-b", "atomb")
94+
chainACfg := newDefaultSimappConfig(tc.ChainAConfig, "simapp-a", "chain-a", "atoma")
95+
chainBCfg := newDefaultSimappConfig(tc.ChainBConfig, "simapp-b", "chain-b", "atomb")
6796
return ChainOptions{
6897
ChainAConfig: &chainACfg,
6998
ChainBConfig: &chainBCfg,
7099
}
71100
}
72101

73102
// newDefaultSimappConfig creates an ibc configuration for simd.
74-
func newDefaultSimappConfig(tc TestConfig, name, chainID, denom string) ibc.ChainConfig {
103+
func newDefaultSimappConfig(cc ChainConfig, name, chainID, denom string) ibc.ChainConfig {
75104
return ibc.ChainConfig{
76105
Type: "cosmos",
77106
Name: name,
78107
ChainID: chainID,
79108
Images: []ibc.DockerImage{
80109
{
81-
Repository: tc.SimdImage,
82-
Version: tc.SimdTag,
110+
Repository: cc.Image,
111+
Version: cc.Tag,
83112
},
84113
},
85114
Bin: "simd",

0 commit comments

Comments
 (0)