1) Open the Ganach
2) Open Sublimetext3 editor
3) create the folder contest1
4) install the truffle in the directory F:/>contest1>npm install truffle –g
5) Make the contract Election.sol using Solidity Program
7) f:
8) Check the truffle version
9) Write Solidity Program
10) Configure the deployment files in migration folder
12) Compile the Contract Program
13) Deploy the contract on blockchain network i.e. Ganache localhost blockchain
pragma solidity 0.4.24;
contract Election
{
struct Candidate
{
uint id; string name;
uint voteCount;
} // this is store candidate information
// Fetch candidate information using
// reference variable
mapping(uint => Candidate) public candidate;
//variable for vote counting uint public candidateCount;
//constructor
function Election() public
{
addCandidate(“Sourabh”); addCandidate(“Neeta”);
}
// define addcandidate function
function addCandidate(string memory _name)private
{
candidateCount++;
candidate[candidateCount] = Candidate(candidateCount,_name,0);
}
}
14) Recompile the same Election contract
15) Deploy the Contract over the Ethereum Ganach
16) Fetching candidate
17) Fetch Individual Ganache node address
18) Open the two library files to deploy contract on Ethereum
Here Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing.. Assertion Library: Chai – Chai is a BDD/TDD assertion library for[node](http://nodejs.org) and browser that can be paired with it In the Test folder we have to create election.js file in sublimetext3
const Election = artifacts.require(“./Election.sol”); require(‘chai’).use(require(‘chai-as-promised’)).should();
contract(“Election”,function(accounts){it(“initialize with two candidate”,function(){return Election.deployed().then(function(instance){return instance.candidateCount();}).then(function(count){assert.equal(count,2);})});});