testutil

package
v0.0.0-...-b90f043 Latest Latest
Warning

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

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

Documentation

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 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 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 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 ControlledBlockBuilder

type ControlledBlockBuilder interface {
	simplex.BlockBuilder
	TriggerNewBlock()
	TriggerBlockShouldBeBuilt()
	ShouldBlockBeBuilt() bool
}

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 InMemNetwork

type InMemNetwork struct {
	Instances []*TestNode
	// contains filtered or unexported fields
}

func NewInMemNetwork

func NewInMemNetwork(t *testing.T, nodes []simplex.NodeID) *InMemNetwork

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

func (*InMemNetwork) AdvanceTime

func (n *InMemNetwork) AdvanceTime(duration time.Duration)

func (*InMemNetwork) AdvanceWithoutLeader

func (n *InMemNetwork) AdvanceWithoutLeader(round uint64, laggingNodeId simplex.NodeID)

func (*InMemNetwork) Connect

func (n *InMemNetwork) Connect(node simplex.NodeID)

func (*InMemNetwork) Disconnect

func (n *InMemNetwork) Disconnect(node simplex.NodeID)

func (*InMemNetwork) IsDisconnected

func (n *InMemNetwork) IsDisconnected(node simplex.NodeID) bool

func (*InMemNetwork) SetAllNodesMessageFilter

func (n *InMemNetwork) SetAllNodesMessageFilter(filter MessageFilter)

func (*InMemNetwork) SetNodeMessageFilter

func (n *InMemNetwork) SetNodeMessageFilter(node simplex.NodeID, filter MessageFilter)

func (*InMemNetwork) StartInstances

func (n *InMemNetwork) StartInstances()

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

func (*InMemNetwork) StopInstances

func (n *InMemNetwork) StopInstances()

func (*InMemNetwork) TriggerLeaderBlockBuilder

func (n *InMemNetwork) TriggerLeaderBlockBuilder(round uint64)

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 LongRunningInMemoryNetwork

type LongRunningInMemoryNetwork struct {
	*InMemNetwork
	// contains filtered or unexported fields
}

func NewDefaultLongRunningNetwork

func NewDefaultLongRunningNetwork(t *testing.T, numNodes int) *LongRunningInMemoryNetwork

func (*LongRunningInMemoryNetwork) ConnectNodes

func (n *LongRunningInMemoryNetwork) ConnectNodes(nodeIndexes ...uint64)

func (*LongRunningInMemoryNetwork) ContinueBlocks

func (n *LongRunningInMemoryNetwork) ContinueBlocks()

func (*LongRunningInMemoryNetwork) CrashNodes

func (n *LongRunningInMemoryNetwork) CrashNodes(nodeIndexes ...uint64)

func (*LongRunningInMemoryNetwork) DisconnectNodes

func (n *LongRunningInMemoryNetwork) DisconnectNodes(nodeIndexes ...uint64)

func (*LongRunningInMemoryNetwork) NoMoreBlocks

func (n *LongRunningInMemoryNetwork) NoMoreBlocks()

func (*LongRunningInMemoryNetwork) StartInstances

func (n *LongRunningInMemoryNetwork) StartInstances()

func (*LongRunningInMemoryNetwork) StartNodes

func (n *LongRunningInMemoryNetwork) StartNodes(nodeIndexes ...uint64)

func (*LongRunningInMemoryNetwork) StopAndAssert

func (n *LongRunningInMemoryNetwork) StopAndAssert(tailingMessages bool)

StopAndAssert stops all nodes and asserts their storage and WALs are consistent. If tailingMessages is true, it will also assert that no extra messages are being sent after telling the network no more blocks should be built. TailingMessages is useful for debugging, but is currently flakey because NoMoreBlocks does not stop block building atomically for all nodes in the network. Therefore, some nodes may timeout on a block they think should be built, and keep resending empty votes.

func (*LongRunningInMemoryNetwork) UpdateTime

