testutil

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const TotalWeight = 1<<16 - 1 // max uint16

Variables

View Source
var (
	PrivKey1 *ecdsa.PrivateKey // has weight 1/7
	PrivKey2 *ecdsa.PrivateKey // has weight 3/7
	PrivKey3 *ecdsa.PrivateKey // has weight 3/7
)
View Source
var MockSigningPolicy, MockPrivKeys = GeneratePolicy(100, true)
View Source
var TestSigningPolicy *policy.SigningPolicy

Functions

func CreateBlock

func CreateBlock(prevHash string, number uint64) (*database.Block, common.Hash)

func GeneratePolicy

func GeneratePolicy(n int, randomWeights bool) (*policy.SigningPolicy, []*ecdsa.PrivateKey)

GeneratePolicy creates a policy with n providers and returns the policy and providers private keys.

If randomWeights is true, the weights are randomized, if not, the weights are uniform.

func InMemoryDB

func InMemoryDB(t *testing.T, name string) (*gorm.DB, string)

func RandomNormalizedArray

func RandomNormalizedArray(n int, seed int64) []float64

RandomNormalizedArray generates an array of n random floats that sum to 1

Types

type MemStorage

type MemStorage[T any] struct {
	// contains filtered or unexported fields
}

MemStorage is an in-memory implementation of storage.Storage[T] for use in tests.

func NewMemStorage

func NewMemStorage[T any]() *MemStorage[T]

NewMemStorage creates a new empty MemStorage[T].

func (*MemStorage[T]) Get

func (k *MemStorage[T]) Get(_ context.Context, key string) (T, error)

func (*MemStorage[T]) Remove

func (k *MemStorage[T]) Remove(_ context.Context, key string) error

func (*MemStorage[T]) Set

func (k *MemStorage[T]) Set(_ context.Context, key string, item T) error

func (*MemStorage[T]) SetWithTTL

func (k *MemStorage[T]) SetWithTTL(ctx context.Context, key string, item T, _ time.Duration) error

Jump to

Keyboard shortcuts

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