trufflesuite / ganache

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github&utm_medium=referral&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_
MIT License
2.62k stars 675 forks source link

Support synchronous calls #15

Closed onbjerg closed 6 years ago

onbjerg commented 6 years ago

In relation to #11, one way I thought I could avoid using WebSockets would be to use the provider from ganache-core directly in my tests.

This did not work, since Web3 1.0.0 heavily relies on synchronous calls for things that are not subscriptions, but ganache-core does not support synchronous calls.

Expected Behavior

Current Behavior

Steps to Reproduce (for bugs)

  1. Install Web3 1.0.0.
  2. Create a new instance of Web3 using the provider from ganache-core (ganache.provider()).
  3. Use any method that is not a subscription, e.g. web3.eth.getAccounts()

Context

I am trying to use ganache or testrpc for my integration tests, but ganache does not support WebSockets or IPC (which is required for subscriptions since Web3 1.0.0), and ganache does not work by using the provider directly either, since synchronous calls will not work this way.

This sort of traps me in two ways. Either I...

onbjerg commented 6 years ago

Related to ethereumjs/testrpc#246

ewingrj commented 6 years ago

just do provider.send = provider.sendAsync. web3 1.0 only implements async requests. It just replaced the send with sendAsync and removed sendAsync. You can monkey patch the provider as a work around to get it to work with 1.0

onbjerg commented 6 years ago

Ah really? That's interesting information, thanks @perissology 😊 This should still be reflected in a new version (obviously breaking) of ganache-core when they migrate to Web3 1.0.0.

onbjerg commented 6 years ago

Can be fixed with a monkey patch where you bind send to sendAsync since these are the same in Web3 1.0.0.