From 0e4127146261450cdf4f32a28b15345d0788bfe2 Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Tue, 4 Jan 2022 13:48:37 -0500 Subject: [PATCH 01/10] move tests to integeration files / delete empty files remove empty files that were moved to xx_integration_tests --- ...o => bootstrap_syncer_integration_test.go} | 0 ...go => chain_processor_integration_test.go} | 2 +- ...est.go => chain_sync_integeration_test.go} | 29 ++++------ ...> disjoint_block_set_integeration_test.go} | 54 ++++-------------- ...e_test.go => message_integeration_test.go} | 6 +- ..._test.go => outliers_integeration_test.go} | 0 ...er_test.go => syncer_integeration_test.go} | 55 +++++++------------ ...est.go => tip_syncer_integeration_test.go} | 15 +---- 8 files changed, 50 insertions(+), 111 deletions(-) rename dot/sync/{bootstrap_syncer_test.go => bootstrap_syncer_integration_test.go} (100%) rename dot/sync/{chain_processor_test.go => chain_processor_integration_test.go} (99%) rename dot/sync/{chain_sync_test.go => chain_sync_integeration_test.go} (96%) rename dot/sync/{disjoint_block_set_test.go => disjoint_block_set_integeration_test.go} (81%) rename dot/sync/{message_test.go => message_integeration_test.go} (99%) rename dot/sync/{outliers_test.go => outliers_integeration_test.go} (100%) rename dot/sync/{syncer_test.go => syncer_integeration_test.go} (77%) rename dot/sync/{tip_syncer_test.go => tip_syncer_integeration_test.go} (95%) diff --git a/dot/sync/bootstrap_syncer_test.go b/dot/sync/bootstrap_syncer_integration_test.go similarity index 100% rename from dot/sync/bootstrap_syncer_test.go rename to dot/sync/bootstrap_syncer_integration_test.go diff --git a/dot/sync/chain_processor_test.go b/dot/sync/chain_processor_integration_test.go similarity index 99% rename from dot/sync/chain_processor_test.go rename to dot/sync/chain_processor_integration_test.go index 9f3e1c80a6..da1f2d2e58 100644 --- a/dot/sync/chain_processor_test.go +++ b/dot/sync/chain_processor_integration_test.go @@ -206,7 +206,7 @@ func TestChainProcessor_HandleJustification(t *testing.T) { d, err := types.NewBabeSecondaryPlainPreDigest(0, 1).ToPreRuntimeDigest() require.NoError(t, err) digest := types.NewDigest() - err = digest.Add(*d) + err = digest.Add(d) require.NoError(t, err) header := &types.Header{ diff --git a/dot/sync/chain_sync_test.go b/dot/sync/chain_sync_integeration_test.go similarity index 96% rename from dot/sync/chain_sync_test.go rename to dot/sync/chain_sync_integeration_test.go index 07dca3337d..f5146d2544 100644 --- a/dot/sync/chain_sync_test.go +++ b/dot/sync/chain_sync_integeration_test.go @@ -40,8 +40,7 @@ func newTestChainSync(t *testing.T) (*chainSync, *blockQueue) { bs.On("HasHeader", mock.AnythingOfType("common.Hash")).Return(true, nil) net := new(syncmocks.Network) - net.On("DoBlockRequest", mock.AnythingOfType("peer.ID"), - mock.AnythingOfType("*network.BlockRequestMessage")).Return(nil, nil) + net.On("DoBlockRequest", mock.AnythingOfType("peer.ID"), mock.AnythingOfType("*network.BlockRequestMessage")).Return(nil, nil) net.On("ReportPeer", mock.AnythingOfType("peerset.ReputationChange"), mock.AnythingOfType("peer.ID")) readyBlocks := newBlockQueue(maxResponseSize) @@ -261,6 +260,7 @@ func TestWorkerToRequests(t *testing.T) { max128 = uint32(128) max9 = uint32(9) max64 = uint32(64) + max1 = uint32(1) ) testCases := []testCase{ @@ -318,7 +318,7 @@ func TestWorkerToRequests(t *testing.T) { StartingBlock: *variadic.MustNewUint32OrHash(1), EndBlockHash: nil, Direction: network.Ascending, - Max: &max128, + Max: &max9, }, }, }, @@ -359,7 +359,7 @@ func TestWorkerToRequests(t *testing.T) { StartingBlock: *variadic.MustNewUint32OrHash(1 + maxResponseSize), EndBlockHash: nil, Direction: network.Ascending, - Max: &max128, + Max: &max64, }, }, }, @@ -377,7 +377,7 @@ func TestWorkerToRequests(t *testing.T) { StartingBlock: *variadic.MustNewUint32OrHash(1), EndBlockHash: &(common.Hash{0xa}), Direction: network.Ascending, - Max: &max128, + Max: &max9, }, }, }, @@ -396,7 +396,7 @@ func TestWorkerToRequests(t *testing.T) { StartingBlock: *variadic.MustNewUint32OrHash(common.Hash{0xb}), EndBlockHash: &(common.Hash{0xc}), Direction: network.Ascending, - Max: &max128, + Max: &max9, }, }, }, @@ -412,7 +412,7 @@ func TestWorkerToRequests(t *testing.T) { RequestedData: bootstrapRequestData, StartingBlock: *variadic.MustNewUint32OrHash(10), Direction: network.Ascending, - Max: &max128, + Max: &max1, }, }, }, @@ -465,7 +465,7 @@ func TestValidateBlockData(t *testing.T) { err = cs.validateBlockData(req, &types.BlockData{ Header: &types.Header{}, }, "") - require.ErrorIs(t, err, errNilBodyInResponse) + require.Equal(t, errNilBodyInResponse, err) err = cs.validateBlockData(req, &types.BlockData{ Header: &types.Header{}, @@ -647,7 +647,6 @@ func TestChainSync_doSync(t *testing.T) { resp := &network.BlockResponseMessage{ BlockData: []*types.BlockData{ { - Hash: common.Hash{0x1}, Header: &types.Header{ Number: 1, }, @@ -657,9 +656,7 @@ func TestChainSync_doSync(t *testing.T) { } cs.network = new(syncmocks.Network) - cs.network.(*syncmocks.Network).On("DoBlockRequest", - mock.AnythingOfType("peer.ID"), - mock.AnythingOfType("*network.BlockRequestMessage")).Return(resp, nil) + cs.network.(*syncmocks.Network).On("DoBlockRequest", mock.AnythingOfType("peer.ID"), mock.AnythingOfType("*network.BlockRequestMessage")).Return(resp, nil) workerErr = cs.doSync(req, make(map[peer.ID]struct{})) require.Nil(t, workerErr) @@ -673,7 +670,6 @@ func TestChainSync_doSync(t *testing.T) { resp = &network.BlockResponseMessage{ BlockData: []*types.BlockData{ { - Hash: common.Hash{0x3}, Header: &types.Header{ ParentHash: parent, Number: 3, @@ -681,7 +677,6 @@ func TestChainSync_doSync(t *testing.T) { Body: &types.Body{}, }, { - Hash: common.Hash{0x2}, Header: &types.Header{ Number: 2, }, @@ -693,9 +688,7 @@ func TestChainSync_doSync(t *testing.T) { // test to see if descending blocks get reversed req.Direction = network.Descending cs.network = new(syncmocks.Network) - cs.network.(*syncmocks.Network).On("DoBlockRequest", - mock.AnythingOfType("peer.ID"), - mock.AnythingOfType("*network.BlockRequestMessage")).Return(resp, nil) + cs.network.(*syncmocks.Network).On("DoBlockRequest", mock.AnythingOfType("peer.ID"), mock.AnythingOfType("*network.BlockRequestMessage")).Return(resp, nil) workerErr = cs.doSync(req, make(map[peer.ID]struct{})) require.Nil(t, workerErr) @@ -750,7 +743,7 @@ func TestHandleReadyBlock(t *testing.T) { } cs.pendingBlocks.addBlock(block2NotDescendant) - cs.handleReadyBlock(block1.ToBlockData()) + handleReadyBlock(block1.ToBlockData(), cs.pendingBlocks, cs.readyBlocks) require.False(t, cs.pendingBlocks.hasBlock(header1.Hash())) require.False(t, cs.pendingBlocks.hasBlock(header2.Hash())) diff --git a/dot/sync/disjoint_block_set_test.go b/dot/sync/disjoint_block_set_integeration_test.go similarity index 81% rename from dot/sync/disjoint_block_set_test.go rename to dot/sync/disjoint_block_set_integeration_test.go index 2f909d2aba..d74d54a562 100644 --- a/dot/sync/disjoint_block_set_test.go +++ b/dot/sync/disjoint_block_set_integeration_test.go @@ -5,7 +5,6 @@ package sync import ( "testing" - "time" "github.com/ChainSafe/gossamer/dot/types" "github.com/ChainSafe/gossamer/lib/common" @@ -15,9 +14,6 @@ import ( func TestDisjointBlockSet(t *testing.T) { s := newDisjointBlockSet(pendingBlocksLimit) - s.timeNow = func() time.Time { - return time.Time{} - } hash := common.Hash{0xa, 0xb} const number uint = 100 @@ -26,9 +22,8 @@ func TestDisjointBlockSet(t *testing.T) { require.Equal(t, 1, s.size()) expected := &pendingBlock{ - hash: hash, - number: number, - clearAt: time.Time{}.Add(ttl), + hash: hash, + number: number, } blocks := s.getBlocks() require.Equal(t, 1, len(blocks)) @@ -40,12 +35,10 @@ func TestDisjointBlockSet(t *testing.T) { s.addHeader(header) require.True(t, s.hasBlock(header.Hash())) require.Equal(t, 2, s.size()) - expected = &pendingBlock{ - hash: header.Hash(), - number: header.Number, - header: header, - clearAt: time.Time{}.Add(ttl), + hash: header.Hash(), + number: header.Number, + header: header, } require.Equal(t, expected, s.getBlock(header.Hash())) @@ -57,10 +50,9 @@ func TestDisjointBlockSet(t *testing.T) { s.addHeader(header2) require.Equal(t, 3, s.size()) expected = &pendingBlock{ - hash: header2.Hash(), - number: header2.Number, - header: header2, - clearAt: time.Time{}.Add(ttl), + hash: header2.Hash(), + number: header2.Number, + header: header2, } require.Equal(t, expected, s.getBlock(header2.Hash())) @@ -71,11 +63,10 @@ func TestDisjointBlockSet(t *testing.T) { s.addBlock(block) require.Equal(t, 3, s.size()) expected = &pendingBlock{ - hash: header2.Hash(), - number: header2.Number, - header: header2, - body: &block.Body, - clearAt: time.Time{}.Add(ttl), + hash: header2.Hash(), + number: header2.Number, + header: header2, + body: &block.Body, } require.Equal(t, expected, s.getBlock(header2.Hash())) @@ -203,24 +194,3 @@ func TestDisjointBlockSet_getReadyDescendants_blockNotComplete(t *testing.T) { require.Equal(t, block1.ToBlockData(), ready[0]) require.Equal(t, block2.ToBlockData(), ready[1]) } - -func TestDisjointBlockSet_ClearBlocks(t *testing.T) { - s := newDisjointBlockSet(pendingBlocksLimit) - - testHashA := common.Hash{0} - testHashB := common.Hash{1} - - s.blocks[testHashA] = &pendingBlock{ - hash: testHashA, - clearAt: time.Unix(1000, 0), - } - s.blocks[testHashB] = &pendingBlock{ - hash: testHashB, - clearAt: time.Now().Add(ttl * 2), - } - - s.clearBlocks() - require.Equal(t, 1, len(s.blocks)) - _, has := s.blocks[testHashB] - require.True(t, has) -} diff --git a/dot/sync/message_test.go b/dot/sync/message_integeration_test.go similarity index 99% rename from dot/sync/message_test.go rename to dot/sync/message_integeration_test.go index 22b619d8aa..f286fa5d4d 100644 --- a/dot/sync/message_test.go +++ b/dot/sync/message_integeration_test.go @@ -32,7 +32,7 @@ func addTestBlocksToState(t *testing.T, depth uint, blockState BlockState) { ParentHash: previousHash, Number: previousNum + i, StateRoot: trie.EmptyHash, - Digest: digest, + Digest: types.NewDigest(), }, Body: types.Body{}, } @@ -367,7 +367,7 @@ func TestService_checkOrGetDescendantHash(t *testing.T) { branches := map[uint]int{ 8: 1, } - state.AddBlocksToStateWithFixedBranches(t, s.blockState.(*state.BlockState), 16, branches) + state.AddBlocksToStateWithFixedBranches(t, s.blockState.(*state.BlockState), 16, branches, 1) // base case ancestor, err := s.blockState.GetHashByNumber(1) @@ -432,7 +432,7 @@ func TestService_checkOrGetDescendantHash(t *testing.T) { // expected is non-canonical block 16 for _, leaf := range leaves { - is, err := s.blockState.IsDescendantOf(ancestor, leaf) + is, err := s.blockState.IsDescendantOf(ancestor, leaf) //nolint require.NoError(t, err) if is { expected = leaf diff --git a/dot/sync/outliers_test.go b/dot/sync/outliers_integeration_test.go similarity index 100% rename from dot/sync/outliers_test.go rename to dot/sync/outliers_integeration_test.go diff --git a/dot/sync/syncer_test.go b/dot/sync/syncer_integeration_test.go similarity index 77% rename from dot/sync/syncer_test.go rename to dot/sync/syncer_integeration_test.go index 7f1d37aced..324563d1cc 100644 --- a/dot/sync/syncer_test.go +++ b/dot/sync/syncer_integeration_test.go @@ -9,7 +9,6 @@ import ( "path/filepath" "testing" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/mock" "github.com/ChainSafe/gossamer/dot/state" @@ -57,29 +56,19 @@ func newMockBabeVerifier() *mocks.BabeVerifier { func newMockNetwork() *mocks.Network { m := new(mocks.Network) - m.On("DoBlockRequest", mock.AnythingOfType("peer.ID"), - mock.AnythingOfType("*network.BlockRequestMessage")).Return(nil, nil) + m.On("DoBlockRequest", mock.AnythingOfType("peer.ID"), mock.AnythingOfType("*network.BlockRequestMessage")).Return(nil, nil) return m } -//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, - } + cfg := &Config{} testDatadirPath := t.TempDir() scfg := state.Config{ - Path: testDatadirPath, - LogLevel: log.Info, - Telemetry: telemetryMock, + Path: testDatadirPath, + LogLevel: log.Info, } stateSrvc := state.NewService(scfg) stateSrvc.UseMemDB() @@ -100,7 +89,7 @@ func newTestSyncer(t *testing.T) *Service { } // initialise runtime - genState, err := rtstorage.NewTrieState(genTrie) + genState, err := rtstorage.NewTrieState(genTrie) //nolint require.NoError(t, err) rtCfg := &wasmer.Config{} @@ -124,24 +113,22 @@ func newTestSyncer(t *testing.T) *Service { cfg.BlockState.StoreRuntime(cfg.BlockState.BestBlockHash(), instance) cfg.BlockImportHandler = new(mocks.BlockImportHandler) - cfg.BlockImportHandler.(*mocks.BlockImportHandler).On( - "HandleBlockImport", mock.AnythingOfType("*types.Block"), mock.AnythingOfType("*storage.TrieState")). - Return(func(block *types.Block, ts *rtstorage.TrieState) error { - // store updates state trie nodes in database - if err = stateSrvc.Storage.StoreTrie(ts, &block.Header); err != nil { - logger.Warnf("failed to store state trie for imported block %s: %s", block.Header.Hash(), err) - return err - } - - // store block in database - err = stateSrvc.Block.AddBlock(block) - require.NoError(t, err) - - stateSrvc.Block.StoreRuntime(block.Header.Hash(), instance) - logger.Debugf("imported block %s and stored state trie with root %s", - block.Header.Hash(), ts.MustRoot()) - return nil - }) + cfg.BlockImportHandler.(*mocks.BlockImportHandler).On("HandleBlockImport", mock.AnythingOfType("*types.Block"), mock.AnythingOfType("*storage.TrieState")).Return(func(block *types.Block, ts *rtstorage.TrieState) error { + // store updates state trie nodes in database + if err = stateSrvc.Storage.StoreTrie(ts, &block.Header); err != nil { + logger.Warnf("failed to store state trie for imported block %s: %s", block.Header.Hash(), err) + return err + } + + // store block in database + err = stateSrvc.Block.AddBlock(block) + require.NoError(t, err) + + stateSrvc.Block.StoreRuntime(block.Header.Hash(), instance) + logger.Debugf("imported block %s and stored state trie with root %s", + block.Header.Hash(), ts.MustRoot()) + return nil + }) cfg.TransactionState = stateSrvc.Transaction cfg.BabeVerifier = newMockBabeVerifier() diff --git a/dot/sync/tip_syncer_test.go b/dot/sync/tip_syncer_integeration_test.go similarity index 95% rename from dot/sync/tip_syncer_test.go rename to dot/sync/tip_syncer_integeration_test.go index 79569c06cd..c4a8eef767 100644 --- a/dot/sync/tip_syncer_test.go +++ b/dot/sync/tip_syncer_integeration_test.go @@ -27,13 +27,7 @@ func newTestTipSyncer(t *testing.T) *tipSyncer { readyBlocks := newBlockQueue(maxResponseSize) pendingBlocks := newDisjointBlockSet(pendingBlocksLimit) - cs := &chainSync{ - blockState: bs, - readyBlocks: readyBlocks, - pendingBlocks: pendingBlocks, - } - - return newTipSyncer(bs, pendingBlocks, readyBlocks, cs.handleReadyBlock) + return newTipSyncer(bs, pendingBlocks, readyBlocks) } func TestTipSyncer_handleNewPeerState(t *testing.T) { @@ -163,7 +157,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) @@ -175,10 +169,8 @@ func TestTipSyncer_handleTick_case1(t *testing.T) { targetNumber: uintPtr(fin.Number), direction: network.Descending, requestData: bootstrapRequestData, - pendingBlock: s.pendingBlocks.getBlock(common.Hash{0xb}), }, } - w, err = s.handleTick() require.NoError(t, err) require.Equal(t, expected, w) @@ -205,7 +197,6 @@ func TestTipSyncer_handleTick_case2(t *testing.T) { targetNumber: uintPtr(header.Number), direction: network.Ascending, requestData: network.RequestedDataBody + network.RequestedDataJustification, - pendingBlock: s.pendingBlocks.getBlock(header.Hash()), }, } w, err := s.handleTick() @@ -213,7 +204,6 @@ func TestTipSyncer_handleTick_case2(t *testing.T) { require.Equal(t, expected, w) require.True(t, s.pendingBlocks.hasBlock(header.Hash())) } - func TestTipSyncer_handleTick_case3(t *testing.T) { s := newTestTipSyncer(t) @@ -257,7 +247,6 @@ func TestTipSyncer_handleTick_case3(t *testing.T) { targetNumber: uintPtr(fin.Number), direction: network.Descending, requestData: bootstrapRequestData, - pendingBlock: s.pendingBlocks.getBlock(header.Hash()), }, } From 20d18709b68341c6aa12834bddf02e9e7ab88e78 Mon Sep 17 00:00:00 2001 From: edwardmack Date: Mon, 7 Feb 2022 17:13:59 -0500 Subject: [PATCH 02/10] add build integration tag, lint and address PR comments fix lint issues address PR comments re-add deleted code fix TestWorkerToRequest and re-add TestChainSync_highestBlock --- dot/sync/bootstrap_syncer_integration_test.go | 3 ++ dot/sync/chain_processor_integration_test.go | 3 ++ dot/sync/chain_sync_integeration_test.go | 27 +++++++++------- .../disjoint_block_set_integeration_test.go | 25 +++++++++++++++ dot/sync/message_integeration_test.go | 7 ++-- dot/sync/outliers_integeration_test.go | 3 ++ dot/sync/syncer_integeration_test.go | 32 ++++++++++++------- dot/sync/tip_syncer_integeration_test.go | 13 +++++++- 8 files changed, 88 insertions(+), 25 deletions(-) diff --git a/dot/sync/bootstrap_syncer_integration_test.go b/dot/sync/bootstrap_syncer_integration_test.go index c49438921d..281f191f3f 100644 --- a/dot/sync/bootstrap_syncer_integration_test.go +++ b/dot/sync/bootstrap_syncer_integration_test.go @@ -1,3 +1,6 @@ +//go:build integration +// +build integration + // Copyright 2021 ChainSafe Systems (ON) // SPDX-License-Identifier: LGPL-3.0-only diff --git a/dot/sync/chain_processor_integration_test.go b/dot/sync/chain_processor_integration_test.go index da1f2d2e58..9b08ec96e0 100644 --- a/dot/sync/chain_processor_integration_test.go +++ b/dot/sync/chain_processor_integration_test.go @@ -1,3 +1,6 @@ +//go:build integration +// +build integration + // Copyright 2021 ChainSafe Systems (ON) // SPDX-License-Identifier: LGPL-3.0-only diff --git a/dot/sync/chain_sync_integeration_test.go b/dot/sync/chain_sync_integeration_test.go index f5146d2544..22538daa32 100644 --- a/dot/sync/chain_sync_integeration_test.go +++ b/dot/sync/chain_sync_integeration_test.go @@ -1,3 +1,6 @@ +//go:build integration +// +build integration + // Copyright 2021 ChainSafe Systems (ON) // SPDX-License-Identifier: LGPL-3.0-only @@ -40,7 +43,8 @@ func newTestChainSync(t *testing.T) (*chainSync, *blockQueue) { bs.On("HasHeader", mock.AnythingOfType("common.Hash")).Return(true, nil) net := new(syncmocks.Network) - net.On("DoBlockRequest", mock.AnythingOfType("peer.ID"), mock.AnythingOfType("*network.BlockRequestMessage")).Return(nil, nil) + net.On("DoBlockRequest", mock.AnythingOfType("peer.ID"), mock.AnythingOfType("*network.BlockRequestMessage")). + Return(nil, nil) net.On("ReportPeer", mock.AnythingOfType("peerset.ReputationChange"), mock.AnythingOfType("peer.ID")) readyBlocks := newBlockQueue(maxResponseSize) @@ -260,7 +264,6 @@ func TestWorkerToRequests(t *testing.T) { max128 = uint32(128) max9 = uint32(9) max64 = uint32(64) - max1 = uint32(1) ) testCases := []testCase{ @@ -318,7 +321,7 @@ func TestWorkerToRequests(t *testing.T) { StartingBlock: *variadic.MustNewUint32OrHash(1), EndBlockHash: nil, Direction: network.Ascending, - Max: &max9, + Max: &max128, }, }, }, @@ -359,7 +362,7 @@ func TestWorkerToRequests(t *testing.T) { StartingBlock: *variadic.MustNewUint32OrHash(1 + maxResponseSize), EndBlockHash: nil, Direction: network.Ascending, - Max: &max64, + Max: &max128, }, }, }, @@ -377,7 +380,7 @@ func TestWorkerToRequests(t *testing.T) { StartingBlock: *variadic.MustNewUint32OrHash(1), EndBlockHash: &(common.Hash{0xa}), Direction: network.Ascending, - Max: &max9, + Max: &max128, }, }, }, @@ -396,7 +399,7 @@ func TestWorkerToRequests(t *testing.T) { StartingBlock: *variadic.MustNewUint32OrHash(common.Hash{0xb}), EndBlockHash: &(common.Hash{0xc}), Direction: network.Ascending, - Max: &max9, + Max: &max128, }, }, }, @@ -412,7 +415,7 @@ func TestWorkerToRequests(t *testing.T) { RequestedData: bootstrapRequestData, StartingBlock: *variadic.MustNewUint32OrHash(10), Direction: network.Ascending, - Max: &max1, + Max: &max128, }, }, }, @@ -465,7 +468,7 @@ func TestValidateBlockData(t *testing.T) { err = cs.validateBlockData(req, &types.BlockData{ Header: &types.Header{}, }, "") - require.Equal(t, errNilBodyInResponse, err) + require.ErrorIs(t, err, errNilBodyInResponse) err = cs.validateBlockData(req, &types.BlockData{ Header: &types.Header{}, @@ -656,7 +659,8 @@ func TestChainSync_doSync(t *testing.T) { } cs.network = new(syncmocks.Network) - cs.network.(*syncmocks.Network).On("DoBlockRequest", mock.AnythingOfType("peer.ID"), mock.AnythingOfType("*network.BlockRequestMessage")).Return(resp, nil) + cs.network.(*syncmocks.Network).On("DoBlockRequest", mock.AnythingOfType("peer.ID"), + mock.AnythingOfType("*network.BlockRequestMessage")).Return(resp, nil) workerErr = cs.doSync(req, make(map[peer.ID]struct{})) require.Nil(t, workerErr) @@ -688,7 +692,8 @@ func TestChainSync_doSync(t *testing.T) { // test to see if descending blocks get reversed req.Direction = network.Descending cs.network = new(syncmocks.Network) - cs.network.(*syncmocks.Network).On("DoBlockRequest", mock.AnythingOfType("peer.ID"), mock.AnythingOfType("*network.BlockRequestMessage")).Return(resp, nil) + cs.network.(*syncmocks.Network).On("DoBlockRequest", mock.AnythingOfType("peer.ID"), + mock.AnythingOfType("*network.BlockRequestMessage")).Return(resp, nil) workerErr = cs.doSync(req, make(map[peer.ID]struct{})) require.Nil(t, workerErr) @@ -743,7 +748,7 @@ func TestHandleReadyBlock(t *testing.T) { } cs.pendingBlocks.addBlock(block2NotDescendant) - handleReadyBlock(block1.ToBlockData(), cs.pendingBlocks, cs.readyBlocks) + cs.handleReadyBlock(block1.ToBlockData()) require.False(t, cs.pendingBlocks.hasBlock(header1.Hash())) require.False(t, cs.pendingBlocks.hasBlock(header2.Hash())) diff --git a/dot/sync/disjoint_block_set_integeration_test.go b/dot/sync/disjoint_block_set_integeration_test.go index d74d54a562..450a25c6a2 100644 --- a/dot/sync/disjoint_block_set_integeration_test.go +++ b/dot/sync/disjoint_block_set_integeration_test.go @@ -1,3 +1,6 @@ +//go:build integration +// +build integration + // Copyright 2021 ChainSafe Systems (ON) // SPDX-License-Identifier: LGPL-3.0-only @@ -5,6 +8,7 @@ package sync import ( "testing" + "time" "github.com/ChainSafe/gossamer/dot/types" "github.com/ChainSafe/gossamer/lib/common" @@ -194,3 +198,24 @@ func TestDisjointBlockSet_getReadyDescendants_blockNotComplete(t *testing.T) { require.Equal(t, block1.ToBlockData(), ready[0]) require.Equal(t, block2.ToBlockData(), ready[1]) } + +func TestDisjointBlockSet_ClearBlocks(t *testing.T) { + s := newDisjointBlockSet(pendingBlocksLimit) + + testHashA := common.Hash{0} + testHashB := common.Hash{1} + + s.blocks[testHashA] = &pendingBlock{ + hash: testHashA, + clearAt: time.Unix(1000, 0), + } + s.blocks[testHashB] = &pendingBlock{ + hash: testHashB, + clearAt: time.Now().Add(ttl * 2), + } + + s.clearBlocks() + require.Equal(t, 1, len(s.blocks)) + _, has := s.blocks[testHashB] + require.True(t, has) +} diff --git a/dot/sync/message_integeration_test.go b/dot/sync/message_integeration_test.go index f286fa5d4d..b97b970c50 100644 --- a/dot/sync/message_integeration_test.go +++ b/dot/sync/message_integeration_test.go @@ -1,3 +1,6 @@ +//go:build integration +// +build integration + // Copyright 2021 ChainSafe Systems (ON) // SPDX-License-Identifier: LGPL-3.0-only @@ -367,7 +370,7 @@ func TestService_checkOrGetDescendantHash(t *testing.T) { branches := map[uint]int{ 8: 1, } - state.AddBlocksToStateWithFixedBranches(t, s.blockState.(*state.BlockState), 16, branches, 1) + state.AddBlocksToStateWithFixedBranches(t, s.blockState.(*state.BlockState), 16, branches) // base case ancestor, err := s.blockState.GetHashByNumber(1) @@ -432,7 +435,7 @@ func TestService_checkOrGetDescendantHash(t *testing.T) { // expected is non-canonical block 16 for _, leaf := range leaves { - is, err := s.blockState.IsDescendantOf(ancestor, leaf) //nolint + is, err := s.blockState.IsDescendantOf(ancestor, leaf) require.NoError(t, err) if is { expected = leaf diff --git a/dot/sync/outliers_integeration_test.go b/dot/sync/outliers_integeration_test.go index d5c8a818ca..86d5313094 100644 --- a/dot/sync/outliers_integeration_test.go +++ b/dot/sync/outliers_integeration_test.go @@ -1,3 +1,6 @@ +//go:build integration +// +build integration + // Copyright 2021 ChainSafe Systems (ON) // SPDX-License-Identifier: LGPL-3.0-only diff --git a/dot/sync/syncer_integeration_test.go b/dot/sync/syncer_integeration_test.go index 324563d1cc..279ce861ac 100644 --- a/dot/sync/syncer_integeration_test.go +++ b/dot/sync/syncer_integeration_test.go @@ -1,3 +1,6 @@ +//go:build integration +// +build integration + // Copyright 2021 ChainSafe Systems (ON) // SPDX-License-Identifier: LGPL-3.0-only @@ -9,10 +12,10 @@ import ( "path/filepath" "testing" - "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" @@ -20,11 +23,9 @@ import ( "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) { @@ -56,19 +57,27 @@ func newMockBabeVerifier() *mocks.BabeVerifier { func newMockNetwork() *mocks.Network { m := new(mocks.Network) - m.On("DoBlockRequest", mock.AnythingOfType("peer.ID"), mock.AnythingOfType("*network.BlockRequestMessage")).Return(nil, nil) + m.On("DoBlockRequest", mock.AnythingOfType("peer.ID"), mock.AnythingOfType("*network.BlockRequestMessage")). + Return(nil, nil) return m } func newTestSyncer(t *testing.T) *Service { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + mockTelemetryClient := NewMockClient(ctrl) + mockTelemetryClient.EXPECT().SendMessage(gomock.Any()) + wasmer.DefaultTestLogLvl = 3 cfg := &Config{} testDatadirPath := t.TempDir() scfg := state.Config{ - Path: testDatadirPath, - LogLevel: log.Info, + Path: testDatadirPath, + LogLevel: log.Info, + Telemetry: mockTelemetryClient, } stateSrvc := state.NewService(scfg) stateSrvc.UseMemDB() @@ -89,7 +98,7 @@ func newTestSyncer(t *testing.T) *Service { } // initialise runtime - genState, err := rtstorage.NewTrieState(genTrie) //nolint + genState, err := rtstorage.NewTrieState(genTrie) require.NoError(t, err) rtCfg := &wasmer.Config{} @@ -113,7 +122,8 @@ func newTestSyncer(t *testing.T) *Service { cfg.BlockState.StoreRuntime(cfg.BlockState.BestBlockHash(), instance) cfg.BlockImportHandler = new(mocks.BlockImportHandler) - cfg.BlockImportHandler.(*mocks.BlockImportHandler).On("HandleBlockImport", mock.AnythingOfType("*types.Block"), mock.AnythingOfType("*storage.TrieState")).Return(func(block *types.Block, ts *rtstorage.TrieState) error { + cfg.BlockImportHandler.(*mocks.BlockImportHandler).On("HandleBlockImport", mock.AnythingOfType("*types.Block"), + mock.AnythingOfType("*storage.TrieState")).Return(func(block *types.Block, ts *rtstorage.TrieState) error { // store updates state trie nodes in database if err = stateSrvc.Storage.StoreTrie(ts, &block.Header); err != nil { logger.Warnf("failed to store state trie for imported block %s: %s", block.Header.Hash(), err) diff --git a/dot/sync/tip_syncer_integeration_test.go b/dot/sync/tip_syncer_integeration_test.go index c4a8eef767..c407248ce9 100644 --- a/dot/sync/tip_syncer_integeration_test.go +++ b/dot/sync/tip_syncer_integeration_test.go @@ -1,3 +1,6 @@ +//go:build integration +// +build integration + // Copyright 2021 ChainSafe Systems (ON) // SPDX-License-Identifier: LGPL-3.0-only @@ -27,7 +30,12 @@ func newTestTipSyncer(t *testing.T) *tipSyncer { readyBlocks := newBlockQueue(maxResponseSize) pendingBlocks := newDisjointBlockSet(pendingBlocksLimit) - return newTipSyncer(bs, pendingBlocks, readyBlocks) + cs := &chainSync{ + blockState: bs, + readyBlocks: readyBlocks, + pendingBlocks: pendingBlocks, + } + return newTipSyncer(bs, pendingBlocks, readyBlocks, cs.handleReadyBlock) } func TestTipSyncer_handleNewPeerState(t *testing.T) { @@ -169,6 +177,7 @@ func TestTipSyncer_handleTick_case1(t *testing.T) { targetNumber: uintPtr(fin.Number), direction: network.Descending, requestData: bootstrapRequestData, + pendingBlock: s.pendingBlocks.getBlock(common.Hash{0xb}), }, } w, err = s.handleTick() @@ -197,6 +206,7 @@ func TestTipSyncer_handleTick_case2(t *testing.T) { targetNumber: uintPtr(header.Number), direction: network.Ascending, requestData: network.RequestedDataBody + network.RequestedDataJustification, + pendingBlock: s.pendingBlocks.getBlock(header.Hash()), }, } w, err := s.handleTick() @@ -247,6 +257,7 @@ func TestTipSyncer_handleTick_case3(t *testing.T) { targetNumber: uintPtr(fin.Number), direction: network.Descending, requestData: bootstrapRequestData, + pendingBlock: s.pendingBlocks.getBlock(header.Hash()), }, } From 0a12d5e842bc44c36d852bf3efba75d90d06250f Mon Sep 17 00:00:00 2001 From: edwardmack Date: Fri, 11 Mar 2022 16:59:42 -0500 Subject: [PATCH 03/10] address PR comments --- dot/sync/syncer_integeration_test.go | 3 +-- dot/sync/tip_syncer_integeration_test.go | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dot/sync/syncer_integeration_test.go b/dot/sync/syncer_integeration_test.go index 279ce861ac..19a88cd19b 100644 --- a/dot/sync/syncer_integeration_test.go +++ b/dot/sync/syncer_integeration_test.go @@ -64,12 +64,11 @@ func newMockNetwork() *mocks.Network { func newTestSyncer(t *testing.T) *Service { ctrl := gomock.NewController(t) - defer ctrl.Finish() mockTelemetryClient := NewMockClient(ctrl) mockTelemetryClient.EXPECT().SendMessage(gomock.Any()) - wasmer.DefaultTestLogLvl = 3 + wasmer.DefaultTestLogLvl = log.Warn cfg := &Config{} testDatadirPath := t.TempDir() diff --git a/dot/sync/tip_syncer_integeration_test.go b/dot/sync/tip_syncer_integeration_test.go index c407248ce9..8f935c828b 100644 --- a/dot/sync/tip_syncer_integeration_test.go +++ b/dot/sync/tip_syncer_integeration_test.go @@ -214,6 +214,7 @@ func TestTipSyncer_handleTick_case2(t *testing.T) { require.Equal(t, expected, w) require.True(t, s.pendingBlocks.hasBlock(header.Hash())) } + func TestTipSyncer_handleTick_case3(t *testing.T) { s := newTestTipSyncer(t) From 62a1a96f2595a7cc7d116c2373d2bc0783a5b179 Mon Sep 17 00:00:00 2001 From: edwardmack Date: Mon, 14 Mar 2022 18:08:10 -0400 Subject: [PATCH 04/10] address PR comments, revert code --- dot/sync/chain_sync_integeration_test.go | 10 +++--- dot/sync/message_integeration_test.go | 2 +- dot/sync/syncer_integeration_test.go | 39 ++++++++++++------------ 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/dot/sync/chain_sync_integeration_test.go b/dot/sync/chain_sync_integeration_test.go index 22538daa32..b601653eec 100644 --- a/dot/sync/chain_sync_integeration_test.go +++ b/dot/sync/chain_sync_integeration_test.go @@ -43,8 +43,8 @@ func newTestChainSync(t *testing.T) (*chainSync, *blockQueue) { bs.On("HasHeader", mock.AnythingOfType("common.Hash")).Return(true, nil) net := new(syncmocks.Network) - net.On("DoBlockRequest", mock.AnythingOfType("peer.ID"), mock.AnythingOfType("*network.BlockRequestMessage")). - Return(nil, nil) + net.On("DoBlockRequest", mock.AnythingOfType("peer.ID"), + mock.AnythingOfType("*network.BlockRequestMessage")).Return(nil, nil) net.On("ReportPeer", mock.AnythingOfType("peerset.ReputationChange"), mock.AnythingOfType("peer.ID")) readyBlocks := newBlockQueue(maxResponseSize) @@ -659,7 +659,8 @@ func TestChainSync_doSync(t *testing.T) { } cs.network = new(syncmocks.Network) - cs.network.(*syncmocks.Network).On("DoBlockRequest", mock.AnythingOfType("peer.ID"), + cs.network.(*syncmocks.Network).On("DoBlockRequest", + mock.AnythingOfType("peer.ID"), mock.AnythingOfType("*network.BlockRequestMessage")).Return(resp, nil) workerErr = cs.doSync(req, make(map[peer.ID]struct{})) @@ -692,7 +693,8 @@ func TestChainSync_doSync(t *testing.T) { // test to see if descending blocks get reversed req.Direction = network.Descending cs.network = new(syncmocks.Network) - cs.network.(*syncmocks.Network).On("DoBlockRequest", mock.AnythingOfType("peer.ID"), + cs.network.(*syncmocks.Network).On("DoBlockRequest", + mock.AnythingOfType("peer.ID"), mock.AnythingOfType("*network.BlockRequestMessage")).Return(resp, nil) workerErr = cs.doSync(req, make(map[peer.ID]struct{})) require.Nil(t, workerErr) diff --git a/dot/sync/message_integeration_test.go b/dot/sync/message_integeration_test.go index b97b970c50..ac0f34f096 100644 --- a/dot/sync/message_integeration_test.go +++ b/dot/sync/message_integeration_test.go @@ -35,7 +35,7 @@ func addTestBlocksToState(t *testing.T, depth uint, blockState BlockState) { ParentHash: previousHash, Number: previousNum + i, StateRoot: trie.EmptyHash, - Digest: types.NewDigest(), + Digest: digest, }, Body: types.Body{}, } diff --git a/dot/sync/syncer_integeration_test.go b/dot/sync/syncer_integeration_test.go index 19a88cd19b..44ed30349f 100644 --- a/dot/sync/syncer_integeration_test.go +++ b/dot/sync/syncer_integeration_test.go @@ -57,8 +57,8 @@ func newMockBabeVerifier() *mocks.BabeVerifier { func newMockNetwork() *mocks.Network { m := new(mocks.Network) - m.On("DoBlockRequest", mock.AnythingOfType("peer.ID"), mock.AnythingOfType("*network.BlockRequestMessage")). - Return(nil, nil) + m.On("DoBlockRequest", mock.AnythingOfType("peer.ID"), + mock.AnythingOfType("*network.BlockRequestMessage")).Return(nil, nil) return m } @@ -121,23 +121,24 @@ func newTestSyncer(t *testing.T) *Service { cfg.BlockState.StoreRuntime(cfg.BlockState.BestBlockHash(), instance) cfg.BlockImportHandler = new(mocks.BlockImportHandler) - cfg.BlockImportHandler.(*mocks.BlockImportHandler).On("HandleBlockImport", mock.AnythingOfType("*types.Block"), - mock.AnythingOfType("*storage.TrieState")).Return(func(block *types.Block, ts *rtstorage.TrieState) error { - // store updates state trie nodes in database - if err = stateSrvc.Storage.StoreTrie(ts, &block.Header); err != nil { - logger.Warnf("failed to store state trie for imported block %s: %s", block.Header.Hash(), err) - return err - } - - // store block in database - err = stateSrvc.Block.AddBlock(block) - require.NoError(t, err) - - stateSrvc.Block.StoreRuntime(block.Header.Hash(), instance) - logger.Debugf("imported block %s and stored state trie with root %s", - block.Header.Hash(), ts.MustRoot()) - return nil - }) + cfg.BlockImportHandler.(*mocks.BlockImportHandler).On( + "HandleBlockImport", mock.AnythingOfType("*types.Block"), mock.AnythingOfType("*storage.TrieState")). + Return(func(block *types.Block, ts *rtstorage.TrieState) error { + // store updates state trie nodes in database + if err = stateSrvc.Storage.StoreTrie(ts, &block.Header); err != nil { + logger.Warnf("failed to store state trie for imported block %s: %s", block.Header.Hash(), err) + return err + } + + // store block in database + err = stateSrvc.Block.AddBlock(block) + require.NoError(t, err) + + stateSrvc.Block.StoreRuntime(block.Header.Hash(), instance) + logger.Debugf("imported block %s and stored state trie with root %s", + block.Header.Hash(), ts.MustRoot()) + return nil + }) cfg.TransactionState = stateSrvc.Transaction cfg.BabeVerifier = newMockBabeVerifier() From 1a9dbe145aa87a0d5ab58883a1c59bdfcb940ca4 Mon Sep 17 00:00:00 2001 From: edwardmack Date: Mon, 14 Mar 2022 18:19:35 -0400 Subject: [PATCH 05/10] fix TestDisjointBlockSet test --- .../disjoint_block_set_integeration_test.go | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/dot/sync/disjoint_block_set_integeration_test.go b/dot/sync/disjoint_block_set_integeration_test.go index 450a25c6a2..70f26d3ddb 100644 --- a/dot/sync/disjoint_block_set_integeration_test.go +++ b/dot/sync/disjoint_block_set_integeration_test.go @@ -18,6 +18,9 @@ import ( func TestDisjointBlockSet(t *testing.T) { s := newDisjointBlockSet(pendingBlocksLimit) + s.timeNow = func() time.Time { + return time.Time{} + } hash := common.Hash{0xa, 0xb} const number uint = 100 @@ -26,8 +29,9 @@ func TestDisjointBlockSet(t *testing.T) { require.Equal(t, 1, s.size()) expected := &pendingBlock{ - hash: hash, - number: number, + hash: hash, + number: number, + clearAt: time.Time{}.Add(ttl), } blocks := s.getBlocks() require.Equal(t, 1, len(blocks)) @@ -40,9 +44,10 @@ func TestDisjointBlockSet(t *testing.T) { require.True(t, s.hasBlock(header.Hash())) require.Equal(t, 2, s.size()) expected = &pendingBlock{ - hash: header.Hash(), - number: header.Number, - header: header, + hash: header.Hash(), + number: header.Number, + header: header, + clearAt: time.Time{}.Add(ttl), } require.Equal(t, expected, s.getBlock(header.Hash())) @@ -54,9 +59,10 @@ func TestDisjointBlockSet(t *testing.T) { s.addHeader(header2) require.Equal(t, 3, s.size()) expected = &pendingBlock{ - hash: header2.Hash(), - number: header2.Number, - header: header2, + hash: header2.Hash(), + number: header2.Number, + header: header2, + clearAt: time.Time{}.Add(ttl), } require.Equal(t, expected, s.getBlock(header2.Hash())) @@ -67,10 +73,11 @@ func TestDisjointBlockSet(t *testing.T) { s.addBlock(block) require.Equal(t, 3, s.size()) expected = &pendingBlock{ - hash: header2.Hash(), - number: header2.Number, - header: header2, - body: &block.Body, + hash: header2.Hash(), + number: header2.Number, + header: header2, + body: &block.Body, + clearAt: time.Time{}.Add(ttl), } require.Equal(t, expected, s.getBlock(header2.Hash())) From 1f06bbcde2b0339112d77481584e2b8a37e02715 Mon Sep 17 00:00:00 2001 From: edwardmack Date: Mon, 11 Apr 2022 10:50:10 -0400 Subject: [PATCH 06/10] Add dot/sync package to github integration workflow --- .github/workflows/integration-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 9cdd995b38..80e138ef09 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -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, ] runs-on: ubuntu-latest steps: From 23e0204c0a03e2c4ae3494df8c8729595df32cd1 Mon Sep 17 00:00:00 2001 From: edwardmack Date: Wed, 4 May 2022 13:28:02 -0400 Subject: [PATCH 07/10] address PR comments --- dot/sync/chain_processor_integration_test.go | 2 +- dot/sync/disjoint_block_set_integeration_test.go | 1 + dot/sync/tip_syncer_integeration_test.go | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/dot/sync/chain_processor_integration_test.go b/dot/sync/chain_processor_integration_test.go index 9b08ec96e0..f875edfa34 100644 --- a/dot/sync/chain_processor_integration_test.go +++ b/dot/sync/chain_processor_integration_test.go @@ -209,7 +209,7 @@ func TestChainProcessor_HandleJustification(t *testing.T) { d, err := types.NewBabeSecondaryPlainPreDigest(0, 1).ToPreRuntimeDigest() require.NoError(t, err) digest := types.NewDigest() - err = digest.Add(d) + err = digest.Add(*d) require.NoError(t, err) header := &types.Header{ diff --git a/dot/sync/disjoint_block_set_integeration_test.go b/dot/sync/disjoint_block_set_integeration_test.go index 70f26d3ddb..afcd7458b3 100644 --- a/dot/sync/disjoint_block_set_integeration_test.go +++ b/dot/sync/disjoint_block_set_integeration_test.go @@ -43,6 +43,7 @@ func TestDisjointBlockSet(t *testing.T) { s.addHeader(header) require.True(t, s.hasBlock(header.Hash())) require.Equal(t, 2, s.size()) + expected = &pendingBlock{ hash: header.Hash(), number: header.Number, diff --git a/dot/sync/tip_syncer_integeration_test.go b/dot/sync/tip_syncer_integeration_test.go index 8f935c828b..b24c0c4dc9 100644 --- a/dot/sync/tip_syncer_integeration_test.go +++ b/dot/sync/tip_syncer_integeration_test.go @@ -180,6 +180,7 @@ func TestTipSyncer_handleTick_case1(t *testing.T) { pendingBlock: s.pendingBlocks.getBlock(common.Hash{0xb}), }, } + w, err = s.handleTick() require.NoError(t, err) require.Equal(t, expected, w) From 6880a9bf2bb1e527ee319ab343e2a1f2e8d38385 Mon Sep 17 00:00:00 2001 From: edwardmack Date: Thu, 5 May 2022 10:29:46 -0400 Subject: [PATCH 08/10] fix test, add reference to mock telemetry client --- dot/sync/syncer_integeration_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dot/sync/syncer_integeration_test.go b/dot/sync/syncer_integeration_test.go index 44ed30349f..1536a989d0 100644 --- a/dot/sync/syncer_integeration_test.go +++ b/dot/sync/syncer_integeration_test.go @@ -66,7 +66,7 @@ func newTestSyncer(t *testing.T) *Service { ctrl := gomock.NewController(t) mockTelemetryClient := NewMockClient(ctrl) - mockTelemetryClient.EXPECT().SendMessage(gomock.Any()) + mockTelemetryClient.EXPECT().SendMessage(gomock.Any()).AnyTimes() wasmer.DefaultTestLogLvl = log.Warn @@ -145,6 +145,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) From 7a45a3d13d90ff21639398ce9785e1d8c42d1758 Mon Sep 17 00:00:00 2001 From: edwardmack Date: Thu, 12 May 2022 14:54:26 -0400 Subject: [PATCH 09/10] re-add deleted go:generate tag --- dot/sync/syncer_integeration_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/dot/sync/syncer_integeration_test.go b/dot/sync/syncer_integeration_test.go index 1536a989d0..aac17d73e3 100644 --- a/dot/sync/syncer_integeration_test.go +++ b/dot/sync/syncer_integeration_test.go @@ -62,6 +62,7 @@ func newMockNetwork() *mocks.Network { return m } +//go:generate mockgen -destination=mock_telemetry_test.go -package $GOPACKAGE github.com/ChainSafe/gossamer/dot/telemetry Client func newTestSyncer(t *testing.T) *Service { ctrl := gomock.NewController(t) From a8c0a0c72b5587966e6035f7ca7aa1eec7c15bc6 Mon Sep 17 00:00:00 2001 From: edwardmack Date: Thu, 12 May 2022 15:57:47 -0400 Subject: [PATCH 10/10] fix TestChainSync_doSync test --- dot/sync/chain_sync_integeration_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dot/sync/chain_sync_integeration_test.go b/dot/sync/chain_sync_integeration_test.go index b601653eec..b742226705 100644 --- a/dot/sync/chain_sync_integeration_test.go +++ b/dot/sync/chain_sync_integeration_test.go @@ -650,6 +650,7 @@ func TestChainSync_doSync(t *testing.T) { resp := &network.BlockResponseMessage{ BlockData: []*types.BlockData{ { + Hash: common.Hash{0x1}, Header: &types.Header{ Number: 1, }, @@ -675,6 +676,7 @@ func TestChainSync_doSync(t *testing.T) { resp = &network.BlockResponseMessage{ BlockData: []*types.BlockData{ { + Hash: common.Hash{0x3}, Header: &types.Header{ ParentHash: parent, Number: 3, @@ -682,6 +684,7 @@ func TestChainSync_doSync(t *testing.T) { Body: &types.Body{}, }, { + Hash: common.Hash{0x2}, Header: &types.Header{ Number: 2, },