Skip to content

Commit

Permalink
allow using gaia as provider in integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MSalopek committed Feb 28, 2023
1 parent bf6cdae commit 19ff7ee
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 14 deletions.
16 changes: 12 additions & 4 deletions tests/integration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ type TestRun struct {
// lengthening the timeout_commit increases the test runtime because blocks are produced slower but the test is more reliable
tendermintConfigOverride string
localSdkPath string
useGaia bool
gaiaTag string

name string
}
Expand Down Expand Up @@ -315,11 +317,17 @@ func MultiConsumerTestRun() TestRun {
}
}

func (s *TestRun) SetLocalSDKPath(path string) {
if path != "" {
fmt.Println("USING LOCAL SDK", path)
func (s *TestRun) SetDockerConfig(localSdkPath string, useGaia bool, gaiaTag string) {
if localSdkPath != "" {
fmt.Println("USING LOCAL SDK", localSdkPath)
}
s.localSdkPath = path
if useGaia {
fmt.Println("USING GAIA INSTEAD OF ICS provider app", gaiaTag)
}

s.useGaia = useGaia
s.gaiaTag = gaiaTag
s.localSdkPath = localSdkPath
}

// validateStringLiterals enforces that configs follow the constraints
Expand Down
38 changes: 29 additions & 9 deletions tests/integration/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ var includeMultiConsumer = flag.Bool("include-multi-consumer", false, "include m
var parallel = flag.Bool("parallel", false, "run all tests in parallel")
var localSdkPath = flag.String("local-sdk-path", "",
"path of a local sdk version to build and reference in integration tests")
var useGaia = flag.Bool("use-gaia", false, "use gaia instead of ICS provider app")
var gaiaTag = flag.String("gaia-tag", "", "gaia tag to use - default is latest")

// runs integration tests
// all docker containers are built sequentially to avoid race conditions when using local cosmos-sdk
Expand All @@ -29,7 +31,7 @@ func main() {
if happyPathOnly != nil && *happyPathOnly {
fmt.Println("=============== running happy path only ===============")
tr := DefaultTestRun()
tr.Run(happyPathSteps, *localSdkPath)
tr.Run(happyPathSteps, *localSdkPath, *useGaia, *gaiaTag)
return
}

Expand All @@ -51,7 +53,7 @@ func main() {
go func(run testRunWithSteps) {
defer wg.Done()
tr := run.testRun
tr.Run(run.steps, *localSdkPath)
tr.Run(run.steps, *localSdkPath, *useGaia, *gaiaTag)
}(run)
}
wg.Wait()
Expand All @@ -61,15 +63,16 @@ func main() {

for _, run := range testRuns {
tr := run.testRun
tr.Run(run.steps, *localSdkPath)
tr.Run(run.steps, *localSdkPath, *useGaia, *gaiaTag)
}
fmt.Printf("TOTAL TIME ELAPSED: %v\n", time.Since(start))
}

// Run sets up docker container and executes the steps in the test run.
// Docker containers are torn down after the test run is complete.
func (tr *TestRun) Run(steps []Step, localSdkPath string) {
tr.SetLocalSDKPath(localSdkPath)
func (tr *TestRun) Run(steps []Step, localSdkPath string, useGaia bool, gaiaTag string) {
tr.SetDockerConfig(localSdkPath, useGaia, gaiaTag)

tr.validateStringLiterals()
tr.startDocker()
tr.executeSteps(steps)
Expand Down Expand Up @@ -165,10 +168,27 @@ func (tr *TestRun) executeSteps(steps []Step) {

func (tr *TestRun) startDocker() {
fmt.Printf("=============== building %s testRun ===============\n", tr.name)
scriptStr := "tests/integration/testnet-scripts/start-docker.sh " +
tr.containerConfig.containerName + " " +
tr.containerConfig.instanceName + " " +
tr.localSdkPath
localSdk := tr.localSdkPath
if localSdk == "" {
localSdk = "default"
}
useGaia := "false"
gaiaTag := ""
if tr.useGaia {
useGaia = "true"
if tr.gaiaTag != "" {
gaiaTag = tr.gaiaTag
}
}
scriptStr := fmt.Sprintf(
"tests/integration/testnet-scripts/start-docker.sh %s %s %s %s %s",
tr.containerConfig.containerName,
tr.containerConfig.instanceName,
localSdk,
useGaia,
gaiaTag,
)

//#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments.
cmd := exec.Command("/bin/bash", "-c", scriptStr)

Expand Down
12 changes: 11 additions & 1 deletion tests/integration/testnet-scripts/start-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ set -eux
CONTAINER_NAME=$1
INSTANCE_NAME=$2
LOCAL_SDK_PATH=${3:-"default"} # Sets this var to default if null or unset
USE_GAIA_PROVIDER=${4:-"false"} # if true, use gaia as provider; if false, use ICS app
USE_GAIA_TAG=${5:-""} # gaia tag to use if using gaia as provider; by default the latest tag is used

# Remove existing container instance
set +e
Expand All @@ -28,7 +30,15 @@ else
fi

# Build the Docker container
docker build -t "$CONTAINER_NAME" .
if [[ "$USE_GAIA_PROVIDER" = "true" ]]
then
printf "\n\nUsing gaia as provider\n\n"
printf "\n\nUsing gaia tag %s\n\n" "$USE_GAIA_TAG"
docker build -f Dockerfile.gaia -t "$CONTAINER_NAME" --build-arg USE_GAIA_TAG="$USE_GAIA_TAG" .
else
printf "\n\nUsing ICS provider app as provider\n\n\n"
docker build -f Dockerfile -t "$CONTAINER_NAME" .
fi

# Remove copied sdk directory
rm -rf ./cosmos-sdk/
Expand Down

0 comments on commit 19ff7ee

Please sign in to comment.