-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Create a simple test for Manager.whenSystemNotPaused
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
}) | ||
}) | ||
}) |