Skip to content

Commit

Permalink
✅ contracts: inject test deployments through custom setups
Browse files Browse the repository at this point in the history
  • Loading branch information
cruzdanilo committed Dec 31, 2024
1 parent 7d7a9fb commit 750df11
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 105 deletions.
78 changes: 39 additions & 39 deletions contracts/.gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
ExaAccountFactoryTest:testFuzz_createAccount_EOAOwners(uint256,address[63]) (runs: 256, μ: 3621366, ~: 3460632)
ExaPluginTest:testFork_crossRepay_repays() (gas: 19666737)
ExaPluginTest:testFork_debitCollateral_collects() (gas: 19756315)
ExaPluginTest:testFork_swap_swaps() (gas: 16912274)
ExaPluginTest:testFork_crossRepay_repays() (gas: 19662215)
ExaPluginTest:testFork_debitCollateral_collects() (gas: 19751793)
ExaPluginTest:testFork_swap_swaps() (gas: 16907764)
ExaPluginTest:test_borrowAtMaturity_reverts_withUnauthorized_whenReceiverNotCollector() (gas: 408975)
ExaPluginTest:test_borrow_reverts_withUnauthorized_whenReceiverNotCollector() (gas: 408553)
ExaPluginTest:test_collectCredit_collects() (gas: 921083)
ExaPluginTest:test_collectCredit_collects_whenHealthFactorHigherThanMinHealthFactor() (gas: 801758)
ExaPluginTest:test_collectCredit_collects_whenHealthFactorHigherThanMinHealthFactor() (gas: 801746)
ExaPluginTest:test_collectCredit_collects_withEnoughSlippage() (gas: 800271)
ExaPluginTest:test_collectCredit_passes_whenProposalLeavesEnoughLiquidity() (gas: 1010088)
ExaPluginTest:test_collectCredit_passes_whenProposalLeavesEnoughLiquidity() (gas: 1010124)
ExaPluginTest:test_collectCredit_reverts_asNotKeeper() (gas: 362757)
ExaPluginTest:test_collectCredit_reverts_whenDisagreement() (gas: 556074)
ExaPluginTest:test_collectCredit_reverts_whenExpired() (gas: 358845)
ExaPluginTest:test_collectCredit_reverts_whenHealthFactorLowerThanMinHealthFactor() (gas: 832014)
ExaPluginTest:test_collectCredit_reverts_whenPrposalCausesInsufficientLiquidity() (gas: 1010277)
ExaPluginTest:test_collectCredit_reverts_whenExpired() (gas: 358857)
ExaPluginTest:test_collectCredit_reverts_whenHealthFactorLowerThanMinHealthFactor() (gas: 832002)
ExaPluginTest:test_collectCredit_reverts_whenPrposalCausesInsufficientLiquidity() (gas: 1010301)
ExaPluginTest:test_collectCredit_reverts_whenReplay() (gas: 843323)
ExaPluginTest:test_collectCredit_reverts_whenTimelocked() (gas: 355114)
ExaPluginTest:test_collectCredit_reverts_whenTimelocked() (gas: 355102)
ExaPluginTest:test_collectCredit_toleratesTimeDrift() (gas: 803748)
ExaPluginTest:test_collectDebit_collects() (gas: 651749)
ExaPluginTest:test_collectDebit_collects_whenProposalLeavesEnoughLiquidity() (gas: 855108)
ExaPluginTest:test_collectDebit_collects_whenProposalLeavesEnoughLiquidity() (gas: 855132)
ExaPluginTest:test_collectDebit_reverts_asNotKeeper() (gas: 362589)
ExaPluginTest:test_collectDebit_reverts_whenExpired() (gas: 358651)
ExaPluginTest:test_collectDebit_reverts_whenProposalCausesInsufficientLiquidity() (gas: 852099)
ExaPluginTest:test_collectDebit_reverts_whenExpired() (gas: 358663)
ExaPluginTest:test_collectDebit_reverts_whenProposalCausesInsufficientLiquidity() (gas: 852123)
ExaPluginTest:test_collectDebit_reverts_whenReplay() (gas: 691191)
ExaPluginTest:test_collectDebit_reverts_whenTimelocked() (gas: 354855)
ExaPluginTest:test_collectDebit_reverts_whenTimelocked() (gas: 354843)
ExaPluginTest:test_collectDebit_toleratesTimeDrift() (gas: 651826)
ExaPluginTest:test_collectInstallments_collects() (gas: 1338830)
ExaPluginTest:test_collectInstallments_revertsWhenNoSlippage() (gas: 1203025)
ExaPluginTest:test_collectInstallments_collects() (gas: 1338854)
ExaPluginTest:test_collectInstallments_revertsWhenNoSlippage() (gas: 1203049)
ExaPluginTest:test_collectInstallments_reverts_asNotKeeper() (gas: 363607)
ExaPluginTest:test_collectInstallments_reverts_whenExpired() (gas: 361030)
ExaPluginTest:test_collectInstallments_reverts_whenExpired() (gas: 361018)
ExaPluginTest:test_collectInstallments_reverts_whenReplay() (gas: 1070925)
ExaPluginTest:test_collectInstallments_reverts_whenTimelocked() (gas: 357218)
ExaPluginTest:test_collectInstallments_reverts_whenTimelocked() (gas: 357206)
ExaPluginTest:test_collectInstallments_toleratesTimeDrift() (gas: 1195516)
ExaPluginTest:test_crossRepay_repays() (gas: 1466544)
ExaPluginTest:test_crossRepay_repays_whenKeeper() (gas: 1463190)
ExaPluginTest:test_crossRepay_reverts_whenDisagreement() (gas: 1575464)
ExaPluginTest:test_crossRepay_reverts_whenNotKeeper() (gas: 961090)
ExaPluginTest:test_debitCollateral_collects() (gas: 776959)
ExaPluginTest:test_debitCollateral_collects() (gas: 776947)
ExaPluginTest:test_exitMarket_reverts() (gas: 389259)
ExaPluginTest:test_onUninstall_uninstalls() (gas: 284122)
ExaPluginTest:test_poke() (gas: 315952)
ExaPluginTest:test_pokeETH_deposits() (gas: 375965)
ExaPluginTest:test_propose_emitsProposed() (gas: 218655)
ExaPluginTest:test_refund_refunds() (gas: 361505)
ExaPluginTest:test_repay_partiallyRepays() (gas: 1250119)
ExaPluginTest:test_propose_emitsProposed() (gas: 218667)
ExaPluginTest:test_refund_refunds() (gas: 361517)
ExaPluginTest:test_repay_partiallyRepays() (gas: 1250131)
ExaPluginTest:test_repay_partiallyRepays_whenKeeper() (gas: 1192284)
ExaPluginTest:test_repay_repays() (gas: 1166226)
ExaPluginTest:test_repay_repays() (gas: 1166238)
ExaPluginTest:test_repay_repays_whenKeeper() (gas: 1108950)
ExaPluginTest:test_rollDebt_rolls() (gas: 1234108)
ExaPluginTest:test_rollDebt_rolls_asKeeper() (gas: 1233734)
Expand All @@ -57,28 +57,28 @@ ExaPluginTest:test_setMinHealthFactor_reverts_whenNotAdmin() (gas: 33768)
ExaPluginTest:test_setMinHealthFactor_sets_whenAdmin() (gas: 39463)
ExaPluginTest:test_swap_reverts_withDisagreement() (gas: 289042)
ExaPluginTest:test_swap_swaps() (gas: 268686)
ExaPluginTest:test_withdrawWETH_transfersETH() (gas: 848687)
ExaPluginTest:test_withdraw_reverts_whenNoProposal() (gas: 415178)
ExaPluginTest:test_withdrawWETH_transfersETH() (gas: 848711)
ExaPluginTest:test_withdraw_reverts_whenNoProposal() (gas: 415202)
ExaPluginTest:test_withdraw_reverts_whenNoProposalKeeper() (gas: 358000)
ExaPluginTest:test_withdraw_reverts_whenNotKeeper() (gas: 355018)
ExaPluginTest:test_withdraw_reverts_whenReceiverIsContractAndMarketNotWETH() (gas: 621314)
ExaPluginTest:test_withdraw_reverts_whenTimelocked() (gas: 307315)
ExaPluginTest:test_withdraw_reverts_whenTimelockedKeeper() (gas: 309148)
ExaPluginTest:test_withdraw_reverts_whenWrongAmount() (gas: 308712)
ExaPluginTest:test_withdraw_reverts_whenWrongMarket() (gas: 309038)
ExaPluginTest:test_withdraw_reverts_whenWrongReceiver() (gas: 308405)
ExaPluginTest:test_withdraw_transfersAsset_asKeeper() (gas: 820334)
ExaPluginTest:test_withdraw_transfersAsset_asOwner() (gas: 819025)
ExaPluginTest:test_withdraw_reverts_whenReceiverIsContractAndMarketNotWETH() (gas: 621338)
ExaPluginTest:test_withdraw_reverts_whenTimelocked() (gas: 307363)
ExaPluginTest:test_withdraw_reverts_whenTimelockedKeeper() (gas: 309172)
ExaPluginTest:test_withdraw_reverts_whenWrongAmount() (gas: 308760)
ExaPluginTest:test_withdraw_reverts_whenWrongMarket() (gas: 309086)
ExaPluginTest:test_withdraw_reverts_whenWrongReceiver() (gas: 308429)
ExaPluginTest:test_withdraw_transfersAsset_asKeeper() (gas: 820346)
ExaPluginTest:test_withdraw_transfersAsset_asOwner() (gas: 819049)
InstallmentsPreviewerTest:test_preview_returns() (gas: 135598)
IssuerCheckerTest:test_setIssuer_emits_IssuerSet() (gas: 41782)
IssuerCheckerTest:test_setIssuer_reverts_whenNotAdmin() (gas: 37070)
IssuerCheckerTest:test_setIssuer_reverts_whenZeroAddress() (gas: 35449)
MockSwapperTest:test_swapExactAmountIn_swaps() (gas: 220530)
MockSwapperTest:test_swapExactAmountOut_swaps() (gas: 220657)
RefunderTest:test_refund_refunds() (gas: 242371)
RefunderTest:test_refund_reverts_whenExpired() (gas: 69551)
RefunderTest:test_refund_reverts_whenNotKeeper() (gas: 56897)
RefunderTest:test_refund_reverts_whenReplay() (gas: 279261)
RefunderTest:test_refund_reverts_whenTimelocked() (gas: 63310)
MockSwapperTest:test_swapExactAmountIn_swaps() (gas: 220542)
MockSwapperTest:test_swapExactAmountOut_swaps() (gas: 220669)
RefunderTest:test_refund_refunds() (gas: 242383)
RefunderTest:test_refund_reverts_whenExpired() (gas: 69563)
RefunderTest:test_refund_reverts_whenNotKeeper() (gas: 56909)
RefunderTest:test_refund_reverts_whenReplay() (gas: 279285)
RefunderTest:test_refund_reverts_whenTimelocked() (gas: 63298)
RefunderTest:test_refund_reverts_whenWrongSignature() (gas: 68975)
RefunderTest:test_refund_toleratesTimeDrift() (gas: 242469)
49 changes: 38 additions & 11 deletions contracts/script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,42 @@ import { BaseScript } from "./Base.s.sol";
contract DeployScript is BaseScript {
ExaAccountFactory public factory;
ExaPlugin public exaPlugin;
IssuerChecker public issuerChecker;
WebauthnOwnerPlugin public ownerPlugin;

IAuditor public auditor;
IMarket public exaUSDC;
IMarket public exaWETH;
IDebtManager public debtManager;
IInstallmentsRouter public installmentsRouter;
Refunder public refunder;
IBalancerVault public balancerVault;

WebauthnOwnerPlugin public ownerPlugin;
IssuerChecker public issuerChecker;
Refunder public refunder;
address public admin;
address public keeper;
address public deployer;
address public collector;
address public swapper;

function setUp() external {
ownerPlugin = WebauthnOwnerPlugin(dependency("webauthn-owner-plugin", "WebauthnOwnerPlugin", "Plugin", 0));
issuerChecker = IssuerChecker(broadcast("IssuerChecker"));
auditor = IAuditor(protocol("Auditor"));
exaUSDC = IMarket(protocol("MarketUSDC"));
exaWETH = IMarket(protocol("MarketWETH"));
debtManager = IDebtManager(protocol("DebtManager"));
installmentsRouter = IInstallmentsRouter(protocol("InstallmentsRouter"));
refunder = Refunder(broadcast("Refunder"));

balancerVault = IBalancerVault(protocol("BalancerVault"));

ownerPlugin = WebauthnOwnerPlugin(dependency("webauthn-owner-plugin", "WebauthnOwnerPlugin", "Plugin", 0));

issuerChecker = IssuerChecker(broadcast("IssuerChecker"));
refunder = Refunder(broadcast("Refunder"));

admin = acct("admin");
keeper = acct("keeper");
deployer = acct("deployer");
collector = acct("collector");
swapper = acct("swapper");
}

function run() external {
vm.startBroadcast(deployer);
vm.startBroadcast(acct("deployer"));

exaPlugin = new ExaPlugin(
admin,
Expand All @@ -72,4 +71,32 @@ contract DeployScript is BaseScript {

vm.stopBroadcast();
}

function _setUp(
IAuditor auditor_,
IMarket exaUSDC_,
IMarket exaWETH_,
IDebtManager debtManager_,
IInstallmentsRouter installmentsRouter_,
IBalancerVault balancerVault_,
WebauthnOwnerPlugin ownerPlugin_,
IssuerChecker issuerChecker_,
Refunder refunder_,
address keeper_,
address swapper_
) external {
auditor = auditor_;
exaUSDC = exaUSDC_;
exaWETH = exaWETH_;
debtManager = debtManager_;
installmentsRouter = installmentsRouter_;
balancerVault = balancerVault_;
ownerPlugin = ownerPlugin_;
issuerChecker = issuerChecker_;
refunder = refunder_;
keeper = keeper_;
swapper = swapper_;
collector = msg.sender;
admin = msg.sender;
}
}
12 changes: 11 additions & 1 deletion contracts/script/InstallmentsPreviewer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@ import { BaseScript } from "./Base.s.sol";
contract DeployInstallmentsPreviewer is BaseScript {
InstallmentsPreviewer public installmentsPreviewer;

ICollectableMarket public exaUSDC;

function setUp() external {
exaUSDC = ICollectableMarket(protocol("MarketUSDC"));
}

function run() external {
vm.broadcast(acct("deployer"));
installmentsPreviewer = new InstallmentsPreviewer(ICollectableMarket(protocol("MarketUSDC")));
installmentsPreviewer = new InstallmentsPreviewer(exaUSDC);
}

function _setUp(ICollectableMarket exaUSDC_) external {
exaUSDC = exaUSDC_;
}
}
15 changes: 14 additions & 1 deletion contracts/script/IssuerChecker.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,21 @@ import { BaseScript } from "./Base.s.sol";
contract DeployIssuerChecker is BaseScript {
IssuerChecker public issuerChecker;

address public admin;
address public issuer;

function setUp() external {
admin = acct("admin");
issuer = acct("issuer");
}

function run() external {
vm.broadcast(acct("deployer"));
issuerChecker = new IssuerChecker(acct("admin"), acct("issuer"));
issuerChecker = new IssuerChecker(admin, issuer);
}

function _setUp(address issuer_) external {
issuer = issuer_;
admin = msg.sender;
}
}
20 changes: 13 additions & 7 deletions contracts/script/Refunder.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,29 @@ import { IMarket, IssuerChecker, Refunder } from "../src/Refunder.sol";
import { BaseScript } from "./Base.s.sol";

contract DeployRefunder is BaseScript {
IMarket public exaUSDC;
IssuerChecker public issuerChecker;
Refunder public refunder;

IMarket public exaUSDC;
IssuerChecker public issuerChecker;
address public admin;
address public keeper;
address public deployer;

function setUp() external {
exaUSDC = IMarket(protocol("MarketUSDC"));
issuerChecker = IssuerChecker(broadcast("IssuerChecker"));

admin = acct("admin");
keeper = acct("keeper");
deployer = acct("deployer");
}

function run() external {
vm.broadcast(deployer);
refunder = new Refunder(acct("admin"), exaUSDC, issuerChecker, keeper);
vm.broadcast(acct("deployer"));
refunder = new Refunder(admin, exaUSDC, issuerChecker, keeper);
}

function _setUp(IMarket exaUSDC_, IssuerChecker issuerChecker_, address keeper_) external {
exaUSDC = exaUSDC_;
issuerChecker = issuerChecker_;
keeper = keeper_;
admin = msg.sender;
}
}
34 changes: 6 additions & 28 deletions contracts/test/ExaPlugin.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { Address } from "openzeppelin-contracts/contracts/utils/Address.sol";

import { ECDSA } from "solady/utils/ECDSA.sol";
import { FixedPointMathLib } from "solady/utils/FixedPointMathLib.sol";
import { LibString } from "solady/utils/LibString.sol";

import { MockERC20 } from "solmate/src/test/utils/mocks/MockERC20.sol";

Expand Down Expand Up @@ -60,7 +59,6 @@ import { DeployProtocol } from "./mocks/Protocol.s.sol";
contract ExaPluginTest is ForkTest {
using FixedPointMathLib for uint256;
using OwnersLib for address[];
using LibString for address;
using Address for address;
using ECDSA for bytes32;

Expand All @@ -87,16 +85,12 @@ contract ExaPluginTest is ForkTest {
MockERC20 internal usdc;

function setUp() external {
vm.setEnv("DEPLOYER_ADDRESS", address(this).toHexString());

collector = payable(makeAddr("collector"));
(owner, ownerKey) = makeAddrAndKey("owner");
owners = new address[](1);
owners[0] = owner;
(keeper, keeperKey) = makeAddrAndKey("keeper");
(issuer, issuerKey) = makeAddrAndKey("issuer");
vm.setEnv("KEEPER_ADDRESS", keeper.toHexString());
vm.setEnv("ISSUER_ADDRESS", issuer.toHexString());

new DeployAccount().run();
DeployProtocol p = new DeployProtocol();
Expand All @@ -107,25 +101,20 @@ contract ExaPluginTest is ForkTest {
exaWETH = IMarket(address(p.exaWETH()));
exa = p.exa();
usdc = p.usdc();
vm.setEnv("PROTOCOL_AUDITOR_ADDRESS", address(auditor).toHexString());
vm.setEnv("PROTOCOL_MARKETUSDC_ADDRESS", address(exaUSDC).toHexString());
vm.setEnv("PROTOCOL_USDC_ADDRESS", address(usdc).toHexString());

DeployMocks m = new DeployMocks();
m.setUp();
m.run();
vm.setEnv("SWAPPER_ADDRESS", address(m.swapper()).toHexString());

DeployIssuerChecker ic = new DeployIssuerChecker();
ic._setUp(issuer);
ic.run();
issuerChecker = ic.issuerChecker();
vm.setEnv("BROADCAST_ISSUERCHECKER_ADDRESS", address(issuerChecker).toHexString());

DeployMocks m = new DeployMocks();
m._setUp(auditor, usdc);
m.run();

DeployRefunder r = new DeployRefunder();
r.setUp();
r._setUp(exaUSDC, issuerChecker, keeper);
r.run();
refunder = r.refunder();
vm.setEnv("BROADCAST_REFUNDER_ADDRESS", address(refunder).toHexString());

exaPlugin = new ExaPlugin(
address(this),
Expand Down Expand Up @@ -1215,17 +1204,6 @@ contract ExaPluginTest is ForkTest {
function _setUpLifiFork() internal {
vm.createSelectFork("optimism", 127_050_624);
account = ExaAccount(payable(0x6120Fb2A9d47f7955298b80363F00C620dB9f6E6));

vm.setEnv("DEPLOYER_ADDRESS", "");
vm.setEnv("KEEPER_ADDRESS", "");
vm.setEnv("ISSUER_ADDRESS", "");
vm.setEnv("SWAPPER_ADDRESS", "");
vm.setEnv("PROTOCOL_AUDITOR_ADDRESS", "");
vm.setEnv("PROTOCOL_MARKETUSDC_ADDRESS", "");
vm.setEnv("PROTOCOL_USDC_ADDRESS", "");
vm.setEnv("BROADCAST_ISSUERCHECKER_ADDRESS", "");
vm.setEnv("BROADCAST_REFUNDER_ADDRESS", "");

issuerChecker = IssuerChecker(broadcast("IssuerChecker"));
vm.prank(acct("deployer"));
issuerChecker.setIssuer(issuer);
Expand Down
8 changes: 1 addition & 7 deletions contracts/test/InstallmentsPreviewer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,21 @@ pragma solidity ^0.8.0;

import { ForkTest } from "./Fork.t.sol";

import { LibString } from "solady/utils/LibString.sol";

import { DeployInstallmentsPreviewer } from "../script/InstallmentsPreviewer.s.sol";
import { ICollectableMarket, InstallmentsPreviewer } from "../src/InstallmentsPreviewer.sol";
import { DeployProtocol } from "./mocks/Protocol.s.sol";

contract InstallmentsPreviewerTest is ForkTest {
using LibString for address;

ICollectableMarket internal exaUSDC;
InstallmentsPreviewer internal previewer;

function setUp() external {
vm.setEnv("DEPLOYER_ADDRESS", address(this).toHexString());

DeployProtocol p = new DeployProtocol();
p.run();
exaUSDC = ICollectableMarket(address(p.exaUSDC()));
vm.setEnv("PROTOCOL_MARKETUSDC_ADDRESS", address(exaUSDC).toHexString());

DeployInstallmentsPreviewer ip = new DeployInstallmentsPreviewer();
ip._setUp(exaUSDC);
ip.run();
previewer = ip.installmentsPreviewer();
}
Expand Down
Loading

0 comments on commit 750df11

Please sign in to comment.