-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
blockchain_integration/pi_network/tests/test_VotingContract.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// tests/test_VotingContract.js | ||
const { expect } = require("chai"); | ||
const { ethers } = require("hardhat"); | ||
|
||
describe("VotingContract", function () { | ||
let Voting; | ||
let voting; | ||
let owner; | ||
let addr1; | ||
|
||
beforeEach(async function () { | ||
Voting = await ethers.getContractFactory("VotingContract"); | ||
[owner, addr1] = await ethers.getSigners(); | ||
voting = await Voting.deploy(["Option1", "Option2"]); | ||
await voting.deployed(); | ||
}); | ||
|
||
it("Should allow users to vote", async function () { | ||
await voting.connect(addr1).vote(0); | ||
expect(await voting.getVotes(0)).to.equal(1); | ||
}); | ||
|
||
it("Should not allow voting for an invalid option", async function () { | ||
await expect(voting.connect(addr1).vote(2)).to.be.revertedWith("Invalid option"); | ||
}); | ||
|
||
it("Should not allow double voting", async function () { | ||
await voting.connect(addr1).vote(0); | ||
await expect(voting.connect(addr1).vote(0)).to.be.revertedWith("You have already voted"); | ||
}); | ||
}); |