3

I am using backends.SimulatedBackend in unit testing.

however, backends.SimulatedBackend is not compatible with ethclient.Client.

Any one can advise how to create a ethclient.Client in unit testing? Thank you

1 Answer 1

0

check this out..

Use backends.SimulatedBackend and ethclient.Client synonymously

Probably the following package helps with what you try to achieve...

https://github.com/bonedaddy/go-defi/blob/main/utils/blockchain.go

At line 12 at the comments it says:

// Blockchain is a generalized interface for interacting with the ethereum blockchain

// it satisfies all functions required by the ethclient, and simulated backend types.

// This allows you to use ethclient and the simulated backend interchangeably which is

// particularly useful for testing

You could try to use exactly this "Blockchain" interface or treat the backends.SimulatedBackend and the ethclient.Client sperately (as it should be).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.