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

blocktest

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertBlockEqual

func AssertBlockEqual(t *testing.T, expected, actual block.Block)

AssertBlockEqual asserts that two blocks are equal

Types

type CantBuildBlock

type CantBuildBlock struct{}

func (CantBuildBlock) BuildBlock

func (CantBuildBlock) BuildBlock(context.Context) (block.Block, error)

type CantGetBlock

type CantGetBlock struct{}

func (CantGetBlock) GetBlock

type CantLastAccepted

type CantLastAccepted struct{}

func (CantLastAccepted) LastAccepted

func (CantLastAccepted) LastAccepted(context.Context) (ids.ID, error)

type CantParseBlock

type CantParseBlock struct{}

func (CantParseBlock) ParseBlock

func (CantParseBlock) ParseBlock(context.Context, []byte) (block.Block, error)

type CantSetPreference

type CantSetPreference struct{}

func (CantSetPreference) SetPreference

func (CantSetPreference) SetPreference(context.Context, ids.ID) error

type TestBlock

type TestBlock struct {
	TestDecidable
	HeightV uint64
	TimeV   uint64
	VerifyV error
	BytesV  []byte
}

TestBlock is a test implementation of block.Block

func MakeBlock

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

MakeBlock creates a new test block

func MakeBlockWithVerifyError

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

MakeBlockWithVerifyError creates a block that returns an error on verify

func (*TestBlock) Bytes

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

func (*TestBlock) Height

func (b *TestBlock) Height() uint64

func (*TestBlock) Time

func (b *TestBlock) Time() uint64

func (*TestBlock) Verify

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

type TestDecidable

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

TestDecidable is embedded in TestBlock to implement choices.Decidable.

func (*TestDecidable) Accept

func (d *TestDecidable) Accept() error

func (*TestDecidable) ID

func (d *TestDecidable) ID() ids.ID

func (*TestDecidable) Parent

func (d *TestDecidable) Parent() ids.ID

func (*TestDecidable) Reject

func (d *TestDecidable) Reject() error

func (*TestDecidable) Status

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

type TestVM

type TestVM struct {
	CantBuildBlock
	CantParseBlock
	CantGetBlock
	CantSetPreference
	CantLastAccepted

	BuildBlockF    func(context.Context) (block.Block, error)
	ParseBlockF    func(context.Context, []byte) (block.Block, error)
	GetBlockF      func(context.Context, ids.ID) (block.Block, error)
	SetPreferenceF func(context.Context, ids.ID) error
	LastAcceptedF  func(context.Context) (ids.ID, error)
}

TestVM is a test implementation of block.ChainVM

func (*TestVM) BuildBlock

func (vm *TestVM) BuildBlock(ctx context.Context) (block.Block, error)

func (*TestVM) GetBlock

func (vm *TestVM) GetBlock(ctx context.Context, blkID ids.ID) (block.Block, error)

func (*TestVM) LastAccepted

func (vm *TestVM) LastAccepted(ctx context.Context) (ids.ID, error)

func (*TestVM) ParseBlock

func (vm *TestVM) ParseBlock(ctx context.Context, b []byte) (block.Block, error)

func (*TestVM) SetPreference

func (vm *TestVM) SetPreference(ctx context.Context, blkID ids.ID) error

Jump to

Keyboard shortcuts

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