Skip to content

Commit

Permalink
feat(e2e): build Gossamer on any test run (#2608)
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Jun 29, 2022
1 parent 1826896 commit f97e0ef
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 78 deletions.
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
}

0 comments on commit f97e0ef

Please sign in to comment.