Skip to content

Commit

Permalink
test: Create a simple test for Manager.whenSystemNotPaused
Browse files Browse the repository at this point in the history
  • Loading branch information
victorges committed Mar 15, 2024
1 parent 04a0fa8 commit e935cbe
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
12 changes: 12 additions & 0 deletions 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";
}
}
56 changes: 56 additions & 0 deletions 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")
})
})
})

0 comments on commit e935cbe

Please sign in to comment.