chaintest

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: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// GenesisID is the ID of the genesis block
	GenesisID = ids.GenerateTestID()

	// GenesisBytes is the byte representation of genesis
	GenesisBytes = GenesisID[:]

	// GenesisTimestamp is the timestamp of genesis
	GenesisTimestamp = uint64(0)

	// Genesis is the genesis block
	Genesis = &TestBlock{
		IDV:     GenesisID,
		ParentV: ids.Empty,
		HeightV: 0,
		TimeV:   0,
		StatusV: choices.Accepted,
		BytesV:  GenesisBytes,
	}
)

Functions

func MakeLastAcceptedBlockF

func MakeLastAcceptedBlockF(blocks []*TestBlock, opts []*TestBlock) func() (string, error)

MakeLastAcceptedBlockF creates a function that returns the last accepted block

Types

type Block

type Block interface {
	choices.Decidable
	Parent() ids.ID
	Height() uint64
	Time() uint64
	Verify(context.Context) error
	Bytes() []byte
	Accept() error
}

Block interface matches chain.Block to avoid import cycle

type CantAdd

type CantAdd struct{}

func (CantAdd) Add

type CantInitialize

type CantInitialize struct{}

func (CantInitialize) Initialize

type CantRecordPoll

type CantRecordPoll struct{}

func (CantRecordPoll) RecordPoll

func (CantRecordPoll) RecordPoll(context.Context, []ids.ID) error

type Parameters

type Parameters struct {
	K                     int
	AlphaPreference       int
	AlphaConfidence       int
	Beta                  int
	ConcurrentRepolls     int
	OptimalProcessing     int
	MaxOutstandingItems   int
	MaxItemProcessingTime int64
}

Parameters matches Parameters to avoid import cycle

type TestBlock

type TestBlock struct {
	IDV     ids.ID
	AcceptV error
	RejectV error
	StatusV choices.Status
	ParentV ids.ID
	HeightV uint64
	TimeV   uint64
	VerifyV error
	BytesV  []byte
}

TestBlock is a test implementation of Block

func BuildChild

func BuildChild(parent Block) *TestBlock

BuildChild builds a child block of the given parent

func BuildLinear

func BuildLinear(parent Block, count int) []*TestBlock

BuildLinear builds a linear chain of blocks

func MakeTestBlock

func MakeTestBlock(
	id ids.ID,
	parent ids.ID,
	height uint64,
	timestamp uint64,
	status choices.Status,
) *TestBlock

MakeTestBlock creates a new test block

func (*TestBlock) Accept

func (b *TestBlock) Accept() error

func (*TestBlock) Bytes

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

func (*TestBlock) Height

func (b *TestBlock) Height() uint64

func (*TestBlock) ID

func (b *TestBlock) ID() string

func (*TestBlock) Parent

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

func (*TestBlock) Reject

func (b *TestBlock) Reject() error

func (*TestBlock) Status

func (b *TestBlock) Status() choices.Status

func (*TestBlock) Time

func (b *TestBlock) Time() uint64

func (*TestBlock) Verify

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

type TestConsensus

type TestConsensus struct {
	T *testing.T

	CantInitialize
	CantAdd
	CantRecordPoll

	InitializeF    func(context.Context, Parameters, string, uint64, uint64) error
	ParametersF    func() Parameters
	AddF           func(context.Context, Block) error
	IssuedF        func(Block) bool
	ProcessingF    func(ids.ID) bool
	DecidedF       func(Block) bool
	IsPreferredF   func(Block) bool
	PreferenceF    func() ids.ID
	RecordPollF    func(context.Context, []ids.ID) error
	FinalizedF     func() bool
	HealthCheckF   func(context.Context) (interface{}, error)
	NumProcessingF func() int
}

TestConsensus is a test implementation of chain.Consensus

func (*TestConsensus) Add

func (c *TestConsensus) Add(ctx context.Context, blk Block) error

func (*TestConsensus) Decided

func (c *TestConsensus) Decided(blk Block) bool

func (*TestConsensus) Finalized

func (c *TestConsensus) Finalized() bool

func (*TestConsensus) HealthCheck

func (c *TestConsensus) HealthCheck(ctx context.Context) (interface{}, error)

func (*TestConsensus) Initialize

func (c *TestConsensus) Initialize(ctx context.Context, params Parameters, lastAcceptedID string, lastAcceptedHeight uint64, lastAcceptedTime uint64) error

func (*TestConsensus) IsPreferred

func (c *TestConsensus) IsPreferred(blk Block) bool

func (*TestConsensus) Issued

func (c *TestConsensus) Issued(blk Block) bool

func (*TestConsensus) NumProcessing

func (c *TestConsensus) NumProcessing() int

func (*TestConsensus) Parameters

func (c *TestConsensus) Parameters() Parameters

func (*TestConsensus) Preference

func (c *TestConsensus) Preference() ids.ID

func (*TestConsensus) Processing

func (c *TestConsensus) Processing(blkID ids.ID) bool

func (*TestConsensus) RecordPoll

func (c *TestConsensus) RecordPoll(ctx context.Context, votes []ids.ID) error

Jump to

Keyboard shortcuts

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