Skip to content

Commit

Permalink
fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBger committed Sep 5, 2024
1 parent a000eb2 commit dd4fc46
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 18 deletions.
5 changes: 3 additions & 2 deletions tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM ghcr.io/streamingfast/substreams:5e372ed as substreams
FROM bufbuild/buf as buf
FROM ghcr.io/streamingfast/substreams:5e372ed AS substreams
FROM bufbuild/buf AS buf
FROM rust:latest

WORKDIR /app
Expand All @@ -10,6 +10,7 @@ COPY --from=substreams /app/substreams /usr/local/bin/substreams
COPY --from=buf /usr/local/bin/buf /usr/local/bin/buf

RUN rustup target add wasm32-unknown-unknown

RUN chmod +x /usr/local/bin/substreams && \
chmod +x /app/entrypoint.sh

Expand Down
9 changes: 8 additions & 1 deletion tests/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#!/bin/sh

substreams init --state-file /app/generator.json --force-download-cwd --codegen-endpoint https://codegen-staging.substreams.dev
if [ "$TEST_LOCAL_CODEGEN" = "true" ]; then
substreams init --state-file /app/generator.json --force-download-cwd --codegen-endpoint http://host.docker.internal:9000
else
substreams init --state-file /app/generator.json --force-download-cwd --codegen-endpoint https://codegen-staging.substreams.dev
fi

substreams build


26 changes: 16 additions & 10 deletions tests/evm-events-calls/generator.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions tests/evm-minimal/generator.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

"generator": "evm-minimal",
"state": {
"name": "my_project",
"chainName": "mainnet",
"initialBlockSet": true
}
}
73 changes: 68 additions & 5 deletions tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,37 @@ package tests

import (
"fmt"
"os"
"os/exec"
"regexp"
"testing"
"time"

"github.com/stretchr/testify/require"

"github.com/streamingfast/logging"

"github.com/streamingfast/dstore"

"github.com/streamingfast/substreams-codegen/server"

"golang.org/x/net/context"
)

func TestIntegration(t *testing.T) {
if os.Getenv("RUN_INTEGRATION_TESTS") != "true" {
t.Skip()
}

cases := []struct {
name string
stateFile string
name string
stateFile string
explorerApiKeyEnvName string
}{
{
name: "evm-events-calls",
stateFile: "./evm-events-calls/generator.json",
name: "evm-events-calls",
stateFile: "./evm-events-calls/generator.json",
explorerApiKeyEnvName: "CODEGEN_MAINNET_API_KEY",
},
{
name: "evm-minimal",
Expand All @@ -25,8 +42,22 @@ func TestIntegration(t *testing.T) {
name: "injective-minimal",
stateFile: "./injective-minimal/generator.json",
},
{
name: "vara-minimal",
stateFile: "./vara-minimal/generator.json",
},
{
name: "sol-minimal",
stateFile: "./sol-minimal/generator.json",
},
{
name: "starknet-minimal",
stateFile: "./starknet-minimal/generator.json",
},
}

ctx := context.Background()

buildArgs := []string{
"build",
"-t",
Expand All @@ -35,7 +66,32 @@ func TestIntegration(t *testing.T) {
"--platform",
"linux/amd64",
}
ctx := context.Background()

if os.Getenv("TEST_LOCAL_CODEGEN") == "true" {
go func() {
var cors *regexp.Regexp
hostRegex, err := regexp.Compile("^localhost")
require.NoError(t, err)
cors = hostRegex

sessionStore, err := dstore.NewStore("", "", "", false)
require.NoError(t, err)

var zlog, _ = logging.RootLogger("test", "test")

server := server.New(
":9000",
cors,
sessionStore,
zlog)

server.Run()
}()

//Make sure server is running before, `substreams init`
time.Sleep(2 * time.Second)
}

buildCmd := exec.CommandContext(ctx, "docker", buildArgs...)
buildCmd.Dir = "./"

Expand All @@ -46,13 +102,20 @@ func TestIntegration(t *testing.T) {

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
explorerApiKey := os.Getenv(c.explorerApiKeyEnvName)
if explorerApiKey == "" {
fmt.Printf("NO %s has been provided, please make sure to provide it to enable code generation...", c.explorerApiKeyEnvName)
}

runArgs := []string{
"run",
"--rm",
"--platform",
"linux/amd64",
"-v",
fmt.Sprintf("%s:/app/generator.json", c.stateFile),
"-e",
fmt.Sprintf("TEST_LOCAL_CODEGEN=%s", os.Getenv("TEST_LOCAL_CODEGEN")),
"test-image",
}

Expand Down
8 changes: 8 additions & 0 deletions tests/sol-minimal/generator.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"generator": "sol-minimal",
"state": {
"name": "my_project",
"chainName": "",
"initialBlockSet": true
}
}
8 changes: 8 additions & 0 deletions tests/starknet-minimal/generator.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"generator": "starknet-minimal",
"state": {
"name": "my_project",
"chainName": "starknet-mainnet",
"initialBlockSet": true
}
}
8 changes: 8 additions & 0 deletions tests/vara-minimal/generator.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"generator": "vara-minimal",
"state": {
"name": "my_project",
"chainName": "vara-mainnet",
"initialBlockSet": true
}
}

0 comments on commit dd4fc46

Please sign in to comment.