diff --git a/test/SparkLendFreezerMom.t.sol b/test/SparkLendFreezerMom.t.sol index 107d204..9a2dabb 100644 --- a/test/SparkLendFreezerMom.t.sol +++ b/test/SparkLendFreezerMom.t.sol @@ -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 { @@ -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); + } + +} + diff --git a/test/harnesses/SparkLendFreezerMomHarness.sol b/test/harnesses/SparkLendFreezerMomHarness.sol new file mode 100644 index 0000000..dd7e2c8 --- /dev/null +++ b/test/harnesses/SparkLendFreezerMomHarness.sol @@ -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); + } + +}