testutil

package
v0.0.0-...-35615aa Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2025 License: BSD-3-Clause Imports: 17 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)

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 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) AdvanceWithoutLeader

func (n *InMemNetwork) AdvanceWithoutLeader(epochTimes []time.Time, 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) 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) TriggerLeaderBlockBuilder

func (n *InMemNetwork) TriggerLeaderBlockBuilder(round uint64) *TestBlock

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) 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 {
	Out                chan *TestBlock
	In                 chan *TestBlock
	BlockShouldBeBuilt chan struct{}
}

func NewTestBlockBuilder

func NewTestBlockBuilder() *TestBlockBuilder

func (*TestBlockBuilder) BuildBlock

BuildBlock builds a new testblock and sends it to the BlockBuilder channel

func (*TestBlockBuilder) WaitForPendingBlock

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

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) Intercept

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

func (*TestLogger) Silence

func (t *TestLogger) Silence()

func (*TestLogger) Trace

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

func (*TestLogger) Verbo

func (tl *TestLogger) Verbo(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 *testControlledBlockBuilder
	// 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) HandleMessage

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

func (*TestNode) Silence

func (t *TestNode) Silence()

func (*TestNode) Start

func (t *TestNode) Start()

func (*TestNode) TriggerBlockShouldBeBuilt

func (t *TestNode) TriggerBlockShouldBeBuilt()

TriggerBlockShouldBeBuilt signals this nodes block builder it is expecting a block to be built.

type TestNodeConfig

type TestNodeConfig struct {
	// optional
	InitialStorage     []simplex.VerifiedFinalizedBlock
	Comm               simplex.Communication
	ReplicationEnabled bool
}

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
}

func (*TestSignatureAggregator) Aggregate

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