From d721503da6e9153f954715a7539da5fb230c3210 Mon Sep 17 00:00:00 2001 From: bruwbird Date: Thu, 27 Feb 2025 10:27:51 +0900 Subject: [PATCH] simulated: add WithHTTPRPCServer config Introduce a new WithHTTPRPCServer function to configure the simulated backend with host, port, and modules: - Enable HTTP-based RPC access for local testing - Simplify node setup for developers and testers --- ethclient/simulated/options.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ethclient/simulated/options.go b/ethclient/simulated/options.go index 40bcb37bd1..b6ef9565ac 100644 --- a/ethclient/simulated/options.go +++ b/ethclient/simulated/options.go @@ -53,3 +53,17 @@ func WithMinerMinTip(tip *big.Int) func(nodeConf *node.Config, ethConf *ethconfi ethConf.Miner.GasPrice = tip } } + +// WithHTTPRPCServer configures the simulated backend so that the node runs an HTTP server +// on the specified host and port, and enables the specified HTTP modules. +// Example usage: +// +// NewBackend(alloc, WithHTTPRPCServer("localhost", 8545, []string{"eth", "net", "web3"})) +func WithHTTPRPCServer(host string, port int, + modules []string) func(nodeConf *node.Config, ethConf *ethconfig.Config) { + return func(nodeConf *node.Config, ethConf *ethconfig.Config) { + nodeConf.HTTPHost = host + nodeConf.HTTPPort = port + nodeConf.HTTPModules = modules + } +}