Skip to content
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

Enhancement/smart contract #92

Merged
merged 30 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d998282
rewire waitlist page
Jan 15, 2025
eabeaf7
change waitlist destination
Jan 18, 2025
ecf17b1
bringing the waitlist notification local
mikehammond Jan 18, 2025
8086b2c
wip: light mode
Jan 18, 2025
aac36f9
minor light mode fixes
Jan 18, 2025
581ab20
refactor: remove election-related pages and components
Jan 18, 2025
d0f7661
feat: add framer-motion for animations
Jan 18, 2025
d206d8f
feat: add hide-scrollbar utility and update animations in landing com…
Jan 18, 2025
ead6324
only deploy if branch is main
mikehammond Jan 18, 2025
dcf36a8
updating hardhat config
mikehammond Jan 18, 2025
259b7cf
cleaning up the root folder
mikehammond Jan 18, 2025
195e353
feat: add Logo and LightSource components, update Footer and Header t…
Jan 22, 2025
8229c3f
add supportedBy dark mode images
Jan 22, 2025
07bd2cd
fix: update border color in WaitlistForm for better visibility
Jan 22, 2025
ba1cb01
feat: create LandingLayout component to encapsulate Header and improv…
Jan 22, 2025
c6ec26d
feat: implement Dashboard layout with Sidebar component and navigatio…
Jan 25, 2025
f4e6b45
feat: add Header component to Dashboard layout and create placeholder…
Jan 25, 2025
3747a1a
feat: implement CreateElection page with tabbed navigation and form c…
Jan 25, 2025
3532800
feat: add candidates slide to createElection flow
Jan 29, 2025
8269b4e
cleanup sponsors
Jan 29, 2025
181cbf7
feat: add mobile navigation
Jan 29, 2025
5dd3a0a
feat: implement theme switcher
Jan 29, 2025
3a0b9f8
Merge branch 'main' of https://github.com/mowblox/truecast into featu…
Feb 1, 2025
442c891
update tailwind config
Feb 1, 2025
9fdca4e
feat: add image upload functionality to candidate form
Feb 1, 2025
5bcfd95
feat: add Voters component and update election creation page
Feb 1, 2025
c560bf7
add voter function modified to accept array or voter addresses
AngeloKwakye Feb 8, 2025
06e8c3e
Merge remote-tracking branch 'origin/main' into enhancement/smart-con…
mikehammond Feb 8, 2025
dda34ba
refactoring test and renaming addVoter to addVoters
mikehammond Feb 8, 2025
e95bca0
adding registered field to voter struct to check if is registered
mikehammond Feb 8, 2025
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
13 changes: 10 additions & 3 deletions blockchain/contracts/Election.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ contract Election {
string image;
}
struct Voter {
bool registered;
bool voted;
uint candidateId;
}
Expand Down Expand Up @@ -86,9 +87,15 @@ contract Election {
return allCandidates;
}

function addVoter(address _voterAddress) public onlyWhileOpen {
require(!voters[_voterAddress].voted, "Voter is already registered");
voters[_voterAddress] = Voter(false, 0);
function addVoters(address[] memory _voterAddresses) public onlyWhileOpen {
uint length = _voterAddresses.length;
for (uint i = 0; i < length; i++) {
require(
!voters[_voterAddresses[i]].registered,
"Voter is already registered"
);
voters[_voterAddresses[i]] = Voter(true, false, 0);
}
}

function getVoter(address _voterAddress) public view returns (bool, uint) {
Expand Down
12 changes: 6 additions & 6 deletions blockchain/test/Election.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe("Election Contract", function () {
await hre.ethers.provider.send("evm_mine", []);

await expect(
election.addCandidate("Invalid", "Team X", "invalid.jpg")
election.addCandidate("Invalid", "Team X", "invalid.jpg")
).to.be.revertedWithCustomError(election, "ElectionEnded");
});

Expand Down Expand Up @@ -107,7 +107,7 @@ describe("Election Contract", function () {
await hre.ethers.provider.send("evm_mine", []);

await election.addCandidate("Alice", "Team A", "alice.jpg");
await election.addVoter(voter1.address);
await election.addVoters([voter1.address]);

await expect(election.connect(voter1).castVote(999))
.to.be.revertedWith("Invalid candidate. Please enter a valid candidate ID");
Expand All @@ -124,7 +124,7 @@ describe("Election Contract", function () {
await hre.ethers.provider.send("evm_mine", []);

await election.addCandidate("Alice", "Team A", "alice.jpg");
await election.addVoter(voter1.address);
await election.addVoters([voter1.address]);

// Cast the first vote
await election.connect(voter1).castVote(1);
Expand All @@ -144,15 +144,15 @@ describe("Election Contract", function () {
await hre.ethers.provider.send("evm_increaseTime", [timeToAdvance]);
await hre.ethers.provider.send("evm_mine", []);

await expect(election.addVoter(voter1.address))
await expect(election.addVoters([voter1.address]))
.to.be.revertedWithCustomError(election, "ElectionEnded");
});

it("should prevent adding a voter before election starts", async function () {
const { election, startDate, voter1 } = await loadFixture(deployElectionFixture);

// Attempt to add a voter before the election starts
await expect(election.addVoter(voter1.address))
await expect(election.addVoters([voter1.address]))
.to.be.revertedWithCustomError(election, "ElectionNotStarted");
});

Expand All @@ -168,7 +168,7 @@ describe("Election Contract", function () {

// Add a candidate and a voter
await election.addCandidate("Alice", "Team A", "alice.jpg");
await election.addVoter(voter1.address);
await election.addVoters([voter1.address]);

// Cast a vote
await election.connect(voter1).castVote(1);
Expand Down
2 changes: 1 addition & 1 deletion frontend/tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ const config: Config = {
},
};

export default config;
export default config;