Skip to content

Commit

Permalink
missed push
Browse files Browse the repository at this point in the history
  • Loading branch information
ibourn committed Jun 25, 2023
1 parent ec43e61 commit a4ec224
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
15 changes: 14 additions & 1 deletion 4. Truffle & CI-CD/VotingTest/test/Test_02_RegisterVoter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const Voting = artifacts.require("Voting");
const { getMockVoters, workflow } = require("./Test_VotingHelpers.js");

contract("Voting / Test_02", (accounts) => {
const { owner, voter1 } = getMockVoters(accounts);
const { owner, voter1, voter2 } = getMockVoters(accounts);

const curStatusId = 0;
const nextStatusId = 1;
Expand All @@ -26,6 +26,19 @@ contract("Voting / Test_02", (accounts) => {
expect(status.toNumber()).to.equal(curStatusId);
});

it("should revert to get Voter1 when Voter1 not registered", async function () {
await expectRevert(
votingInstance.getVoter(voter1, { from: voter1 }),
"You're not a voter"
);
});

it("checks voter2 is not registered", async function () {
await votingInstance.addVoter(voter1, { from: owner });
const voter = await votingInstance.getVoter(voter2, { from: voter1 });
expect(voter.isRegistered).to.equal(false);
});

describe("adding a voter", () => {
beforeEach(async () => {
receipt = await votingInstance.addVoter(voter1, { from: owner });
Expand Down
18 changes: 12 additions & 6 deletions 4. Truffle & CI-CD/VotingTest/test/Test_04_VotingSesson.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,27 @@ contract("Voting / Test_04", (accounts) => {
const testProposals = [0, 1, 2, 3];
testProposals.forEach(function (t) {
it(`checks that the ${t} proposal has no vote`, async function () {
const receipt = await votingInstance.getOneProposal(t, {
const proposal = await votingInstance.getOneProposal(t, {
from: voter1,
});
const voteCount = receipt[1];
expect(voteCount).to.not.equal(0);
expect(proposal.voteCount).to.be.bignumber.equal(new BN(0));
});
});
const testVoters = [voter1, voter2, voter3];
testVoters.forEach(function (t) {
it(`checks that the ${t} voter has no voted proposal`, async function () {
const receipt = await votingInstance.getVoter(t, {
const voter = await votingInstance.getVoter(t, {
from: voter1,
});
const votedProposal = receipt[2];
expect(votedProposal).to.not.equal(0);
expect(voter.hasVoted).to.equal(false);
});
});
testVoters.forEach(function (t) {
it(`checks that the ${t} voter votedProposalId is default value: 0`, async function () {
const voter = await votingInstance.getVoter(t, {
from: voter1,
});
expect(voter.votedProposalId).to.be.bignumber.equal(new BN(0));
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion 4. Truffle & CI-CD/VotingTest/test/Test_VotingHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = {
return votingInstance;
},
mockEndProposal: async (votingInstance, owner, voter1, voter2, voter3) => {
await votingInstance.addProposal("first propsoal", {
await votingInstance.addProposal("first proposal", {
from: voter1,
});
await votingInstance.addProposal("second proposal", {
Expand Down

0 comments on commit a4ec224

Please sign in to comment.