testutils

package
v0.42.2-experimental-b... Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2025 License: AGPL-3.0 Imports: 44 Imported by: 0

Documentation ¶

Index ¶

Constants ¶

View Source
const EOATestAccount1KeyHex = "9c647b8b7c4e7c3490668fb6c11473619db80c93704c70893d3813af4090c39c"

address: 658bdf435d810c91414ec09147daa6db62406379

Variables ¶

View Source
var TestComputationLimit = uint64(100_000_000)
View Source
var TestFlowEVMRootAddress = flow.Address{1, 2, 3, 4}

Functions ¶

func AggregatedPrecompiledCallsFixture ¶ added in v0.36.3

func AggregatedPrecompiledCallsFixture(t testing.TB) types.AggregatedPrecompiledCalls

func BlockEventToPayload ¶ added in v0.36.2

func BlockEventToPayload(t testing.TB, event flow.Event, evmContract flow.Address) *events.BlockEventPayload

func COAOwnershipProofFixture ¶ added in v0.33.30

func COAOwnershipProofFixture(t testing.TB) *types.COAOwnershipProof

func COAOwnershipProofInContextFixture ¶ added in v0.33.30

func COAOwnershipProofInContextFixture(t testing.TB) *types.COAOwnershipProofInContext

func CheckCadenceEventTypes ¶ added in v0.33.30

func CheckCadenceEventTypes(t testing.TB, events []cadence.Event, expectedTypes []string)

func ConvertToCadence ¶

func ConvertToCadence(data []byte) []cadence.Value

func DeployContract ¶

func DeployContract(t testing.TB, caller types.Address, tc *TestContract, led atree.Ledger, flowEVMRootAddress flow.Address)

func DeserializeAllocator ¶ added in v0.38.0

func DeserializeAllocator(filename string) (map[string]uint64, error)

Deserialize function: reads map data from a file

func DeserializeState ¶ added in v0.38.0

func DeserializeState(filename string) (map[string][]byte, error)

Deserialize function: reads map data from a file

func EncodeArgs ¶

func EncodeArgs(argValues []cadence.Value) [][]byte

func GetRandomLogFixture ¶

func GetRandomLogFixture(t testing.TB) *gethTypes.Log

func MakeCallData ¶ added in v0.33.30

func MakeCallData(t testing.TB, abiString string, name string, args ...interface{}) []byte

func RandomAddress ¶

func RandomAddress(t testing.TB) types.Address

func RandomBigInt ¶

func RandomBigInt(limit int64) *big.Int

func RandomCommonAddress ¶

func RandomCommonAddress(t testing.TB) gethCommon.Address

func RandomCommonHash ¶

func RandomCommonHash(t testing.TB) gethCommon.Hash

func RandomData ¶

func RandomData(t testing.TB) []byte

func RandomGas ¶

func RandomGas(limit int64) uint64

func RandomResultFixture ¶ added in v0.36.2

func RandomResultFixture(t testing.TB) *types.Result

func RandomUint256Int ¶ added in v0.36.2

func RandomUint256Int(limit int64) *uint256.Int

func RunWithDeployedContract ¶

func RunWithDeployedContract(t testing.TB, tc *TestContract, led atree.Ledger, flowEVMRootAddress flow.Address, f func(*TestContract))

func RunWithEOATestAccount ¶

func RunWithEOATestAccount(t testing.TB, led atree.Ledger, flowEVMRootAddress flow.Address, f func(*EOATestAccount))

func RunWithTestBackend ¶

func RunWithTestBackend(t testing.TB, f func(*TestBackend))

func RunWithTestFlowEVMRootAddress ¶

func RunWithTestFlowEVMRootAddress(t testing.TB, backend atree.Ledger, f func(flow.Address))

func SerializeAllocator ¶ added in v0.38.0

func SerializeAllocator(filename string, data map[string]uint64) error

Serialize function: saves map data to a file

func SerializeState ¶ added in v0.38.0

func SerializeState(filename string, data map[string][]byte) error

Serialize function: saves map data to a file

func SetupHandler ¶ added in v0.38.0

func SetupHandler(
	chainID flow.ChainID,
	backend types.Backend,
	rootAddr flow.Address,
) *handler.ContractHandler

func TxEventToPayload ¶ added in v0.36.2

func TxEventToPayload(t testing.TB, event flow.Event, evmContract flow.Address) *events.TransactionEventPayload

Types ¶

type EOATestAccount ¶

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

func FundAndGetEOATestAccount ¶

func FundAndGetEOATestAccount(t testing.TB, led atree.Ledger, flowEVMRootAddress flow.Address) *EOATestAccount

func GetTestEOAAccount ¶

func GetTestEOAAccount(t testing.TB, keyHex string) *EOATestAccount

func (*EOATestAccount) Address ¶

