testutils

package
v1.11.1-beta2 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2023 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultWaitTimeout = 30 * time.Second

DefaultWaitTimeout is the default wait timeout. If you have a *testing.T, use WaitTimeout instead.

View Source
const (
	// Password just a password we use everywhere for testing
	Password = "16charlengthp4SsW0rD1!@#_"
)
View Source
const TestInterval = 100 * time.Millisecond

TestInterval is just a sensible poll interval that gives fast tests without risk of spamming

Variables

View Source
var FixtureChainID = big.NewInt(0)

FixtureChainID matches the chain always added by fixtures.sql It is set to 0 since no real chain ever has this ID and allows a virtual "test" chain ID to be used without clashes

View Source
var SimulatedChainID = big.NewInt(1337)

SimulatedChainID is the chain ID for the go-ethereum simulated backend

Functions

func AfterWaitTimeout added in v1.5.0

func AfterWaitTimeout(t *testing.T) <-chan time.Time

AfterWaitTimeout returns a channel that will send a time value when the WaitTimeout is reached

func AssertCount added in v1.8.0

func AssertCount(t *testing.T, db *sqlx.DB, tableName string, expected int64)

func AssertEventually added in v1.3.0

func AssertEventually(t *testing.T, f func() bool)

AssertEventually waits for f to return true

func Context

func Context(tb testing.TB) context.Context

Context returns a context with the test's deadline, if available.

func IntToHex added in v1.3.0

func IntToHex(n int) string

IntToHex converts int to geth-compatible hex

func LoggerAssertMaxLevel added in v1.4.0

func LoggerAssertMaxLevel(t *testing.T, lvl zapcore.Level) logger.Logger

LoggerAssertMaxLevel returns a test logger which is observed on cleanup and asserts that no lines were logged at a higher level.

func MustNewSimTransactor added in v1.4.0

func MustNewSimTransactor(t *testing.T) *bind.TransactOpts

MustNewSimTransactor returns a transactor for interacting with the geth simulated backend.

func MustParseBigInt added in v1.4.0

func MustParseBigInt(t *testing.T, input string) *big.Int

MustParseBigInt parses a big int value from string or fails the test

func MustParseURL added in v1.3.0

func MustParseURL(t testing.TB, input string) *url.URL

MustParseURL parses the URL or fails the test

func NewAddress

func NewAddress() common.Address

NewAddress return a random new address

func NewAddressPtr added in v1.5.0

func NewAddressPtr() *common.Address

func NewRandomEVMChainID added in v1.3.0

func NewRandomEVMChainID() *big.Int

NewRandomEVMChainID returns a suitable random chain ID that will not conflict with fixtures

func NewRandomPositiveInt64 added in v1.8.0

func NewRandomPositiveInt64() int64

NewRandomPositiveInt64 returns a (non-cryptographically secure) random positive int64

func NewTestFlagSet added in v1.8.0

func NewTestFlagSet() *flag.FlagSet

func NewWSServer added in v1.3.0

func NewWSServer(t *testing.T, chainID *big.Int, callback JSONRPCHandler) (ts *testWSServer)

NewWSServer starts a websocket server which invokes callback for each message received. If chainID is set, then eth_chainId calls will be automatically handled.

func Ptr added in v1.10.0

func Ptr[T any](v T) *T

Ptr takes pointer of anything

func Random32Byte

func Random32Byte() (b [32]byte)

Random32Byte returns a random [32]byte

func RandomizeName added in v1.6.0

func RandomizeName(n string) string

RandomizeName appends a random UUID to the provided name

func RequireLogMessage added in v1.3.0

func RequireLogMessage(t *testing.T, observedLogs *observer.ObservedLogs, msg string)

RequireLogMessage fails the test if emitted logs don't contain the given message

func SkipShort added in v1.3.0

func SkipShort(tb testing.TB, why string)

SkipShort skips tb during -short runs, and notes why.

func SkipShortDB added in v1.3.0

func SkipShortDB(tb testing.TB)

SkipShortDB skips tb during -short runs, and notes the DB dependency.

func WSServerURL added in v1.3.0

func WSServerURL(t *testing.T, s *httptest.Server) *url.URL

WSServerURL returns a ws:// url for the server

func WaitForLogMessage added in v1.3.0

func WaitForLogMessage(t *testing.T, observedLogs *observer.ObservedLogs, msg string)

WaitForLogMessage waits until at least one log message containing the specified msg is emitted. NOTE: This does not "pop" messages so it cannot be used multiple times to check for new instances of the same msg. See WaitForLogMessageCount instead.

Get a *observer.ObservedLogs like so:

observedZapCore, observedLogs := observer.New(zap.DebugLevel)
lggr := logger.TestLogger(t, observedZapCore)

func WaitForLogMessageCount added in v1.3.0

func WaitForLogMessageCount(t *testing.T, observedLogs *observer.ObservedLogs, msg string, count int)

WaitForLogMessageCount waits until at least count log message containing the specified msg is emitted

func WaitTimeout

func WaitTimeout(t *testing.T) time.Duration

WaitTimeout returns a timeout based on the test's Deadline, if available. Especially important to use in parallel tests, as their individual execution can get paused for arbitrary amounts of time.

func WaitWithTimeout added in v1.3.0

func WaitWithTimeout(t *testing.T, ch <-chan struct{}, failMsg string)

WaitWithTimeout waits for the channel to close (or receive anything) and fatals the test if the default wait timeout is exceeded

Types

type JSONRPCHandler added in v1.3.0

type JSONRPCHandler func(reqMethod string, reqParams gjson.Result) JSONRPCResponse

JSONRPCHandler is called with the method and request param(s). respResult will be sent immediately. notifyResult is optional, and sent after a short delay.

type JSONRPCResponse added in v1.11.0

type JSONRPCResponse struct {
	Result, Notify string // raw JSON (i.e. quoted strings etc.)

	Error struct {
		Code    int
		Message string
	}
}

Directories

Path Synopsis
v2
v2

Jump to

Keyboard shortcuts

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