chaintest

package
v1.22.21 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package chaintest provides test utilities for chains

Package chaintest provides test utilities for chain testing

Package chaintest provides test utilities for chain testing

Index

Constants

This section is empty.

Variables

View Source
var Genesis = &TestBlock{
	id:        ids.GenerateTestID(),
	parentID:  ids.Empty,
	height:    0,
	bytes:     []byte("genesis"),
	status:    uint8(choices.Accepted),
	timestamp: time.Now(),
	BytesV:    []byte("genesis"),
	ParentV:   ids.Empty,
	Decidable: choices.Decidable{Status: choices.Accepted},
}

Genesis is the genesis test block

Functions

This section is empty.

Types

type TestBlock

type TestBlock struct {

	// Additional fields for BFT testing
	BytesV    []byte
	ParentV   ids.ID
	Decidable choices.Decidable
	// contains filtered or unexported fields
}

TestBlock is a mock block for testing

func BuildChild

func BuildChild(parent *TestBlock) *TestBlock

BuildChild builds a child block

func BuildChildWithTime

func BuildChildWithTime(parent *TestBlock, timestamp time.Time) *TestBlock

BuildChildWithTime builds a child block with timestamp

func (*TestBlock) Accept

func (b *TestBlock) Accept(ctx context.Context) error

Accept accepts the block

func (*TestBlock) Bytes

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

Bytes returns the block bytes

func (*TestBlock) Height

func (b *TestBlock) Height() uint64

Height returns the block height

func (*TestBlock) ID

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

ID returns the block ID

func (*TestBlock) Parent

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

Parent returns the parent block ID (alias for ParentID)

func (*TestBlock) ParentID

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

ParentID returns the parent block ID

func (*TestBlock) Reject

func (b *TestBlock) Reject(ctx context.Context) error

Reject rejects the block

func (*TestBlock) Status

func (b *TestBlock) Status() uint8

Status returns the block status

func (*TestBlock) Timestamp

func (b *TestBlock) Timestamp() time.Time

Timestamp returns the block timestamp

func (*TestBlock) Verify

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

Verify verifies the block

type TestChain

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

TestChain provides a test implementation for chains

func NewTestChain

func NewTestChain(id []byte) *TestChain

NewTestChain creates a new test chain

func (*TestChain) Height

func (t *TestChain) Height() uint64

Height returns the current height

func (*TestChain) ID

func (t *TestChain) ID() []byte

ID returns the chain ID

func (*TestChain) SetHeight

func (t *TestChain) SetHeight(height uint64)

SetHeight sets the chain height

type VM added in v1.19.8

type VM struct {
	T           *testing.T
	ParseBlockF func(context.Context, []byte) (block.Block, error)
}

VM is a test VM for chain testing

func (*VM) BuildBlock added in v1.19.8

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

BuildBlock builds a new block

func (*VM) GetBlock added in v1.19.8

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

GetBlock gets a block by ID

func (*VM) GetBlockIDAtHeight added in v1.19.8

func (vm *VM) GetBlockIDAtHeight(ctx context.Context, height uint64) (ids.ID, error)

GetBlockIDAtHeight gets the block ID at a given height

func (*VM) Initialize added in v1.19.8

func (vm *VM) Initialize(
	ctx context.Context,
	chainCtx interface{},
	db interface{},
	genesisBytes []byte,
	upgradeBytes []byte,
	configBytes []byte,
	msgChan interface{},
	fxs []interface{},
	appSender interface{},
) error

Initialize initializes the VM

func (*VM) LastAccepted added in v1.19.8

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

LastAccepted returns the last accepted block ID

func (*VM) ParseBlock added in v1.19.8

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

ParseBlock parses a block from bytes

func (*VM) SetPreference added in v1.19.8

func (vm *VM) SetPreference(ctx context.Context, id ids.ID) error

SetPreference sets the preferred block ID

func (*VM) WaitForEvent added in v1.19.8

func (vm *VM) WaitForEvent(ctx context.Context) (interface{}, error)

WaitForEvent waits for a blockchain event

Jump to

Keyboard shortcuts

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