rpctest

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package rpctest provides utilities for testing RPC methods.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunTestCases added in v0.9.0

func RunTestCases[T any](t *testing.T, tests []TestCase[T], opts ...cmp.Option)

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is a fake RPC endpoint that responds only to a single requests that is definded in a golden-file.

Request golden-files have the following format to define a single request and the corresponding response:

// Comments and empty lines will be ignored.
// Request starts with ">".
> {"jsonrpc":"2.0","id":1,"method":"eth_chainId"}
// Response starts with "<".
< {"jsonrpc":"2.0","id":1,"result":"0x1"}

func NewFileServer

func NewFileServer(t *testing.T, filename string) *Server

NewFileServer returns a new instance of Server that serves the golden-file from the given filename.

func NewServer

func NewServer(t *testing.T, r io.Reader) *Server

NewServer returns a new instance of Server that serves the golden-file from Reader r.

func (*Server) Close

func (srv *Server) Close()

Close shuts down the server.

func (*Server) ServeHTTP

func (srv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) URL

func (srv *Server) URL() string

URL returns the servers RPC endpoint url.

type TestCase added in v0.9.0

type TestCase[T any] struct {
	Golden  string                   // File name in local "testdata/" directory without ".golden" extension
	Call    w3types.CallerFactory[T] // Call to test
	GotRet  T                        // Actual return value of the call
	WantRet T                        // Wanted return value of the call
	WantErr error                    // Wanted error of the call
}

Jump to

Keyboard shortcuts

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