firehosetest

package
v0.0.0-...-948650a Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package firehosetest provides test doubles for the StreamingFast Firehose service, coupled to EVM code running on a simulated blockchain.

See the tests of the github.com/cxkoda firehose package for example usage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Arg

func Arg(tb testing.TB, name string, val interface{}, indexed bool) *ethpb.Argument

Arg acts similarly to ethpb.NewArgument(), but allows for concrete types that can be unambiguously mapped to ethpb.Value_Payload types. If unmabiguous mapping isn't possible, tb.Fatal() will be called.

func CmpOpts

func CmpOpts() cmp.Options

CmpOpts returns options for performing diffs between Hydrant.BlockResponse test results and expected values.

func CollectAll

func CollectAll(tb testing.TB, client HydrantClient) []*svcpb.BlockResponse

CollectAll calls client.Recv() until an error occurs. If the error is io.EOF then all received BlockResponses are returned, otherwise the error is reported on tb.Fatal. io.EOF is the standard end-of-stream indicator for gRPC stream methods, so indicates a clean close.

func Cursor

func Cursor(b *types.Block) string

Cursor returns the cursor returned by a fake Firehose for a given block. This will change and its stability MUST NOT be depended upon. It is exposed to couple test results with their expected values.

Types

type Config

type Config struct {
	// UseETHServer instructs NewFake to call firehose.ETHServer() instead of
	// firehose.ETHClient(). This typically makes no difference, but SHOULD
	// ideally match whichever is to be used in production in case there are
	// edge-case differences. If true, the returned server will be connected to
	// with the grpctest package.
	UseETHServer bool
}

A Config configures new Fakes.

func (*Config) NewFake

func (c *Config) NewFake(ctx context.Context, tb testing.TB) *Fake

NewFake returns a new Fake, reporting all errors on tb.Fatal.

type Fake

type Fake struct {
	Client    svcpb.HydrantServiceClient
	RawClient hosepb.StreamClient
	// contains filtered or unexported fields
}

A Fake couples a bind.ContractBackend() running a real EVM implementation, with a fake Firehose Stream server. Solidity bindings generated by abigen can be used to trigger real EVM events that are propagated to the Firehose fake.

The Firehose fake can be accessed directly with the RawClient, or abstracted with ETH-specific "Hydrant" APIs via the Client. Filtering other than Start- and StopBlockNum is not currently supported by the Firehose fake so all transactions, in all blocks, are propagated. This MUST NOT be depended upon, and is open to breaking changes as the fake's behaviour approaches the real Firehose.

func NewFake

func NewFake(ctx context.Context, tb testing.TB) *Fake

NewFake returns NewFake() called on a zero Config.

func (*Fake) Backend

func (f *Fake) Backend() bind.ContractBackend

Backend returns the ContractBackend running the Fake's EVM.

func (*Fake) MineBlock

func (f *Fake) MineBlock(ctx context.Context, tb testing.TB) *types.Block

MineBlock "mines" all transactions sent to f.Backend(). This moves the transactions out of the pending state, and queues the block for being returned by the Fake's Firehose/Hydrant clients.

This is NOT thread-safe so all blocks MUST be mined before calls to either of the gRPC clients.

func (*Fake) RPCClient

func (f *Fake) RPCClient(ctx context.Context, tb testing.TB) *ethclient.Client

RPCClient returns an ethclient.Client connected to the Fake's underlying EVM backend.

func (*Fake) TxOpts

func (f *Fake) TxOpts() *bind.TransactOpts

TxOpts returns TransactOpts for sending transactions to f.Backend().

type HydrantClient

type HydrantClient interface {
	Recv() (*svcpb.BlockResponse, error)
}

A HydrantClient can receive BlockResponse protos. It is implemented by both of the HydrantService_{EventsClient,ERC721TransferEventsClient} types.

Jump to

Keyboard shortcuts

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