Index

Ethereum

  1. Election
  2. Accounts
  3. Test
  4. Frontend
  5. Voting
  6. Validation
  7. Events

Events

 // voted event
    event votedEvent(
        uint indexed _candidateId
    );


 // trigger voted event
emit votedEvent(_candidateId);




assert.equal(receipt.logs.length, 1, "an event was triggerd");
assert.equal(receipt.logs[0].event, "votedEvent", "the event type is correct");
assert.equal(receipt.logs[0].args._candidateId.toNumber(), candidateId, "the candidate id is correct")

 it("allows a voter to cast a vote", function(){
        return Election.deployed().then(function(instance) {
            electionInstance = instance;
            candidateId = 1;
            return electionInstance.vote(candidateId, { from: accounts[0]});
        }).then(function(receipt) {
            assert.equal(receipt.logs.length, 1, "an event was triggerd");
            assert.equal(receipt.logs[0].event, "votedEvent", "the event type is correct");
            assert.equal(receipt.logs[0].args._candidateId.toNumber(), candidateId, "the candidate id is correct")
            return electionInstance.voters(accounts[0]);
        }).then(function(voted){
            assert(voted, "the voter was marked as voted");
            return electionInstance.candidates(candidateId);
        }).then(function(candidate){
            var voteCount = candidate[2];
            assert.equal(voteCount, 1, "increments the candidate's vote count");
        })
    });