From 57b7c6377ebf36808aa9f0bfd0dcb861278047c2 Mon Sep 17 00:00:00 2001 From: Victor Elias Date: Tue, 19 Mar 2024 15:28:18 -0300 Subject: [PATCH] test: Get to 100% test coverage (#639) * 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 --- .../helpers/truffle/AssertBytes32Array.sol | 2 +- contracts/test/mocks/ManagerFixture.sol | 12 ++++ test/unit/BondingManager.js | 10 ++++ test/unit/Manager.js | 56 +++++++++++++++++++ 4 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 contracts/test/mocks/ManagerFixture.sol create mode 100644 test/unit/Manager.js diff --git a/contracts/test/helpers/truffle/AssertBytes32Array.sol b/contracts/test/helpers/truffle/AssertBytes32Array.sol index 8d57f1a5..5b46197a 100644 --- a/contracts/test/helpers/truffle/AssertBytes32Array.sol +++ b/contracts/test/helpers/truffle/AssertBytes32Array.sol @@ -210,7 +210,7 @@ library AssertBytes32Array { } return string(bts); } - + */ /* 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/BondingManager.js b/test/unit/BondingManager.js index 648a6b86..0dee6c34 100644 --- a/test/unit/BondingManager.js +++ b/test/unit/BondingManager.js @@ -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) 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") + }) + }) +})