func (a *EOATestAccount) Address() types.Address

func (*EOATestAccount) Nonce ¶ added in v0.33.30

func (a *EOATestAccount) Nonce() uint64

func (*EOATestAccount) PrepareAndSignTx ¶

func (a *EOATestAccount) PrepareAndSignTx(
	t testing.TB,
	to gethCommon.Address,
	data []byte,
	amount *big.Int,
	gasLimit uint64,
	gasPrice *big.Int,
) *gethTypes.Transaction

func (*EOATestAccount) PrepareSignAndEncodeTx ¶

func (a *EOATestAccount) PrepareSignAndEncodeTx(
	t testing.TB,
	to gethCommon.Address,
	data []byte,
	amount *big.Int,
	gasLimit uint64,
	gasPrice *big.Int,
) []byte

func (*EOATestAccount) SetNonce ¶

func (a *EOATestAccount) SetNonce(nonce uint64)

func (*EOATestAccount) SignTx ¶

type MockUploader ¶ added in v0.33.30

type MockUploader struct {
	UploadFunc func(string, json.RawMessage) error
}

func (MockUploader) Upload ¶ added in v0.33.30

func (m MockUploader) Upload(id string, data json.RawMessage) error

type TestBackend ¶

type TestBackend struct {
	*TestValueStore

	*TestBlockInfo
	*TestRandomGenerator
	*TestContractFunctionInvoker

	*TestTracer
	*TestMetricsReporter
	*TestLoggerProvider
	// contains filtered or unexported fields
}

func (TestBackend) ComputationAvailable ¶

func (m TestBackend) ComputationAvailable(usage common.ComputationUsage) bool

func (TestBackend) ComputationIntensities ¶

func (m TestBackend) ComputationIntensities() meter.MeteredComputationIntensities

func (TestBackend) ComputationUsed ¶

func (m TestBackend) ComputationUsed() (uint64, error)

func (TestBackend) ConvertedServiceEvents ¶

func (vs TestBackend) ConvertedServiceEvents() flow.ServiceEventList

func (*TestBackend) DropEvents ¶

func (tb *TestBackend) DropEvents()

func (TestBackend) EmitEvent ¶

func (vs TestBackend) EmitEvent(event cadence.Event) error

func (TestBackend) Events ¶

func (vs TestBackend) Events() flow.EventsList

func (TestBackend) GenerateUUID ¶ added in v0.33.30

func (t TestBackend) GenerateUUID() (uint64, error)

func (*TestBackend) Get ¶ added in v0.33.30

func (TestBackend) InteractionUsed ¶

func (m TestBackend) InteractionUsed() (uint64, error)

func (TestBackend) MemoryUsed ¶

func (m TestBackend) MemoryUsed() (uint64, error)

func (TestBackend) MeterComputation ¶

func (m TestBackend) MeterComputation(usage common.ComputationUsage) error

func (TestBackend) MeterEmittedEvent ¶

func (m TestBackend) MeterEmittedEvent(byteSize uint64) error

func (TestBackend) MeterMemory ¶

func (m TestBackend) MeterMemory(usage common.MemoryUsage) error

func (TestBackend) Reset ¶

func (vs TestBackend) Reset()

func (TestBackend) ServiceEvents ¶

func (vs TestBackend) ServiceEvents() flow.EventsList

func (TestBackend) TotalEmittedEventBytes ¶

func (m TestBackend) TotalEmittedEventBytes() uint64

func (*TestBackend) TotalStorageSize ¶

func (tb *TestBackend) TotalStorageSize() int

type TestBlockInfo ¶ added in v0.33.30

type TestBlockInfo struct {
	GetCurrentBlockHeightFunc func() (uint64, error)
	GetBlockAtHeightFunc      func(height uint64) (runtime.Block, bool, error)
}

func (*TestBlockInfo) GetBlockAtHeight ¶ added in v0.33.30

func (tb *TestBlockInfo) GetBlockAtHeight(height uint64) (runtime.Block, bool, error)

GetBlockAtHeight returns the block at the given height.

func (*TestBlockInfo) GetCurrentBlockHeight ¶ added in v0.33.30

func (tb *TestBlockInfo) GetCurrentBlockHeight() (uint64, error)

GetCurrentBlockHeight returns the current block height.

type TestContract ¶

type TestContract struct {
	ABI        string
	ByteCode   []byte
	DeployedAt types.Address
}

func GetDummyKittyTestContract ¶

func GetDummyKittyTestContract(t testing.TB) *TestContract

func GetFactoryTestContract ¶ added in v0.37.1

func GetFactoryTestContract(t testing.TB) *TestContract

func GetProxyContract ¶ added in v0.37.1

func GetProxyContract(t testing.TB) *TestContract

func GetStorageTestContract ¶

