Documentation ¶
Index ¶
- Constants
- Variables
- func AssertEventually(t *testing.T, f func() bool)
- func Context(t *testing.T) (ctx context.Context)
- func IntToHex(n int) string
- func MustParseURL(t *testing.T, input string) *url.URL
- func NewAddress() common.Address
- func NewRandomEVMChainID() *big.Int
- func NewRandomInt64() int64
- func NewWSServer(t *testing.T, chainID *big.Int, callback JSONRPCHandler) (ts *testWSServer)
- func Random32Byte() (b [32]byte)
- func RequireLogMessage(t *testing.T, observedLogs *observer.ObservedLogs, msg string)
- func SkipShort(tb testing.TB, why string)
- func SkipShortDB(tb testing.TB)
- func TestCtx(t *testing.T) context.Context
- func WSServerURL(t *testing.T, s *httptest.Server) *url.URL
- func WaitForLogMessage(t *testing.T, observedLogs *observer.ObservedLogs, msg string)
- func WaitForLogMessageCount(t *testing.T, observedLogs *observer.ObservedLogs, msg string, count int)
- func WaitTimeout(t *testing.T) time.Duration
- func WaitWithTimeout(t *testing.T, ch <-chan struct{}, failMsg string)
- type JSONRPCHandler
Constants ¶
const DefaultWaitTimeout = 30 * time.Second
DefaultWaitTimeout is the default wait timeout. If you have a *testing.T, use WaitTimeout instead.
const TestInterval = 10 * time.Millisecond
TestInterval is just a sensible poll interval that gives fast tests without risk of spamming
Variables ¶
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
Functions ¶
func AssertEventually ¶ added in v1.3.0
AssertEventually waits for f to return true
func MustParseURL ¶ added in v1.3.0
MustParseURL parses the URL or fails the test
func NewRandomEVMChainID ¶ added in v1.3.0
NewRandomEVMChainID returns a suitable random chain ID that will not conflict with fixtures
func NewRandomInt64 ¶ added in v1.3.0
func NewRandomInt64() int64
NewRandomInt64 returns a (non-cryptographically secure) random positive int64
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 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 SkipShortDB ¶ added in v1.3.0
SkipShortDB skips tb during -short runs, and notes the DB dependency.
func WSServerURL ¶ added in v1.3.0
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 ¶
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
WaitWithTimeout waits for the channel to close (or receive anything) and fatals the test if the default wait timeout is exceeded