Debugging with Truffle

Truffle includes a built-in debugger to debug transactions made against your contracts. It supports elementary debugging operations, such as code-stepping (over, into, out, next, and instruction), breakpoints, and watching expressions.

To try the debugging features, let's intentionally introduce a bug into the Ctontine contract and redeploy it into Ganache. Afterward, we will run the tests and use Truffle’s debugger to detect the source of the error.

First, in the Ctontine contract code, change the first require() statement in the join() method as follows:

require(!Tplayer.exist(msg.sender));

As you can see, we reversed the required condition by adding an exclamation mark, "!", indicating that the player shouldn’t be registered in the Cplayer contract. This goes against our previous test's logic as we add the testing player before calling each unit test, including a test for the join() method.

Now, if you run the truffle test test/test.js --network my_ganache tests, you will see the following error:

The output shows that we have a serious problem with the Ctontine tests and the VM exception while processing transaction error message isn’t much help in detecting the cause behind it. Let’s chase the bug.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset