Help us shape the future of Go! Take the 2026 Go Developer Survey

consensustest

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2025 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Accepted represents an accepted status
	Accepted = choices.Accepted

	// Rejected represents a rejected status
	Rejected = choices.Rejected

	// Processing represents a processing status
	Processing = choices.Processing

	// Unknown represents an unknown status
	Unknown = choices.Unknown
)

Status constants for test assertions

View Source
var CChainID = ids.GenerateTestID()

CChainID is a test chain ID

View Source
var ErrTest = errors.New("test error")

ErrTest is a test error.

Functions

func ConsensusContext

func ConsensusContext(ctx *consensus.Context) *consensus.Context

ConsensusContext returns the context as-is (for compatibility)

func Context

func Context(t *testing.T, chainID ids.ID) *consensus.Context

Context creates a test consensus context

Types

type BlockFactory

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

BlockFactory creates test blocks.

func NewBlockFactory

func NewBlockFactory() *BlockFactory

NewBlockFactory creates a new block factory.

func (*BlockFactory) New

func (f *BlockFactory) New(parent ids.ID) *TestBlock

New creates a new test block.

type MockPoll

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

MockPoll is a mock poll for testing.

func NewMockPoll

func NewMockPoll() *MockPoll

NewMockPoll creates a new mock poll.

func (*MockPoll) Finished

func (p *MockPoll) Finished() bool

Finished returns true if the poll has finished.

func (*MockPoll) Result

func (p *MockPoll) Result() []string

Result returns the poll results.

func (*MockPoll) SetFinished

func (p *MockPoll) SetFinished(finished bool)

SetFinished sets the poll as finished.

func (*MockPoll) SetResult

func (p *MockPoll) SetResult(result []string)

SetResult sets the poll result.

func (*MockPoll) Vote

func (p *MockPoll) Vote(vdr string, vote string)

Vote adds a vote to the poll.

func (*MockPoll) Votes

func (p *MockPoll) Votes() []string

Votes returns all votes cast.

type Poll

type Poll interface {
	Vote(vdr string, vote string)
	Finished() bool
	Result() []string
}

Poll defines the interface for a poll.

type PollFactory

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

PollFactory creates test polls.

func NewPollFactory

func NewPollFactory(alpha int) *PollFactory

NewPollFactory creates a new poll factory.

func (*PollFactory) New

func (f *PollFactory) New() Poll

New creates a new poll.

type TestBlock

type TestBlock struct {
	TestDecidable
	ParentV ids.ID
	HeightV uint64
	TimeV   uint64
	VerifyV error
	BytesV  []byte
}

TestBlock is a test implementation of a block.

func (*TestBlock) Bytes

func (b *TestBlock) Bytes() []byte

Bytes returns the byte representation.

func (*TestBlock) Height

func (b *TestBlock) Height() uint64

Height returns the height of the block.

func (*TestBlock) Parent

func (b *TestBlock) Parent() ids.ID

Parent returns the parent block ID.

func (*TestBlock) Time

func (b *TestBlock) Time() uint64

Time returns the time the block was created.

func (*TestBlock) Verify

func (b *TestBlock) Verify(context.Context) error

Verify returns the verification error.

type TestDecidable

type TestDecidable struct {
	IDV     ids.ID
	AcceptV error
	RejectV error
	StatusV choices.Status
}

TestDecidable is a test implementation of choices.Decidable.

func (*TestDecidable) Accept

func (d *TestDecidable) Accept(context.Context) error

Accept accepts this element.

func (*TestDecidable) ID

func (d *TestDecidable) ID() string

ID returns the ID of this element.

func (*TestDecidable) Reject

func (d *TestDecidable) Reject(context.Context) error

Reject rejects this element.

func (*TestDecidable) Status

func (d *TestDecidable) Status() choices.Status

Status returns the status of this element.

type TestPoll

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

TestPoll is a test poll implementation.

func NewPoll

func NewPoll(alpha int) *TestPoll

NewPoll creates a new test poll.

func (*TestPoll) Finished

func (p *TestPoll) Finished() bool

Finished returns true if the poll has finished.

func (*TestPoll) Result

func (p *TestPoll) Result() []string

Result returns the poll results.

func (*TestPoll) String

func (p *TestPoll) String() string

String returns a string representation of the poll.

func (*TestPoll) Vote

func (p *TestPoll) Vote(vdr string, vote string)

Vote adds a vote to the poll.

type TestVertex

type TestVertex struct {
	TestDecidable
	ParentsV []ids.ID
	HeightV  uint64
	EpochV   uint32
	VerifyV  error
	BytesV   []byte
}

TestVertex is a test implementation of a vertex.

func (*TestVertex) Bytes

func (v *TestVertex) Bytes() []byte

Bytes returns the byte representation.

func (*TestVertex) Epoch

func (v *TestVertex) Epoch() uint32

Epoch returns the epoch of this vertex.

func (*TestVertex) Height

func (v *TestVertex) Height() uint64

Height returns the height of this vertex.

func (*TestVertex) Parents

func (v *TestVertex) Parents() []ids.ID

Parents returns the parents of this vertex.

func (*TestVertex) Verify

func (v *TestVertex) Verify(context.Context) error

Verify returns the verification error.

func (*TestVertex) Vertex

func (v *TestVertex) Vertex() ids.ID

Vertex returns the ID of this vertex.

type VertexFactory

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

VertexFactory creates test vertices.

func NewVertexFactory

func NewVertexFactory() *VertexFactory

NewVertexFactory creates a new vertex factory.

func (*VertexFactory) New

func (f *VertexFactory) New(parents []ids.ID) *TestVertex

New creates a new test vertex.

Jump to

Keyboard shortcuts

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