testutil

package
v0.0.0-...-545153e Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Overview

Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. See the file LICENSE for licensing terms.

Index

Constants

View Source
const (
	LOG_LEVEL      = "log_level"
	INFO_LOG_LEVEL = "info"
)

Variables

This section is empty.

Functions

func AllowAllMessages

func AllowAllMessages(*common.Message, common.NodeID, common.NodeID) bool

AllowAllMessages allows every message to be sent

func DefaultTestNodeEpochConfig

func DefaultTestNodeEpochConfig(t *testing.T, nodeID common.NodeID, comm common.Communication, bb common.BlockBuilder) (simplex.EpochConfig, *TestWAL, *InMemStorage)

DefaultTestNodeEpochConfig returns a default epoch config for a given node.

func GenerateNodeID

func GenerateNodeID(t *testing.T) common.NodeID

func InjectTestFinalization

func InjectTestFinalization(t *testing.T, e *simplex.Epoch, finalization *common.Finalization, from common.NodeID)

func InjectTestFinalizeVote

func InjectTestFinalizeVote(t *testing.T, e *simplex.Epoch, block common.VerifiedBlock, id common.NodeID)

func InjectTestNotarization

func InjectTestNotarization(t *testing.T, e *simplex.Epoch, notarization common.Notarization, id common.NodeID)

func InjectTestVote

func InjectTestVote(t *testing.T, e *simplex.Epoch, block common.VerifiedBlock, id common.NodeID)

func NewEmptyNotarization

func NewEmptyNotarization(nodes []common.NodeID, round uint64) *common.EmptyNotarization

NewEmptyNotarization creates a new empty notarization

func NewFinalizationRecord

func NewFinalizationRecord(t *testing.T, signatureAggregator common.SignatureAggregator, block common.VerifiedBlock, ids []common.NodeID) (common.Finalization, []byte)

creates a new finalization

func NewNotarization

func NewNotarization(logger common.Logger, signatureAggregator common.SignatureAggregator, block common.VerifiedBlock, ids []common.NodeID) (common.Notarization, error)

func NewNotarizationRecord

func NewNotarizationRecord(logger common.Logger, signatureAggregator common.SignatureAggregator, block common.VerifiedBlock, ids []common.NodeID) ([]byte, error)

func NewTestControlledBlockBuilder

func NewTestControlledBlockBuilder(t *testing.T) *testControlledBlockBuilder

NewTestControlledBlockBuilder returns a BlockBuilder that only builds a block when triggerNewBlock is called.

func NewTestFinalizeVote

func NewTestFinalizeVote(t *testing.T, block common.VerifiedBlock, id common.NodeID) *common.FinalizeVote

func NewTestVote

func NewTestVote(block AnyBlock, id common.NodeID) (*common.Vote, error)

func UpdateEpochConfig

func UpdateEpochConfig(epochConfig *simplex.EpochConfig, testConfig *TestNodeConfig)

func WaitForBlockProposerTimeout

func WaitForBlockProposerTimeout(t *testing.T, e *simplex.Epoch, startTime *time.Time, startRound uint64)

func WaitToEnterRound

func WaitToEnterRound(t *testing.T, e *simplex.Epoch, round uint64)

func WaitToEnterRoundWithTimeout

func WaitToEnterRoundWithTimeout(t *testing.T, e *simplex.Epoch, round uint64, timeoutDuration time.Duration)

Types

type AnyBlock

type AnyBlock interface {
	// BlockHeader encodes a succinct and collision-free representation of a block.
	BlockHeader() common.BlockHeader
}

type BasicInMemoryNetwork

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

func NewBasicInMemoryNetwork

func NewBasicInMemoryNetwork(t *testing.T, nodes common.NodeIDs) *BasicInMemoryNetwork

func (*BasicInMemoryNetwork) AddNode

func (b *BasicInMemoryNetwork) AddNode(node *BasicNode)

func (*BasicInMemoryNetwork) AdvanceTime