func GetStorageTestContract(tb testing.TB) *TestContract

func (*TestContract) MakeCallData ¶

func (tc *TestContract) MakeCallData(t testing.TB, name string, args ...interface{}) []byte

func (*TestContract) SetDeployedAt ¶

func (tc *TestContract) SetDeployedAt(deployedAt types.Address)

type TestContractFunctionInvoker ¶ added in v0.33.30

type TestContractFunctionInvoker struct {
	InvokeFunc func(
		spec environment.ContractFunctionSpec,
		arguments []cadence.Value,
	) (
		cadence.Value,
		error,
	)
}

func (*TestContractFunctionInvoker) Invoke ¶ added in v0.33.30

type TestEmulator ¶

type TestEmulator struct {
	BalanceOfFunc           func(address types.Address) (*big.Int, error)
	NonceOfFunc             func(address types.Address) (uint64, error)
	CodeOfFunc              func(address types.Address) (types.Code, error)
	CodeHashOfFunc          func(address types.Address) ([]byte, error)
	DirectCallFunc          func(call *types.DirectCall) (*types.Result, error)
	RunTransactionFunc      func(tx *gethTypes.Transaction) (*types.Result, error)
	DryRunTransactionFunc   func(tx *gethTypes.Transaction, address gethCommon.Address) (*types.Result, error)
	BatchRunTransactionFunc func(txs []*gethTypes.Transaction) ([]*types.Result, error)
}

func (*TestEmulator) BalanceOf ¶

func (em *TestEmulator) BalanceOf(address types.Address) (*big.Int, error)

BalanceOf returns the balance of this address

func (*TestEmulator) BatchRunTransactions ¶ added in v0.33.30

func (em *TestEmulator) BatchRunTransactions(txs []*gethTypes.Transaction) ([]*types.Result, error)

BatchRunTransactions batch runs transactions and collect gas fees to the coinbase account

func (*TestEmulator) CodeHashOf ¶ added in v0.33.30

func (em *TestEmulator) CodeHashOf(address types.Address) ([]byte, error)

CodeHashOf returns the code hash for this address

func (*TestEmulator) CodeOf ¶

func (em *TestEmulator) CodeOf(address types.Address) (types.Code, error)

CodeOf returns the code for this address

func (*TestEmulator) DirectCall ¶

func (em *TestEmulator) DirectCall(call *types.DirectCall) (*types.Result, error)

DirectCall executes a direct call

func (*TestEmulator) DryRunTransaction ¶ added in v0.33.30

func (em *TestEmulator) DryRunTransaction(tx *gethTypes.Transaction, address gethCommon.Address) (*types.Result, error)

DryRunTransaction simulates transaction execution

func (*TestEmulator) NewBlockView ¶

func (em *TestEmulator) NewBlockView(_ types.BlockContext) (types.BlockView, error)

NewBlock returns a new block

func (*TestEmulator) NewReadOnlyBlockView ¶

func (em *TestEmulator) NewReadOnlyBlockView(_ types.BlockContext) (types.ReadOnlyBlockView, error)

NewBlock returns a new block view

func (*TestEmulator) NonceOf ¶

func (em *TestEmulator) NonceOf(address types.Address) (uint64, error)

NonceOfFunc returns the nonce for this address

func (*TestEmulator) RunTransaction ¶

func (em *TestEmulator) RunTransaction(tx *gethTypes.Transaction) (*types.Result, error)

RunTransaction runs a transaction and collect gas fees to the coinbase account

type TestLoggerProvider ¶ added in v0.37.5

type TestLoggerProvider struct {
	LoggerFunc func() zerolog.Logger
}

func (*TestLoggerProvider) Logger ¶ added in v0.37.5

func (tlp *TestLoggerProvider) Logger() zerolog.Logger

type TestMetricsReporter ¶ added in v0.36.3

type TestMetricsReporter struct {
	SetNumberOfDeployedCOAsFunc func(uint64)
	EVMTransactionExecutedFunc  func(uint64, bool, bool)
	EVMBlockExecutedFunc        func(int, uint64, float64)
}

func (*TestMetricsReporter) EVMBlockExecuted ¶ added in v0.36.3

func (tmr *TestMetricsReporter) EVMBlockExecuted(txCount int, totalGasUsed uint64, totalSupplyInFlow float64)

func (*TestMetricsReporter) EVMTransactionExecuted ¶ added in v0.36.3

func (tmr *TestMetricsReporter) EVMTransactionExecuted(gasUsed uint64, isDirectCall bool, failed bool)

func (*TestMetricsReporter) SetNumberOfDeployedCOAs ¶ added in v0.36.3

func (tmr *TestMetricsReporter) SetNumberOfDeployedCOAs(count uint64)

type TestPrecompiledContract ¶ added in v0.38.0

