2021-03-29 21:04:35 +00:00
|
|
|
package testutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2024-02-15 05:46:47 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
|
2023-08-24 21:11:41 +00:00
|
|
|
|
2024-02-15 05:46:47 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
|
2021-03-29 21:04:35 +00:00
|
|
|
)
|
|
|
|
|
2023-03-28 16:44:41 +00:00
|
|
|
// MockStater is a fake implementation of lookup.Stater.
|
|
|
|
type MockStater struct {
|
2023-08-24 21:11:41 +00:00
|
|
|
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
|
2021-03-29 21:04:35 +00:00
|
|
|
}
|
|
|
|
|
2021-04-23 12:06:05 +00:00
|
|
|
// State --
|
2023-08-24 21:11:41 +00:00
|
|
|
func (m *MockStater) State(ctx context.Context, id []byte) (state.BeaconState, error) {
|
|
|
|
if m.StateProviderFunc != nil {
|
|
|
|
return m.StateProviderFunc(ctx, id)
|
|
|
|
}
|
|
|
|
|
2023-07-25 10:04:08 +00:00
|
|
|
if m.BeaconState != nil {
|
|
|
|
return m.BeaconState, nil
|
|
|
|
}
|
2023-08-24 21:11:41 +00:00
|
|
|
|
2023-07-25 10:04:08 +00:00
|
|
|
return m.StatesByRoot[bytesutil.ToBytes32(id)], nil
|
2021-03-29 21:04:35 +00:00
|
|
|
}
|
2021-06-15 15:28:49 +00:00
|
|
|
|
|
|
|
// StateRoot --
|
2023-03-28 16:44:41 +00:00
|
|
|
func (m *MockStater) StateRoot(context.Context, []byte) ([]byte, error) {
|
2021-06-15 15:28:49 +00:00
|
|
|
return m.BeaconStateRoot, nil
|
|
|
|
}
|
2022-03-09 19:33:18 +00:00
|
|
|
|
2023-03-28 16:44:41 +00:00
|
|
|
// StateBySlot --
|
|
|
|
func (m *MockStater) StateBySlot(_ context.Context, s primitives.Slot) (state.BeaconState, error) {
|
2022-12-21 16:28:16 +00:00
|
|
|
return m.StatesBySlot[s], nil
|
2022-03-09 19:33:18 +00:00
|
|
|
}
|