Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(e2e): build Gossamer on any test run #2608

Merged
merged 1 commit into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tests/polkadotjs_test/start_polkadotjs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ func TestStartGossamerAndPolkadotAPI(t *testing.T) {
return
}

err := utils.BuildGossamer()
require.NoError(t, err)

const nodePackageManager = "npm"
t.Logf("Checking %s is available...", nodePackageManager)
_, err := exec.LookPath(nodePackageManager)
_, err = exec.LookPath(nodePackageManager)
if err != nil {
t.Fatalf("%s is not available: %s", nodePackageManager, err)
}
Expand Down
18 changes: 15 additions & 3 deletions tests/rpc/rpc_00_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,28 @@ package rpc
import (
"context"
"fmt"
"os"
"testing"
"time"

"github.com/ChainSafe/gossamer/tests/utils"
"github.com/ChainSafe/gossamer/tests/utils/rpc"
"github.com/stretchr/testify/require"
)

var (
rpcSuite = "rpc"
)
func TestMain(m *testing.M) {
if utils.MODE != "rpc" {
fmt.Println("Going to skip RPC suite tests")
os.Exit(0)
}

err := utils.BuildGossamer()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
os.Exit(m.Run())
}

type testCase struct {
description string
Expand Down
6 changes: 0 additions & 6 deletions tests/rpc/rpc_01-system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/ChainSafe/gossamer/dot/rpc/modules"
"github.com/ChainSafe/gossamer/lib/common"
libutils "github.com/ChainSafe/gossamer/lib/utils"
"github.com/ChainSafe/gossamer/tests/utils"
"github.com/ChainSafe/gossamer/tests/utils/config"
"github.com/ChainSafe/gossamer/tests/utils/node"
"github.com/ChainSafe/gossamer/tests/utils/retry"
Expand All @@ -22,11 +21,6 @@ import (
const peerIDRegex = `^[a-zA-Z0-9]{52}$`

func TestSystemRPC(t *testing.T) {
if utils.MODE != rpcSuite {
t.Log("Going to skip RPC suite tests")
return
}

const testTimeout = 8 * time.Minute
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)

Expand Down
11 changes: 0 additions & 11 deletions tests/rpc/rpc_02-author_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/centrifuge/go-substrate-rpc-client/v3/scale"

libutils "github.com/ChainSafe/gossamer/lib/utils"
"github.com/ChainSafe/gossamer/tests/utils"
"github.com/ChainSafe/gossamer/tests/utils/config"
"github.com/ChainSafe/gossamer/tests/utils/node"
"github.com/ChainSafe/gossamer/tests/utils/retry"
Expand All @@ -24,11 +23,6 @@ import (
)

func TestAuthorSubmitExtrinsic(t *testing.T) {
if utils.MODE != rpcSuite {
t.Log("Going to skip RPC suite tests")
return
}

genesisPath := libutils.GetDevGenesisSpecPathTest(t)
tomlConfig := config.Default()
tomlConfig.Init.Genesis = genesisPath
Expand Down Expand Up @@ -100,11 +94,6 @@ func TestAuthorSubmitExtrinsic(t *testing.T) {
}

func TestAuthorRPC(t *testing.T) {
if utils.MODE != rpcSuite {
t.Log("Going to skip RPC suite tests")
return
}

genesisPath := libutils.GetGssmrGenesisRawPathTest(t)
tomlConfig := config.Default()
tomlConfig.Init.Genesis = genesisPath
Expand Down
11 changes: 0 additions & 11 deletions tests/rpc/rpc_03-chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/ChainSafe/gossamer/dot/rpc/subscription"
"github.com/ChainSafe/gossamer/lib/common"
libutils "github.com/ChainSafe/gossamer/lib/utils"
"github.com/ChainSafe/gossamer/tests/utils"
"github.com/ChainSafe/gossamer/tests/utils/config"
"github.com/ChainSafe/gossamer/tests/utils/node"
"github.com/ChainSafe/gossamer/tests/utils/retry"
Expand All @@ -32,11 +31,6 @@ const (
)

func TestChainRPC(t *testing.T) {
if utils.MODE != rpcSuite {
t.Log("Going to skip RPC suite tests")
return
}

genesisPath := libutils.GetDevGenesisSpecPathTest(t)
tomlConfig := config.Default()
tomlConfig.Init.Genesis = genesisPath
Expand Down Expand Up @@ -129,11 +123,6 @@ func TestChainRPC(t *testing.T) {
}

func TestChainSubscriptionRPC(t *testing.T) {
if utils.MODE != rpcSuite {
t.Log("Going to skip RPC suite tests")
return
}

genesisPath := libutils.GetDevGenesisSpecPathTest(t)
tomlConfig := config.Default()
tomlConfig.Init.Genesis = genesisPath
Expand Down
6 changes: 0 additions & 6 deletions tests/rpc/rpc_04-offchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@ import (
"testing"

libutils "github.com/ChainSafe/gossamer/lib/utils"
"github.com/ChainSafe/gossamer/tests/utils"
"github.com/ChainSafe/gossamer/tests/utils/config"
"github.com/ChainSafe/gossamer/tests/utils/node"
)

func TestOffchainRPC(t *testing.T) {
t.SkipNow() // TODO

if utils.MODE != rpcSuite {
t.Log("Going to skip RPC suite tests")
return
}

genesisPath := libutils.GetGssmrGenesisRawPathTest(t)
tomlConfig := config.Default()
tomlConfig.Core.BABELead = true
Expand Down
16 changes: 0 additions & 16 deletions tests/rpc/rpc_05-state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,13 @@ import (
"github.com/ChainSafe/gossamer/dot/rpc/modules"
"github.com/ChainSafe/gossamer/lib/common"
libutils "github.com/ChainSafe/gossamer/lib/utils"
"github.com/ChainSafe/gossamer/tests/utils"
"github.com/ChainSafe/gossamer/tests/utils/config"
"github.com/ChainSafe/gossamer/tests/utils/node"
"github.com/ChainSafe/gossamer/tests/utils/rpc"
"github.com/stretchr/testify/require"
)

func TestStateRPCResponseValidation(t *testing.T) {
if utils.MODE != rpcSuite {
t.Log("Going to skip RPC suite tests")
return
}

genesisPath := libutils.GetGssmrGenesisRawPathTest(t)
tomlConfig := config.Default()
tomlConfig.Init.Genesis = genesisPath
Expand Down Expand Up @@ -168,11 +162,6 @@ func TestStateRPCResponseValidation(t *testing.T) {
}

func TestStateRPCAPI(t *testing.T) {
if utils.MODE != rpcSuite {
t.Log("Going to skip RPC suite tests")
return
}

genesisPath := libutils.GetGssmrGenesisRawPathTest(t)
tomlConfig := config.Default()
tomlConfig.Init.Genesis = genesisPath
Expand Down Expand Up @@ -374,11 +363,6 @@ func TestStateRPCAPI(t *testing.T) {
}

func TestRPCStructParamUnmarshal(t *testing.T) {
if utils.MODE != rpcSuite {
t.Log("Going to skip RPC suite tests")
return
}

genesisPath := libutils.GetDevGenesisSpecPathTest(t)
tomlConfig := config.Default()
tomlConfig.Core.BABELead = true
Expand Down
6 changes: 0 additions & 6 deletions tests/rpc/rpc_06-engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@ import (
"testing"

libutils "github.com/ChainSafe/gossamer/lib/utils"
"github.com/ChainSafe/gossamer/tests/utils"
"github.com/ChainSafe/gossamer/tests/utils/config"
"github.com/ChainSafe/gossamer/tests/utils/node"
)

func TestEngineRPC(t *testing.T) {
t.SkipNow()

if utils.MODE != rpcSuite {
t.Log("Going to skip RPC suite tests")
return
}

genesisPath := libutils.GetGssmrGenesisRawPathTest(t)
tomlConfig := config.Default()
tomlConfig.Init.Genesis = genesisPath
Expand Down
6 changes: 0 additions & 6 deletions tests/rpc/rpc_07-payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@ import (
"testing"

libutils "github.com/ChainSafe/gossamer/lib/utils"
"github.com/ChainSafe/gossamer/tests/utils"
"github.com/ChainSafe/gossamer/tests/utils/config"
"github.com/ChainSafe/gossamer/tests/utils/node"
)

func TestPaymentRPC(t *testing.T) {
t.SkipNow() // TODO

if utils.MODE != rpcSuite {
t.Log("Going to skip RPC suite tests")
return
}

genesisPath := libutils.GetGssmrGenesisRawPathTest(t)
tomlConfig := config.Default()
tomlConfig.Init.Genesis = genesisPath
Expand Down
6 changes: 0 additions & 6 deletions tests/rpc/rpc_08-contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@ import (
"testing"

libutils "github.com/ChainSafe/gossamer/lib/utils"
"github.com/ChainSafe/gossamer/tests/utils"
"github.com/ChainSafe/gossamer/tests/utils/config"
"github.com/ChainSafe/gossamer/tests/utils/node"
)

func TestContractsRPC(t *testing.T) {
t.SkipNow() // TODO

if utils.MODE != rpcSuite {
t.Log("Going to skip RPC suite tests")
return
}

genesisPath := libutils.GetGssmrGenesisRawPathTest(t)
tomlConfig := config.Default()
tomlConfig.Init.Genesis = genesisPath
Expand Down
6 changes: 0 additions & 6 deletions tests/rpc/rpc_09-babe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@ import (
"testing"

libutils "github.com/ChainSafe/gossamer/lib/utils"
"github.com/ChainSafe/gossamer/tests/utils"
"github.com/ChainSafe/gossamer/tests/utils/config"
"github.com/ChainSafe/gossamer/tests/utils/node"
)

func TestBabeRPC(t *testing.T) {
t.SkipNow() // TODO

if utils.MODE != rpcSuite {
t.Log("Going to skip RPC suite tests")
return
}

genesisPath := libutils.GetGssmrGenesisRawPathTest(t)
tomlConfig := config.Default()
tomlConfig.Init.Genesis = genesisPath
Expand Down
6 changes: 6 additions & 0 deletions tests/stress/stress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ func TestMain(m *testing.M) {
return
}

err := utils.BuildGossamer()
if err != nil {
fmt.Println(err)
os.Exit(1)
}

logLvl := log.Info
if utils.LOGLEVEL != "" {
var err error
Expand Down
3 changes: 3 additions & 0 deletions tests/sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ func TestCalls(t *testing.T) {
t.Skip("MODE != 'sync', skipping stress test")
}

err := utils.BuildGossamer()
require.NoError(t, err)

ctx := context.Background()

const qtyNodes = 3
Expand Down
32 changes: 32 additions & 0 deletions tests/utils/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2022 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

package utils

import (
"context"
"fmt"
"os/exec"

libutils "github.com/ChainSafe/gossamer/lib/utils"
)

// BuildGossamer finds the project root path and builds the Gossamer
// binary to ./bin/gossamer at the project root path.
func BuildGossamer() (err error) {
rootPath, err := libutils.GetProjectRootPath()
if err != nil {
return fmt.Errorf("get project root path: %w", err)
}

ctx := context.Background()
cmd := exec.CommandContext(ctx, "go", "build",
"-trimpath", "-o", "./bin/gossamer", "./cmd/gossamer")
cmd.Dir = rootPath
output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("building Gossamer: %w\n%s", err, output)
}

return nil
}