type TestPrecompiledContract struct {
	RequiredGasFunc func(input []byte) uint64
	RunFunc         func(input []byte) ([]byte, error)
	AddressFunc     func() types.Address
}

func (*TestPrecompiledContract) Address ¶ added in v0.38.0

func (pc *TestPrecompiledContract) Address() types.Address

Address returns the address that this contract is deployed to

func (*TestPrecompiledContract) RequiredGas ¶ added in v0.38.0

func (pc *TestPrecompiledContract) RequiredGas(input []byte) uint64

RequiredGas returns the contract gas use

func (*TestPrecompiledContract) Run ¶ added in v0.38.0

func (pc *TestPrecompiledContract) Run(input []byte) ([]byte, error)

Run runs the precompiled contract

type TestRandomGenerator ¶ added in v0.33.30

type TestRandomGenerator struct {
	ReadRandomFunc func([]byte) error
}

func (*TestRandomGenerator) ReadRandom ¶ added in v0.33.30

func (t *TestRandomGenerator) ReadRandom(buffer []byte) error

type TestStorageProvider ¶ added in v0.38.0

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

TestStorageProvider constructs a new storage provider that only provides storage for an specific height

func NewTestStorageProvider ¶ added in v0.38.0

func NewTestStorageProvider(
	initSnapshot types.BackendStorageSnapshot,
	height uint64,
) *TestStorageProvider

NewTestStorageProvider constructs a new TestStorageProvider

func (*TestStorageProvider) GetSnapshotAt ¶ added in v0.38.0

func (sp *TestStorageProvider) GetSnapshotAt(height uint64) (types.BackendStorageSnapshot, error)

GetSnapshotAt returns the snapshot at specific block height

type TestTracer ¶ added in v0.35.17

type TestTracer struct {
	StartChildSpanFunc func(trace.SpanName, ...otelTrace.SpanStartOption) tracing.TracerSpan
}

func (*TestTracer) ExpectedSpan ¶ added in v0.35.17

func (tt *TestTracer) ExpectedSpan(t *testing.T, expected trace.SpanName)

func (*TestTracer) StartChildSpan ¶ added in v0.35.17

func (tt *TestTracer) StartChildSpan(
	name trace.SpanName,
	options ...otelTrace.SpanStartOption,
) tracing.TracerSpan

type TestValueStore ¶

type TestValueStore struct {
	GetValueFunc          func(owner, key []byte) ([]byte, error)
	SetValueFunc          func(owner, key, value []byte) error
	ValueExistsFunc       func(owner, key []byte) (bool, error)
	AllocateSlabIndexFunc func(owner []byte) (atree.SlabIndex, error)
	TotalStorageSizeFunc  func() int
	TotalBytesReadFunc    func() int
	TotalBytesWrittenFunc func() int
	TotalStorageItemsFunc func() int
	ResetStatsFunc        func()
	CloneFunc             func() *TestValueStore
	DumpFunc              func() (map[string][]byte, map[string]uint64)
}

func GetSimpleValueStore ¶

func GetSimpleValueStore() *TestValueStore

func GetSimpleValueStorePopulated ¶ added in v0.38.0

func GetSimpleValueStorePopulated(
	data map[string][]byte,
	allocator map[string]uint64,
) *TestValueStore

func (*TestValueStore) AllocateSlabIndex ¶ added in v0.37.1

func (vs *TestValueStore) AllocateSlabIndex(owner []byte) (atree.SlabIndex, error)

func (*TestValueStore) Clone ¶ added in v0.38.0

func (vs *TestValueStore) Clone() *TestValueStore

func (*TestValueStore) Dump ¶ added in v0.38.0

func (vs *TestValueStore) Dump() (map[string][]byte, map[string]uint64)

func (*TestValueStore) GetValue ¶

func (vs *TestValueStore) GetValue(owner, key []byte) ([]byte, error)

func (*TestValueStore) ResetStats ¶

func (vs *TestValueStore) ResetStats()

func (*TestValueStore) SetValue ¶

func (vs *TestValueStore) SetValue(owner, key, value []byte) error

func (*TestValueStore) TotalBytesRead ¶

func (vs *TestValueStore) TotalBytesRead() int

func (*TestValueStore) TotalBytesWritten ¶

func (vs *TestValueStore) TotalBytesWritten() int

func (*TestValueStore) TotalStorageItems ¶

func (vs *TestValueStore) TotalStorageItems() int

func (*TestValueStore) TotalStorageSize ¶

func (vs *TestValueStore) TotalStorageSize() int

func (*TestValueStore) ValueExists ¶

func (vs *TestValueStore) ValueExists(owner, key []byte) (bool, error)

Directories ¶

Path Synopsis

Jump to

Keyboard shortcuts

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