testutils

package
v0.0.0-...-03d585d Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2025 License: MIT Imports: 34 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 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 AssertEventually

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

AssertEventually calls assert.Eventually with default wait and tick durations.

func Context

func Context(tb testing.TB) context.Context

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

func Head(val interface{}) *evmtypes.Head

Head given the value convert it into an Head

func MustExec

func MustExec(t *testing.T, ds sqlutil.DataSource, stmt string, args ...interface{})

func MustNewSimTransactor

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

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

func NewAddress

func NewAddress() common.Address

NewAddress return a random new address

func NewAddressPtr

func NewAddressPtr() *common.Address

func NewHash

func NewHash() common.Hash

NewHash return random Keccak256

func NewIndependentSqlxDB

func NewIndependentSqlxDB(t testing.TB) *sqlx.DB

NewIndependentSqlxDB return a new independent test database, which does not use txdb and therefore supports txs etc. Use this with caution, as it is much more costly than NewSqlxDB.

func NewLegacyTransaction

func NewLegacyTransaction(nonce uint64, to common.Address, value *big.Int, gasLimit uint32, gasPrice *big.Int, data []byte) *types.Transaction

func NewRandomEVMChainID

func NewRandomEVMChainID() *big.Int

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

func NewSqlxDB

func NewSqlxDB(t testing.TB) *sqlx.DB

func NewTestChainScopedConfig deprecated

func NewTestChainScopedConfig(t testing.TB, overrideFn func(c *toml.EVMConfig)) config.ChainScopedConfig

Deprecated: use configtest.NewChainScopedConfig

func NewWSServer

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 RequireEventually

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

RequireEventually calls assert.Eventually with default wait and tick durations.

func SkipShortDB

func SkipShortDB(tb testing.TB)

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

func WSServerURL

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

WSServerURL returns a ws:// url for the server

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.

Types

type Awaiter

type Awaiter chan struct{}

func NewAwaiter

func NewAwaiter() Awaiter

func (Awaiter) AssertHappened

func (a Awaiter) AssertHappened(t *testing.T, expected bool)

func (Awaiter) AwaitOrFail

func (a Awaiter) AwaitOrFail(t testing.TB, durationParams ...time.Duration)

func (Awaiter) ItHappened

func (a Awaiter) ItHappened()

type JSONRPCHandler

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

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

	Error struct {
		Code    int
		Message string
	}
}

type RawSub

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

func NewRawSub

func NewRawSub[T any](ch chan<- T, err <-chan error) RawSub[T]

func (*RawSub[T]) CloseCh

func (r *RawSub[T]) CloseCh()

func (*RawSub[T]) TrySend

func (r *RawSub[T]) TrySend(t T)

Jump to

Keyboard shortcuts

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