func (b *BasicInMemoryNetwork) AdvanceTime(increment time.Duration)

func (*BasicInMemoryNetwork) Connect

func (b *BasicInMemoryNetwork) Connect(node common.NodeID)

func (*BasicInMemoryNetwork) Disconnect

func (b *BasicInMemoryNetwork) Disconnect(node common.NodeID)

func (*BasicInMemoryNetwork) GetInstances

func (b *BasicInMemoryNetwork) GetInstances() []*BasicNode

func (*BasicInMemoryNetwork) IsDisconnected

func (b *BasicInMemoryNetwork) IsDisconnected(node common.NodeID) bool

func (*BasicInMemoryNetwork) RemoveNode

func (b *BasicInMemoryNetwork) RemoveNode(node *BasicNode)

func (*BasicInMemoryNetwork) ReplaceNode

func (b *BasicInMemoryNetwork) ReplaceNode(node *BasicNode)

func (*BasicInMemoryNetwork) SetAllNodesMessageFilter

func (b *BasicInMemoryNetwork) SetAllNodesMessageFilter(filter MessageFilter)

func (*BasicInMemoryNetwork) SetNodeMessageFilter

func (b *BasicInMemoryNetwork) SetNodeMessageFilter(node common.NodeID, filter MessageFilter)

func (*BasicInMemoryNetwork) StartInstances

func (b *BasicInMemoryNetwork) StartInstances()

StartInstances starts all instances in the network. The first one is typically the leader, so we make sure to start it last.

func (*BasicInMemoryNetwork) StopInstances

func (b *BasicInMemoryNetwork) StopInstances()

type BasicNode

type BasicNode struct {
	E *simplex.Epoch

	CustomHandler func(msg *common.Message, from common.NodeID) error
	// contains filtered or unexported fields
}

BasicNode is a simple representation of an instance running an epoch. It does not know about any particular custom types, its sole responsibility is to run the epoch and handle messages.

func NewBasicNode

func NewBasicNode(t *testing.T, epoch *simplex.Epoch, logger *TestLogger) *BasicNode

func (*BasicNode) AdvanceTime

func (b *BasicNode) AdvanceTime(duration time.Duration)

func (*BasicNode) GetMessageTypesSent

func (b *BasicNode) GetMessageTypesSent() map[string]uint64

func (*BasicNode) HandleMessage

func (b *BasicNode) HandleMessage(msg *common.Message, from common.NodeID) error

func (*BasicNode) PrintMessageTypesSent

func (b *BasicNode) PrintMessageTypesSent()

func (*BasicNode) RecordMessageTypeSent

func (b *BasicNode) RecordMessageTypeSent(msg *common.Message)

func (*BasicNode) ResetMessageTypesSent

func (b *BasicNode) ResetMessageTypesSent()

func (*BasicNode) Silence

func (b *BasicNode) Silence()

func (*BasicNode) SilenceExceptKeywords

func (b *BasicNode) SilenceExceptKeywords(keywords ...string)

func (*BasicNode) Start

func (b *BasicNode) Start()

func (*BasicNode) Stop

func (b *BasicNode) Stop()

type BlockDeserializer

type BlockDeserializer struct {
	// DelayedVerification will block verifying any deserialized blocks until we send to the channel
	DelayedVerification chan struct{}
}

func (*BlockDeserializer) DeserializeBlock

func (b *BlockDeserializer) DeserializeBlock(ctx context.Context, buff []byte) (common.Block, error)

type ControlledInMemoryNetwork

type ControlledInMemoryNetwork struct {
	*BasicInMemoryNetwork
	Instances []*ControlledNode
}

func NewControlledNetwork

func NewControlledNetwork(t *testing.T, nodes common.NodeIDs) *ControlledInMemoryNetwork

NewControlledNetwork creates an in-memory network. Node IDs must be provided before adding instances, as nodeWeights require prior knowledge of all participants.

