mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
2b40c44879
Co-authored-by: Nishant Das <nishdas93@gmail.com>
35 lines
993 B
Go
35 lines
993 B
Go
package testutil
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces"
|
|
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
|
|
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
|
|
)
|
|
|
|
// MockBlocker is a fake implementation of lookup.Blocker.
|
|
type MockBlocker struct {
|
|
BlockToReturn interfaces.ReadOnlySignedBeaconBlock
|
|
ErrorToReturn error
|
|
SlotBlockMap map[primitives.Slot]interfaces.ReadOnlySignedBeaconBlock
|
|
RootBlockMap map[[32]byte]interfaces.ReadOnlySignedBeaconBlock
|
|
}
|
|
|
|
// Block --
|
|
func (m *MockBlocker) Block(_ context.Context, b []byte) (interfaces.ReadOnlySignedBeaconBlock, error) {
|
|
if m.ErrorToReturn != nil {
|
|
return nil, m.ErrorToReturn
|
|
}
|
|
if m.BlockToReturn != nil {
|
|
return m.BlockToReturn, nil
|
|
}
|
|
slotNumber, parseErr := strconv.ParseUint(string(b), 10, 64)
|
|
if parseErr != nil {
|
|
//nolint:nilerr
|
|
return m.RootBlockMap[bytesutil.ToBytes32(b)], nil
|
|
}
|
|
return m.SlotBlockMap[primitives.Slot(slotNumber)], nil
|
|
}
|