diff --git a/contracts/Periods.sol b/contracts/Periods.sol index bb7bcb9..7085c31 100644 --- a/contracts/Periods.sol +++ b/contracts/Periods.sol @@ -2,11 +2,16 @@ pragma solidity 0.8.23; contract Periods { + error Periods_InvalidSecondsPerPeriod(); + type Period is uint256; uint256 internal immutable _secondsPerPeriod; constructor(uint256 secondsPerPeriod) { + if (secondsPerPeriod == 0) { + revert Periods_InvalidSecondsPerPeriod(); + } _secondsPerPeriod = secondsPerPeriod; } diff --git a/test/Periods.test.js b/test/Periods.test.js new file mode 100644 index 0000000..f265b68 --- /dev/null +++ b/test/Periods.test.js @@ -0,0 +1,16 @@ +const { expect } = require("chai") +const { ethers } = require("hardhat") + +describe("Periods", function () { + it("should revert when secondsPerPeriod is 0", async function () { + const PeriodsContract = await ethers.getContractFactory("Periods") + await expect(PeriodsContract.deploy(0)).to.be.revertedWith( + "Periods_InvalidSecondsPerPeriod" + ) + }) + + it("should not revert when secondsPerPeriod more than 0", async function () { + const PeriodsContract = await ethers.getContractFactory("Periods") + await expect(PeriodsContract.deploy(10)).not.to.be.reverted + }) +})