Skip to content

Commit

Permalink
feat(sync): Add bad block validation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dimartiro committed Apr 25, 2023
1 parent c8e129d commit facf8a9
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions dot/sync/chain_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,8 @@ func TestWorkerToRequests(t *testing.T) {

func TestChainSync_validateResponse(t *testing.T) {
t.Parallel()
badBlockHash := common.NewHash([]byte("badblockhash"))

tests := map[string]struct {
blockStateBuilder func(ctrl *gomock.Controller) BlockState
networkBuilder func(ctrl *gomock.Controller) Network
Expand Down Expand Up @@ -813,6 +815,31 @@ func TestChainSync_validateResponse(t *testing.T) {
},
expectedError: errUnknownParent,
},
"handle_error_bad_block": {
blockStateBuilder: func(ctrl *gomock.Controller) BlockState {
mockBlockState := NewMockBlockState(ctrl)
mockBlockState.EXPECT().GetFinalisedNotifierChannel().Return(make(chan *types.FinalisationInfo))
return mockBlockState
},
networkBuilder: func(ctrl *gomock.Controller) Network {
return NewMockNetwork(ctrl)
},
req: &network.BlockRequestMessage{
RequestedData: network.RequestedDataHeader,
},
resp: &network.BlockResponseMessage{
BlockData: []*types.BlockData{
{
Hash: badBlockHash,
Header: &types.Header{
Number: 2,
},
Body: &types.Body{},
},
},
},
expectedError: errBadBlock,
},
"no_error": {
blockStateBuilder: func(ctrl *gomock.Controller) BlockState {
mockBlockState := NewMockBlockState(ctrl)
Expand Down Expand Up @@ -858,6 +885,9 @@ func TestChainSync_validateResponse(t *testing.T) {
pendingBlocks: newDisjointBlockSet(pendingBlocksLimit),
readyBlocks: newBlockQueue(maxResponseSize),
net: tt.networkBuilder(ctrl),
badBlocks: []string{
badBlockHash.String(),
},
}
cs := newChainSync(cfg)

Expand Down

0 comments on commit facf8a9

Please sign in to comment.