Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Get to 100% test coverage #639

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/test/helpers/truffle/AssertBytes32Array.sol
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ library AssertBytes32Array {
}
return string(bts);
}

*/

/*
Expand Down
12 changes: 12 additions & 0 deletions contracts/test/mocks/ManagerFixture.sol
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";
}
}
10 changes: 10 additions & 0 deletions test/unit/BondingManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ describe("BondingManager", () => {
).to.be.revertedWith("caller must be Controller owner")
})

it("should fail if cut rate is not a valid precise perc", async () => {
const invalidPerc = math.precise.percPoints(
BigNumber.from(101),
100
)
await expect(
bondingManager.setTreasuryRewardCutRate(invalidPerc)
).to.be.revertedWith("_cutRate is invalid precise percentage")
})

it("should set only nextRoundTreasuryRewardCutRate", async () => {
const tx = await bondingManager.setTreasuryRewardCutRate(FIFTY_PCT)
await expect(tx)
Expand Down
56 changes: 56 additions & 0 deletions test/unit/Manager.js
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")
})
})
})
Loading