testutil

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package testutil contains mock deployers for interacting with the mock backend

Index

Constants

View Source
const (
	// TestContractType is the type of the test contract.
	TestContractType contractTypeImpl = iota
)

Variables

View Source
var AllContractTypes []contractTypeImpl

AllContractTypes is a list of all contract types. Since we use stringer and this is a testing library, instead of manually copying all these out we pull the names out of stringer. In order to make sure stringer is updated, we panic on any method called where the index is higher than the stringer array length.

Functions

func EmitEvents added in v0.0.207

func EmitEvents(ctx context.Context, t *testing.T, backend backends.SimulatedTestBackend, desiredBlockHeight uint64, testChainHandler *TestChainHandler) error

EmitEvents emits events from the test contracts until the desired block height is reached.

func GetLogsUntilNoneLeft added in v0.0.207

func GetLogsUntilNoneLeft(ctx context.Context, testDB db.EventDB, filter db.LogFilter) ([]*types.Log, error)

GetLogsUntilNoneLeft gets all receipts from the database until there are none left (iterates page num).

func GetReceiptsUntilNoneLeft added in v0.0.207

func GetReceiptsUntilNoneLeft(ctx context.Context, testDB db.EventDB, filter db.ReceiptFilter) ([]types.Receipt, error)

GetReceiptsUntilNoneLeft gets all receipts from the database until there are none left (iterates page num).

func GetTxBlockNumber added in v0.0.207

func GetTxBlockNumber(ctx context.Context, chain backends.SimulatedTestBackend, tx *types.Transaction) (uint64, error)

GetTxBlockNumber gets the block number of a transaction.

func MakeRandomLog added in v0.0.207

func MakeRandomLog(txHash common.Hash) types.Log

MakeRandomLog makes a random log.

func NewTestContractDeployer

NewTestContractDeployer creates a new test contract deployer.

func PopulateChainsWithLogs added in v0.0.207

func PopulateChainsWithLogs(ctx context.Context, t *testing.T, chainBackends map[uint32]geth.Backend, desiredBlockHeight uint64, managers []*DeployManager, handler metrics.Handler) (map[uint32]*TestChainHandler, map[uint32][]backend.ScribeBackend, error)

PopulateChainsWithLogs creates scribe backends for each chain backend and emits events from various contracts on each chain.

func ReachBlockHeight added in v0.0.207

func ReachBlockHeight(ctx context.Context, t *testing.T, backend backends.SimulatedTestBackend, desiredBlockHeight uint64) error

ReachBlockHeight reaches a block height on a backend.

func StartOmnirpcServer added in v0.0.207

func StartOmnirpcServer(ctx context.Context, t *testing.T, backend backends.SimulatedTestBackend) string

StartOmnirpcServer starts an omnirpc server and returns the url to it.

Types

type DeployManager

type DeployManager struct {
	*manager.DeployerManager
}

DeployManager wraps DeployManager and allows typed contract handles to be returned.

func NewDeployManager

func NewDeployManager(t *testing.T) *DeployManager

NewDeployManager creates a deploy manager.

func (*DeployManager) GetTestContract

GetTestContract gets the test contract.

type TestChainHandler added in v0.0.207

type TestChainHandler struct {
	Addresses           []common.Address
	ContractStartBlocks map[common.Address]uint64
	ContractRefs        map[common.Address]*testcontract.TestContractRef
	EventsEmitted       map[common.Address]uint64
}

TestChainHandler is a handler for interacting with test contracts on a chain to aid in building extensive tests. It is returned when emitting events with the test contracts in the PopulateWithLogs function.

func PopulateWithLogs added in v0.0.207

func PopulateWithLogs(ctx context.Context, t *testing.T, backend backends.SimulatedTestBackend, desiredBlockHeight uint64, managers []*DeployManager) (*TestChainHandler, error)

PopulateWithLogs populates a backend with logs until it reaches a desired block height.

nolint:cyclop

type TestContractDeployer

type TestContractDeployer struct {
	*deployer.BaseDeployer
}

TestContractDeployer deploys a test contract.

func (TestContractDeployer) Deploy

Deploy deploys the test contract.

Directories

Path Synopsis
Package testcontract contains a contract used for testing event and transaction emission.
Package testcontract contains a contract used for testing event and transaction emission.

Jump to

Keyboard shortcuts

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