mirror of
https://github.com/status-im/dagger-contracts.git
synced 2025-02-05 03:04:30 +00:00
Verify than secondsPerPeriod cannot be zero (#211)
* Assert than secondsPerPeriod cannot be zero * Apply custom error
This commit is contained in:
parent
02e3b8d22b
commit
bfa5a78b4f
@ -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;
|
||||
}
|
||||
|
||||
|
16
test/Periods.test.js
Normal file
16
test/Periods.test.js
Normal file
@ -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
|
||||
})
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user