func (*ControlledInMemoryNetwork) AdvanceWithoutLeader

func (n *ControlledInMemoryNetwork) AdvanceWithoutLeader(round uint64, laggingNodeId common.NodeID)

func (*ControlledInMemoryNetwork) TriggerLeaderBlockBuilder

func (n *ControlledInMemoryNetwork) TriggerLeaderBlockBuilder(round uint64)

type ControlledNode

type ControlledNode struct {
	*BasicNode

	WAL     *TestWAL
	Storage *InMemStorage
	// contains filtered or unexported fields
}

func NewControlledSimplexNode

func NewControlledSimplexNode(t *testing.T, nodeID common.NodeID, net *ControlledInMemoryNetwork, config *TestNodeConfig) *ControlledNode

newSimplexNode creates a new testNode and adds it to net.

func (*ControlledNode) BlockShouldBeBuilt

func (t *ControlledNode) BlockShouldBeBuilt()

func (*ControlledNode) ShouldBlockBeBuilt

func (t *ControlledNode) ShouldBlockBeBuilt() bool

func (*ControlledNode) TickUntilRoundAdvanced

func (t *ControlledNode) TickUntilRoundAdvanced(round uint64, tick time.Duration)

func (*ControlledNode) TimeoutOnRound

func (t *ControlledNode) TimeoutOnRound(round uint64)

TimeoutOnRound advances time until the node times out of the given round.

func (*ControlledNode) TriggerNewBlock

func (t *ControlledNode) TriggerNewBlock()

type DebugSwallowingEncoder

type DebugSwallowingEncoder struct {
	zapcore.ObjectEncoder
	// contains filtered or unexported fields
}

func (*DebugSwallowingEncoder) Clone

func (dse *DebugSwallowingEncoder) Clone() zapcore.Encoder

func (*DebugSwallowingEncoder) EncodeEntry

func (dse *DebugSwallowingEncoder) EncodeEntry(entry zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error)

type EncodedTestBlock

type EncodedTestBlock struct {
	Data      []byte
	Metadata  []byte
	Blacklist []byte
}

type InMemStorage

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

func NewInMemStorage

func NewInMemStorage() *InMemStorage

func (*InMemStorage) Clone

func (mem *InMemStorage) Clone() *InMemStorage

func (*InMemStorage) CloneUntil

func (mem *InMemStorage) CloneUntil(stopSeq uint64) *InMemStorage

CloneUntil will copy the storage up until a given sequence(not including).

func (*InMemStorage) Compare

func (mem *InMemStorage) Compare(other *InMemStorage) error

func (*InMemStorage) EnsureNoBlockCommit

func (mem *InMemStorage) EnsureNoBlockCommit(t *testing.T, seq uint64)

func (*InMemStorage) Index

func (mem *InMemStorage) Index(ctx context.Context, block common.VerifiedBlock, certificate common.Finalization) error

func (*InMemStorage) NumBlocks

func (mem *InMemStorage) NumBlocks() uint64

func (*InMemStorage) Retrieve

func (*InMemStorage) WaitForBlockCommit

func (mem *InMemStorage) WaitForBlockCommit(seq uint64) common.VerifiedBlock

type MessageFilter

type MessageFilter func(msg *common.Message, from common.NodeID, to common.NodeID) bool

MessageFilter is a function type that determines whether a message can be transmitted from one node to another. Parameters:

  • msg: The message being evaluated for transmission
  • from: The ID of the sending node
  • to: The ID of the receiving node

Returns:

  • bool: true if the message can be transmitted, false otherwise

type NoopComm

type NoopComm common.Nodes

func NewNoopComm

func NewNoopComm(nodes common.NodeIDs) NoopComm

func (NoopComm) Broadcast

func (n NoopComm) Broadcast(msg *common.Message)

func (NoopComm) Send

func (n NoopComm) Send(*common.Message, common.NodeID)

func (NoopComm) Validators

func (n NoopComm) Validators() common.Nodes

