|
| 1 | +import { ethers } from "hardhat"; |
| 2 | +import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers"; |
| 3 | +import { expect } from "chai"; |
| 4 | +import { Reverter } from "@/test/helpers/reverter"; |
| 5 | +import { ZERO_ADDR } from "@/scripts/utils/constants"; |
| 6 | + |
| 7 | +import { PermanentOwnableMock } from "@ethers-v6"; |
| 8 | + |
| 9 | +describe("PermanentOwnable", () => { |
| 10 | + const reverter = new Reverter(); |
| 11 | + |
| 12 | + let OWNER: SignerWithAddress; |
| 13 | + let OTHER: SignerWithAddress; |
| 14 | + |
| 15 | + let permanentOwnable: PermanentOwnableMock; |
| 16 | + |
| 17 | + before("setup", async () => { |
| 18 | + [OWNER, OTHER] = await ethers.getSigners(); |
| 19 | + |
| 20 | + const permanentOwnableMock = await ethers.getContractFactory("PermanentOwnableMock"); |
| 21 | + permanentOwnable = await permanentOwnableMock.deploy(OWNER); |
| 22 | + |
| 23 | + await reverter.snapshot(); |
| 24 | + }); |
| 25 | + |
| 26 | + afterEach(reverter.revert); |
| 27 | + |
| 28 | + describe("PermanentOwnable", () => { |
| 29 | + it("should set the correct owner", async () => { |
| 30 | + expect(await permanentOwnable.owner()).to.equal(OWNER.address); |
| 31 | + }); |
| 32 | + |
| 33 | + it("should reject zero address during the owner initialization", async () => { |
| 34 | + const permanentOwnableMock = await ethers.getContractFactory("PermanentOwnableMock"); |
| 35 | + |
| 36 | + await expect(permanentOwnableMock.deploy(ZERO_ADDR)).to.be.revertedWith( |
| 37 | + "PermanentOwnable: zero address can not be the owner", |
| 38 | + ); |
| 39 | + }); |
| 40 | + |
| 41 | + it("only owner should call this function", async () => { |
| 42 | + expect(await permanentOwnable.connect(OWNER).onlyOwnerMethod()).to.emit(permanentOwnable, "ValidOwner"); |
| 43 | + await expect(permanentOwnable.connect(OTHER).onlyOwnerMethod()).to.be.revertedWith( |
| 44 | + "PermanentOwnable: caller is not the owner", |
| 45 | + ); |
| 46 | + }); |
| 47 | + }); |
| 48 | +}); |
0 commit comments