An example truffle project showing how to use 0x dev tools with the Truffle framework.
First run yarn
or npm i
to install the dependencies.
This project contains two contracts. MetaCoin
and SafeMath
. MetaCoin
is a coin-like contract where the owner of it initially has 1 token. SafeMath
is called by MetaCoin
to perform addition and substraction safely.
There is a single test that tries to send 2 tokens from the owner. Owner doesn't have enough tokens so it reverts.
Now we're ready to run the tests:
yarn test
They will fail and we'll get an error:
Error: Transaction: 0x012d87cbbd7799ef361872571e75d37b7e53192161a1955ef5d6c97f1531d613 exited with an error (status 0).
Please check that the transaction:
- satisfies all conditions set by Solidity `require` statements.
- does not trigger a Solidity `revert` statement.
Not very helpful. Now let's run it using @0x/sol-trace
yarn trace
dev-tools-truffle-example/contracts/SafeMath.sol:12:8:
require(b <= a)
dev-tools-truffle-example/contracts/MetaCoin.sol:13:25:
SafeMath(safeMath).sub(balances[msg.sender], amount)
That's better. Now we don't need to check all the require and revert statements but we know exactly which one reverted and who called it.
yarn coverage
It will generate the HTML report and open it in the default browser. You can use any other istanbul reporter too. (text, json, etc.).
yarn profile
To test sol-compiler run
yarn sol-compiler
or
yarn sol-compiler:watch
Apache 2.0