Documentation
¶
Overview ¶
Package provider contains EVM chain providers for the Chainlink Deployments Framework.
This file implements CTFAnvilChainProvider, which provides Anvil EVM chain instances running inside Chainlink Testing Framework (CTF) Docker containers.
Anvil Integration ¶
Anvil is a local Ethereum node designed for development and testing, part of the Foundry toolkit. It provides fast, deterministic blockchain simulation with pre-funded accounts and configurable mining behavior.
Usage Patterns ¶
Basic usage for simple testing:
func TestBasicContract(t *testing.T) { var once sync.Once config := CTFAnvilChainProviderConfig{ Once: &once, ConfirmFunctor: ConfirmFuncGeth(2 * time.Minute), T: t, // Required when Port is not provided } provider := NewCTFAnvilChainProvider(chainSelector, config) blockchain, err := provider.Initialize(context.Background()) require.NoError(t, err) // Deploy and test contracts... }
Advanced usage with custom configuration:
func TestAdvancedScenario(t *testing.T) { var once sync.Once config := CTFAnvilChainProviderConfig{ Once: &once, ConfirmFunctor: ConfirmFuncGeth(30 * time.Second), NumAdditionalAccounts: 5, // Limit to 5 additional accounts + deployer T: t, // Required when Port is not provided } provider := NewCTFAnvilChainProvider(chainSelector, config) blockchain, err := provider.Initialize(context.Background()) require.NoError(t, err) // Run complex multi-account tests... }
Usage with custom deployer key (using TransactorFromRaw):
func TestWithCustomDeployer(t *testing.T) { var once sync.Once config := CTFAnvilChainProviderConfig{ Once: &once, ConfirmFunctor: ConfirmFuncGeth(2 * time.Minute), DeployerTransactorGen: TransactorFromRaw("your-custom-private-key-here"), // 64 chars hex, no 0x prefix T: t, // Required when Port is not provided } provider := NewCTFAnvilChainProvider(chainSelector, config) blockchain, err := provider.Initialize(context.Background()) require.NoError(t, err) // The deployer account will use your custom key instead of Anvil's default // User accounts will still use Anvil's standard test accounts }
Usage with KMS deployer key:
func TestWithKMSDeployer(t *testing.T) { var once sync.Once config := CTFAnvilChainProviderConfig{ Once: &once, ConfirmFunctor: ConfirmFuncGeth(2 * time.Minute), DeployerTransactorGen: TransactorFromKMS("your-kms-key-id"), T: t, // Required when Port is not provided } provider := NewCTFAnvilChainProvider(chainSelector, config) blockchain, err := provider.Initialize(context.Background()) require.NoError(t, err) // The deployer account will use KMS for signing // User accounts will still use Anvil's standard test accounts }
Usage with custom client options:
func TestWithCustomClientOpts(t *testing.T) { var once sync.Once config := CTFAnvilChainProviderConfig{ Once: &once, ConfirmFunctor: ConfirmFuncGeth(2 * time.Minute), ClientOpts: []func(client *rpcclient.MultiClient){ func(client *rpcclient.MultiClient) { // Custom client configuration client.SetTimeout(30 * time.Second) }, }, T: t, // Required when Port is not provided } provider := NewCTFAnvilChainProvider(chainSelector, config) blockchain, err := provider.Initialize(context.Background()) require.NoError(t, err) // The MultiClient will use the custom configuration options }
Usage with custom Docker command parameters:
func TestWithDockerCmdOverrides(t *testing.T) { var once sync.Once config := CTFAnvilChainProviderConfig{ Once: &once, ConfirmFunctor: ConfirmFuncGeth(2 * time.Minute), DockerCmdParamsOverrides: []string{ "--block-time", "2", // Mine blocks every 2 seconds "--gas-limit", "30000000", // Set gas limit to 30M "--gas-price", "1000000000", // Set gas price to 1 gwei }, T: t, // Required when Port is not provided } provider := NewCTFAnvilChainProvider(chainSelector, config) blockchain, err := provider.Initialize(context.Background()) require.NoError(t, err) // Anvil will run with the custom parameters }
Usage with custom Port and Image:
func TestWithCustomContainer(t *testing.T) { var once sync.Once config := CTFAnvilChainProviderConfig{ Once: &once, ConfirmFunctor: ConfirmFuncGeth(2 * time.Minute), Port: "8545", // Use specific port (T not required when Port is provided) Image: "ghcr.io/foundry-rs/foundry:latest", // Custom Anvil image } provider := NewCTFAnvilChainProvider(chainSelector, config) blockchain, err := provider.Initialize(context.Background()) require.NoError(t, err) // Anvil will run on port 8545, using the specified image // Chain ID is automatically derived from the chainSelector }
Usage in production/non-test contexts with manual cleanup:
func main() { var once sync.Once config := CTFAnvilChainProviderConfig{ Once: &once, ConfirmFunctor: ConfirmFuncGeth(2 * time.Minute), Port: "8545", // T not required when Port is provided } provider := NewCTFAnvilChainProvider(chainSelector, config) blockchain, err := provider.Initialize(context.Background()) if err != nil { log.Fatal(err) } // Use the blockchain... // Important: Clean up the container when done defer func() { if err := provider.Cleanup(context.Background()); err != nil { log.Printf("Failed to cleanup container: %v", err) } }() }
Chain Selectors ¶
Common chain selectors for Anvil testing:
- 13264668187771770619: Chain ID 31337 (default Anvil chain ID)
Standard Test Accounts ¶
The provider uses Anvil's standard test accounts:
- Account 0 (Deployer): 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
- Account 1: 0x70997970c51812dc3a010c7d01b50e0d17dc79c8
- Account 2: 0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc
- ... up to 10 total pre-funded accounts
Port Management ¶
The provider supports two modes for port allocation:
- Explicit Port: When Port is specified in the config, that exact port will be used
- Automatic Port: When Port is empty, a free port is automatically allocated using freeport (requires T field to be set in the config for cleanup management)
Requirements ¶
- Docker must be installed and running
- CTF framework must be properly configured
- Sufficient system resources for container execution
- When using automatic port allocation (Port not specified), T field must be set in config
Package provider contains EVM chain providers for the Chainlink Deployments Framework.
This file implements CTFGethChainProvider, which provides Geth EVM chain instances running inside Chainlink Testing Framework (CTF) Docker container.
Geth Integration ¶
Geth is a local Ethereum node.
Usage Patterns ¶
Basic usage for simple testing:
func TestBasicContract(t *testing.T) { var once sync.Once config := CTFGethChainProviderConfig{ Once: &once, ConfirmFunctor: ConfirmFuncGeth(2 * time.Minute), T: t, // Required when Port is not provided } provider := NewCTFGethChainProvider(chainSelector, config) blockchain, err := provider.Initialize(context.Background()) require.NoError(t, err) // Deploy and test contracts... }
Advanced usage with custom configuration:
func TestAdvancedScenario(t *testing.T) { var once sync.Once config := CTFGethChainProviderConfig{ Once: &once, ConfirmFunctor: ConfirmFuncGeth(30 * time.Second), AdditionalAccounts: true, // Create & auto-fund all extra users from the built-in pool T: t, // Required when Port is not provided } provider := NewCTFGethChainProvider(chainSelector, config) blockchain, err := provider.Initialize(context.Background()) require.NoError(t, err) // Run complex multi-account tests... }
Usage with custom deployer key (using TransactorFromRaw):
func TestWithCustomDeployer(t *testing.T) { var once sync.Once config := CTFGethChainProviderConfig{ Once: &once, ConfirmFunctor: ConfirmFuncGeth(2 * time.Minute), DeployerTransactorGen: TransactorFromRaw("your-custom-private-key-here"), // 64 chars hex, no 0x prefix T: t, // Required when Port is not provided } provider := NewCTFGethChainProvider(chainSelector, config) blockchain, err := provider.Initialize(context.Background()) require.NoError(t, err) // The deployer account will use your custom key instead of Geth's default // User accounts will still use Geth's standard test accounts }
Usage with KMS deployer key:
func TestWithKMSDeployer(t *testing.T) { var once sync.Once config := CTFGethChainProviderConfig{ Once: &once, ConfirmFunctor: ConfirmFuncGeth(2 * time.Minute), DeployerTransactorGen: TransactorFromKMS("your-kms-key-id"), T: t, // Required when Port is not provided } provider := NewCTFGethChainProvider(chainSelector, config) blockchain, err := provider.Initialize(context.Background()) require.NoError(t, err) // The deployer account will use KMS for signing // User accounts will still use Geth's standard test accounts }
Usage with custom client options:
func TestWithCustomClientOpts(t *testing.T) { var once sync.Once config := CTFGethChainProviderConfig{ Once: &once, ConfirmFunctor: ConfirmFuncGeth(2 * time.Minute), ClientOpts: []func(client *rpcclient.MultiClient){ func(client *rpcclient.MultiClient) { // Custom client configuration client.SetTimeout(30 * time.Second) }, }, T: t, // Required when Port is not provided } provider := NewCTFGethChainProvider(chainSelector, config) blockchain, err := provider.Initialize(context.Background()) require.NoError(t, err) // The MultiClient will use the custom configuration options }
Usage with custom Docker command parameters:
func TestWithDockerCmdOverrides(t *testing.T) { var once sync.Once config := CTFGethChainProviderConfig{ Once: &once, ConfirmFunctor: ConfirmFuncGeth(2 * time.Minute), DockerCmdParamsOverrides: []string{ "--miner.gasprice", "1000000000", // Set min gas price to 1 gwei "--miner.threads", "1", // Use 1 mining thread "--cache", "1024", // Allocate 1GB cache }, T: t, // Required when Port is not provided } provider := NewCTFGethChainProvider(chainSelector, config) blockchain, err := provider.Initialize(context.Background()) require.NoError(t, err) // Geth will run with the custom parameters }
Usage with custom Port and Image:
func TestWithCustomContainer(t *testing.T) { var once sync.Once config := CTFGethChainProviderConfig{ Once: &once, ConfirmFunctor: ConfirmFuncGeth(2 * time.Minute), Port: "8546", // Use specific port (T not required when Port is provided) Image: "ethereum/client-go:stable", // Custom Geth image/version if desired } provider := NewCTFGethChainProvider(chainSelector, config) blockchain, err := provider.Initialize(context.Background()) require.NoError(t, err) // Geth will run on port 8546, using the specified image // Chain ID is automatically derived from the chainSelector }
Usage in production/non-test contexts with manual cleanup:
func main() { var once sync.Once config := CTFGethChainProviderConfig{ Once: &once, ConfirmFunctor: ConfirmFuncGeth(2 * time.Minute), Port: "8546", // T not required when Port is provided } provider := NewCTFGethChainProvider(chainSelector, config) blockchain, err := provider.Initialize(context.Background()) if err != nil { log.Fatal(err) } // Use the blockchain... // Important: Clean up the container when done defer func() { if err := provider.Cleanup(context.Background()); err != nil { log.Printf("Failed to cleanup container: %v", err) } }() }
Chain Selectors ¶
Common chain selectors for Geth testing:
- 13264668187771770619: Chain ID 31337 (default Geth chain ID)
Standard Test Accounts ¶
This provider ships with a built-in pool of Geth-style test keys:
- Account 0 (Deployer): 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
- Account 1: 0x70997970c51812dc3a010c7d01b50e0d17dc79c8
- Account 2: 0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc
- Account 3: 0x90f79bf6eb2c4f870365e785982e1f101e93b906
- Account 4: 0x15d34aaf54267db7d7c367839aaf71a00a2c6a65
Behavior:
- By default, only the deployer (Account 0) is created.
- If config.AdditionalAccounts == true, *all* extra users (Accounts 1..N) from the pool are created and auto-funded during Initialize().
Port Management ¶
The provider supports two modes for port allocation:
- Explicit Port: When Port is specified in the config, that exact port will be used
- Automatic Port: When Port is empty, a free port is automatically allocated using freeport (requires T field to be set in the config for cleanup management)
Requirements ¶
- Docker must be installed and running
- CTF framework must be properly configured
- Sufficient system resources for container execution
- When using automatic port allocation (Port not specified), T field must be set in config
Index ¶
- func ZkSyncSignerFromKMS(keyID, keyRegion, awsProfileName string) (*zkSyncSignerFromKMS, error)
- func ZkSyncSignerFromRaw(privKey string) *zkSyncSignerFromRaw
- type CTFAnvilChainProvider
- func (p *CTFAnvilChainProvider) BlockChain() chain.BlockChain
- func (p *CTFAnvilChainProvider) ChainSelector() uint64
- func (p *CTFAnvilChainProvider) Cleanup(ctx context.Context) error
- func (p *CTFAnvilChainProvider) GetNodeHTTPURL() string
- func (p *CTFAnvilChainProvider) Initialize(ctx context.Context) (chain.BlockChain, error)
- func (*CTFAnvilChainProvider) Name() string
- type CTFAnvilChainProviderConfig
- type CTFGethChainProvider
- func (p *CTFGethChainProvider) BlockChain() chain.BlockChain
- func (p *CTFGethChainProvider) ChainSelector() uint64
- func (p *CTFGethChainProvider) Cleanup(ctx context.Context) error
- func (p *CTFGethChainProvider) GetNodeHTTPURL() string
- func (p *CTFGethChainProvider) Initialize(ctx context.Context) (chain.BlockChain, error)
- func (*CTFGethChainProvider) Name() string
- type CTFGethChainProviderConfig
- type ConfirmFunctor
- type ContractCaller
- type GeneratorOption
- type GeneratorOptions
- type KMSSigner
- type RPCChainProvider
- type RPCChainProviderConfig
- type SignerGenerator
- type SimChainProvider
- type SimChainProviderConfig
- type SimClient
- type ZkSyncCTFChainProvider
- type ZkSyncCTFChainProviderConfig
- type ZkSyncRPCChainProvider
- type ZkSyncRPCChainProviderConfig
- type ZkSyncSignerGenerator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ZkSyncSignerFromKMS ¶ added in v0.15.0
ZkSyncSignerFromKMS returns a generator which creates a ZkSync signer using AWS KMS.
It requires the KMS key ID, region, and optionally an AWS profile name. If the AWS profile name is not provided, it defaults to using the environment variables to determine the AWS profile.
func ZkSyncSignerFromRaw ¶ added in v0.15.0
func ZkSyncSignerFromRaw(privKey string) *zkSyncSignerFromRaw
ZkSyncSignerFromRaw returns a generator which creates a ZkSync signer from a raw private key.
Types ¶
type CTFAnvilChainProvider ¶ added in v0.30.0
type CTFAnvilChainProvider struct {
// contains filtered or unexported fields
}
CTFAnvilChainProvider manages an Anvil EVM chain instance running inside a Chainlink Testing Framework (CTF) Docker container.
This provider requires Docker to be installed and operational. Spinning up a new container can be slow, so it is recommended to initialize the provider only once per test suite or parent test to optimize performance.
func NewCTFAnvilChainProvider ¶ added in v0.30.0
func NewCTFAnvilChainProvider( selector uint64, config CTFAnvilChainProviderConfig, ) *CTFAnvilChainProvider
NewCTFAnvilChainProvider creates a new CTFAnvilChainProvider with the given selector and configuration.
Parameters:
- selector: Chain selector that maps to a specific chain ID
- config: Configuration struct containing all necessary setup parameters. Note: config.T is required when config.Port is not provided (for automatic port allocation)
Returns a new CTFAnvilChainProvider instance ready for initialization.
func (*CTFAnvilChainProvider) BlockChain ¶ added in v0.30.0
func (p *CTFAnvilChainProvider) BlockChain() chain.BlockChain
BlockChain returns the Anvil EVM chain instance managed by this provider.
You must call Initialize before using this method to ensure the chain is properly set up. Calling this method before initialization will return an uninitialized chain instance.
Returns the chain.BlockChain interface that can be used for blockchain operations such as deploying contracts, sending transactions, and querying blockchain state.
func (*CTFAnvilChainProvider) ChainSelector ¶ added in v0.30.0
func (p *CTFAnvilChainProvider) ChainSelector() uint64
ChainSelector returns the chain selector of the Anvil EVM chain managed by this provider. The chain selector is a unique identifier that maps to a specific blockchain network.
func (*CTFAnvilChainProvider) Cleanup ¶ added in v0.33.0
func (p *CTFAnvilChainProvider) Cleanup(ctx context.Context) error
Cleanup terminates the Anvil container and cleans up associated resources.
This method provides explicit control over container lifecycle, which is especially important when the provider is used outside of test contexts where automatic cleanup via testcontainers.CleanupContainer is not available.
It's safe to call this method multiple times - subsequent calls will be no-ops if the container has already been terminated.
Returns an error if the container termination fails.
func (*CTFAnvilChainProvider) GetNodeHTTPURL ¶ added in v0.30.0
func (p *CTFAnvilChainProvider) GetNodeHTTPURL() string
GetNodeHTTPURL returns the external HTTP URL of the first Anvil node.
This URL can be used to connect to the Anvil node directly for RPC calls or other operations. You must call Initialize before using this method to ensure the container is started and the URL is available.
Returns an empty string if the provider has not been initialized yet.
func (*CTFAnvilChainProvider) Initialize ¶ added in v0.30.0
func (p *CTFAnvilChainProvider) Initialize(ctx context.Context) (chain.BlockChain, error)
Initialize sets up the Anvil EVM chain instance managed by this provider. It starts a CTF container, initializes the Ethereum client, and sets up the chain instance with the necessary transactors and deployer key gathered from the standard Anvil test accounts.
func (*CTFAnvilChainProvider) Name ¶ added in v0.30.0
func (*CTFAnvilChainProvider) Name() string
Name returns the human-readable name of the CTFAnvilChainProvider. This name is used for logging and identification purposes.
type CTFAnvilChainProviderConfig ¶ added in v0.30.0
type CTFAnvilChainProviderConfig struct { // Required: A sync.Once instance to ensure that the CTF framework only sets up the new // DefaultNetwork once Once *sync.Once // Required: ConfirmFunctor is a type that generates a confirmation function for transactions. // Use ConfirmFuncGeth to use the Geth client for transaction confirmation, or // ConfirmFuncSeth to use the Seth client for transaction confirmation with richer debugging. // // If in doubt, use ConfirmFuncGeth. ConfirmFunctor ConfirmFunctor // Optional: DeployerTransactorGen is a generator for the deployer key. Use TransactorFromRaw // to create a deployer key from a private key, or TransactorFromKMS to create a deployer // key from a KMS key. If not provided, the default Anvil deployer account will be used. DeployerTransactorGen SignerGenerator // Optional: ClientOpts are additional options to configure the MultiClient used by the // CTFAnvilChainProvider. These options are applied to the MultiClient instance created by the // provider. You can use this to set up custom HTTP clients, timeouts, or other // configurations for the RPC connections. ClientOpts []func(client *rpcclient.MultiClient) // Optional: DockerCmdParamsOverrides allows customization of Docker command parameters // for the Anvil container. These parameters are passed directly to the Docker container // startup command, enabling advanced Anvil configurations such as custom block time, // gas limits, or other Anvil-specific options. DockerCmdParamsOverrides []string // Optional: Port specifies the port for the Anvil container. If not provided, // a free port will be automatically allocated. Use this when you need the Anvil // instance to run on a specific port. Port string // Optional: Image specifies the Docker image to use for the Anvil container. // If not provided, the default Anvil image from the CTF framework will be used. // This allows using custom Anvil builds or specific versions. Image string // Optional: Number of additional accounts to generate beyond the default Anvil accounts. // If not specified, defaults to using all available default Anvil accounts. NumAdditionalAccounts uint // Optional: This is only required when Port is not provided so we can use freeport to get a free port. // This will be ignored when Port is provided. T testing.TB }
CTFAnvilChainProviderConfig holds the configuration to initialize the CTFAnvilChainProvider.
This configuration struct provides all necessary parameters to set up an Anvil EVM chain instance running inside a Chainlink Testing Framework (CTF) Docker container.
type CTFGethChainProvider ¶ added in v0.46.0
type CTFGethChainProvider struct {
// contains filtered or unexported fields
}
CTFGethChainProvider manages an Geth EVM chain instance running inside a Chainlink Testing Framework (CTF) Docker container.
This provider requires Docker to be installed and operational. Spinning up a new container can be slow, so it is recommended to initialize the provider only once per test suite or parent test to optimize performance.
func NewCTFGethChainProvider ¶ added in v0.46.0
func NewCTFGethChainProvider( selector uint64, config CTFGethChainProviderConfig, ) *CTFGethChainProvider
NewCTFGethChainProvider creates a new CTFGethChainProvider with the given selector and configuration.
Parameters:
- selector: Chain selector that maps to a specific chain ID
- config: Configuration struct containing all necessary setup parameters. Note: config.T is required when config.Port is not provided (for automatic port allocation)
Returns a new CTFGethChainProvider instance ready for initialization.
func (*CTFGethChainProvider) BlockChain ¶ added in v0.46.0
func (p *CTFGethChainProvider) BlockChain() chain.BlockChain
BlockChain returns the Geth EVM chain instance managed by this provider.
You must call Initialize before using this method to ensure the chain is properly set up. Calling this method before initialization will return an uninitialized chain instance.
Returns the chain.BlockChain interface that can be used for blockchain operations such as deploying contracts, sending transactions, and querying blockchain state.
func (*CTFGethChainProvider) ChainSelector ¶ added in v0.46.0
func (p *CTFGethChainProvider) ChainSelector() uint64
ChainSelector returns the chain selector of the Geth EVM chain managed by this provider. The chain selector is a unique identifier that maps to a specific blockchain network.
func (*CTFGethChainProvider) Cleanup ¶ added in v0.46.0
func (p *CTFGethChainProvider) Cleanup(ctx context.Context) error
Cleanup terminates the Geth container and cleans up associated resources.
This method provides explicit control over container lifecycle, which is especially important when the provider is used outside of test contexts where automatic cleanup via testcontainers.CleanupContainer is not available.
It's safe to call this method multiple times - subsequent calls will be no-ops if the container has already been terminated.
Returns an error if the container termination fails.
func (*CTFGethChainProvider) GetNodeHTTPURL ¶ added in v0.46.0
func (p *CTFGethChainProvider) GetNodeHTTPURL() string
GetNodeHTTPURL returns the external HTTP URL of the first Geth node.
This URL can be used to connect to the Geth node directly for RPC calls or other operations. You must call Initialize before using this method to ensure the container is started and the URL is available.
Returns an empty string if the provider has not been initialized yet.
func (*CTFGethChainProvider) Initialize ¶ added in v0.46.0
func (p *CTFGethChainProvider) Initialize(ctx context.Context) (chain.BlockChain, error)
Initialize sets up the Geth EVM chain instance managed by this provider. It starts a CTF container, initializes the Ethereum client, and sets up the chain instance with the necessary transactors and deployer key gathered from the standard Geth test accounts.
func (*CTFGethChainProvider) Name ¶ added in v0.46.0
func (*CTFGethChainProvider) Name() string
Name returns the human-readable name of the CTFGethChainProvider. This name is used for logging and identification purposes.
type CTFGethChainProviderConfig ¶ added in v0.46.0
type CTFGethChainProviderConfig struct { // Required: A sync.Once instance to ensure that the CTF framework only sets up the new // DefaultNetwork once Once *sync.Once // Required: ConfirmFunctor is a type that generates a confirmation function for transactions. // Use ConfirmFuncGeth to use the Geth client for transaction confirmation, or // ConfirmFuncSeth to use the Seth client for transaction confirmation with richer debugging. // // If in doubt, use ConfirmFuncGeth. ConfirmFunctor ConfirmFunctor // Optional: DeployerTransactorGen is a generator for the deployer key. Use TransactorFromRaw // to create a deployer key from a private key, or TransactorFromKMS to create a deployer // key from a KMS key. If not provided, the default Geth deployer account will be used. DeployerTransactorGen SignerGenerator // Optional: ClientOpts are additional options to configure the MultiClient used by the // CTFGethChainProvider. These options are applied to the MultiClient instance created by the // provider. You can use this to set up custom HTTP clients, timeouts, or other // configurations for the RPC connections. ClientOpts []func(client *rpcclient.MultiClient) // Optional: DockerCmdParamsOverrides allows customization of Docker command parameters // for the Geth container. These parameters are passed directly to the Docker container // startup command, enabling advanced Geth configurations such as custom block time, // gas limits, or other Geth-specific options. DockerCmdParamsOverrides []string // Optional: Port specifies the port for the Geth container. If not provided, // a free port will be automatically allocated. Use this when you need the Geth // instance to run on a specific port. Port string // Optional: Image specifies the Docker image to use for the Geth container. // If not provided, the default Geth image from the CTF framework will be used. // This allows using custom Geth builds or specific versions. Image string // Optional: Whether to create and auto-fund additional user accounts from the built-in pool. // When false (default), only the deployer is available. // When true, ALL users from gethTestPrivateKeys (excluding the deployer) are created and auto-funded. AdditionalAccounts bool // Optional: This is only required when Port is not provided so we can use freeport to get a free port. // This will be ignored when Port is provided. T testing.TB }
CTFGethChainProviderConfig holds the configuration to initialize the CTFGethChainProvider.
This configuration struct provides all necessary parameters to set up an Geth EVM chain instance running inside a Chainlink Testing Framework (CTF) Docker container.
type ConfirmFunctor ¶ added in v0.14.0
type ConfirmFunctor interface { // Generate returns a function that confirms transactions on the EVM chain. Generate( ctx context.Context, selector uint64, client evm.OnchainClient, from common.Address, ) (evm.ConfirmFunc, error) }
ConfirmFunctor is an interface for creating a confirmation function for transactions on the EVM chain.
func ConfirmFuncGeth ¶ added in v0.14.0
func ConfirmFuncGeth(waitMinedTimeout time.Duration) ConfirmFunctor
ConfirmFuncGeth returns a ConfirmFunctor that uses the Geth client to confirm transactions.
func ConfirmFuncSeth ¶ added in v0.14.0
func ConfirmFuncSeth( rpcURL string, waitMinedTimeout time.Duration, gethWrapperDirs []string, configFilePath string, ) ConfirmFunctor
ConfirmFuncSeth returns a ConfirmFunctor that uses the Seth client to confirm transactions. It requires the RPC URL, a list of directories where Geth wrappers are located, and an optional configuration file path for the Seth client. If you do not have a configuration file, you can pass an empty string.
type ContractCaller ¶ added in v0.14.0
type ContractCaller interface {
CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
}
ContractCaller is an interface that defines the CallContract method. This is copied from the go-ethereum package method to limit the scope of dependencies provided to the functions.
type GeneratorOption ¶ added in v0.33.0
type GeneratorOption func(*GeneratorOptions)
GeneratorOption is a function that modifies GeneratorOptions.
func WithGasLimit ¶ added in v0.33.0
func WithGasLimit(gasLimit uint64) GeneratorOption
type GeneratorOptions ¶ added in v0.33.0
type GeneratorOptions struct {
// contains filtered or unexported fields
}
GeneratorOptions contains configuration options for the SignerGenerator.
type KMSSigner ¶ added in v0.14.0
type KMSSigner struct {
// contains filtered or unexported fields
}
KMSSigner provides a signer for EVM transactions using a KMS key. It provides methods to convert KMS keys to EVM-compatible public keys, signatures, and geth bindings.
func NewKMSSigner ¶ added in v0.14.0
NewKMSSigner creates a new KMSSigner instance using the provided KMS key ID, region, and AWS profile. If you prefer to use environment variables to define the AWS profile, you may set the awsProfile as an empty string.
func (*KMSSigner) GetAddress ¶ added in v0.14.0
GetAddress returns the EVM address corresponding to the public key managed by KMS.
func (*KMSSigner) GetECDSAPublicKey ¶ added in v0.14.0
GetECDSAPublicKey retrieves the public key from KMS and converts it to its ECDSA representation.
func (*KMSSigner) GetTransactOpts ¶ added in v0.14.0
func (s *KMSSigner) GetTransactOpts( ctx context.Context, chainID *big.Int, ) (*bind.TransactOpts, error)
GetTransactOpts returns a *bind.TransactOpts configured to sign EVM transactions using the KMS-backed key.
The returned TransactOpts uses the KMS key for signing and sets the correct sender address derived from the KMS public key.
func (*KMSSigner) SignHash ¶ added in v0.15.0
SignHash signs the given transaction hash using the KMS key. It retrieves the public key, signs the hash using KMS, and converts the KMS signature to an Ethereum-compatible signature.
The returned signature is in the format expected by Ethereum transactions, including the recovery ID (v) and the r and s values.
type RPCChainProvider ¶ added in v0.14.0
type RPCChainProvider struct {
// contains filtered or unexported fields
}
RPCChainProvider is a chain provider that provides a chain that connects to an EVM node via RPC.
func NewRPCChainProvider ¶ added in v0.14.0
func NewRPCChainProvider( selector uint64, config RPCChainProviderConfig, ) *RPCChainProvider
NewRPCChainProvider creates a new RPCChainProvider with the given selector and configuration.
func (*RPCChainProvider) BlockChain ¶ added in v0.14.0
func (p *RPCChainProvider) BlockChain() chain.BlockChain
BlockChain returns the simulated chain instance managed by this provider. You must call Initialize before using this method to ensure the chain is properly set up.
func (*RPCChainProvider) ChainSelector ¶ added in v0.14.0
func (p *RPCChainProvider) ChainSelector() uint64
ChainSelector returns the chain selector of the simulated chain managed by this provider.
func (*RPCChainProvider) Initialize ¶ added in v0.14.0
func (p *RPCChainProvider) Initialize(ctx context.Context) (chain.BlockChain, error)
Initialize initializes the RPCChainProvider, setting up the EVM chain with the provided configuration. It returns the initialized chain.BlockChain or an error if initialization fails.
func (*RPCChainProvider) Name ¶ added in v0.14.0
func (*RPCChainProvider) Name() string
Name returns the name of the RPCChainProvider.
type RPCChainProviderConfig ¶ added in v0.14.0
type RPCChainProviderConfig struct { // Required: A generator for the deployer key. Use TransactorFromRaw to create a deployer // key from a private key, or TransactorFromKMS to create a deployer key from a KMS key. DeployerTransactorGen SignerGenerator // Required: At least one RPC must be provided to connect to the EVM node. RPCs []rpcclient.RPC // Required: ConfirmFunctor is a type that generates a confirmation function for transactions. // Use ConfirmFuncGeth to use the Geth client for transaction confirmation, or // ConfirmFuncSeth to use the Seth client for transaction confirmation with richer debugging. // // If in doubt, use ConfirmFuncGeth. ConfirmFunctor ConfirmFunctor // Optional: ClientOpts are additional options to configure the MultiClient used by the // RPCChainProvider. These options are applied to the MultiClient instance created by the // RPCChainProvider. You can use this to set up custom HTTP clients, timeouts, or other // configurations for the RPC connections. ClientOpts []func(client *rpcclient.MultiClient) // Optional: A generator for the additional user transactors. If not provided, no user // transactors will be generated. UsersTransactorGen []SignerGenerator // Optional: Logger is the logger to use for the RPCChainProvider. If not provided, a default // logger will be used. Logger logger.Logger }
RPCChainProviderConfig holds the configuration to initialize the RPCChainProvider.
type SignerGenerator ¶ added in v0.16.0
type SignerGenerator interface { Generate(chainID *big.Int) (*bind.TransactOpts, error) SignHash(hash []byte) ([]byte, error) }
SignerGenerator is an interface for generating geth's *bind.TransactOpts instances and providing hash signing capabilities. These instances are used to sign transactions using geth bindings, and the SignHash method allows signing of arbitrary hashes.
func TransactorFromKMS ¶ added in v0.14.0
func TransactorFromKMS(keyID, keyRegion, awsProfileName string) (SignerGenerator, error)
TransactorFromKMS creates a SignerGenerator that uses a KMS key to sign transactions.
It requires the KMS key ID, region, and optionally an AWS profile name. If the AWS profile name is not provided, it defaults to using the environment variables to determine the AWS profile.
func TransactorFromKMSSigner ¶ added in v0.14.0
func TransactorFromKMSSigner(signer *KMSSigner) SignerGenerator
TransactorFromKMSSigner creates a SignerGenerator from an existing KMSSigner instance.
func TransactorFromRaw ¶ added in v0.14.0
func TransactorFromRaw(privKey string, opts ...GeneratorOption) SignerGenerator
TransactorFromRaw returns a generator which creates a transactor from a raw private key.
func TransactorRandom ¶ added in v0.14.0
func TransactorRandom() SignerGenerator
TransactorRandom is a SignerGenerator that creates a transactor with a random private key. A random private key is generated the first time Generate() or SignHash is called, and the same key is used for subsequent calls.
type SimChainProvider ¶ added in v0.14.0
type SimChainProvider struct {
// contains filtered or unexported fields
}
SimChainProvider manages an Simulated EVM chain that is backed by go-ethereum's in memory simulated backend.
func NewSimChainProvider ¶ added in v0.14.0
func NewSimChainProvider( t *testing.T, selector uint64, config SimChainProviderConfig, ) *SimChainProvider
NewSimChainProvider creates a new SimChainProvider with the given selector and configuration.
func (*SimChainProvider) BlockChain ¶ added in v0.14.0
func (p *SimChainProvider) BlockChain() chain.BlockChain
BlockChain returns the simulated chain instance managed by this provider. You must call Initialize before using this method to ensure the chain is properly set up.
func (*SimChainProvider) ChainSelector ¶ added in v0.14.0
func (p *SimChainProvider) ChainSelector() uint64
ChainSelector returns the chain selector of the simulated chain managed by this provider.
func (*SimChainProvider) Initialize ¶ added in v0.14.0
func (p *SimChainProvider) Initialize(ctx context.Context) (chain.BlockChain, error)
Initialize sets up the simulated chain with a deployer account and additional accounts as specified in the configuration. It returns an initialized evm.Chain instance that can be used to interact with the simulated chain.
Each account is prefunded with 1,000,000 Ether (1 million wei).
func (*SimChainProvider) Name ¶ added in v0.14.0
func (*SimChainProvider) Name() string
Name returns the name of the SimChainProvider.
type SimChainProviderConfig ¶ added in v0.14.0
type SimChainProviderConfig struct { // Optional: NumAdditionalAccounts is the number of additional accounts to generate for the // simulated chain. NumAdditionalAccounts uint // Optional: BlockTime configures the time between blocks being committed. By default, this is // set to 0s, meaning that blocks are not mined automatically and you must call the Commit // method on the Simulated Backend to produce a new block. BlockTime time.Duration }
SimChainProviderConfig holds the configuration to initialize the SimChainProvider.
type SimClient ¶ added in v0.14.0
type SimClient struct { // Embed the simulated.Client to provide access to its methods and adhere to the OnchainClient interface. simulated.Client // contains filtered or unexported fields }
SimClient is a wrapper struct around a simulated backend which implements OnchainClient but also exposes backend methods.
func NewSimClient ¶ added in v0.14.0
NewSimClient creates a new wrappedSimBackend instance from a simulated backend.
type ZkSyncCTFChainProvider ¶
type ZkSyncCTFChainProvider struct {
// contains filtered or unexported fields
}
ZkSyncCTFChainProvider manages an ZkSync EVM chain instance running inside a (CTF) Docker container.
This provider requires Docker to be installed and operational. Spinning up a new container can be slow, so it is recommended to initialize the provider only once per test suite or parent test to optimize performance.
func NewZkSyncCTFChainProvider ¶
func NewZkSyncCTFChainProvider( t *testing.T, selector uint64, config ZkSyncCTFChainProviderConfig, ) *ZkSyncCTFChainProvider
NewZkCTFChainProvider creates a new ZkSyncCTFChainProvider with the given selector and configuration.
func (*ZkSyncCTFChainProvider) BlockChain ¶
func (p *ZkSyncCTFChainProvider) BlockChain() chain.BlockChain
BlockChain returns the ZkSync EVM chain instance managed by this provider. You must call Initialize before using this method to ensure the chain is properly set up.
func (*ZkSyncCTFChainProvider) ChainSelector ¶
func (p *ZkSyncCTFChainProvider) ChainSelector() uint64
ChainSelector returns the chain selector of the ZkSync EVM chain managed by this provider.
func (*ZkSyncCTFChainProvider) Initialize ¶
func (p *ZkSyncCTFChainProvider) Initialize(ctx context.Context) (chain.BlockChain, error)
Initialize sets up the ZkSync EVM chain instance managed by this provider. It starts a CTF container, initializes the Ethereum client, and sets up the chain instance with the necessary transactors and deployer key gathered from the CTF's default zkSync accounts. The first account is used as the deployer key, and the rest are used as users for the chain.
func (*ZkSyncCTFChainProvider) Name ¶
func (*ZkSyncCTFChainProvider) Name() string
Name returns the name of the ZkSyncCTFChainProvider.
type ZkSyncCTFChainProviderConfig ¶
type ZkSyncCTFChainProviderConfig struct { // Required: A sync.Once instance to ensure that the CTF framework only sets up the new // DefaultNetwork once Once *sync.Once }
ZkSyncCTFChainProviderConfig holds the configuration to initialize the ZkSyncCTFChainProvider.
type ZkSyncRPCChainProvider ¶ added in v0.15.0
type ZkSyncRPCChainProvider struct {
// contains filtered or unexported fields
}
ZkSyncRPCChainProvider is a chain provider that provides a chain that connects to an EVM node via RPC.
func NewZkSyncRPCChainProvider ¶ added in v0.15.0
func NewZkSyncRPCChainProvider( selector uint64, config ZkSyncRPCChainProviderConfig, ) *ZkSyncRPCChainProvider
NewZkSyncRPCChainProvider creates a new instance with the given selector and configuration.
func (*ZkSyncRPCChainProvider) BlockChain ¶ added in v0.15.0
func (p *ZkSyncRPCChainProvider) BlockChain() chain.BlockChain
BlockChain returns the simulated chain instance managed by this provider. You must call Initialize before using this method to ensure the chain is properly set up.
func (*ZkSyncRPCChainProvider) ChainSelector ¶ added in v0.15.0
func (p *ZkSyncRPCChainProvider) ChainSelector() uint64
ChainSelector returns the chain selector of the simulated chain managed by this provider.
func (*ZkSyncRPCChainProvider) Initialize ¶ added in v0.15.0
func (p *ZkSyncRPCChainProvider) Initialize(ctx context.Context) (chain.BlockChain, error)
Initialize initializes the ZkSyncRPCChainProvider, setting up the EVM chain with the provided configuration. It returns the initialized chain.BlockChain or an error if initialization fails.
func (*ZkSyncRPCChainProvider) Name ¶ added in v0.15.0
func (*ZkSyncRPCChainProvider) Name() string
Name returns the name of the ZkSyncRPCChainProvider.
type ZkSyncRPCChainProviderConfig ¶ added in v0.15.0
type ZkSyncRPCChainProviderConfig struct { // Required: A generator for the deployer key. Use TransactorFromRaw to create a deployer // key from a private key, or TransactorFromKMS to create a deployer key from a KMS key. DeployerTransactorGen SignerGenerator // Required: A generator for the ZkSync signer. The generator you choose should match the // type of deployer transactor generator you are using. For example, if you are using // TransactorFromRaw, you should use ZkSyncSignerFromRaw, or if you are using // TransactorFromKMS, you should use ZkSyncSignerFromKMS. ZkSyncSignerGen ZkSyncSignerGenerator // Required: At least one RPC must be provided to connect to the EVM node. RPCs []rpcclient.RPC // Required: ConfirmFunctor is a type that generates a confirmation function for transactions. // Use ConfirmFuncGeth to use the Geth client for transaction confirmation, or // ConfirmFuncSeth to use the Seth client for transaction confirmation with richer debugging. // // If in doubt, use ConfirmFuncGeth. ConfirmFunctor ConfirmFunctor // Optional: ClientOpts are additional options to configure the MultiClient used by the // RPCChainProvider. These options are applied to the MultiClient instance created by the // RPCChainProvider. You can use this to set up custom HTTP clients, timeouts, or other // configurations for the RPC connections. ClientOpts []func(client *rpcclient.MultiClient) // Optional: Logger is the logger to use for the RPCChainProvider. If not provided, a default // logger will be used. Logger logger.Logger }
ZkSyncRPCChainProviderConfig holds the configuration to initialize the RPCChainProvider. While zkSync uses the same underlying EVM chain, it requires a different setup for the deployer key and signer.
type ZkSyncSignerGenerator ¶ added in v0.15.0
type ZkSyncSignerGenerator interface {
Generate(chainID *big.Int) (zkAccounts.Signer, error)
}
ZkSyncSignerGenerator is an interface for
func ZKSyncSignerRandom ¶ added in v0.15.0
func ZKSyncSignerRandom() ZkSyncSignerGenerator
ZkSyncSignerRandom returns a generator which creates a ZkSync signer with a random private key.