Documentation ¶
Index ¶
- Constants
- Variables
- func AfterWaitTimeout(t *testing.T) <-chan time.Time
- func AssertCount(t *testing.T, db *sqlx.DB, tableName string, expected int64)
- func AssertCountPerSubject(t *testing.T, db *sqlx.DB, expected int64, subject uuid.UUID)
- func AssertEventually(t *testing.T, f func() bool)
- func Context(tb testing.TB) context.Context
- func IntToHex(n int) string
- func LoggerAssertMaxLevel(t *testing.T, lvl zapcore.Level) logger.Logger
- func MustNewSimTransactor(t testing.TB) *bind.TransactOpts
- func MustParseBigInt(t *testing.T, input string) *big.Int
- func MustParseURL(t testing.TB, input string) *url.URL
- func NewAddress() common.Address
- func NewAddressPtr() *common.Address
- func NewRandomEVMChainID() *big.Int
- func NewRandomPositiveInt64() int64
- func NewTestFlagSet() *flag.FlagSet
- func NewWSServer(t *testing.T, chainID *big.Int, callback JSONRPCHandler) (ts *testWSServer)
- func Ptr[T any](v T) *T
- func Random32Byte() (b [32]byte)
- func RandomizeName(n string) string
- func RequireLogMessage(t *testing.T, observedLogs *observer.ObservedLogs, msg string)
- func SkipShort(tb testing.TB, why string)
- func SkipShortDB(tb testing.TB)
- 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
- type JSONRPCResponse
Constants ¶
const DefaultWaitTimeout = 30 * time.Second
DefaultWaitTimeout is the default wait timeout. If you have a *testing.T, use WaitTimeout instead.
const (
// Password just a password we use everywhere for testing
Password = "16charlengthp4SsW0rD1!@#_"
)
const TestInterval = 100 * 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
var SimulatedChainID = big.NewInt(1337)
SimulatedChainID is the chain ID for the go-ethereum simulated backend
Functions ¶
func AfterWaitTimeout ¶
AfterWaitTimeout returns a channel that will send a time value when the WaitTimeout is reached
func AssertCountPerSubject ¶ added in v2.3.0
func AssertEventually ¶
AssertEventually waits for f to return true
func LoggerAssertMaxLevel ¶
LoggerAssertMaxLevel returns a test logger which is observed on cleanup and asserts that no lines were logged at a higher level.
func MustNewSimTransactor ¶
func MustNewSimTransactor(t testing.TB) *bind.TransactOpts
MustNewSimTransactor returns a transactor for interacting with the geth simulated backend.
func MustParseBigInt ¶
MustParseBigInt parses a big int value from string or fails the test
func MustParseURL ¶
MustParseURL parses the URL or fails the test
func NewAddressPtr ¶
func NewRandomEVMChainID ¶
NewRandomEVMChainID returns a suitable random chain ID that will not conflict with fixtures
func NewRandomPositiveInt64 ¶
func NewRandomPositiveInt64() int64
NewRandomPositiveInt64 returns a (non-cryptographically secure) random positive int64
func NewTestFlagSet ¶
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 RandomizeName ¶
RandomizeName appends a random UUID to the provided name
func RequireLogMessage ¶
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 ¶
SkipShortDB skips tb during -short runs, and notes the DB dependency.
func WSServerURL ¶
WSServerURL returns a ws:// url for the server
func WaitForLogMessage ¶
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 ¶
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 ¶
WaitWithTimeout waits for the channel to close (or receive anything) and fatals the test if the default wait timeout is exceeded
Types ¶
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.