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

testing(dot): migrate dot/sync tests to integration tests #2116

Merged
merged 10 commits into from
May 17, 2022
1 change: 1 addition & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
github.com/ChainSafe/gossamer/dot/core,
github.com/ChainSafe/gossamer/dot/rpc/modules,
github.com/ChainSafe/gossamer/lib/babe,
github.com/ChainSafe/gossamer/dot/sync,
qdm12 marked this conversation as resolved.
Show resolved Hide resolved
]
runs-on: ubuntu-latest
steps:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build integration
// +build integration

// Copyright 2021 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build integration
// +build integration

// Copyright 2021 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build integration
// +build integration

// Copyright 2021 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build integration
// +build integration

// Copyright 2021 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build integration
// +build integration

// Copyright 2021 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build integration
// +build integration

// Copyright 2021 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

Expand Down
29 changes: 14 additions & 15 deletions dot/sync/syncer_test.go → dot/sync/syncer_integeration_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build integration
// +build integration

// Copyright 2021 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

Expand All @@ -9,23 +12,20 @@ import (
"path/filepath"
"testing"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/mock"

"github.com/ChainSafe/gossamer/dot/state"
"github.com/ChainSafe/gossamer/dot/sync/mocks"
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/internal/log"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/genesis"
"github.com/ChainSafe/gossamer/lib/runtime"
rtstorage "github.com/ChainSafe/gossamer/lib/runtime/storage"
"github.com/ChainSafe/gossamer/lib/runtime/wasmer"
"github.com/ChainSafe/gossamer/lib/trie"
"github.com/ChainSafe/gossamer/lib/utils"

"github.com/ChainSafe/gossamer/internal/log"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/ChainSafe/gossamer/dot/sync/mocks"
)

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -63,23 +63,21 @@ func newMockNetwork() *mocks.Network {
}

//go:generate mockgen -destination=mock_telemetry_test.go -package $GOPACKAGE github.com/ChainSafe/gossamer/dot/telemetry Client

func newTestSyncer(t *testing.T) *Service {
wasmer.DefaultTestLogLvl = 3
ctrl := gomock.NewController(t)
telemetryMock := NewMockClient(ctrl)
telemetryMock.EXPECT().SendMessage(gomock.Any()).AnyTimes()

cfg := &Config{
Telemetry: telemetryMock,
}
mockTelemetryClient := NewMockClient(ctrl)
mockTelemetryClient.EXPECT().SendMessage(gomock.Any()).AnyTimes()

wasmer.DefaultTestLogLvl = log.Warn

cfg := &Config{}
testDatadirPath := t.TempDir()

scfg := state.Config{
Path: testDatadirPath,
LogLevel: log.Info,
Telemetry: telemetryMock,
Telemetry: mockTelemetryClient,
}
stateSrvc := state.NewService(scfg)
stateSrvc.UseMemDB()
Expand Down Expand Up @@ -148,6 +146,7 @@ func newTestSyncer(t *testing.T) *Service {
cfg.LogLvl = log.Trace
cfg.FinalityGadget = newMockFinalityGadget()
cfg.Network = newMockNetwork()
cfg.Telemetry = mockTelemetryClient

syncer, err := NewService(cfg)
require.NoError(t, err)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build integration
// +build integration

// Copyright 2021 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

Expand Down Expand Up @@ -32,7 +35,6 @@ func newTestTipSyncer(t *testing.T) *tipSyncer {
readyBlocks: readyBlocks,
pendingBlocks: pendingBlocks,
}

return newTipSyncer(bs, pendingBlocks, readyBlocks, cs.handleReadyBlock)
}

Expand Down Expand Up @@ -163,7 +165,7 @@ func TestTipSyncer_handleTick_case1(t *testing.T) {

fin, _ := s.blockState.GetHighestFinalisedHeader()

// add pending blocks w/ only hash and number, equal or lower than finalised should be removed
// add pending blocks w/ only hash and number, lower than finalised should be removed
s.pendingBlocks.addHashAndNumber(common.Hash{0xa}, fin.Number)
s.pendingBlocks.addHashAndNumber(common.Hash{0xb}, fin.Number+1)

Expand Down