1

I'm new to blockchain development and can't figure out what I have done wrong. This is my smart contract Election :

    pragma solidity ^0.5.0;


contract Election {
    struct Candidate {
        uint id;
        string name;
        uint votecount;
    
    }
    
mapping (uint => Candidate) public candidates;
uint public candidateCount;

  constructor() public {
  a=5;
   addCandidate("Candidate 1");
   addCandidate("Candidate 2");
  }
  function addCandidate (string memory _name)  private {
    candidateCount++;
    candidates[candidateCount]=Candidate(candidateCount,_name,0);

  }

 
}

This is a javascript file to test if there are exactly two candidates:

var elec=artifacts.require("./Election.sol");
contract("Election",function(accounts){
    it("initialised with two candidates", function(){
         var a;
        return Election.deployed().then(function(instance)
        {

            return instance.candidateCount.call();

        }).then(function(count){
            assert.equal(count.toNumber(),2);
        });

    });

});

enter image description here

This is the error I'm getting. Somebody please help.

1 Answer 1

1

Change this:

var elec = artifacts.require("./Election.sol");

To this:

var Election = artifacts.require("./Election.sol");

Or this:

Election.deployed()

To this:

elec.deployed()

Note that artifacts.require takes as input a contract name, not a file path.

So you can get rid of the ./ part and the .sol part in the string that you are passing to it.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.