Skip to content

Commit

Permalink
feat: get to full coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-manuel committed Nov 9, 2023
1 parent 24278f2 commit c4f64bf
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
55 changes: 55 additions & 0 deletions test/SparkLendFreezerMom.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import "forge-std/Test.sol";

import { SparkLendFreezerMom } from "../src/SparkLendFreezerMom.sol";

import { SparkLendFreezerMomHarness } from "./harnesses/SparkLendFreezerMomHarness.sol";

import { AuthorityMock, ConfiguratorMock, PoolMock } from "./Mocks.sol";

contract SparkLendFreezerMomUnitTestBase is Test {
Expand Down Expand Up @@ -138,4 +140,57 @@ contract FreezeMarketTests is SparkLendFreezerMomUnitTestBase {

}

contract SparkLendFreezerMomIsAuthorizedTest is Test {

address public configurator;
address public pool;
address public owner;

AuthorityMock public authority;

SparkLendFreezerMomHarness public freezer;

address caller = makeAddr("caller");

function setUp() public {
owner = makeAddr("owner");

authority = new AuthorityMock();
configurator = address(new ConfiguratorMock());
pool = address(new PoolMock());
freezer = new SparkLendFreezerMomHarness(configurator, pool, address(authority));

freezer.setOwner(owner);
}

function test_isAuthorized_internalCall() external {
assertEq(freezer.isAuthorizedExternal(address(freezer), bytes4("0")), true);
}

function test_isAuthorized_srcIsOwner() external {
assertEq(freezer.isAuthorizedExternal(owner, bytes4("0")), true);
}

function test_isAuthorized_authorityIsZero() external {
vm.prank(owner);
freezer.setAuthority(address(0));
assertEq(freezer.isAuthorizedExternal(caller, bytes4("0")), false);
}

function test_isAuthorized_canCall() external {
vm.prank(owner);
authority.__setCanCall(caller, address(freezer), bytes4("0"), true);

vm.expectCall(
address(authority),
abi.encodePacked(
AuthorityMock.canCall.selector,
abi.encode(caller, address(freezer), bytes4("0"))
)
);
assertEq(freezer.isAuthorizedExternal(caller, bytes4("0")), true);
}

}


15 changes: 15 additions & 0 deletions test/harnesses/SparkLendFreezerMomHarness.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.0;

import { SparkLendFreezerMom } from "src/SparkLendFreezerMom.sol";

contract SparkLendFreezerMomHarness is SparkLendFreezerMom {

constructor(address poolConfigurator_, address pool_, address authority_)
SparkLendFreezerMom(poolConfigurator_, pool_, authority_) {}

function isAuthorizedExternal(address src, bytes4 sig) public view returns (bool) {
return super.isAuthorized(src, sig);
}

}

0 comments on commit c4f64bf

Please sign in to comment.