From e935cbe67249eba2d5f4937a5c1ae4c7150fd44c Mon Sep 17 00:00:00 2001 From: Victor Elias Date: Fri, 15 Mar 2024 16:53:33 -0300 Subject: [PATCH] test: Create a simple test for Manager.whenSystemNotPaused --- contracts/test/mocks/ManagerFixture.sol | 12 ++++++ test/unit/Manager.js | 56 +++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 contracts/test/mocks/ManagerFixture.sol create mode 100644 test/unit/Manager.js diff --git a/contracts/test/mocks/ManagerFixture.sol b/contracts/test/mocks/ManagerFixture.sol new file mode 100644 index 00000000..082245ea --- /dev/null +++ b/contracts/test/mocks/ManagerFixture.sol @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.9; + +import "../../Manager.sol"; + +contract ManagerFixture is Manager { + constructor(address controller) Manager(controller) {} + + function checkSchrodingerCat() public view whenSystemPaused returns (string memory) { + return "alive"; + } +} diff --git a/test/unit/Manager.js b/test/unit/Manager.js new file mode 100644 index 00000000..4a0214df --- /dev/null +++ b/test/unit/Manager.js @@ -0,0 +1,56 @@ +import Fixture from "./helpers/Fixture" + +import {web3, ethers} from "hardhat" + +import chai, {expect, assert} from "chai" +import {solidity} from "ethereum-waffle" +chai.use(solidity) + +describe("Manager", () => { + let fixture + let manager + + before(async () => { + fixture = new Fixture(web3) + await fixture.deploy() + await fixture.deployAndRegister( + await ethers.getContractFactory("ManagerFixture"), + "ManagerFixture", + fixture.controller.address + ) + + const managerFixtureFac = await ethers.getContractFactory( + "ManagerFixture" + ) + const managerFixture = await managerFixtureFac.deploy( + fixture.controller.address + ) + manager = await ethers.getContractAt( + "ManagerFixture", + managerFixture.address + ) + }) + + beforeEach(async () => { + await fixture.setUp() + }) + + afterEach(async () => { + await fixture.tearDown() + }) + + // This is the only function not already tested in other tests, so it's the only one tested here + describe("whenSystemPaused", () => { + it("should disallow the call when the system is not paused", async () => { + await expect(manager.checkSchrodingerCat()).to.be.revertedWith( + "system is not paused" + ) + }) + + it("should allow the call when the system is paused", async () => { + await fixture.controller.pause() + const state = await manager.checkSchrodingerCat() + assert.equal(state, "alive") + }) + }) +})