testutil

package
v0.0.0-...-57be261 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllowAllMessages

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

AllowAllMessages allows every message to be sent

func DefaultTestNodeEpochConfig

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

DefaultTestNodeEpochConfig returns a default epoch config for a given node.

func GenerateNodeID

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

func InjectTestFinalization

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

func InjectTestFinalizeVote

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

func InjectTestNotarization

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

func InjectTestVote

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

func NewEmptyNotarization

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

NewEmptyNotarization creates a new empty notarization

func NewFinalizationRecord

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

creates a new finalization

func NewNotarization

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

func NewNotarizationRecord

func NewNotarizationRecord(logger simplex.Logger, signatureAggregator simplex.SignatureAggregator, block simplex.VerifiedBlock, ids []simplex.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 simplex.VerifiedBlock, id simplex.NodeID) *simplex.FinalizeVote

func NewTestVote

func NewTestVote(block AnyBlock, id simplex.NodeID) (*simplex.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() simplex.BlockHeader
}

type BasicInMemoryNetwork

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

func NewBasicInMemoryNetwork

func NewBasicInMemoryNetwork(t *testing.T, nodes []simplex.NodeID) *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 simplex.NodeID)

func (*BasicInMemoryNetwork) Disconnect

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

func (*BasicInMemoryNetwork) GetInstances

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

func (*BasicInMemoryNetwork) IsDisconnected

func (b *BasicInMemoryNetwork) IsDisconnected(node simplex.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 simplex.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 *simplex.Message, from simplex.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 *simplex.Message, from simplex.NodeID) error

func (*BasicNode) PrintMessageTypesSent

func (b *BasicNode) PrintMessageTypesSent()

func (*BasicNode) RecordMessageTypeSent

func (b *BasicNode) RecordMessageTypeSent(msg *simplex.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) (simplex.Block, error)

type ControlledInMemoryNetwork

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

func NewControlledNetwork

func NewControlledNetwork(t *testing.T, nodes []simplex.NodeID) *ControlledInMemoryNetwork

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

func (*ControlledInMemoryNetwork) AdvanceWithoutLeader

func (n *ControlledInMemoryNetwork) AdvanceWithoutLeader(round uint64, laggingNodeId simplex.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 simplex.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) 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 simplex.VerifiedBlock, certificate simplex.Finalization) error

func (*InMemStorage) NumBlocks

func (mem *InMemStorage) NumBlocks() uint64

func (*InMemStorage) Retrieve

func (*InMemStorage) WaitForBlockCommit

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

type MessageFilter

type MessageFilter func(msg *simplex.Message, from simplex.NodeID, to simplex.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 []simplex.NodeID

func NewNoopComm

func NewNoopComm(nodes []simplex.NodeID) NoopComm

func (NoopComm) Broadcast

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

func (NoopComm) Nodes

func (n NoopComm) Nodes() []simplex.NodeID

func (NoopComm) Send

type TestBlock

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

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

func NewTestBlock

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

func (*TestBlock) Blacklist

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

func (*TestBlock) BlockHeader

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

func (*TestBlock) Bytes

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

func (*TestBlock) ComputeDigest

func (tb *TestBlock) ComputeDigest()

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 simplex.NodeID, net *BasicInMemoryNetwork, messageFilter MessageFilter) *TestComm

func (*TestComm) Broadcast

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

func (*TestComm) Nodes

func (c *TestComm) Nodes() []simplex.NodeID

func (*TestComm) Send

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

func (*TestComm) SetFilter

func (c *TestComm) SetFilter(filter MessageFilter)

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, node ...int) *TestLogger

MakeLoggerWithFile creates a TestLogger that optionally writes to a file in addition to stdout. If fileWriter is nil, logs only to stdout (same as MakeLogger). If fileWriter is provided, logs to both stdout and the file.

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 {
	simplex.Communication
	SetFilter(filter MessageFilter)
}

type TestNodeConfig

type TestNodeConfig struct {
	// optional
	InitialStorage     []simplex.VerifiedFinalizedBlock
	Comm               simplex.Communication
	SigAggregator      simplex.SignatureAggregator
	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 []simplex.Signature

func (TestQC) Bytes

func (t TestQC) Bytes() []byte

func (TestQC) Signers

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

func (TestQC) Verify

func (t TestQC) Verify(msg []byte) error

type TestSignatureAggregator

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

func (*TestSignatureAggregator) Aggregate

func (*TestSignatureAggregator) IsQuorum

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

type TestWAL

type TestWAL struct {
	simplex.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 simplex.BlockDeserializer, qcd simplex.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