mocks

package
v0.43.1-rc.1.access-me... Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2025 License: AGPL-3.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertStorageOutput added in v0.33.1

func ConvertStorageOutput[K comparable, V any, R any](fn func(key K) (V, error), mapper func(V) R) func(key K) (R, error)

ConvertStorageOutput maps the output type from a getter function to a different type. This is useful to avoid maintaining multiple maps for the same data.

Example usage:

blockMap := map[uint64]*flow.Block{}

headers.On("BlockIDByHeight", mock.AnythingOfType("uint64")).Return(
	mocks.ConvertStorageOutput(
		mocks.StorageMapGetter(s.blockMap),
		func(block *flow.Block) flow.Identifier { return block.ID() },
	),
)

func NewFinalizedHeaderCache added in v0.31.0

func NewFinalizedHeaderCache(t *testing.T, state protocol.State) *finalizedHeaderCache

func StorageMapGetter added in v0.33.1

func StorageMapGetter[K comparable, V any](m map[K]V) func(key K) (V, error)

StorageMapGetter implements a simple generic getter function for mock storage methods. This is useful to avoid duplicating boilerplate code for mock storage methods.

Example: Instead of the following code:

results.On("ByID", mock.AnythingOfType("flow.Identifier")).Return(
	func(resultID flow.Identifier) (*flow.ExecutionResult, error) {
		if result, ok := s.resultMap[resultID]; ok {
			return result, nil
		}
		return nil, storage.ErrNotFound
	},
)

Use this:

results.On("ByID", mock.AnythingOfType("flow.Identifier")).Return(
	mocks.StorageMapGetter(s.resultMap),
)

Types

type EpochQuery

type EpochQuery struct {
	// contains filtered or unexported fields
}

EpochQuery implements protocol.EpochQuery for testing purposes. Safe for concurrent use by multiple goroutines.

func NewEpochQuery

func NewEpochQuery(t *testing.T, counter uint64, epochs ...protocol.CommittedEpoch) *EpochQuery

func (*EpochQuery) AddCommitted added in v0.39.2

func (mock *EpochQuery) AddCommitted(epoch protocol.CommittedEpoch)

AddCommitted adds the given Committed Epoch to this EpochQuery implementation, so its information can be retrieved by the business logic via the protocol.EpochQuery API.

func (*EpochQuery) AddTentative added in v0.39.2

func (mock *EpochQuery) AddTentative(epoch protocol.TentativeEpoch)

AddTentative adds the given Tentative Epoch to this EpochQuery implementation, so its information can be retrieved by the business logic via the protocol.EpochQuery API.

func (*EpochQuery) ByCounter

func (mock *EpochQuery) ByCounter(counter uint64) protocol.CommittedEpoch

func (*EpochQuery) Current

func (mock *EpochQuery) Current() (protocol.CommittedEpoch, error)

func (*EpochQuery) NextCommitted added in v0.39.2

func (mock *EpochQuery) NextCommitted() (protocol.CommittedEpoch, error)

func (*EpochQuery) NextUnsafe added in v0.39.2

func (mock *EpochQuery) NextUnsafe() (protocol.TentativeEpoch, error)

func (*EpochQuery) Phase added in v0.31.0

func (mock *EpochQuery) Phase() flow.EpochPhase

Phase returns a phase consistent with the current epoch state.

func (*EpochQuery) Previous added in v0.13.0

func (mock *EpochQuery) Previous() (protocol.CommittedEpoch, error)

func (*EpochQuery) Transition

func (mock *EpochQuery) Transition()

Transition increments the counter indicating which epoch is the "current epoch". It is assumed that an epoch corresponding to the current epoch counter exists; otherwise this mock is in a state that is illegal according to protocol rules.

type MockCloser added in v0.38.0

type MockCloser struct{}

func (*MockCloser) Close added in v0.38.0

func (mc *MockCloser) Close() error

type Params added in v0.11.0

type Params struct {
	// contains filtered or unexported fields
}

func (*Params) ChainID added in v0.11.0

func (p *Params) ChainID() flow.ChainID

func (*Params) EpochFallbackTriggered added in v0.29.0

func (p *Params) EpochFallbackTriggered() (bool, error)

func (*Params) FinalizedRoot added in v0.30.7

func (p *Params) FinalizedRoot() *flow.Header

func (*Params) Seal added in v0.11.0

func (p *Params) Seal() *flow.Seal

func (*Params) SealedRoot added in v0.30.7

func (p *Params) SealedRoot() *flow.Header

func (*Params) SporkID added in v0.23.2

func (p *Params) SporkID() flow.Identifier

func (*Params) SporkRootBlock added in v0.43.0

func (p *Params) SporkRootBlock() *flow.Block

func (*Params) SporkRootBlockHeight added in v0.29.6

func (p *Params) SporkRootBlockHeight() uint64

func (*Params) SporkRootBlockView added in v0.43.0

func (p *Params) SporkRootBlockView() uint64

type ProtocolState added in v0.11.0

type ProtocolState struct {
	sync.Mutex
	protocol.ParticipantState
	// contains filtered or unexported fields
}

ProtocolState is a mocked version of protocol state, which has very close behavior to the real implementation but for testing purpose. If you are testing a module that depends on protocol state's behavior, but you don't want to mock up the methods and its return value, then just use this module

func NewProtocolState added in v0.11.0

func NewProtocolState() *ProtocolState

func (*ProtocolState) AtBlockID added in v0.11.0

func (ps *ProtocolState) AtBlockID(blockID flow.Identifier) protocol.Snapshot

func (*ProtocolState) AtHeight added in v0.11.0

func (ps *ProtocolState) AtHeight(height uint64) protocol.Snapshot

func (*ProtocolState) Bootstrap added in v0.14.0

func (m *ProtocolState) Bootstrap(root *flow.Block, result *flow.ExecutionResult, seal *flow.Seal) error

func (*ProtocolState) Extend added in v0.14.0

func (m *ProtocolState) Extend(block *flow.Block) error

func (*ProtocolState) Final added in v0.11.0

func (ps *ProtocolState) Final() protocol.Snapshot

func (*ProtocolState) Finalize added in v0.14.0

func (m *ProtocolState) Finalize(blockID flow.Identifier) error

func (*ProtocolState) MakeSeal added in v0.39.1

func (m *ProtocolState) MakeSeal(blockID flow.Identifier) error

func (*ProtocolState) Params added in v0.11.0

func (ps *ProtocolState) Params() protocol.Params

func (*ProtocolState) Sealed added in v0.39.1

func (ps *ProtocolState) Sealed() protocol.Snapshot

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL