Documentation
¶
Index ¶
- Variables
- func NewTestFrameworkProvider(logger zerolog.Logger, fileResolver FileResolver, ...) stdlib.TestFramework
- func PrettyPrintResult(scriptPath, funcName string, err error) string
- func PrettyPrintResults(results Results, scriptPath string) string
- type BackendOptions
- type ContractAddressResolver
- type EmulatorBackend
- func (e *EmulatorBackend) AddTransaction(context stdlib.TestFrameworkAddTransactionContext, code string, ...) error
- func (e *EmulatorBackend) CommitBlock() error
- func (e *EmulatorBackend) CreateAccount() (*stdlib.Account, error)
- func (e *EmulatorBackend) CreateSnapshot(name string) error
- func (e *EmulatorBackend) DeployContract(context stdlib.TestFrameworkContractDeploymentContext, name string, ...) error
- func (e *EmulatorBackend) Events(context stdlib.TestFrameworkEventsContext, eventType interpreter.StaticType) interpreter.Value
- func (e *EmulatorBackend) ExecuteNextTransaction() *stdlib.TransactionResult
- func (e *EmulatorBackend) GetAccount(address interpreter.AddressValue) (*stdlib.Account, error)
- func (e *EmulatorBackend) LoadSnapshot(name string) error
- func (e *EmulatorBackend) Logs() []string
- func (e *EmulatorBackend) MoveTime(timeDelta int64)
- func (e *EmulatorBackend) NetworkLabel() string
- func (e *EmulatorBackend) Reset(height uint64)
- func (e *EmulatorBackend) RunScript(context stdlib.TestFrameworkScriptExecutionContext, code string, ...) *stdlib.ScriptResult
- func (e *EmulatorBackend) ServiceAccount() (*stdlib.Account, error)
- func (e *EmulatorBackend) StandardLibraryHandler() stdlib.StandardLibraryHandler
- type FileResolver
- type FileResolverNotProvidedError
- type ForkConfig
- type ImportResolver
- type ImportResolverNotProvidedError
- type Result
- type Results
- type TestFrameworkProvider
- type TestRunner
- func (r *TestRunner) GetTests(script string) ([]string, error)
- func (r *TestRunner) Logs() []string
- func (r *TestRunner) RunTest(script string, funcName string) (result *Result, err error)
- func (r *TestRunner) RunTests(script string) (results Results, err error)
- func (r *TestRunner) WithContractAddressResolver(resolver ContractAddressResolver) *TestRunner
- func (r *TestRunner) WithCoverageReport(coverageReport *runtime.CoverageReport) *TestRunner
- func (r *TestRunner) WithFileResolver(fileResolver FileResolver) *TestRunner
- func (r *TestRunner) WithFork(cfg ForkConfig) *TestRunner
- func (r *TestRunner) WithImportResolver(importResolver ImportResolver) *TestRunner
- func (r *TestRunner) WithLogger(logger zerolog.Logger) *TestRunner
- func (r *TestRunner) WithNetworkLabel(label string) *TestRunner
- func (r *TestRunner) WithNetworkResolver(resolver func(network string) (host string, found bool)) *TestRunner
- func (r *TestRunner) WithRandomSeed(seed int64) *TestRunner
Constants ¶
This section is empty.
Variables ¶
var BurnFlow []byte
var GetCurrentBlockHeight []byte
var GetFlowBalance []byte
var MintFlowTransaction []byte
Functions ¶
func NewTestFrameworkProvider ¶ added in v0.13.0
func NewTestFrameworkProvider( logger zerolog.Logger, fileResolver FileResolver, stdlibHandler stdlib.StandardLibraryHandler, coverageReport *runtime.CoverageReport, backendOptions *BackendOptions, ) stdlib.TestFramework
func PrettyPrintResult ¶
func PrettyPrintResults ¶
PrettyPrintResults is a utility function to pretty print the test results.
Types ¶
type BackendOptions ¶ added in v1.8.0
type BackendOptions struct {
// ForkHost is the Access node RPC host:port to fork from. If empty, fork mode is disabled.
ForkHost string
// ForkHeight indicates the block height to fork from (0 means latest sealed block).
ForkHeight uint64
// NetworkLabel is the network identifier used for resolving contract addresses (e.g., "mainnet", "testnet").
NetworkLabel string
// ChainID is the chain ID to use for the emulator. If empty, the emulator will use the default chain ID.
// For fork mode, the ChainID will use the ChainID of the forked network.
ChainID flow.ChainID
// NetworkResolver maps network labels to Access node host:port addresses (e.g., "mainnet" -> "access.mainnet.nodes.onflow.org:9000").
NetworkResolver func(network string) (host string, found bool)
// ContractAddressResolver resolves contract addresses based on network
ContractAddressResolver ContractAddressResolver
}
BackendOptions configures how the emulator backend should be created. When ForkHost is provided, the backend will run in fork mode, skipping emulator common-contract injection and using the ChainID of the forked network.
type ContractAddressResolver ¶ added in v1.9.0
type ContractAddressResolver func(network string, contractName string) (address common.Address, error error)
ContractAddressResolver resolves contract names to addresses based on the current network. This is used during import rewriting to convert string imports like `import "Foo"` into address imports like `import Foo from 0xADDRESS`.
type EmulatorBackend ¶
type EmulatorBackend struct {
// contains filtered or unexported fields
}
EmulatorBackend is the emulator-backed implementation of the interpreter.TestFramework.
func NewEmulatorBackend ¶
func NewEmulatorBackend( logger zerolog.Logger, stdlibHandler stdlib.StandardLibraryHandler, coverageReport *runtime.CoverageReport, backendOptions *BackendOptions, ) *EmulatorBackend
func (*EmulatorBackend) AddTransaction ¶
func (e *EmulatorBackend) AddTransaction( context stdlib.TestFrameworkAddTransactionContext, code string, authorizers []common.Address, signers []*stdlib.Account, args []interpreter.Value, ) error
func (*EmulatorBackend) CommitBlock ¶
func (e *EmulatorBackend) CommitBlock() error
func (*EmulatorBackend) CreateAccount ¶
func (e *EmulatorBackend) CreateAccount() (*stdlib.Account, error)
func (*EmulatorBackend) CreateSnapshot ¶ added in v0.13.0
func (e *EmulatorBackend) CreateSnapshot(name string) error
CreateSnapshot Creates a snapshot of the blockchain, at the current ledger state, with the given name.
func (*EmulatorBackend) DeployContract ¶
func (e *EmulatorBackend) DeployContract( context stdlib.TestFrameworkContractDeploymentContext, name string, path string, args []interpreter.Value, ) error
func (*EmulatorBackend) Events ¶ added in v0.8.0
func (e *EmulatorBackend) Events( context stdlib.TestFrameworkEventsContext, eventType interpreter.StaticType, ) interpreter.Value
Events returns all the emitted events up until the latest block, optionally filtered by event type. In fork mode, events are bounded to [forkStartHeight + 1, latest] (local blocks only).
func (*EmulatorBackend) ExecuteNextTransaction ¶
func (e *EmulatorBackend) ExecuteNextTransaction() *stdlib.TransactionResult
func (*EmulatorBackend) GetAccount ¶ added in v0.13.0
func (e *EmulatorBackend) GetAccount( address interpreter.AddressValue, ) (*stdlib.Account, error)
func (*EmulatorBackend) LoadSnapshot ¶ added in v0.13.0
func (e *EmulatorBackend) LoadSnapshot(name string) error
LoadSnapshot Loads a snapshot of the blockchain, with the given name, and updates the current ledger state.
func (*EmulatorBackend) Logs ¶ added in v0.8.0
func (e *EmulatorBackend) Logs() []string
Logs returns all the log messages from the blockchain.
func (*EmulatorBackend) MoveTime ¶ added in v0.13.0
func (e *EmulatorBackend) MoveTime(timeDelta int64)
MoveTime Moves the time of the Blockchain's clock, by the given time delta, in the form of seconds.
func (*EmulatorBackend) NetworkLabel ¶ added in v1.9.0
func (e *EmulatorBackend) NetworkLabel() string
NetworkLabel returns the network identifier used for contract resolution
func (*EmulatorBackend) Reset ¶ added in v0.8.0
func (e *EmulatorBackend) Reset(height uint64)
func (*EmulatorBackend) RunScript ¶
func (e *EmulatorBackend) RunScript( context stdlib.TestFrameworkScriptExecutionContext, code string, args []interpreter.Value, ) *stdlib.ScriptResult
func (*EmulatorBackend) ServiceAccount ¶ added in v0.8.0
func (e *EmulatorBackend) ServiceAccount() (*stdlib.Account, error)
func (*EmulatorBackend) StandardLibraryHandler ¶ added in v0.3.0
func (e *EmulatorBackend) StandardLibraryHandler() stdlib.StandardLibraryHandler
type FileResolver ¶
FileResolver is used to resolve and get local files. Returns the content of the file as a string. Must be provided by the user of the TestRunner.
type FileResolverNotProvidedError ¶
type FileResolverNotProvidedError struct {
Err error
}
FileResolverNotProvidedError is thrown if the file resolver is not set in the TestRunner, when running tests.
func (FileResolverNotProvidedError) Error ¶
func (e FileResolverNotProvidedError) Error() string
func (FileResolverNotProvidedError) Unwrap ¶
func (e FileResolverNotProvidedError) Unwrap() error
type ForkConfig ¶ added in v1.8.0
type ForkConfig struct {
ForkHost string // Access node host:port to fork from
ForkHeight uint64 // Block height to fork from (latest sealed if empty)
ChainID flow.ChainID // Chain ID to use (optional, will auto-detect if empty)
}
ForkConfig configures a single forked environment for the entire test run.
type ImportResolver ¶
ImportResolver resolves imports by providing source code for a given location. The network parameter indicates the current network context ("emulator", "testnet", "mainnet", etc.).
type ImportResolverNotProvidedError ¶
type ImportResolverNotProvidedError struct {
Err error
}
ImportResolverNotProvidedError is thrown if the import resolver is not set in the TestRunner, when running tests.
func (ImportResolverNotProvidedError) Error ¶
func (e ImportResolverNotProvidedError) Error() string
func (ImportResolverNotProvidedError) Unwrap ¶
func (e ImportResolverNotProvidedError) Unwrap() error
type TestFrameworkProvider ¶ added in v0.13.0
type TestFrameworkProvider struct {
// contains filtered or unexported fields
}
func (*TestFrameworkProvider) EmulatorBackend ¶ added in v0.13.0
func (tf *TestFrameworkProvider) EmulatorBackend() stdlib.Blockchain
type TestRunner ¶
type TestRunner struct {
// contains filtered or unexported fields
}
TestRunner runs tests.
func NewTestRunner ¶
func NewTestRunner() *TestRunner
func (*TestRunner) GetTests ¶ added in v0.14.4
func (r *TestRunner) GetTests(script string) ([]string, error)
func (*TestRunner) Logs ¶ added in v0.8.1
func (r *TestRunner) Logs() []string
Logs returns all the log messages from the script environment that test cases run. Unit tests run in this environment too, so the logs from their respective contracts, also appear in the resulting string slice.
func (*TestRunner) RunTest ¶
func (r *TestRunner) RunTest(script string, funcName string) (result *Result, err error)
RunTest runs a single test in the provided test script.
func (*TestRunner) RunTests ¶
func (r *TestRunner) RunTests(script string) (results Results, err error)
RunTests runs all the tests in the provided test script.
func (*TestRunner) WithContractAddressResolver ¶ added in v1.9.0
func (r *TestRunner) WithContractAddressResolver(resolver ContractAddressResolver) *TestRunner
WithContractAddressResolver sets a resolver to dynamically determine contract addresses based on the current network. This is used during import rewriting.
func (*TestRunner) WithCoverageReport ¶ added in v0.6.0
func (r *TestRunner) WithCoverageReport(coverageReport *runtime.CoverageReport) *TestRunner
func (*TestRunner) WithFileResolver ¶
func (r *TestRunner) WithFileResolver(fileResolver FileResolver) *TestRunner
func (*TestRunner) WithFork ¶ added in v1.8.0
func (r *TestRunner) WithFork(cfg ForkConfig) *TestRunner
WithFork enables fork mode with the given configuration.
func (*TestRunner) WithImportResolver ¶
func (r *TestRunner) WithImportResolver(importResolver ImportResolver) *TestRunner
func (*TestRunner) WithLogger ¶ added in v0.14.6
func (r *TestRunner) WithLogger(logger zerolog.Logger) *TestRunner
func (*TestRunner) WithNetworkLabel ¶ added in v1.9.0
func (r *TestRunner) WithNetworkLabel(label string) *TestRunner
WithNetworkLabel sets the network identifier used for contract address resolution. Defaults to "emulator" if not set.
func (*TestRunner) WithNetworkResolver ¶ added in v1.9.0
func (r *TestRunner) WithNetworkResolver(resolver func(network string) (host string, found bool)) *TestRunner
WithNetworkResolver sets a resolver for mapping network labels to host:port addresses.
func (*TestRunner) WithRandomSeed ¶ added in v0.13.0
func (r *TestRunner) WithRandomSeed(seed int64) *TestRunner