Giter Club home page Giter Club logo

dev-tools-truffle-example's Introduction

dev-tools-truffle-example

An example truffle project showing how to use 0x dev tools with the Truffle framework.

Intro

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.

Tests

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

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.

Sol-coverage

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.).

Sol-profiler

@0x/sol-profiler is gonna require some setup.

Because of a few issues with Ganache - it's not supported by @0x/sol-profiler yet. We'll be running Geth from a docker container for simplicity.

docker run -it --rm -p 8545:8501 0xorg/devnet
yarn profile

Sol-compiler

To test sol-compiler run

yarn sol-compiler

or

yarn sol-compiler:watch

Licence

Apache 2.0

dev-tools-truffle-example's People

Contributors

logvinovleon avatar nitper avatar

Watchers

James Cloos avatar Aleksei Tcelishchev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.