Skip to content

Commit

Permalink
chore (dot/tests): Add integration tests into CI process (#2215)
Browse files Browse the repository at this point in the history
  • Loading branch information
EclesioMeloJunior authored Jan 21, 2022
1 parent e4bc375 commit 17e557d
Show file tree
Hide file tree
Showing 23 changed files with 724 additions and 275 deletions.
2 changes: 2 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ For coding style, you may refer to the [code style](CODE_STYLE.md) document whic
⚠️ We are still using `mockery` instead of `gomock` for older mocks, so you need to run `go generate -run "mockery|mockgen" ./...` to update all the existing mocks. We are slowly migrating our mocks and test code to use `gomock`.
> To execute `//go:generate` commands that are placed at files with `// +build integration` remember to add `-tags integration` in the `go generate` command eg. `go generate -tags integration ...`
9. **Lint your changes.**
Before opening a pull request be sure to run the linter
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
on:
pull_request:
types:
- opened
- edited
- reopened
paths:
- .github/workflows/checks.yml
- .github/PULL_REQUEST/pull_request.go
Expand Down
56 changes: 56 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
on:
pull_request:
paths:
- .github/workflows/integration-tests.yml
- "**/*.go"
- "chain/**"
- "cmd/**"
- "dot/**"
- "internal/**"
- "lib/**"
- "pkg/**"
- "tests/**"
- go.mod
- go.sum
name: integration-tests

jobs:
integration-tests:
timeout-minutes: 60
strategy:
matrix:
packages: [
github.com/ChainSafe/gossamer/dot/rpc/modules,
github.com/ChainSafe/gossamer/lib/babe
]
runs-on: ubuntu-latest
steps:
- id: go-cache-paths
run: |
echo "::set-output name=go-build::$(go env GOCACHE)"
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
- uses: actions/setup-go@v2
with:
go-version: 1.17.x
- uses: actions/checkout@v2

# cache go build cache
- name: Cache go modules
uses: actions/cache@v2
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-build

# cache go mod cache
- name: Cache go modules
uses: actions/cache@v2
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-mod

- name: Run integration tests
run: go test -timeout=30m -tags integration ${{ matrix.packages }}

8 changes: 6 additions & 2 deletions dot/core/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ import (

// NewTestService creates a new test core service
func NewTestService(t *testing.T, cfg *Config) *Service {
t.Helper()

if cfg == nil {
cfg = &Config{}
}

cfg.DigestHandler = new(coremocks.DigestHandler)
cfg.DigestHandler.(*coremocks.DigestHandler).On("HandleDigests", mock.AnythingOfType("*types.Header"))
if cfg.DigestHandler == nil {
cfg.DigestHandler = new(coremocks.DigestHandler)
cfg.DigestHandler.(*coremocks.DigestHandler).On("HandleDigests", mock.AnythingOfType("*types.Header"))
}

if cfg.Keystore == nil {
cfg.Keystore = keystore.NewGlobalKeystore()
Expand Down
4 changes: 0 additions & 4 deletions dot/network/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ func (c *Config) build() error {
c.Roles = DefaultRoles
}

if c.Port == 0 {
c.Port = DefaultPort
}

// build identity configuration
err = c.buildIdentity()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion dot/network/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestBuild(t *testing.T) {
require.Equal(t, testBlockState, cfg.BlockState)
require.Equal(t, testBasePath, cfg.BasePath)
require.Equal(t, DefaultRoles, cfg.Roles)
require.Equal(t, DefaultPort, cfg.Port)
require.Equal(t, uint16(0), cfg.Port)
require.Equal(t, testRandSeed, cfg.RandSeed)
require.Equal(t, DefaultBootnodes, cfg.Bootnodes)
require.Equal(t, DefaultProtocolID, cfg.ProtocolID)
Expand Down
3 changes: 1 addition & 2 deletions dot/rpc/modules/author.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (am *AuthorModule) HasSessionKeys(r *http.Request, req *HasSessionKeyReques
}

// InsertKey inserts a key into the keystore
func (am *AuthorModule) InsertKey(r *http.Request, req *KeyInsertRequest, res *KeyInsertResponse) error {
func (am *AuthorModule) InsertKey(r *http.Request, req *KeyInsertRequest, _ *KeyInsertResponse) error {
keyReq := *req

keyBytes, err := common.HexToBytes(req.Seed)
Expand Down Expand Up @@ -212,7 +212,6 @@ func (am *AuthorModule) SubmitExtrinsic(r *http.Request, req *Extrinsic, res *Ex
return err
}
ext := types.Extrinsic(extBytes)
am.logger.Criticalf("[rpc] extrinsic is %s", ext)

*res = ExtrinsicHashResponse(ext.Hash().String())
err = am.coreAPI.HandleSubmittedExtrinsic(ext)
Expand Down
8 changes: 3 additions & 5 deletions dot/rpc/modules/author_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func TestAuthorModule_SubmitExtrinsic_invalid_input(t *testing.T) {

res := new(ExtrinsicHashResponse)
err := auth.SubmitExtrinsic(nil, &ext, res)
require.EqualError(t, err, "could not byteify non 0x prefixed string: 0x31")
require.EqualError(t, err, "could not byteify non 0x prefixed string: 31")
}

func TestAuthorModule_SubmitExtrinsic_InQueue(t *testing.T) {
Expand Down Expand Up @@ -276,7 +276,7 @@ func TestAuthorModule_HasKey_Integration(t *testing.T) {
require.Nil(t, err)

var res bool
req := []string{kr.Alice().Public().Hex(), "babe"}
req := []string{kr.Alice().Public().Hex(), "acco"}
err = auth.HasKey(nil, &req, &res)
require.NoError(t, err)
require.True(t, res)
Expand Down Expand Up @@ -312,14 +312,12 @@ func TestAuthorModule_HasKey_InvalidKeyType(t *testing.T) {
var res bool
req := []string{kr.Alice().Public().Hex(), "xxxx"}
err = auth.HasKey(nil, &req, &res)
require.EqualError(t, err, "unknown key type: xxxx")
require.EqualError(t, err, "invalid keystore name")
require.False(t, res)
}

func setupAuthModule(t *testing.T, txq *state.TransactionState) *AuthorModule {
fmt.Println("calling setupAuthModule")
cs := newCoreService(t, nil)
fmt.Println("called newCoreService")
rt := wasmer.NewTestInstance(t, runtime.NODE_RUNTIME)
t.Cleanup(func() {
rt.Stop()
Expand Down
10 changes: 8 additions & 2 deletions dot/rpc/modules/chain_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/ChainSafe/gossamer/lib/trie"
"github.com/ChainSafe/gossamer/lib/utils"
"github.com/ChainSafe/gossamer/pkg/scale"
"github.com/golang/mock/gomock"

database "github.com/ChainSafe/chaindb"
rtstorage "github.com/ChainSafe/gossamer/lib/runtime/storage"
Expand Down Expand Up @@ -342,9 +343,14 @@ func TestChainGetFinalizedHeadByRound(t *testing.T) {
func newTestStateService(t *testing.T) *state.Service {
testDatadirPath := t.TempDir()

ctrl := gomock.NewController(t)
telemetryMock := NewMockClient(ctrl)
telemetryMock.EXPECT().SendMessage(gomock.Any()).AnyTimes()

config := state.Config{
Path: testDatadirPath,
LogLevel: log.Info,
Path: testDatadirPath,
LogLevel: log.Info,
Telemetry: telemetryMock,
}
stateSrvc := state.NewService(config)
stateSrvc.UseMemDB()
Expand Down
29 changes: 8 additions & 21 deletions dot/rpc/modules/childstate_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
// Copyright 2021 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

//go:build integration
// +build integration

// Copyright 2019 ChainSafe Systems (ON) Corp.
// This file is part of gossamer.
//
// The gossamer library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The gossamer library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the gossamer library. If not, see <http://www.gnu.org/licenses/>.
package modules

import (
Expand Down Expand Up @@ -105,7 +93,7 @@ func TestChildStateGetStorageSize(t *testing.T) {
keyChild: []byte(":child_storage_key"),
},
{
err: fmt.Errorf("child trie does not exist at key %s%s", trie.ChildStorageKeyPrefix, []byte(":not_exist")),
err: fmt.Errorf("child trie does not exist at key 0x%x%x", trie.ChildStorageKeyPrefix, []byte(":not_exist")),
hash: &blockHash,
entry: []byte(":child_second"),
keyChild: []byte(":not_exist"),
Expand All @@ -127,8 +115,7 @@ func TestChildStateGetStorageSize(t *testing.T) {
err := mod.GetStorageSize(nil, &req, &res)

if test.err != nil {
require.Error(t, err)
require.Equal(t, err, test.err)
require.EqualError(t, err, test.err.Error())
} else {
require.NoError(t, err)
}
Expand Down Expand Up @@ -163,7 +150,8 @@ func TestGetStorageHash(t *testing.T) {
keyChild: []byte(":child_storage_key"),
},
{
err: fmt.Errorf("child trie does not exist at key %s%s", trie.ChildStorageKeyPrefix, []byte(":not_exist")),
err: fmt.Errorf("child trie does not exist at key 0x%x%x",
string(trie.ChildStorageKeyPrefix), []byte(":not_exist")),
hash: &blockHash,
entry: []byte(":child_second"),
keyChild: []byte(":not_exist"),
Expand All @@ -185,8 +173,7 @@ func TestGetStorageHash(t *testing.T) {
err := mod.GetStorageHash(nil, &req, &res)

if test.err != nil {
require.Error(t, err)
require.Equal(t, err, test.err)
require.EqualError(t, err, test.err.Error())
} else {
require.NoError(t, err)
}
Expand Down
3 changes: 1 addition & 2 deletions dot/rpc/modules/grandpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ func (gm *GrandpaModule) ProveFinality(r *http.Request, req *ProveFinalityReques
}

// Leaving check in for linter
//nolint
if req.authorityID != uint64(0) {
if req.authorityID != uint64(0) { // nolint:staticcheck
// TODO: Check if functionality relevant (#1404)
}

Expand Down
19 changes: 3 additions & 16 deletions dot/rpc/modules/grandpa_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
// Copyright 2021 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

//go:build integration
// +build integration

// Copyright 2020 ChainSafe Systems (ON) Corp.
// This file is part of gossamer.
//
// The gossamer library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The gossamer library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the gossamer library. If not, see <http://www.gnu.org/licenses/>.

package modules

import (
Expand Down
Loading

0 comments on commit 17e557d

Please sign in to comment.