Skip to content

Commit

Permalink
Create test_VotingContract.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Oct 31, 2024
1 parent b762490 commit 3d36873
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions blockchain_integration/pi_network/tests/test_VotingContract.js
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");
});
});

0 comments on commit 3d36873

Please sign in to comment.