question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`truffle test` hangs if no `networks` are specified and Ganache is running on port `7545`

See original GitHub issue

From a quick look, I believe https://github.com/trufflesuite/truffle/blob/cbd741b40696d6f7f6053ae007e1fdfb22483237/packages/truffle-core/lib/develop.js#L23-L26 is part of the issue.

If the child process can’t start ganache then when it rejects (here: https://github.com/trufflesuite/truffle/blob/cbd741b40696d6f7f6053ae007e1fdfb22483237/packages/truffle-core/chain.js#L237) truffle never gets notified of the truffle.ready event (here: https://github.com/trufflesuite/truffle/blob/cbd741b40696d6f7f6053ae007e1fdfb22483237/packages/truffle-core/chain.js#L249)

Also, if the chain.js process crashes truffle doesn’t seem to be listening. Might need to listen to the close event: https://nodejs.org/api/child_process.html#child_process_event_close

I don’t seen any harm in using a different port for truffle’s internal ganache server instance, but I don’t have much experience with using truffle myself. For reliability you could (should?) try to start the ganache-core server on a random port, if it fails due to the port already being bound, try again on another random port, and maybe a few more tries before failing.

Alternatively, you could do what truffle migrate does and just (try to) use the already bound 7545 port.

To get a big speed boost you could experiement with running ganache-core as a provider (Ganache.provider(options) instead of Ganache.server(options).

Let me know if you have ganache-related questions!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:18 (15 by maintainers)

github_iconTop GitHub Comments

3reactions
mallapurbharatcommented, Jul 30, 2019

I face a similar issue when I download a fresh instance of MetaCoin box. Truffle compile, truffle migrate works (looks like if Ganache is running, it detects Ganache anyway and deploys successfully), but truffle test just hangs. I was unable to understand why test was hanging, then I realized that in truffle-config.js, there was no network specified as by default all lines are commented out. Once I uncommented the “development” section, truffle test succeeded!

It would be good if truffle test command could check and warn that there is no network specified.

0reactions
ashu17188commented, Mar 17, 2022

I am using Ubuntu 20.X, in my case as well “truffle test” hangs. My Resolution:

  1. Again I have done => npm install -g truffle, truffle updated to v5.5.4 and it started working.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting stuck in truffle testing - Ethereum Stack Exchange
Once I explicitly added the development network, truffle test began to work. ... networks: { development: { host: "127.0.0.1", port: 7545, ...
Read more >
ConsenSys/truffle - Gitter
Hey everyone, truffle test doesn't work at all and just hangs but test from ... to have a Ganache instance running at port...
Read more >
Ganache (from Truffle) hangs when started - Stack Overflow
However, the solution is to close or change the port of the other application that uses the port 7545. Then you can run...
Read more >
Ganache settings - Truffle Suite
Server shows details about the network connection, including hostname, port, network ID, and whether to automatically mine each transaction into a block.
Read more >
A Guide to Building, Testing, and Deploying your First DApp ...
If you're new to Ethereum development and wonder how to put the pieces together to build a... Tagged with dapp, truffle, solidity, web3....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found