-
Notifications
You must be signed in to change notification settings - Fork 509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
throws an exception for double voting. AssertionError: accepts first vote: expected <BN: 0> to equal 1 #57
Comments
Now it is showing assertion error: accepts first vote |
it("throws an exception for double voting", function() { This is the code... |
it("throws an exception for double voting", function() { My last test executes successfully by changing the code as written above. |
it("throws an exception for double voting", function() { return Election.deployed().then(function(instance) { CandidatesInstance = instance; CandidateId = 2; CandidatesInstance.vote(CandidateId, {from: accounts[3]}); return CandidatesInstance.candidates(CandidateId); }).then(function(recipt) { return CandidatesInstance.voters(accounts[3]); }).then(function(voteAdded) { assert("The voter casted his vote"); return CandidatesInstance.candidates(CandidateId); }).then(function(candidate2) { let voteCount = candidate2[2]; assert.equal(voteCount, 1, "accepts the 1st vote"); // If tries to vote again CandidateId = 2; return CandidatesInstance.vote(CandidateId, {from: accounts[3]}); }).then(assert.fail).catch(function(error) { assert(error.message, "Error message must contain revert"); return CandidatesInstance.candidates(1); }).then(function(candidate1) { let voteCount = candidate1[2]; assert.equal(voteCount, 1, "Candidate 1 did not recieve any vote"); return CandidatesInstance.candidates(2); }).then(function(candidate2) { let voteCount = candidate2[2]; assert.equal(voteCount, 1, "Candidate 2 did not recieve any vote"); }); })
|
This approach worked. Simply, we change "assert.equal(voteCount, 1, "candidate 2 did not receive any votes");" to "assert.equal(voteCount, 0, "candidate 2 did not receive any votes");" |
it("throws an exception for double voting", ()=> {
return Election.deployed().then(instance => {
electionInstance = instance;
candidateId = 2;
return electionInstance.vote(candidateId, {from: accounts[2]});
}).then(receipt => {
//console.log(receipt)
return electionInstance.voters(accounts[2]);
}).then(voted => {
assert(voted, "Vote Successfully given");
return electionInstance.vote(candidateId, {from:accounts[2]});
}).then(assert.fail).catch(error=>{
//console.log(error);
assert(error.message.indexOf("revert") >= 0, "Double Vote Not Allowed");
return electionInstance.candidates(1);
}).then(candidate1 => {
var voteCount = candidate1[2];
assert.equal(voteCount, 1, "Candidate 1 did not receive any votes");
return electionInstance.candidates(2);
}).then(candidate2 => {
var voteCount = candidate2[2];
assert.equal(voteCount, 1, "Candidate 2 did not reveive any vote");
})
}); Use this code. This works fine for me. |
hey please can you share your repo |
Truffle test failing because in 'throws an exception for double voting'.
AssertionError: accepts first vote: expected <BN: 0> to equal 1
The text was updated successfully, but these errors were encountered: