Skip to content

Commit

Permalink
chore: remove DigestHandler from core pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
EclesioMeloJunior committed Mar 25, 2022
1 parent cfed2f0 commit 803e18f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
2 changes: 0 additions & 2 deletions dot/core/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ type Service struct {
storageState StorageState
transactionState TransactionState
net Network
digestHandler DigestHandler

// map of code substitutions keyed by block hash
codeSubstitute map[common.Hash]string
Expand Down Expand Up @@ -121,7 +120,6 @@ func NewService(cfg *Config) (*Service, error) {
blockAddCh: blockAddCh,
codeSubstitute: cfg.CodeSubstitutes,
codeSubstitutedState: cfg.CodeSubstitutedState,
digestHandler: cfg.DigestHandler,
}

return srv, nil
Expand Down
36 changes: 13 additions & 23 deletions dot/core/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,15 @@ func Test_Service_handleCodeSubstitution(t *testing.T) {

func Test_Service_handleBlock(t *testing.T) {
t.Parallel()

execTest := func(t *testing.T, s *Service, block *types.Block, trieState *rtstorage.TrieState, expErr error) {
err := s.handleBlock(block, trieState)
assert.ErrorIs(t, err, expErr)
if expErr != nil {
assert.EqualError(t, err, expErr.Error())
}
}

t.Run("nil input", func(t *testing.T) {
t.Parallel()
service := &Service{}
Expand Down Expand Up @@ -366,13 +368,10 @@ func Test_Service_handleBlock(t *testing.T) {
mockBlockState := NewMockBlockState(ctrl)
mockBlockState.EXPECT().AddBlock(&block).Return(blocktree.ErrBlockExists)
mockBlockState.EXPECT().GetRuntime(&block.Header.ParentHash).Return(nil, errTestDummyError)
mockDigestHandler := NewMockDigestHandler(ctrl)
mockDigestHandler.EXPECT().HandleDigests(&block.Header)

service := &Service{
storageState: mockStorageState,
blockState: mockBlockState,
digestHandler: mockDigestHandler,
storageState: mockStorageState,
blockState: mockBlockState,
}
execTest(t, service, &block, trieState, errTestDummyError)
})
Expand All @@ -396,13 +395,10 @@ func Test_Service_handleBlock(t *testing.T) {
mockBlockState.EXPECT().GetRuntime(&block.Header.ParentHash).Return(runtimeMock, nil)
mockBlockState.EXPECT().HandleRuntimeChanges(trieState, runtimeMock, block.Header.Hash()).
Return(errTestDummyError)
mockDigestHandler := NewMockDigestHandler(ctrl)
mockDigestHandler.EXPECT().HandleDigests(&block.Header)

service := &Service{
storageState: mockStorageState,
blockState: mockBlockState,
digestHandler: mockDigestHandler,
storageState: mockStorageState,
blockState: mockBlockState,
}
execTest(t, service, &block, trieState, errTestDummyError)
})
Expand All @@ -425,14 +421,11 @@ func Test_Service_handleBlock(t *testing.T) {
mockBlockState.EXPECT().AddBlock(&block).Return(blocktree.ErrBlockExists)
mockBlockState.EXPECT().GetRuntime(&block.Header.ParentHash).Return(runtimeMock, nil)
mockBlockState.EXPECT().HandleRuntimeChanges(trieState, runtimeMock, block.Header.Hash()).Return(nil)
mockDigestHandler := NewMockDigestHandler(ctrl)
mockDigestHandler.EXPECT().HandleDigests(&block.Header)

service := &Service{
storageState: mockStorageState,
blockState: mockBlockState,
digestHandler: mockDigestHandler,
ctx: context.Background(),
storageState: mockStorageState,
blockState: mockBlockState,
ctx: context.Background(),
}
execTest(t, service, &block, trieState, nil)
})
Expand Down Expand Up @@ -488,17 +481,14 @@ func Test_Service_HandleBlockProduced(t *testing.T) {
mockBlockState.EXPECT().AddBlock(&block).Return(blocktree.ErrBlockExists)
mockBlockState.EXPECT().GetRuntime(&block.Header.ParentHash).Return(runtimeMock, nil)
mockBlockState.EXPECT().HandleRuntimeChanges(trieState, runtimeMock, block.Header.Hash()).Return(nil)
mockDigestHandler := NewMockDigestHandler(ctrl)
mockDigestHandler.EXPECT().HandleDigests(&block.Header)
mockNetwork := NewMockNetwork(ctrl)
mockNetwork.EXPECT().GossipMessage(msg)

service := &Service{
storageState: mockStorageState,
blockState: mockBlockState,
digestHandler: mockDigestHandler,
net: mockNetwork,
ctx: context.Background(),
storageState: mockStorageState,
blockState: mockBlockState,
net: mockNetwork,
ctx: context.Background(),
}
execTest(t, service, &block, trieState, nil)
})
Expand Down

0 comments on commit 803e18f

Please sign in to comment.