-
Notifications
You must be signed in to change notification settings - Fork 20k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable simulated back-end to be used via JSON RPC #21457
Comments
I spent some time thinking about this issue, but I don't think that we should implement it. The SimulatedBackend should imo only be used from go code and I don't think setting up a RPC API on it should be a priority. The sim backend is mainly useful for unit testing in go, for other use cases the For the simulated backend to be able to provide all necessary functions to create a meaningful RPC API, it needs to implement the go-ethereum/internal/ethapi/backend.go Line 41 in 45cb1a5
|
Massive +1 on this for e2e testing. Alternatively, is there a way to run with |
You can start it similar to every other command // start geth in one thread
go func() {
cmd := exec.Command("geth", "dev", "http.port=8545")
err := cmd.Start()
if err != nil {
log.Fatal(err)
}
err = cmd.Wait()
} and then connect to it using the ethclient in another thread cl, err := ethclient.Dial("127.0.0.1:8545") (Untested code) |
I think what @0xNero was asking is whether there is a way to spin up an RPC server that behaves like |
Came across this issue as I was trying to see if its possible to run https://github.com/crytic/etheno to capture calls made during tests using a simulated backend, so +1 to be able to capture JSON RPC sequences. Will give @MariusVanDerWijden 's snippet a try but definitely +1 on the feature overall. |
Plus one on this.
I often run into a situation of wrapping eth client methods like so func WaitForTransactionConfirmed(ctxt context.Context, ethClient *ethclient.Client, txHash common.Hash) (bool, error) with no real way to unit test them without a |
You can also start a normal geth node from code like this:
(You need to provide a genesis file to this method |
Better late than never! |
I'm actually not sure if the merged PR is entirely what you wanted originally though. @MariusVanDerWijden tagged this issue in his PR, but it doesn't fully match the description here. |
Hi there,
This is to continue the discussion in the following thread: #20212. The original thread proposed moving ethapi out of internal but was closed as the problem was solved a different way.
There's another good reason to consider moving ethapi out of internal:
I'm trying to use
go-ethereum
's RPC API over a simulated back-end object as a library. I'm using a simulated back-end for smart contracts from another programming language and would like to have some fallback access to the simulated back-end state through the RPC API rather than having to implement each end-point one by one.In order to set up the RPC API I'm using
NewServer()
and using a bi-directional pipe as thecodec
. The place where this approach fails is thatAPIs()
are only available to full or light ethereum clients, but not the simulated back-end. The simulated back-end exposesGetAPIs()
but this function is only available as part ofinternal/ethapi
.As a result I'm trying to effectively copy & paste the whole
internal/api
folder in my codebase but running into another related issue that I've filed.Would love to also hear your guidance on how to achieve this and hope this helps support the overall thinking around the
ethapi
!To summarize - from my perspective there should be a way to use
APIs
orGetAPIs
with the simulated back-end, I wouldn't actually need the wholeethapi
package to be exposed.The text was updated successfully, but these errors were encountered: