Skip to content
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
24 changes: 15 additions & 9 deletions dot/core/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"path/filepath"
"testing"

coremocks "github.com/ChainSafe/gossamer/dot/core/mocks"
"github.com/ChainSafe/gossamer/dot/network"
"github.com/ChainSafe/gossamer/dot/peerset"
"github.com/ChainSafe/gossamer/dot/state"
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/internal/log"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/crypto/sr25519"
Expand All @@ -19,21 +21,23 @@ import (
"github.com/ChainSafe/gossamer/lib/runtime/wasmer"
"github.com/ChainSafe/gossamer/lib/utils"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/mock"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/stretchr/testify/require"
)

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

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

if cfg.DigestHandler == nil {
cfg.DigestHandler = new(coremocks.DigestHandler)
cfg.DigestHandler.(*coremocks.DigestHandler).On("HandleDigests", mock.AnythingOfType("*types.Header"))
digestHandler := NewMockDigestHandler(ctrl)
digestHandler.EXPECT().HandleDigests(gomock.AssignableToTypeOf(new(types.Header)))
cfg.DigestHandler = digestHandler
}

if cfg.Keystore == nil {
Expand All @@ -56,7 +60,6 @@ func NewTestService(t *testing.T, cfg *Config) *Service {
if cfg.BlockState == nil || cfg.StorageState == nil ||
cfg.TransactionState == nil || cfg.EpochState == nil ||
cfg.CodeSubstitutedState == nil {
ctrl := gomock.NewController(t)
telemetryMock := NewMockClient(ctrl)
telemetryMock.EXPECT().SendMessage(gomock.Any()).AnyTimes()

Expand Down Expand Up @@ -123,10 +126,13 @@ func NewTestService(t *testing.T, cfg *Config) *Service {
cfg.BlockState.StoreRuntime(cfg.BlockState.BestBlockHash(), cfg.Runtime)

if cfg.Network == nil {
net := new(coremocks.Network)
net.On("GossipMessage", mock.AnythingOfType("*network.TransactionMessage"))
net.On("IsSynced").Return(true)
net.On("ReportPeer", mock.AnythingOfType("peerset.ReputationChange"), mock.AnythingOfType("peer.ID"))
net := NewMockNetwork(ctrl)
net.EXPECT().GossipMessage(gomock.AssignableToTypeOf(new(network.TransactionMessage)))
net.EXPECT().IsSynced().Return(true)
net.EXPECT().ReportPeer(
gomock.AssignableToTypeOf(peerset.ReputationChange{}),
gomock.AssignableToTypeOf(peer.ID("")),
)
cfg.Network = net
}

Expand Down
8 changes: 4 additions & 4 deletions dot/core/messages_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"

"github.com/ChainSafe/gossamer/dot/core/mocks"
"github.com/ChainSafe/gossamer/dot/network"
"github.com/ChainSafe/gossamer/dot/state"
"github.com/ChainSafe/gossamer/dot/sync"
Expand Down Expand Up @@ -70,7 +69,9 @@ func createExtrinsic(t *testing.T, rt runtime.Instance, genHash common.Hash, non
}

func TestService_HandleBlockProduced(t *testing.T) {
net := new(mocks.Network)
ctrl := gomock.NewController(t)

net := NewMockNetwork(ctrl)
cfg := &Config{
Network: net,
Keystore: keystore.NewGlobalKeystore(),
Expand Down Expand Up @@ -105,7 +106,7 @@ func TestService_HandleBlockProduced(t *testing.T) {
BestBlock: true,
}

net.On("GossipMessage", expected)
net.EXPECT().GossipMessage(expected)

state, err := s.storageState.TrieState(nil)
require.NoError(t, err)
Expand All @@ -114,7 +115,6 @@ func TestService_HandleBlockProduced(t *testing.T) {
require.NoError(t, err)

time.Sleep(time.Second)
net.AssertCalled(t, "GossipMessage", expected)
}

func TestService_HandleTransactionMessage(t *testing.T) {
Expand Down
Loading