headertest

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDummyVerify = errors.New("dummy verify error")

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 {
	Chainid      string
	PreviousHash header.Hash
	HeightI      uint64
	Timestamp    time.Time

	// VerifyFailure allows for testing scenarios where a header would fail
	// verification. When set to true, it forces a failure.
	VerifyFailure bool
	// SoftFailure allows for testing scenarios where a header would fail
	// verification with SoftFailure set to true
	SoftFailure bool
	// 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() uint64

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() *DummyHeader

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(hdr *DummyHeader) 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[H]] interface {
	NextHeader() H
}

type Store

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

func NewDummyStore

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

NewDummyStore creates a store for DummyHeader.

func NewStore

func NewStore[H header.Header[H]](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]) GetRange added in v0.4.0

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

func (*Store[H]) GetRangeByHeight

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

GetRangeByHeight returns headers in range [from; to).

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, ...header.HeadOption[H]) (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

type Subscriber

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

func NewDummySubscriber

func NewDummySubscriber() *Subscriber[*DummyHeader]

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]) SetVerifier added in v0.3.0

func (mhs *Subscriber[H]) SetVerifier(func(context.Context, H) error) 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