func (n *LongRunningInMemoryNetwork) UpdateTime(frequency time.Duration, increment time.Duration)

func (*LongRunningInMemoryNetwork) WaitForNodesToEnterRound

func (n *LongRunningInMemoryNetwork) WaitForNodesToEnterRound(round uint64, nodeIndexes ...uint64)

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 NetworkBlockBuilder

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

func NewNetworkBlockBuilder

func NewNetworkBlockBuilder(t *testing.T) *NetworkBlockBuilder

func (*NetworkBlockBuilder) BuildBlock

func (b *NetworkBlockBuilder) BuildBlock(
	ctx context.Context,
	metadata simplex.ProtocolMetadata,
	blacklist simplex.Blacklist,
) (simplex.VerifiedBlock, bool)

func (*NetworkBlockBuilder) ShouldBlockBeBuilt

func (b *NetworkBlockBuilder) ShouldBlockBeBuilt() bool

func (*NetworkBlockBuilder) TriggerBlockShouldBeBuilt

func (b *NetworkBlockBuilder) TriggerBlockShouldBeBuilt()

func (*NetworkBlockBuilder) TriggerBlockShouldNotBeBuilt

func (b *NetworkBlockBuilder) TriggerBlockShouldNotBeBuilt()

func (*NetworkBlockBuilder) TriggerNewBlock

func (b *NetworkBlockBuilder) TriggerNewBlock()

func (*NetworkBlockBuilder) WaitForPendingBlock

func (b *NetworkBlockBuilder) WaitForPendingBlock(ctx context.Context)

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 *InMemNetwork, 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 (*TestLogger) Error

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

func (*TestLogger) Intercept

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

func (*TestLogger) SetPanicOnError

func (t *TestLogger) SetPanicOnError(panicOnError bool)

func (*TestLogger) SetPanicOnWarn

func (t *TestLogger) SetPanicOnWarn(panicOnWarn bool)

func (*TestLogger) Silence

func (t *TestLogger) Silence()

func (*TestLogger) SilenceExceptKeywords

func (t *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 TestNode

type TestNode struct {
	WAL     *TestWAL
	Storage *InMemStorage

	E *simplex.Epoch

	BB ControlledBlockBuilder
	// contains filtered or unexported fields
}

func NewSimplexNode

func NewSimplexNode(t *testing.T, nodeID simplex.NodeID, net *InMemNetwork, config *TestNodeConfig) *TestNode

newSimplexNode creates a new testNode and adds it to net.

func (*TestNode) AdvanceTime

func (t *TestNode) AdvanceTime(duration time.Duration)

func (*TestNode) HandleMessage

func (t *TestNode) HandleMessage(msg *simplex.Message, from simplex.NodeID) error

func (*TestNode) RecordMessageTypeSent

func (t *TestNode) RecordMessageTypeSent(msg *simplex.Message)

func (*TestNode) Silence

func (t *TestNode) Silence()

func (*TestNode) SilenceExceptKeywords

func (t *TestNode) SilenceExceptKeywords(keywords ...string)

func (*TestNode) Start

func (t *TestNode) Start()

func (*TestNode) Stop

func (t *TestNode) Stop()

func (*TestNode) TickUntilRoundAdvanced

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

func (*TestNode) TimeoutOnRound

func (t *TestNode) TimeoutOnRound(round uint64)

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

type TestNodeConfig

type TestNodeConfig struct {
	// optional
	InitialStorage     []simplex.VerifiedFinalizedBlock
	Comm               simplex.Communication
	SigAggregator      simplex.SignatureAggregator
	ReplicationEnabled bool
	BlockBuilder       ControlledBlockBuilder

	// Long Running Tests
	MaxRoundWindow uint64
	Logger         *TestLogger
	WAL            *TestWAL
	Storage        *InMemStorage
	StartTime      int64
}

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)

Jump to

Keyboard shortcuts

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