type TestBlock

type TestBlock struct {
	Data     []byte
	Metadata common.ProtocolMetadata

	Digest            [32]byte
	OnVerify          func()
	VerificationDelay chan struct{}
	VerificationError error
	// contains filtered or unexported fields
}

func NewTestBlock

func NewTestBlock(metadata common.ProtocolMetadata, blacklist common.Blacklist) *TestBlock

func (*TestBlock) Blacklist

func (tb *TestBlock) Blacklist() common.Blacklist

func (*TestBlock) BlockHeader

func (t *TestBlock) BlockHeader() common.BlockHeader

func (*TestBlock) Bytes

func (t *TestBlock) Bytes() ([]byte, error)

func (*TestBlock) ComputeDigest

func (tb *TestBlock) ComputeDigest()

func (*TestBlock) SealingBlockInfo

func (tb *TestBlock) SealingBlockInfo() *common.SealingBlockInfo

func (*TestBlock) Verify

type TestBlockBuilder

type TestBlockBuilder struct {
	BlockShouldBeBuilt chan struct{}
	// contains filtered or unexported fields
}

func NewTestBlockBuilder

func NewTestBlockBuilder() *TestBlockBuilder

func (*TestBlockBuilder) BuildBlock

func (*TestBlockBuilder) GetBuiltBlock

func (t *TestBlockBuilder) GetBuiltBlock() *TestBlock

func (*TestBlockBuilder) SetBuiltBlock

func (t *TestBlockBuilder) SetBuiltBlock(block *TestBlock)

func (*TestBlockBuilder) WaitForPendingBlock

func (t *TestBlockBuilder) WaitForPendingBlock(ctx context.Context)

func (*TestBlockBuilder) WithBlockShouldBeBuiltBuffer

func (t *TestBlockBuilder) WithBlockShouldBeBuiltBuffer(buffer uint64) *TestBlockBuilder

func (*TestBlockBuilder) WithBuiltBuffer

func (t *TestBlockBuilder) WithBuiltBuffer(buffer uint64) *TestBlockBuilder

type TestComm

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

func NewTestComm

func NewTestComm(from common.NodeID, net *BasicInMemoryNetwork, messageFilter MessageFilter) *TestComm

func (*TestComm) Broadcast

func (c *TestComm) Broadcast(msg *common.Message)

func (*TestComm) Send

func (c *TestComm) Send(msg *common.Message, destination common.NodeID)

func (*TestComm) SetFilter

func (c *TestComm) SetFilter(filter MessageFilter)

func (*TestComm) Validators

func (c *TestComm) Validators() common.Nodes

type TestLogger

type TestLogger struct {
	*zap.Logger
	// contains filtered or unexported fields
}

func MakeLogger

func MakeLogger(t *testing.T, node ...int) *TestLogger

func MakeLoggerWithFile

func MakeLoggerWithFile(t *testing.T, fileWriter zapcore.WriteSyncer, writeStdout bool, node ...int) *TestLogger

MakeLoggerWithFile creates a TestLogger that can write to a file and optionally to stdout. - If writeStdout is true, logs may be written to stdout. - If fileWriter is non-nil, logs may be written to that fileWriter. - If both are enabled, logs go to both. - If neither is enabled, logs are discarded.

func (*TestLogger) Error

func (tl *TestLogger) Error(msg string, fields ...zap.Field)

func (*TestLogger) Intercept

func (tl *TestLogger) Intercept(hook func(entry zapcore.Entry) error)

func (*TestLogger) SetLevel

func (tl *TestLogger) SetLevel(level zapcore.Level)

func (*TestLogger) SetPanicOnError

func (tl *TestLogger) SetPanicOnError(panicOnError bool)

func (*TestLogger) SetPanicOnWarn

func (tl *TestLogger) SetPanicOnWarn(panicOnWarn bool)

func (*TestLogger) Silence

func (tl *TestLogger) Silence()

func (*TestLogger) SilenceExceptKeywords

