Documentation
¶
Overview ¶
Package testutil provides test utilities for the Narwhal library.
Index ¶
- type TestHash
- type TestNetwork
- func (n *TestNetwork) BroadcastBatch(batch *narwhal.Batch[TestHash, *TestTransaction])
- func (n *TestNetwork) BroadcastCertificate(cert *narwhal.Certificate[TestHash])
- func (n *TestNetwork) BroadcastHeader(header *narwhal.Header[TestHash])
- func (n *TestNetwork) Close() error
- func (n *TestNetwork) Connect(other *TestNetwork)
- func (n *TestNetwork) FetchBatch(_ uint16, _ TestHash) (*narwhal.Batch[TestHash, *TestTransaction], error)
- func (n *TestNetwork) FetchCertificate(_ uint16, _ TestHash) (*narwhal.Certificate[TestHash], error)
- func (n *TestNetwork) FetchCertificatesInRange(_ uint16, _, _ uint64) ([]*narwhal.Certificate[TestHash], error)
- func (n *TestNetwork) Receive() <-chan narwhal.Message[TestHash, *TestTransaction]
- func (n *TestNetwork) SendBatch(to uint16, batch *narwhal.Batch[TestHash, *TestTransaction])
- func (n *TestNetwork) SendCertificate(to uint16, cert *narwhal.Certificate[TestHash])
- func (n *TestNetwork) SendVote(validatorIndex uint16, vote *narwhal.HeaderVote[TestHash])
- type TestPublicKey
- type TestSigner
- type TestStorage
- func (s *TestStorage) Close() error
- func (s *TestStorage) DeleteBeforeRound(_ uint64) error
- func (s *TestStorage) GetBatch(digest TestHash) (*narwhal.Batch[TestHash, *TestTransaction], error)
- func (s *TestStorage) GetCertificate(digest TestHash) (*narwhal.Certificate[TestHash], error)
- func (s *TestStorage) GetCertificatesByRound(round uint64) ([]*narwhal.Certificate[TestHash], error)
- func (s *TestStorage) GetCertificatesInRange(startRound, endRound uint64) ([]*narwhal.Certificate[TestHash], error)
- func (s *TestStorage) GetHeader(digest TestHash) (*narwhal.Header[TestHash], error)
- func (s *TestStorage) GetHighestRound() (uint64, error)
- func (s *TestStorage) HasBatch(digest TestHash) bool
- func (s *TestStorage) PutBatch(batch *narwhal.Batch[TestHash, *TestTransaction]) error
- func (s *TestStorage) PutCertificate(cert *narwhal.Certificate[TestHash]) error
- func (s *TestStorage) PutHeader(header *narwhal.Header[TestHash]) error
- func (s *TestStorage) PutHighestRound(round uint64) error
- type TestTransaction
- type TestValidatorSet
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 HashFromBytes ¶
HashFromBytes creates a TestHash from bytes.
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 (n *TestNetwork) FetchBatch(_ uint16, _ TestHash) (*narwhal.Batch[TestHash, *TestTransaction], error)
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.
type TestStorage ¶
type TestStorage struct {
// contains filtered or unexported fields
}
TestStorage is an in-memory storage for testing.
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) 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) 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.