Skip to content

Commit

Permalink
test: Get to 100% test coverage (#639)
Browse files Browse the repository at this point in the history
* test/unit: Add test case for invalid treasury cut rate value

* contracts/test: Remove trailing whitespace from AssertBytes32Array

no idea why it started failing now, but easy fix

* test: Create test for Manager.whenSystemNotPaused
  • Loading branch information
victorges committed Mar 19, 2024
1 parent 3966c9d commit 57b7c63
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contracts/test/helpers/truffle/AssertBytes32Array.sol
Expand Up @@ -210,7 +210,7 @@ library AssertBytes32Array {
}
return string(bts);
}
*/

/*
Expand Down
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";
}
}
10 changes: 10 additions & 0 deletions test/unit/BondingManager.js
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
@@ -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 57b7c63

Please sign in to comment.