Consider this voting contract
contract Voting {
mapping (bytes32 => uint8) public votesReceived;
mapping (bytes32 => bool) public candidateList;
function Voting(bytes32[] candidateNames) {
for(uint i = 0; i < candidateNames.length; i++) {
candidateList[candidateNames[i]] = true;
}
}
function totalVotesFor(bytes32 candidate) returns (uint8) {
require(validCandidate(candidate) == true);
return votesReceived[candidate];
}
function voteForCandidate(bytes32 candidate) {
require(validCandidate(candidate) == true);
votesReceived[candidate] += 1;
}
function validCandidate(bytes32 candidate) returns (bool) {
return candidateList[candidate];
}
}
if I call validCandidate with a valid name (ie. a name included in the array passed to the constructor), it works. But for invalid names, I got a invalid opcode exception. I thought that maps had 0/false by default, is it not the case?