Book Image

Truffle Quick Start Guide

By : Nikhil Bhaskar
Book Image

Truffle Quick Start Guide

By: Nikhil Bhaskar

Overview of this book

Truffle is a world-class development environment, testing framework and asset pipeline for Ethereum, aiming to make life as an Ethereum developer easier. If you are a web developer wanting to try your hand at developing Dapps with Truffle, then this is the book for you. This book will teach you to write smart contracts and build Dapps with Truffle. You will begin with covering the basics of Truffle, briefly explaining how it integrates Solidity and Web3, in orderto start building a mini decentralized application. Also, you will dive into migration, testing and integrating Truffle with the use of popular JavaScript frameworks. Lastly, you will ship your decentralized application and package it into a product. Moreover, you will go through the best practices in Truffle,so as to increase your proficiency in building Dapps with Truffle. By the end of the book, you will be able to write smart contracts and build decentralized applications with Truffle on Ethereum blockchains.
Table of Contents (9 chapters)

Writing unit tests with JavaScript

Inside the contracts folder, create a .js file that will house our tests; call it test-task-master.js.

Again, stick to the same practice of prepending our contract name with the word test so that it's clear that it's a test file. I prefer JavaScript file names to be snake case, but if you prefer camelCase file names, that is fine too.

Inside the test-task-master.js file, let's import our contract so we can make use of it in our tests:

const TaskMaster = artifacts.require("../contracts/TaskMaster.sol");

artifacts is automatically injected by Truffle inside our test environment, and it allows us to instantiate our contract easily for the purpose of testing.

Next, let's define a function where we will place all of the unit tests of our contract. Underneath the artifacts.require statement, add the following block of...