does truffle is necessary for smart contract testing? Is there any alternative way, so that we can perform smart contract testing without truffle?


Truffle is not necessary. You can write your own compile.js and Contract.test.js files to do the testing using mocha. you will have to install the solc and ganache-cli node modules for this.

Explanation in detail This will be your compile file:

const path = require("path");
const fs = require("fs");
const solc = require("solc");

//change the contractFileName
const path = path.resolve(__dirname, "contracts", contractFileName);
const source = fs.readFileSync(path, "utf8");

instead of 'Contract' it will be the name of the contract 
class you wrote in the solidity file. The colon is
module.exports = solc.compile(source, 1).contracts[":Contract"];

This will be your test file:

const assert = require("assert");
const ganache = require("ganache-cli");
const Web3 = require("web3");
const { interface, bytecode } = require("../compile");

const web3 = new Web3(ganache.provider());

//your before each logic goes here

describe(ContractName, ()=>{
//your it blocks go here
  • can you please explain this with example. – John Carter May 10 '19 at 10:16
  • i have edited the answer to include a basic explanation of compiling and testing without truffle – Sanjay S B May 10 '19 at 11:40

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.