From facf8a92c4a5d2b395be953ab8895c8c9401340d Mon Sep 17 00:00:00 2001 From: Diego Date: Wed, 19 Apr 2023 12:12:10 -0300 Subject: [PATCH] feat(sync): Add bad block validation tests --- dot/sync/chain_sync_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/dot/sync/chain_sync_test.go b/dot/sync/chain_sync_test.go index dad13e5a03..1633371d4c 100644 --- a/dot/sync/chain_sync_test.go +++ b/dot/sync/chain_sync_test.go @@ -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 @@ -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) @@ -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)