Skip to content

Commit

Permalink
chore: update to use latest forge conventions (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-manuel authored May 11, 2023
1 parent b6b0aac commit de840a1
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ jobs:
run: forge install

- name: Run tests
run: make test
run: forge test
env:
ETH_RPC_URL: ${{ secrets.ETH_RPC_URL }}
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
all :; FOUNDRY_OPTIMIZER=true FOUNDRY_OPTIMIZER_RUNS=200 forge build --use solc:0.8.14
clean :; forge clean
test :; ./test.sh solc="0.8.14" match="$(match)" block="$(block)" match-test="$(match-test)" match-contract="$(match-contract)"
certora-hub :; PATH=~/.solc-select/artifacts/solc-0.8.14:~/.solc-select/artifacts/solc-0.5.12:~/.solc-select/artifacts:${PATH} certoraRun --solc_map D3MHub=solc-0.8.14,Vat=solc-0.5.12,DaiJoin=solc-0.5.12,Dai=solc-0.5.12,End=solc-0.5.12,D3MTestPlan=solc-0.8.14,D3MTestPool=solc-0.8.14,TokenMock=solc-0.8.14 --optimize_map D3MHub=200,Vat=0,DaiJoin=0,Dai=0,End=0,D3MTestPlan=200,D3MTestPool=200,TokenMock=200 --rule_sanity basic src/D3MHub.sol certora/dss/Vat.sol certora/dss/DaiJoin.sol certora/dss/Dai.sol certora/dss/End.sol certora/d3m/D3MTestPlan.sol certora/d3m/D3MTestPool.sol src/tests/mocks/TokenMock.sol --link D3MHub:vat=Vat D3MHub:daiJoin=DaiJoin D3MHub:end=End DaiJoin:vat=Vat DaiJoin:dai=Dai End:vat=Vat D3MTestPlan:dai=Dai D3MTestPool:hub=D3MHub D3MTestPool:vat=Vat D3MTestPool:dai=Dai D3MTestPool:share=TokenMock --verify D3MHub:certora/D3MHub.spec --settings -mediumTimeout=1200,-solver=z3,-adaptiveSolverConfig=false,-smt_nonLinearArithmetic=true$(if $(short), --short_output,)$(if $(rule), --rule $(rule),)$(if $(multi), --multi_assert_check,)
deploy :; ./deploy.sh config="$(config)"
deploy-core :; ./deploy-core.sh
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,21 @@ Below is a configurable parameter for the Compound DAI D3M:
- `barb` [wad] - The target borrow rate per block on Compound for the DAI market. This module will aim to enforce that borrow limit.

Any Comp that is accured can be permissionlessly collected into the pause proxy by calling `collect()`.

### Setup and Testing

To set up the environment and run tests, run the following commands:

```bash
forge install
export ETH_RPC_URL=<your eth rpc url>
forge test
```

To run specific tests, run the following command:

```bash
forge t --mt <test name>
```

Verbosity can also be specified inline (`-vvv`), more information on forge test can be found [here](https://book.getfoundry.sh/reference/forge/forge-test).
8 changes: 5 additions & 3 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[profile.default]
src = 'src'
out = 'out'
libs = ['lib']
solc_version = '0.8.14'
verbosity = 3
optimizer = true
optimizer_runs = 200

fs_permissions = [
{ access = "read", path = "./script/input/"},
{ access = "read-write", path = "./script/output/"}
Expand Down
4 changes: 3 additions & 1 deletion src/tests/D3MHub.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ contract D3MHubTest is DssTest {
D3MOracle pip;

function setUp() public {
vm.createSelectFork(vm.envString("ETH_RPC_URL"));

// TODO these should be mocked (or this should be moved to an integration test)
vat = VatAbstract(0x35D1b3F3D7966A1DFe207aa4514C12a259A0492B);
end = EndAbstract(0x0e2e8F1D1326A4B9633D96222Ce399c708B19c28);
Expand Down Expand Up @@ -1162,7 +1164,7 @@ contract D3MHubTest is DssTest {
vat.grab(ilk, receiver, receiver, receiver, int256(pink), int256(part));

assertEq(dai.balanceOf(receiver), balBefore + 50 * WAD);
(uint256 joinInk, uint256 joinArt) = vat.urns(
(uint256 joinInk, uint256 joinArt) = vat.urns(
ilk,
address(pool)
);
Expand Down
2 changes: 2 additions & 0 deletions src/tests/integration/D3MAaveV2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ contract D3MAaveV2IntegrationTest is DssTest {
uint256 constant EPSILON_TOLERANCE = 4;

function setUp() public {
vm.createSelectFork(vm.envString("ETH_RPC_URL"));

vat = VatAbstract(0x35D1b3F3D7966A1DFe207aa4514C12a259A0492B);
end = EndAbstract(0x0e2e8F1D1326A4B9633D96222Ce399c708B19c28);
aavePool = LendingPoolLike(0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9);
Expand Down
2 changes: 2 additions & 0 deletions src/tests/integration/D3MCompoundV2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ contract D3MCompoundV2IntegrationTest is DssTest {
uint256 constant INTEREST_RATE_TOLERANCE = WAD / 10000;

function setUp() public {
vm.createSelectFork(vm.envString("ETH_RPC_URL"));

vat = VatAbstract(0x35D1b3F3D7966A1DFe207aa4514C12a259A0492B);
end = EndAbstract(0x0e2e8F1D1326A4B9633D96222Ce399c708B19c28);
cDai = CErc20Like(0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643);
Expand Down
6 changes: 4 additions & 2 deletions src/tests/integration/IntegrationBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ abstract contract IntegrationBaseTest is DssTest {

D3MHub internal hub;
D3MMom internal mom;

// These are private as inheriting contract should use a more specific type
ID3MPool private pool;
ID3MPlan private plan;

function baseInit() internal {
vm.createSelectFork(vm.envString("ETH_RPC_URL"));

dss = MCD.loadFromChainlog(0xdA0Ab1e0017DEbCd72Be8599041a2aa3bA7e740F);
admin = dss.chainlog.getAddress("MCD_PAUSE_PROXY");
hub = D3MHub(dss.chainlog.getAddress("DIRECT_HUB"));
Expand Down Expand Up @@ -456,7 +458,7 @@ abstract contract IntegrationBaseTest is DssTest {
vow.heal(_min(vat.sin(address(vow)), vat.dai(address(vow))));
assertEq(vat.gem(ilk, address(end)), 0);
assertEq(vat.sin(address(vow)), 0);
assertGe(vat.dai(address(vow)), prevDai); // As also probably accrues interest
assertGe(vat.dai(address(vow)), prevDai); // As also probably accrues interest
}

function test_unwind_mcd_caged_wait_done() public {
Expand Down
16 changes: 10 additions & 6 deletions src/tests/integration/SparkLend.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ contract SparkLendTest is IntegrationBaseTest, IERC3156FlashBorrower {
function setUp() public {
baseInit();

// NOTE: Adding past block until fix to work against deployed protocol is introduced.
// TODO: Update the test to work against deployed protocol with latest block.
vm.createSelectFork(vm.envString("ETH_RPC_URL"), 17_200_000);

sparkPool = PoolLike(0xC13e21B648A5Ee794902342038FF3aDAB66BE987);
daiInterestRateStrategy = DaiInterestRateStrategyLike(getInterestRateStrategy(address(dai)));
adai = ATokenLike(0x4DEDf26112B3Ec8eC46e7E31EA5e123490B05B8B);
Expand Down Expand Up @@ -250,7 +254,7 @@ contract SparkLendTest is IntegrationBaseTest, IERC3156FlashBorrower {
);

vm.stopPrank();

// Give us some DAI
dai.setBalance(address(this), buffer * 100000000);

Expand All @@ -273,7 +277,7 @@ contract SparkLendTest is IntegrationBaseTest, IERC3156FlashBorrower {
// --- Overrides ---
function adjustDebt(int256 deltaAmount) internal override {
if (deltaAmount == 0) return;

int256 newBuffer = int256(plan.buffer()) + deltaAmount;
vm.prank(admin); plan.file("buffer", newBuffer >= 0 ? uint256(newBuffer) : 0);
hub.exec(ilk);
Expand Down Expand Up @@ -387,7 +391,7 @@ contract SparkLendTest is IntegrationBaseTest, IERC3156FlashBorrower {
assertEq(getDebt(), buffer + buffer / 2 - buffer / 4, "should be back down to 1.25x the buffer");
}

/**
/**
* The DAI market is using a new interest model which over-allocates interest to the treasury.
* This is due to the reserve factor not being flexible enough to account for this.
* Confirm that we can later correct the discrepancy by donating the excess liabilities back to the DAI pool. (This can be automated later on)
Expand All @@ -410,7 +414,7 @@ contract SparkLendTest is IntegrationBaseTest, IERC3156FlashBorrower {
liabilities = getTotalLiabilities(address(dai));
assertLe(assets, liabilities, "assets should be less than or equal to liabilities");
}

// Let's fix the accounting
uint256 delta = liabilities - assets;

Expand Down Expand Up @@ -450,7 +454,7 @@ contract SparkLendTest is IntegrationBaseTest, IERC3156FlashBorrower {
liabilities = getTotalLiabilities(address(dai));
assertLe(assets, liabilities, "assets should be less than or equal to liabilities");
}

// Let's fix the accounting
uint256 delta = liabilities - assets;

Expand Down Expand Up @@ -495,7 +499,7 @@ contract SparkLendTest is IntegrationBaseTest, IERC3156FlashBorrower {
sparkPool.withdraw(address(dai), amount, address(this));

ATokenLike(token).approve(address(msg.sender), amount + fee);

return keccak256("ERC3156FlashBorrower.onFlashLoan");
}
}
2 changes: 2 additions & 0 deletions src/tests/plans/D3MAaveV2TypeRateTargetPlan.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ contract D3MAaveV2TypeRateTargetPlanTest is D3MPlanBaseTest {
uint256 constant INTEREST_RATE_TOLERANCE = RAY / 10000;

function setUp() public {
vm.createSelectFork(vm.envString("ETH_RPC_URL"));

// TODO these should be mocked
dai = DaiAbstract(0x6B175474E89094C44Da98b954EedeAC495271d0F);
aavePool = LendingPoolLike(0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9);
Expand Down
2 changes: 2 additions & 0 deletions src/tests/plans/D3MCompoundV2TypeRateTargetPlan.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ contract D3MCompoundV2TypeRateTargetPlanTest is D3MPlanBaseTest {
}

function setUp() public {
vm.createSelectFork(vm.envString("ETH_RPC_URL"));

// TODO these should be mocked
dai = DaiAbstract(0x6B175474E89094C44Da98b954EedeAC495271d0F);
cDai = CErc20Like(0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643);
Expand Down
2 changes: 2 additions & 0 deletions src/tests/pools/D3MCompoundV2TypePool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ contract D3MCompoundV2TypePoolTest is D3MPoolBaseTest {
}

function setUp() public {
vm.createSelectFork(vm.envString("ETH_RPC_URL"));

baseInit("D3MCompoundV2TypePool");

// TODO these should be mocked
Expand Down
47 changes: 0 additions & 47 deletions test.sh

This file was deleted.

0 comments on commit de840a1

Please sign in to comment.