Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions blockchain/test/ElectionFactory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ describe("ElectionFactory", function () {
maxVotes: 3,
options: ["Option 1", "Option 2", "Option 3"]
};
// candidateID is required for tests, although the contract overwrites it during initialization
// This ensures consistent test behavior
const mockCandidates = [
{
name: "Candidate 1",
description: "First candidate",
candidateID: 0
},
{
name: "Candidate 2",
description: "Second candidate",
candidateID: 1
}
];


beforeEach(async function () {
[owner, user1, user2, router] = await ethers.getSigners();
Expand All @@ -35,26 +50,26 @@ describe("ElectionFactory", function () {

describe("Election Creation", function () {
it("Should create a new election", async function () {
await factory.createElection(mockElectionInfo, 0, 0);
await factory.createElection(mockElectionInfo,mockCandidates, 0, 0);
expect(await factory.electionCount()).to.equal(1);

const openElections = await factory.getOpenElections();
expect(openElections.length).to.equal(1);
});

it("Should allow multiple elections creation", async function () {
await factory.createElection(mockElectionInfo, 0, 0);
await factory.createElection(mockElectionInfo, 0, 0);
await factory.createElection(mockElectionInfo,mockCandidates, 0, 0);
await factory.createElection(mockElectionInfo,mockCandidates, 0, 0);

expect(await factory.electionCount()).to.equal(2);
const openElections = await factory.getOpenElections();
expect(openElections.length).to.equal(2);
});
});

describe("Election Deletion", function () {
beforeEach(async function () {
await factory.createElection(mockElectionInfo, 0, 0);
await factory.createElection(mockElectionInfo, mockCandidates,0, 0);
});

it("Should allow owner to delete their election", async function () {
Expand Down Expand Up @@ -89,4 +104,4 @@ describe("ElectionFactory", function () {
).to.be.revertedWithCustomError(factory, "OwnerRestricted");
});
});
});
});