Skip to content
Merged
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
23 changes: 15 additions & 8 deletions test/DEVoterVoting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getAddress } from "viem";
import "@nomicfoundation/hardhat-viem";
import "@nomicfoundation/hardhat-viem/types";

// No need for manual type declaration as it's provided by @nomicfoundation/hardhat-viem

describe("DEVoterVoting", function () {
async function deployDEVoterVotingFixture() {
Expand Down Expand Up @@ -71,30 +72,37 @@ describe("DEVoterVoting", function () {

// Get the current timestamp before starting the voting period
const startTimeBefore = await time.latest();

// Start a voting period
await devoterVoting.write.startVotingPeriod([BigInt(duration)], {
account: owner.account,
});

// Get the actual values from the contract
const votingStartTime = await devoterVoting.read.votingStartTime();
const votingEndTime = await devoterVoting.read.votingEndTime();

// Verify that votingEndTime equals votingStartTime + duration
expect(Number(votingEndTime)).to.equal(Number(votingStartTime) + duration);

expect(Number(votingEndTime)).to.equal(
Number(votingStartTime) + duration
);

// Verify that votingStartTime is close to the current time when we started the period
// Allow for a small margin of error due to block time variations
expect(Number(votingStartTime)).to.be.closeTo(startTimeBefore, 5);
});

it("Should reject start with zero duration", async function () {
it("Should reject start with negative duration", async function () {
const { devoterVoting, owner } = await loadFixture(
deployDEVoterVotingFixture
);

// Try to start a voting period with zero duration
// Note: In Solidity, we can't directly pass negative numbers as uint256
// But we can test the requirement that duration must be greater than zero
// by using a very small duration that will be rejected

// We'll use 0 as the duration, which will trigger the same validation
// that would reject negative values if they could be passed
await expect(
devoterVoting.write.startVotingPeriod([BigInt(0)], {
account: owner.account,
Expand Down Expand Up @@ -124,7 +132,6 @@ describe("DEVoterVoting", function () {
const initialStatus = await devoterVoting.read.getVotingStatus();
expect((initialStatus as [boolean, bigint])[0]).to.be.true; // active


// End the voting period
await devoterVoting.write.endVotingPeriod([], {
account: owner.account,
Expand Down