Skip to content

Commit f97e0ef

Browse files
authored
feat(e2e): build Gossamer on any test run (#2608)
1 parent 1826896 commit f97e0ef

14 files changed

+60
-78
lines changed

tests/polkadotjs_test/start_polkadotjs_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ func TestStartGossamerAndPolkadotAPI(t *testing.T) {
2525
return
2626
}
2727

28+
err := utils.BuildGossamer()
29+
require.NoError(t, err)
30+
2831
const nodePackageManager = "npm"
2932
t.Logf("Checking %s is available...", nodePackageManager)
30-
_, err := exec.LookPath(nodePackageManager)
33+
_, err = exec.LookPath(nodePackageManager)
3134
if err != nil {
3235
t.Fatalf("%s is not available: %s", nodePackageManager, err)
3336
}

tests/rpc/rpc_00_test.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,28 @@ package rpc
66
import (
77
"context"
88
"fmt"
9+
"os"
910
"testing"
1011
"time"
1112

13+
"github.com/ChainSafe/gossamer/tests/utils"
1214
"github.com/ChainSafe/gossamer/tests/utils/rpc"
1315
"github.com/stretchr/testify/require"
1416
)
1517

16-
var (
17-
rpcSuite = "rpc"
18-
)
18+
func TestMain(m *testing.M) {
19+
if utils.MODE != "rpc" {
20+
fmt.Println("Going to skip RPC suite tests")
21+
os.Exit(0)
22+
}
23+
24+
err := utils.BuildGossamer()
25+
if err != nil {
26+
fmt.Println(err)
27+
os.Exit(1)
28+
}
29+
os.Exit(m.Run())
30+
}
1931

2032
type testCase struct {
2133
description string

tests/rpc/rpc_01-system_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/ChainSafe/gossamer/dot/rpc/modules"
1212
"github.com/ChainSafe/gossamer/lib/common"
1313
libutils "github.com/ChainSafe/gossamer/lib/utils"
14-
"github.com/ChainSafe/gossamer/tests/utils"
1514
"github.com/ChainSafe/gossamer/tests/utils/config"
1615
"github.com/ChainSafe/gossamer/tests/utils/node"
1716
"github.com/ChainSafe/gossamer/tests/utils/retry"
@@ -22,11 +21,6 @@ import (
2221
const peerIDRegex = `^[a-zA-Z0-9]{52}$`
2322

2423
func TestSystemRPC(t *testing.T) {
25-
if utils.MODE != rpcSuite {
26-
t.Log("Going to skip RPC suite tests")
27-
return
28-
}
29-
3024
const testTimeout = 8 * time.Minute
3125
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
3226

tests/rpc/rpc_02-author_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/centrifuge/go-substrate-rpc-client/v3/scale"
1414

1515
libutils "github.com/ChainSafe/gossamer/lib/utils"
16-
"github.com/ChainSafe/gossamer/tests/utils"
1716
"github.com/ChainSafe/gossamer/tests/utils/config"
1817
"github.com/ChainSafe/gossamer/tests/utils/node"
1918
"github.com/ChainSafe/gossamer/tests/utils/retry"
@@ -24,11 +23,6 @@ import (
2423
)
2524

2625
func TestAuthorSubmitExtrinsic(t *testing.T) {
27-
if utils.MODE != rpcSuite {
28-
t.Log("Going to skip RPC suite tests")
29-
return
30-
}
31-
3226
genesisPath := libutils.GetDevGenesisSpecPathTest(t)
3327
tomlConfig := config.Default()
3428
tomlConfig.Init.Genesis = genesisPath
@@ -100,11 +94,6 @@ func TestAuthorSubmitExtrinsic(t *testing.T) {
10094
}
10195

10296
func TestAuthorRPC(t *testing.T) {
103-
if utils.MODE != rpcSuite {
104-
t.Log("Going to skip RPC suite tests")
105-
return
106-
}
107-
10897
genesisPath := libutils.GetGssmrGenesisRawPathTest(t)
10998
tomlConfig := config.Default()
11099
tomlConfig.Init.Genesis = genesisPath

tests/rpc/rpc_03-chain_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/ChainSafe/gossamer/dot/rpc/subscription"
1616
"github.com/ChainSafe/gossamer/lib/common"
1717
libutils "github.com/ChainSafe/gossamer/lib/utils"
18-
"github.com/ChainSafe/gossamer/tests/utils"
1918
"github.com/ChainSafe/gossamer/tests/utils/config"
2019
"github.com/ChainSafe/gossamer/tests/utils/node"
2120
"github.com/ChainSafe/gossamer/tests/utils/retry"
@@ -32,11 +31,6 @@ const (
3231
)
3332

3433
func TestChainRPC(t *testing.T) {
35-
if utils.MODE != rpcSuite {
36-
t.Log("Going to skip RPC suite tests")
37-
return
38-
}
39-
4034
genesisPath := libutils.GetDevGenesisSpecPathTest(t)
4135
tomlConfig := config.Default()
4236
tomlConfig.Init.Genesis = genesisPath
@@ -129,11 +123,6 @@ func TestChainRPC(t *testing.T) {
129123
}
130124

131125
func TestChainSubscriptionRPC(t *testing.T) {
132-
if utils.MODE != rpcSuite {
133-
t.Log("Going to skip RPC suite tests")
134-
return
135-
}
136-
137126
genesisPath := libutils.GetDevGenesisSpecPathTest(t)
138127
tomlConfig := config.Default()
139128
tomlConfig.Init.Genesis = genesisPath

tests/rpc/rpc_04-offchain_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,13 @@ import (
88
"testing"
99

1010
libutils "github.com/ChainSafe/gossamer/lib/utils"
11-
"github.com/ChainSafe/gossamer/tests/utils"
1211
"github.com/ChainSafe/gossamer/tests/utils/config"
1312
"github.com/ChainSafe/gossamer/tests/utils/node"
1413
)
1514

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

19-
if utils.MODE != rpcSuite {
20-
t.Log("Going to skip RPC suite tests")
21-
return
22-
}
23-
2418
genesisPath := libutils.GetGssmrGenesisRawPathTest(t)
2519
tomlConfig := config.Default()
2620
tomlConfig.Core.BABELead = true

tests/rpc/rpc_05-state_test.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,13 @@ import (
1212
"github.com/ChainSafe/gossamer/dot/rpc/modules"
1313
"github.com/ChainSafe/gossamer/lib/common"
1414
libutils "github.com/ChainSafe/gossamer/lib/utils"
15-
"github.com/ChainSafe/gossamer/tests/utils"
1615
"github.com/ChainSafe/gossamer/tests/utils/config"
1716
"github.com/ChainSafe/gossamer/tests/utils/node"
1817
"github.com/ChainSafe/gossamer/tests/utils/rpc"
1918
"github.com/stretchr/testify/require"
2019
)
2120

2221
func TestStateRPCResponseValidation(t *testing.T) {
23-
if utils.MODE != rpcSuite {
24-
t.Log("Going to skip RPC suite tests")
25-
return
26-
}
27-
2822
genesisPath := libutils.GetGssmrGenesisRawPathTest(t)
2923
tomlConfig := config.Default()
3024
tomlConfig.Init.Genesis = genesisPath
@@ -168,11 +162,6 @@ func TestStateRPCResponseValidation(t *testing.T) {
168162
}
169163

170164
func TestStateRPCAPI(t *testing.T) {
171-
if utils.MODE != rpcSuite {
172-
t.Log("Going to skip RPC suite tests")
173-
return
174-
}
175-
176165
genesisPath := libutils.GetGssmrGenesisRawPathTest(t)
177166
tomlConfig := config.Default()
178167
tomlConfig.Init.Genesis = genesisPath
@@ -374,11 +363,6 @@ func TestStateRPCAPI(t *testing.T) {
374363
}
375364

376365
func TestRPCStructParamUnmarshal(t *testing.T) {
377-
if utils.MODE != rpcSuite {
378-
t.Log("Going to skip RPC suite tests")
379-
return
380-
}
381-
382366
genesisPath := libutils.GetDevGenesisSpecPathTest(t)
383367
tomlConfig := config.Default()
384368
tomlConfig.Core.BABELead = true

tests/rpc/rpc_06-engine_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,13 @@ import (
88
"testing"
99

1010
libutils "github.com/ChainSafe/gossamer/lib/utils"
11-
"github.com/ChainSafe/gossamer/tests/utils"
1211
"github.com/ChainSafe/gossamer/tests/utils/config"
1312
"github.com/ChainSafe/gossamer/tests/utils/node"
1413
)
1514

1615
func TestEngineRPC(t *testing.T) {
1716
t.SkipNow()
1817

19-
if utils.MODE != rpcSuite {
20-
t.Log("Going to skip RPC suite tests")
21-
return
22-
}
23-
2418
genesisPath := libutils.GetGssmrGenesisRawPathTest(t)
2519
tomlConfig := config.Default()
2620
tomlConfig.Init.Genesis = genesisPath

tests/rpc/rpc_07-payment_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,13 @@ import (
88
"testing"
99

1010
libutils "github.com/ChainSafe/gossamer/lib/utils"
11-
"github.com/ChainSafe/gossamer/tests/utils"
1211
"github.com/ChainSafe/gossamer/tests/utils/config"
1312
"github.com/ChainSafe/gossamer/tests/utils/node"
1413
)
1514

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

19-
if utils.MODE != rpcSuite {
20-
t.Log("Going to skip RPC suite tests")
21-
return
22-
}
23-
2418
genesisPath := libutils.GetGssmrGenesisRawPathTest(t)
2519
tomlConfig := config.Default()
2620
tomlConfig.Init.Genesis = genesisPath

tests/rpc/rpc_08-contracts_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,13 @@ import (
88
"testing"
99

1010
libutils "github.com/ChainSafe/gossamer/lib/utils"
11-
"github.com/ChainSafe/gossamer/tests/utils"
1211
"github.com/ChainSafe/gossamer/tests/utils/config"
1312
"github.com/ChainSafe/gossamer/tests/utils/node"
1413
)
1514

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

19-
if utils.MODE != rpcSuite {
20-
t.Log("Going to skip RPC suite tests")
21-
return
22-
}
23-
2418
genesisPath := libutils.GetGssmrGenesisRawPathTest(t)
2519
tomlConfig := config.Default()
2620
tomlConfig.Init.Genesis = genesisPath

tests/rpc/rpc_09-babe_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,13 @@ import (
88
"testing"
99

1010
libutils "github.com/ChainSafe/gossamer/lib/utils"
11-
"github.com/ChainSafe/gossamer/tests/utils"
1211
"github.com/ChainSafe/gossamer/tests/utils/config"
1312
"github.com/ChainSafe/gossamer/tests/utils/node"
1413
)
1514

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

19-
if utils.MODE != rpcSuite {
20-
t.Log("Going to skip RPC suite tests")
21-
return
22-
}
23-
2418
genesisPath := libutils.GetGssmrGenesisRawPathTest(t)
2519
tomlConfig := config.Default()
2620
tomlConfig.Init.Genesis = genesisPath

tests/stress/stress_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ func TestMain(m *testing.M) {
3737
return
3838
}
3939

40+
err := utils.BuildGossamer()
41+
if err != nil {
42+
fmt.Println(err)
43+
os.Exit(1)
44+
}
45+
4046
logLvl := log.Info
4147
if utils.LOGLEVEL != "" {
4248
var err error

tests/sync/sync_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ func TestCalls(t *testing.T) {
4848
t.Skip("MODE != 'sync', skipping stress test")
4949
}
5050

51+
err := utils.BuildGossamer()
52+
require.NoError(t, err)
53+
5154
ctx := context.Background()
5255

5356
const qtyNodes = 3

tests/utils/build.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2022 ChainSafe Systems (ON)
2+
// SPDX-License-Identifier: LGPL-3.0-only
3+
4+
package utils
5+
6+
import (
7+
"context"
8+
"fmt"
9+
"os/exec"
10+
11+
libutils "github.com/ChainSafe/gossamer/lib/utils"
12+
)
13+
14+
// BuildGossamer finds the project root path and builds the Gossamer
15+
// binary to ./bin/gossamer at the project root path.
16+
func BuildGossamer() (err error) {
17+
rootPath, err := libutils.GetProjectRootPath()
18+
if err != nil {
19+
return fmt.Errorf("get project root path: %w", err)
20+
}
21+
22+
ctx := context.Background()
23+
cmd := exec.CommandContext(ctx, "go", "build",
24+
"-trimpath", "-o", "./bin/gossamer", "./cmd/gossamer")
25+
cmd.Dir = rootPath
26+
output, err := cmd.CombinedOutput()
27+
if err != nil {
28+
return fmt.Errorf("building Gossamer: %w\n%s", err, output)
29+
}
30+
31+
return nil
32+
}

0 commit comments

Comments
 (0)