Documentation
¶
Index ¶
- Constants
- Variables
- func RandBytes(n int) []byte
- type DummyHeader
- func (d *DummyHeader) ChainID() string
- func (d *DummyHeader) Hash() header.Hash
- func (d *DummyHeader) Height() uint64
- func (d *DummyHeader) IsExpired(period time.Duration) bool
- func (d *DummyHeader) IsRecent(blockTime time.Duration) bool
- func (d *DummyHeader) IsZero() bool
- func (d *DummyHeader) LastHeader() header.Hash
- func (d *DummyHeader) MarshalBinary() ([]byte, error)
- func (d *DummyHeader) New() *DummyHeader
- func (d *DummyHeader) Time() time.Time
- func (d *DummyHeader) UnmarshalBinary(data []byte) error
- func (d *DummyHeader) Validate() error
- func (d *DummyHeader) Verify(hdr *DummyHeader) error
- type DummySuite
- type Generator
- type Store
- func (m *Store[H]) Append(_ context.Context, headers ...H) error
- func (m *Store[H]) DeleteRange(ctx context.Context, from, to uint64) error
- func (m *Store[H]) Get(_ context.Context, hash header.Hash) (H, error)
- func (m *Store[H]) GetByHeight(_ context.Context, height uint64) (H, error)
- func (m *Store[H]) GetRange(ctx context.Context, from, to uint64) ([]H, error)
- func (m *Store[H]) GetRangeByHeight(ctx context.Context, fromHead H, to uint64) ([]H, error)
- func (m *Store[H]) Has(context.Context, header.Hash) (bool, error)
- func (m *Store[H]) HasAt(_ context.Context, height uint64) bool
- func (m *Store[H]) Head(context.Context, ...header.HeadOption[H]) (H, error)
- func (m *Store[H]) Height() uint64
- func (m *Store[H]) Init(context.Context, H) error
- func (m *Store[H]) OnDelete(fn func(context.Context, uint64) error)
- func (m *Store[H]) Tail(context.Context) (H, error)
- type Subscriber
- func (mhs *Subscriber[H]) Cancel()
- func (mhs *Subscriber[H]) NextHeader(_ context.Context) (H, error)
- func (mhs *Subscriber[H]) SetVerifier(func(context.Context, H) error) error
- func (mhs *Subscriber[H]) Stop(context.Context) error
- func (mhs *Subscriber[H]) Subscribe() (header.Subscription[H], error)
Constants ¶
View Source
const HeaderTime = time.Nanosecond
Variables ¶
View Source
var ErrDummyVerify = errors.New("dummy verify error")
Functions ¶
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
// VerifyFn can be used to change header.Verify behavior per header.
VerifyFn func(hdr *DummyHeader) error `json:"-"`
// 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) 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 Store ¶
type Store[H header.Header[H]] struct { HeaderMu sync.Mutex Headers map[uint64]H HeadHeight uint64 TailHeight uint64 // contains filtered or unexported fields }
func NewDummyStore ¶
func NewDummyStore(t *testing.T) *Store[*DummyHeader]
NewDummyStore creates a store for DummyHeader.
func NewStore ¶
NewStore creates a generic mock store supporting different type of Headers based on Generator.
func (*Store[H]) DeleteRange ¶ added in v0.8.0
func (*Store[H]) GetByHeight ¶
func (*Store[H]) GetRangeByHeight ¶
GetRangeByHeight returns headers in range [from; to).
type Subscriber ¶
func NewDummySubscriber ¶
func NewDummySubscriber() *Subscriber[*DummyHeader]
func (*Subscriber[H]) Cancel ¶
func (mhs *Subscriber[H]) Cancel()
func (*Subscriber[H]) NextHeader ¶
func (mhs *Subscriber[H]) NextHeader(_ 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]) Subscribe ¶
func (mhs *Subscriber[H]) Subscribe() (header.Subscription[H], error)
Click to show internal directories.
Click to hide internal directories.