all files / contracts/test/ TestModule.sol

97.14% Statements 34/35
50% Branches 4/8
93.33% Functions 14/15
96.88% Lines 31/32
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114                                                                                                                                                                     
// SPDX-License-Identifier: GPL-2.0-or-later
 
pragma solidity ^0.8.0;
 
import "../BaseLogic.sol";
 
contract TestModule is BaseLogic {
    constructor(uint moduleId) BaseLogic(moduleId, bytes32(0)) {}
 
    function setModuleId(address moduleAddr, uint32 id) external {
        trustedSenders[moduleAddr].moduleId = id;
    }
 
    function setModuleImpl(address moduleAddr, address impl) external {
        moduleLookup[trustedSenders[moduleAddr].moduleId] = impl;
        trustedSenders[moduleAddr].moduleImpl = impl;
    }
 
    function setPricingType(address eToken, uint16 val) external {
        eTokenLookup[eToken].pricingType = val;
    }
 
    function testCreateProxyOnInternalModule() external {
        _createProxy(MAX_EXTERNAL_MODULEID + 1);
    }
 
    function testDecreaseBorrow(address eToken, address account, uint amount) external {
        AssetStorage storage assetStorage = eTokenLookup[eToken];
        AssetCache memory assetCache = loadAssetCache(assetStorage.underlying, assetStorage);
        amount = decodeExternalAmount(assetCache, amount);
        decreaseBorrow(assetStorage, assetCache, assetStorage.dTokenAddress, account, amount);
    }
 
    function testTransferBorrow(address eToken, address from, address to, uint amount) external {
        AssetStorage storage assetStorage = eTokenLookup[eToken];
        AssetCache memory assetCache = loadAssetCache(assetStorage.underlying, assetStorage);
        amount = decodeExternalAmount(assetCache, amount);
        transferBorrow(assetStorage, assetCache, assetStorage.dTokenAddress, from, to, amount);
    }
 
    function testEmitViaProxyTransfer(address proxyAddr, address from, address to, uint value) external {
        emitViaProxy_Transfer(proxyAddr, from, to, value);
    }
 
    function testEmitViaProxyApproval(address proxyAddr, address owner, address spender, uint value) external {
        emitViaProxy_Approval(proxyAddr, owner, spender, value);
    }
 
    function testDispatchEmptyData() external {
        trustedSenders[address(this)].moduleId = 200;
        (bool success, bytes memory data) = address(this).call(abi.encodeWithSignature("dispatch()"));
        Eif (!success) revertBytes(data);
    }
 
    function testUnrecognizedETokenCaller() external {
        (bool success, bytes memory data) = moduleLookup[MODULEID__ETOKEN].delegatecall(abi.encodeWithSelector(IERC20.totalSupply.selector));
        Eif (!success) revertBytes(data);
    }
 
    function testUnrecognizedDTokenCaller() external {
        (bool success, bytes memory data) = moduleLookup[MODULEID__DTOKEN].delegatecall(abi.encodeWithSelector(IERC20.totalSupply.selector));
        Eif (!success) revertBytes(data);
    }
 
    function testCall() external {
        upgradeAdmin = upgradeAdmin; // suppress visibility warning
    }
 
    function issueLogToProxy(bytes memory payload) private {
        (, address proxyAddr) = unpackTrailingParams();
        (bool success,) = proxyAddr.call(payload);
        Erequire(success, "e/log-proxy-fail");
    }
 
    function testProxyLogs() external {
        bytes memory extraData = "hello";
 
        issueLogToProxy(abi.encodePacked(
                               uint8(0),
                               extraData
                        ));
 
        issueLogToProxy(abi.encodePacked(
                               uint8(1),
                               bytes32(uint(1)),
                               extraData
                        ));
 
        issueLogToProxy(abi.encodePacked(
                               uint8(2),
                               bytes32(uint(1)),
                               bytes32(uint(2)),
                               extraData
                        ));
 
        issueLogToProxy(abi.encodePacked(
                               uint8(3),
                               bytes32(uint(1)),
                               bytes32(uint(2)),
                               bytes32(uint(3)),
                               extraData
                        ));
 
        issueLogToProxy(abi.encodePacked(
                               uint8(4),
                               bytes32(uint(1)),
                               bytes32(uint(2)),
                               bytes32(uint(3)),
                               bytes32(uint(4)),
                               extraData
                        ));
    }
}