testutil

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package testutil provides test utilities for the Narwhal library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TestHash

type TestHash [32]byte

TestHash is a 32-byte hash type for testing.

func ComputeHash

func ComputeHash(data []byte) TestHash

ComputeHash computes a SHA256 hash.

func HashFromBytes

func HashFromBytes(data []byte) (TestHash, error)

HashFromBytes creates a TestHash from bytes.

func (TestHash) Bytes

func (h TestHash) Bytes() []byte

Bytes returns the hash bytes.

func (TestHash) Equals

func (h TestHash) Equals(other narwhal.Hash) bool

Equals returns true if the hashes are equal.

func (TestHash) String

func (h TestHash) String() string

String returns the hex-encoded hash.

type TestNetwork

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

TestNetwork is a channel-based network for testing.

func NewTestNetwork

func NewTestNetwork(myIndex uint16) *TestNetwork

NewTestNetwork creates a new test network node.

func (*TestNetwork) BroadcastBatch

func (n *TestNetwork) BroadcastBatch(batch *narwhal.Batch[TestHash, *TestTransaction])

func (*TestNetwork) BroadcastCertificate

func (n *TestNetwork) BroadcastCertificate(cert *narwhal.Certificate[TestHash])

func (*TestNetwork) BroadcastHeader

func (n *TestNetwork) BroadcastHeader(header *narwhal.Header[TestHash])

func (*TestNetwork) Close

func (n *TestNetwork) Close() error

func (*TestNetwork) Connect

func (n *TestNetwork) Connect(other *TestNetwork)

Connect connects two network nodes.

func (*TestNetwork) FetchBatch

func (*TestNetwork) FetchCertificate

func (n *TestNetwork) FetchCertificate(_ uint16, _ TestHash) (*narwhal.Certificate[TestHash], error)

func (*TestNetwork) FetchCertificatesInRange

func (n *TestNetwork) FetchCertificatesInRange(_ uint16, _, _ uint64) ([]*narwhal.Certificate[TestHash], error)

func (*TestNetwork) Receive

func (n *TestNetwork) Receive() <-chan narwhal.Message[TestHash, *TestTransaction]

func (*TestNetwork) SendBatch

func (n *TestNetwork) SendBatch(to uint16, batch *narwhal.Batch[TestHash, *TestTransaction])

func (*TestNetwork) SendCertificate

func (n *TestNetwork) SendCertificate(to uint16, cert *narwhal.Certificate[TestHash])

func (*TestNetwork) SendVote

func (n *TestNetwork) SendVote(validatorIndex uint16, vote *narwhal.HeaderVote[TestHash])

type TestPublicKey

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

TestPublicKey wraps an Ed25519 public key.

func (TestPublicKey) Bytes

func (k TestPublicKey) Bytes() []byte

Bytes returns the public key bytes.

func (TestPublicKey) Equals

func (k TestPublicKey) Equals(other interface{ Bytes() []byte }) bool

Equals returns true if the keys are equal.

func (TestPublicKey) Verify

func (k TestPublicKey) Verify(message, signature []byte) bool

Verify verifies a signature.

type TestSigner

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

TestSigner wraps an Ed25519 private key.

func NewTestSigner

func NewTestSigner() *TestSigner

NewTestSigner creates a new test signer with a random key.

func (*TestSigner) PublicKey

func (s *TestSigner) PublicKey() narwhal.PublicKey

PublicKey returns the public key.

func (*TestSigner) Sign

func (s *TestSigner) Sign(message []byte) ([]byte, error)

Sign signs a message.

type TestStorage

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

TestStorage is an in-memory storage for testing.

func NewTestStorage

func NewTestStorage() *TestStorage

NewTestStorage creates a new test storage.

func (*TestStorage) Close

func (s *TestStorage) Close() error

func (*TestStorage) DeleteBeforeRound

func (s *TestStorage) DeleteBeforeRound(_ uint64) error

func (*TestStorage) GetBatch

func (s *TestStorage) GetBatch(digest TestHash) (*narwhal.Batch[TestHash, *TestTransaction], error)

func (*TestStorage) GetCertificate

func (s *TestStorage) GetCertificate(digest TestHash) (*narwhal.Certificate[TestHash], error)

func (*TestStorage) GetCertificatesByRound

func (s *TestStorage) GetCertificatesByRound(round uint64) ([]*narwhal.Certificate[TestHash], error)

func (*TestStorage) GetCertificatesInRange

func (s *TestStorage) GetCertificatesInRange(startRound, endRound uint64) ([]*narwhal.Certificate[TestHash], error)

func (*TestStorage) GetHeader

func (s *TestStorage) GetHeader(digest TestHash) (*narwhal.Header[TestHash], error)

func (*TestStorage) GetHighestRound

func (s *TestStorage) GetHighestRound() (uint64, error)

func (*TestStorage) HasBatch

func (s *TestStorage) HasBatch(digest TestHash) bool

func (*TestStorage) PutBatch

func (s *TestStorage) PutBatch(batch *narwhal.Batch[TestHash, *TestTransaction]) error

func (*TestStorage) PutCertificate

func (s *TestStorage) PutCertificate(cert *narwhal.Certificate[TestHash]) error

func (*TestStorage) PutHeader

func (s *TestStorage) PutHeader(header *narwhal.Header[TestHash]) error

func (*TestStorage) PutHighestRound

func (s *TestStorage) PutHighestRound(round uint64) error

type TestTransaction

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

TestTransaction is a simple transaction for testing.

func NewTestTransaction

func NewTestTransaction(data []byte) *TestTransaction

NewTestTransaction creates a new test transaction.

func NewTestTransactionSized

func NewTestTransactionSized(id []byte, size int) *TestTransaction

NewTestTransactionSized creates a test transaction of a specific size. The data is padded with zeros to reach the target size.

func TransactionFromBytes

func TransactionFromBytes(data []byte) (*TestTransaction, error)

TransactionFromBytes deserializes a transaction.

func (*TestTransaction) Bytes

func (t *TestTransaction) Bytes() []byte

Bytes returns the transaction data.

func (*TestTransaction) Hash

func (t *TestTransaction) Hash() TestHash

Hash returns the transaction hash.

type TestValidatorSet

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

TestValidatorSet is a validator set for testing.

func NewTestValidatorSet

func NewTestValidatorSet(n int) *TestValidatorSet

NewTestValidatorSet creates a new validator set with n validators.

func (*TestValidatorSet) Contains

func (v *TestValidatorSet) Contains(index uint16) bool

Contains returns true if the index is valid.

func (*TestValidatorSet) Count

func (v *TestValidatorSet) Count() int

Count returns the number of validators.

func (*TestValidatorSet) F

func (v *TestValidatorSet) F() int

F returns the max Byzantine faults.

func (*TestValidatorSet) GetByIndex

func (v *TestValidatorSet) GetByIndex(index uint16) (narwhal.PublicKey, error)

GetByIndex returns the public key for a validator.

func (*TestValidatorSet) GetSigner

func (v *TestValidatorSet) GetSigner(index uint16) *TestSigner

GetSigner returns the signer for a validator index.

Jump to

Keyboard shortcuts

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