I am using ganache and truffle to write some tests in solidity (following the example in https://www.trufflesuite.com/docs/truffle/testing/writing-tests-in-solidity).

I am getting the usual, not really helpful, message: "Error: Returned error: VM Exception while processing transaction: revert".

I have added events in my code, both in the test and in the actual contract.

Nothing is shown when the error happens.

It does not show the transaction that failed and so I cannot try to start a debug session.

With no breakpoints and no logging. How can I debug this test?

Using the console, I've verified that the contract is working as expected.


First, event logs are not saved on transactions failing so you can' use logs to see where your code stopped.

If you are using geth you can use the rpc command debug_traceTransaction with the traceCaller argument, it will return all the calls made to each external contract starting from the contract you are calling.

If you are using ganache, the option above is not available, and your best bet is to create a testing smart contract that would never fail transactions in order to get the event logs. Another option is to use solidity's try and catch on the contract calls you think would revert with no message and in your catch block, you can revert with your own message.

the no message revert could easily be an issue with your own contract code not executing correctly, something like an index out of range, or when trying to loop over a list that changes.

  • If I understand correctly, by "a testing smart contract" you mean a proxy that will use raw calls and get a boolean as a result (where true means success). Aug 18 '21 at 21:58
  • No, what i meant is you create a version of the contract you are calling that will never revert. if you can of course. that way you can use the logs to see if your actions were done correctly or not. it's a very specific way, it worked for me in couple of instances but not always. Aug 19 '21 at 15:30
  • That's not feasible for me without a proxy because I do not know where and why it's failing, but thanks: it could be useful in other cases. Aug 21 '21 at 9:54

You might wanna check Hardhat when it comes to debugging. It's a dev environment where you can place console.logs ( the same way as you do in javascript ) inside your smart contract and this will give you better overview where exactly is your logic breaking.

  • Can I use hardat with solidity tests ? I mean, tests written in solidity instead of javascript or typescript. Aug 19 '21 at 10:42

Some possible options to test things:

  1. Use Hardhat console.log.

  2. Use Tenderly Explorer (you can use testnet verified contracts or even local contracts using their CLI) or if the contract is on testnet, you can also run it in their simulator.

  3. Start isolating the function calls. And identifying one by one until where the call is reaching and what state changes are it making, etc.

Doing 1 is the easiest method, 2 is hard, and 3 is the hardest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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