headertest

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandBytes

func RandBytes(n int) []byte

RandBytes returns slice of n-bytes, or nil in case of error

Types

type DummyHeader

type DummyHeader struct {
	Raw
	// contains filtered or unexported fields
}

func RandDummyHeader

func RandDummyHeader(t *testing.T) *DummyHeader

func (*DummyHeader) ChainID

func (d *DummyHeader) ChainID() string

func (*DummyHeader) Hash

func (d *DummyHeader) Hash() header.Hash

func (*DummyHeader) Height

func (d *DummyHeader) Height() int64

func (*DummyHeader) IsExpired

func (d *DummyHeader) IsExpired(period time.Duration) bool

func (*DummyHeader) IsRecent

func (d *DummyHeader) IsRecent(blockTime time.Duration) bool

func (*DummyHeader) IsZero

func (d *DummyHeader) IsZero() bool

func (*DummyHeader) LastHeader

func (d *DummyHeader) LastHeader() header.Hash

func (*DummyHeader) MarshalBinary

func (d *DummyHeader) MarshalBinary() ([]byte, error)

func (*DummyHeader) New

func (d *DummyHeader) New() header.Header

func (*DummyHeader) Time

func (d *DummyHeader) Time() time.Time

func (*DummyHeader) UnmarshalBinary

func (d *DummyHeader) UnmarshalBinary(data []byte) error

func (*DummyHeader) Validate

func (d *DummyHeader) Validate() error

func (*DummyHeader) Verify

func (d *DummyHeader) Verify(header header.Header) error

type DummySuite

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

DummySuite provides everything you need to test chain of DummyHeaders. If not, please don't hesitate to extend it for your case.

func NewTestSuite

func NewTestSuite(t *testing.T) *DummySuite

NewTestSuite setups a new test suite.

func (*DummySuite) GenDummyHeaders

func (s *DummySuite) GenDummyHeaders(num int) []*DummyHeader

func (*DummySuite) Head

func (s *DummySuite) Head() *DummyHeader

func (*DummySuite) NextHeader

func (s *DummySuite) NextHeader() *DummyHeader

type Generator

type Generator[H header.Header] interface {
	NextHeader() H
}

type Raw

type Raw struct {
	ChainID      string
	PreviousHash header.Hash

	Height int64
	Time   time.Time
}

type Store

type Store[H header.Header] struct {
	Headers    map[int64]H
	HeadHeight int64
}

func NewDummyStore

func NewDummyStore(t *testing.T) *Store[*DummyHeader]

NewDummyStore creates a store for DummyHeader.

func NewStore

func NewStore[H header.Header](t *testing.T, gen Generator[H], numHeaders int) *Store[H]

NewStore creates a generic mock store supporting different type of Headers based on Generator.

func (*Store[H]) Append

func (m *Store[H]) Append(ctx context.Context, headers ...H) error

func (*Store[H]) Get

func (m *Store[H]) Get(ctx context.Context, hash header.Hash) (H, error)

func (*Store[H]) GetByHeight

func (m *Store[H]) GetByHeight(ctx context.Context, height uint64) (H, error)

func (*Store[H]) GetRangeByHeight

func (m *Store[H]) GetRangeByHeight(ctx context.Context, from, to uint64) ([]H, error)

func (*Store[H]) GetVerifiedRange

func (m *Store[H]) GetVerifiedRange(
	ctx context.Context,
	h H,
	to uint64,
) ([]H, error)

func (*Store[H]) Has

func (m *Store[H]) Has(context.Context, header.Hash) (bool, error)

func (*Store[H]) HasAt

func (m *Store[H]) HasAt(_ context.Context, height uint64) bool

func (*Store[H]) Head

func (m *Store[H]) Head(context.Context) (H, error)

func (*Store[H]) Height

func (m *Store[H]) Height() uint64

func (*Store[H]) Init

func (m *Store[H]) Init(context.Context, H) error

func (*Store[H]) Start

func (m *Store[H]) Start(context.Context) error

func (*Store[H]) Stop

func (m *Store[H]) Stop(context.Context) error

type Subscriber

type Subscriber[H header.Header] struct {
	Headers []H
}

func NewDummySubscriber

func NewDummySubscriber() *Subscriber[*DummyHeader]

func (*Subscriber[H]) AddValidator

func (mhs *Subscriber[H]) AddValidator(func(context.Context, H) pubsub.ValidationResult) error

func (*Subscriber[H]) Cancel

func (mhs *Subscriber[H]) Cancel()

func (*Subscriber[H]) NextHeader

func (mhs *Subscriber[H]) NextHeader(ctx context.Context) (H, error)

func (*Subscriber[H]) Stop

func (mhs *Subscriber[H]) Stop(context.Context) error

func (*Subscriber[H]) Subscribe

func (mhs *Subscriber[H]) Subscribe() (header.Subscription[H], error)

Jump to

Keyboard shortcuts

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