Skip to content

Commit

Permalink
address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardmack committed Feb 2, 2022
1 parent c86ed49 commit 2b46760
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
8 changes: 4 additions & 4 deletions dot/sync/chain_sync_integeration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ func TestChainSync_SetPeerHead(t *testing.T) {
types.NewDigest())
require.NoError(t, err)
cs.blockState.(*syncmocks.BlockState).On("GetHighestFinalisedHeader").Return(fin, nil)
cs.blockState.(*syncmocks.BlockState).On("GetHashByNumber", mock.AnythingOfType("*big.Int")).Return(common.
Hash{}, nil)
cs.blockState.(*syncmocks.BlockState).On("GetHashByNumber", mock.AnythingOfType("*big.Int")).
Return(common.Hash{}, nil)

number = big.NewInt(999)
err = cs.setPeerHead(testPeer, hash, number)
Expand Down Expand Up @@ -484,7 +484,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{},
Expand Down Expand Up @@ -764,7 +764,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()))
Expand Down
22 changes: 22 additions & 0 deletions dot/sync/disjoint_block_set_integeration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package sync
import (
"math/big"
"testing"
"time"

"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/common"
Expand Down Expand Up @@ -198,3 +199,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)
}
2 changes: 1 addition & 1 deletion dot/sync/tip_syncer_integeration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func newTestTipSyncer(t *testing.T) *tipSyncer {

readyBlocks := newBlockQueue(maxResponseSize)
pendingBlocks := newDisjointBlockSet(pendingBlocksLimit)
return newTipSyncer(bs, pendingBlocks, readyBlocks)
return newTipSyncer(bs, pendingBlocks, readyBlocks, nil)
}

func TestTipSyncer_handleNewPeerState(t *testing.T) {
Expand Down

0 comments on commit 2b46760

Please sign in to comment.