prysm-pulse/beacon-chain/rpc/testutil/mock_stater.go
terence 5a66807989
Update to V5 (#13622)
* First take at updating everything to v5

* Patch gRPC gateway to use prysm v5

Fix patch

* Update go ssz

---------

Co-authored-by: Preston Van Loon <pvanloon@offchainlabs.com>
2024-02-15 05:46:47 +00:00

43 lines
1.1 KiB
Go

package testutil
import (
"context"
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
)
// MockStater is a fake implementation of lookup.Stater.
type MockStater struct {
BeaconState state.BeaconState
StateProviderFunc func(ctx context.Context, stateId []byte) (state.BeaconState, error)
BeaconStateRoot []byte
StatesBySlot map[primitives.Slot]state.BeaconState
StatesByRoot map[[32]byte]state.BeaconState
}
// State --
func (m *MockStater) State(ctx context.Context, id []byte) (state.BeaconState, error) {
if m.StateProviderFunc != nil {
return m.StateProviderFunc(ctx, id)
}
if m.BeaconState != nil {
return m.BeaconState, nil
}
return m.StatesByRoot[bytesutil.ToBytes32(id)], nil
}
// StateRoot --
func (m *MockStater) StateRoot(context.Context, []byte) ([]byte, error) {
return m.BeaconStateRoot, nil
}
// StateBySlot --
func (m *MockStater) StateBySlot(_ context.Context, s primitives.Slot) (state.BeaconState, error) {
return m.StatesBySlot[s], nil
}