1

I'm writing a contract in solidity, in which a test case fails. I want to step through the code to find what's going wrong. I'm using truffle for development. This is what I do after making changes to the contract

truffle develop
compile
test ./test/NameOfMyTestCaseFile.sol

This returns failure on a particular test case.

The manual at DEBUGGING YOUR CONTRACTS, reads:

truffle debug <transaction hash>

I don't see any transaction hash output on my console. How do I use the debugger to step through the code ?

0

You can use Ganache and Remix to get transaction hashes for specific transactions. To use Ganache, go to your truffle.js file, and include a reference to it within module.exports:

module.exports = {
// See <http://truffleframework.com/docs/advanced/configuration>
// to customize your Truffle configuration!
    networks: {
        development: {
            host: "127.0.0.1",
            port: 7545,
            network_id: "*"
        }
    }
};

In Remix, run using a Web3 Provider environment option, and if you're using Ganache then the endpoint is http://127.0.0.1:7545. You can then use truffle or Remix to debug your code. Hope this helps!

| improve this answer | |
  • Thanks for your answer. Does this require going online ? I'm not writing any production code. This is a homework assignment that I'm trying to debug! Can I not do this offline ? – rranjik Dec 7 '18 at 2:57
  • I'm new to this environment. Could you please share more details ? – rranjik Dec 7 '18 at 3:04
  • Nope, this gets you to run an entirely private blockchain with dummy accounts so that you can test your functionality. You can download ganache here: truffleframework.com/ganache. Remix is an online IDE for solidity smart contracts. When you modify your truffle.js file, you are essentially telling it to point towards the accounts set up by Ganache. Then by setting up Remix to point to it too, everything is synchronized to work with the dummy accounts. Remix is an IDE and it allows you to compile, run and test your smart contracts without having to set up a front-end. – galal27 Dec 7 '18 at 3:18
  • If you're testing smart contracts for functionality and writing test cases for that, you can just use remix ide with the JavaScript VM and then write your test files and use truffle to confirm that they pass. You can find more info on Remix in their documentation: remix.readthedocs.io/en/latest/run_tab.html#run-setup – galal27 Dec 7 '18 at 3:36

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.