func (tl *TestLogger) SilenceExceptKeywords(keywords ...string)

SilenceExceptKeywords silences all logs EXCEPT those whose message contains at least one of the provided keywords.

func (*TestLogger) Trace

func (tl *TestLogger) Trace(msg string, fields ...zap.Field)

func (*TestLogger) Verbo

func (tl *TestLogger) Verbo(msg string, fields ...zap.Field)

func (*TestLogger) Warn

func (tl *TestLogger) Warn(msg string, fields ...zap.Field)

type TestNetworkCommunication

type TestNetworkCommunication interface {
	common.Communication
	SetFilter(filter MessageFilter)
}

type TestNodeConfig

type TestNodeConfig struct {
	// optional
	InitialStorage       []common.VerifiedFinalizedBlock
	Comm                 common.Communication
	SigAggregatorCreator common.SignatureAggregatorCreator
	ReplicationEnabled   bool
	BlockBuilder         *testControlledBlockBuilder

	// Long Running Tests
	MaxRoundWindow uint64
	Logger         *TestLogger
	WAL            *TestWAL
	Storage        *InMemStorage
	StartTime      int64
	RandomSeed     *int64 // Optional seed for deterministic tests
}

NodeConfig

type TestQC

type TestQC []common.Signature

func (TestQC) Bytes

func (t TestQC) Bytes() []byte

func (TestQC) Signers

func (t TestQC) Signers() []common.NodeID

func (TestQC) Verify

func (t TestQC) Verify([]byte, common.Nodes) error

type TestSignatureAggregator

type TestSignatureAggregator struct {
	Err          error
	N            int
	IsQuorumFunc func(signatures []common.NodeID) bool
}

func (*TestSignatureAggregator) Aggregate

func (t *TestSignatureAggregator) Aggregate(signatures []common.Signature) (common.QuorumCertificate, error)

func (*TestSignatureAggregator) AppendSignatures

func (t *TestSignatureAggregator) AppendSignatures(existing []byte, sigs ...[]byte) ([]byte, error)

func (*TestSignatureAggregator) IsQuorum

func (t *TestSignatureAggregator) IsQuorum(signers []common.NodeID) bool

type TestSigner

type TestSigner struct {
}

func (*TestSigner) Sign

func (t *TestSigner) Sign([]byte) ([]byte, error)

type TestWAL

type TestWAL struct {
	common.WriteAheadLog
	// contains filtered or unexported fields
}

func NewTestWAL

func NewTestWAL(t *testing.T) *TestWAL

func (*TestWAL) Append

func (tw *TestWAL) Append(b []byte) error

func (*TestWAL) AssertBlockProposal

func (tw *TestWAL) AssertBlockProposal(round uint64)

func (*TestWAL) AssertEmptyVote

func (tw *TestWAL) AssertEmptyVote(round uint64)

func (*TestWAL) AssertHealthy

func (tw *TestWAL) AssertHealthy(bd common.BlockDeserializer, qcd common.QCDeserializer)

AssertHealthy checks that the WAL has at most one of each record type per round.

func (*TestWAL) AssertNotarization

func (tw *TestWAL) AssertNotarization(round uint64) uint16

func (*TestWAL) AssertWALSize

func (tw *TestWAL) AssertWALSize(n int)

func (*TestWAL) Clone

func (tw *TestWAL) Clone() *TestWAL

func (*TestWAL) ContainsEmptyNotarization

func (tw *TestWAL) ContainsEmptyNotarization(round uint64) bool

func (*TestWAL) ContainsEmptyVote

func (tw *TestWAL) ContainsEmptyVote(round uint64) bool

func (*TestWAL) ContainsNotarization

func (tw *TestWAL) ContainsNotarization(round uint64) bool

func (*TestWAL) Delete

func (tw *TestWAL) Delete() error

func (*TestWAL) ReadAll

func (tw *TestWAL) ReadAll() ([][]byte, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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