prysm-pulse/beacon-chain/rpc/testutil/mock_blocker.go
Justin Traglia b6181f8d1a
Enable nilerr linter & fix findings (#12270)
* Enable nilerr linter & fix findings

* Deal with other findings

* Fix another finding that I missed somehow

* Fix another another issue

Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>

* Update tests to expect error

---------

Co-authored-by: Radosław Kapka <rkapka@wp.pl>
Co-authored-by: terencechain <terence@prysmaticlabs.com>
Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
2023-04-18 20:53:16 +00:00

30 lines
787 B
Go

package testutil
import (
"context"
"strconv"
"github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
)
// MockBlocker is a fake implementation of lookup.Blocker.
type MockBlocker struct {
BlockToReturn interfaces.ReadOnlySignedBeaconBlock
ErrorToReturn error
SlotBlockMap map[primitives.Slot]interfaces.ReadOnlySignedBeaconBlock
}
// Block --
func (m *MockBlocker) Block(_ context.Context, b []byte) (interfaces.ReadOnlySignedBeaconBlock, error) {
if m.ErrorToReturn != nil {
return nil, m.ErrorToReturn
}
slotNumber, parseErr := strconv.ParseUint(string(b), 10, 64)
if parseErr != nil {
//nolint:nilerr
return m.BlockToReturn, nil
}
return m.SlotBlockMap[primitives.Slot(slotNumber)], nil
}