Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tests faster by running them with different fuzzing settings #136

Merged
merged 2 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .github/actions/forge-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,19 @@ runs:
key: ${{ github.base_ref || github.ref_name }}-forge-test-${{ inputs.network }} # always keep compiled contracts from base branch

- name: Run tests
run: make test
run: make test-unit
shell: bash
env:
NETWORK: ${{ inputs.network }}

- name: Run tests
run: make test-internal
shell: bash
env:
NETWORK: ${{ inputs.network }}

- name: Run tests
run: make test-integration
shell: bash
env:
NETWORK: ${{ inputs.network }}
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ node_modules/

# IDE
.vscode

# coverage
coverage
lcov.info
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,33 @@ install:
contracts:
FOUNDRY_TEST=/dev/null forge build --via-ir --sizes --force


test:
forge test -vvv

test-unit:
@FOUNDRY_PROFILE=test-unit make test

test-internal:
@FOUNDRY_PROFILE=test-internal make test

test-integration:
@FOUNDRY_PROFILE=test-integration make test


test-%:
@FOUNDRY_MATCH_TEST=$* make test

test-unit-%:
@FOUNDRY_MATCH_TEST=$* make test-unit

test-internal-%:
@FOUNDRY_MATCH_TEST=$* make test-internal

test-integration-%:
@FOUNDRY_MATCH_TEST=$* make test-integration


coverage:
forge coverage --report lcov
lcov --remove lcov.info -o lcov.info "test/*"
Expand Down
2 changes: 1 addition & 1 deletion config/avalanche-mainnet.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"usesRpcPrefix": false,
"rpc": "https://api.avax.network/ext/bc/C/rpc",
"rpc": "https://avalanche-mainnet.infura.io/v3/4d3eaa358c4841e78cb1032d4f6d8726",
"chainId": 43114,
"testBlock": 24437213,
"testMarkets": [
Expand Down
23 changes: 21 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
[profile.default]
fs_permissions = [{ access = "read", path = "./"}]
names = true
sizes = true
libs = ["node_modules", "lib"]
fs_permissions = [{ access = "read", path = "./config/"}]

[fuzz]
runs = 16

[profile.ci.fuzz]

[profile.test-unit]
test = "test/unit/"

[profile.test-unit.fuzz]
runs = 4096


[profile.test-internal]
test = "test/internal/"

[profile.test-internal.fuzz]
runs = 128


[profile.test-integration]
test = "test/integration/"

[profile.test-integration.fuzz]
runs = 512


# See more config options https://github.com/foundry-rs/foundry/tree/master/config
3 changes: 3 additions & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
src/=src/
test/=test/

@forge-std/=lib/forge-std/src/
@ds-test/=lib/forge-std/lib/ds-test/src/

Expand Down
10 changes: 6 additions & 4 deletions test/TestApproval.sol → test/integration/TestApproval.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.17;

import {Errors} from "../src/libraries/Errors.sol";
import {Errors} from "src/libraries/Errors.sol";

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

import {SigUtils} from "./helpers/SigUtils.sol";
import "./helpers/IntegrationTest.sol";
import {SigUtils} from "test/helpers/SigUtils.sol";
import "test/helpers/IntegrationTest.sol";

contract TestApproval is IntegrationTest {
uint256 internal constant OWNER_PK = 0xA11CE;
Expand All @@ -24,6 +24,8 @@ contract TestApproval is IntegrationTest {
}

function testApproveManager(address owner, address manager, bool isAllowed) public {
vm.assume(owner != address(this)); // TransparentUpgradeableProxy: admin cannot fallback to proxy target

vm.prank(owner);
morpho.approveManager(manager, isAllowed);
assertEq(morpho.isManaging(owner, manager), isAllowed);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.17;

import {IPool, IPoolAddressesProvider} from "../../src/interfaces/aave/IPool.sol";
import {IPool, IPoolAddressesProvider} from "src/interfaces/aave/IPool.sol";

import {PoolLib} from "../../src/libraries/PoolLib.sol";
import {DataTypes} from "../../src/libraries/aave/DataTypes.sol";
import {PoolLib} from "src/libraries/PoolLib.sol";
import {DataTypes} from "src/libraries/aave/DataTypes.sol";

import "../helpers/ForkTest.sol";
import "test/helpers/ForkTest.sol";

contract TestPoolLib is ForkTest {
using PoolLib for IPool;
Expand Down
2 changes: 1 addition & 1 deletion test/TestSupply.sol → test/integration/TestSupply.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.17;

import "./helpers/IntegrationTest.sol";
import "test/helpers/IntegrationTest.sol";

contract TestSupply is IntegrationTest {
function testShouldRevertWithZero() public {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.17;

import {MatchingEngine} from "../src/MatchingEngine.sol";
import {MorphoInternal} from "../src/MorphoInternal.sol";
import {MorphoStorage} from "../src/MorphoStorage.sol";
import {MatchingEngine} from "src/MatchingEngine.sol";
import {MorphoInternal} from "src/MorphoInternal.sol";
import {MorphoStorage} from "src/MorphoStorage.sol";

import {MarketLib} from "../src/libraries/MarketLib.sol";
import {MarketBalanceLib} from "../src/libraries/MarketBalanceLib.sol";
import {MarketLib} from "src/libraries/MarketLib.sol";
import {MarketBalanceLib} from "src/libraries/MarketBalanceLib.sol";

import "./helpers/InternalTest.sol";
import "test/helpers/InternalTest.sol";

contract TestMatchingEngine is InternalTest, MatchingEngine {
using MarketLib for Types.Market;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.17;

import {MorphoStorage} from "../src/MorphoStorage.sol";
import {MorphoGetters} from "../src/MorphoGetters.sol";
import {MorphoStorage} from "src/MorphoStorage.sol";
import {MorphoGetters} from "src/MorphoGetters.sol";

import "./helpers/InternalTest.sol";
import "test/helpers/InternalTest.sol";

contract TestMorphoGetters is InternalTest, MorphoGetters {
function testIsManaging(address owner, address manager, bool isAllowed) public {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import {ThreeHeapOrdering} from "@morpho-data-structures/ThreeHeapOrdering.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

import {IPriceOracleGetter} from "@aave/core-v3/contracts/interfaces/IPriceOracleGetter.sol";
import {DataTypes} from "../src/libraries/aave/DataTypes.sol";
import {ReserveConfiguration} from "../src/libraries/aave/ReserveConfiguration.sol";
import {DataTypes} from "src/libraries/aave/DataTypes.sol";
import {ReserveConfiguration} from "src/libraries/aave/ReserveConfiguration.sol";

import {MorphoInternal, MorphoStorage} from "../src/MorphoInternal.sol";
import {MarketLib} from "../src/libraries/MarketLib.sol";
import {MarketBalanceLib} from "../src/libraries/MarketBalanceLib.sol";
import {PoolLib} from "../src/libraries/PoolLib.sol";
import {MorphoInternal, MorphoStorage} from "src/MorphoInternal.sol";
import {MarketLib} from "src/libraries/MarketLib.sol";
import {MarketBalanceLib} from "src/libraries/MarketBalanceLib.sol";
import {PoolLib} from "src/libraries/PoolLib.sol";

import "./helpers/InternalTest.sol";
import "test/helpers/InternalTest.sol";

contract TestMorphoInternal is InternalTest, MorphoInternal {
using MarketLib for Types.Market;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.17;

import {Errors} from "../src/libraries/Errors.sol";
import {MorphoStorage} from "../src/MorphoStorage.sol";
import {PositionsManagerInternal} from "../src/PositionsManagerInternal.sol";
import {Errors} from "src/libraries/Errors.sol";
import {MorphoStorage} from "src/MorphoStorage.sol";
import {PositionsManagerInternal} from "src/PositionsManagerInternal.sol";

import "./helpers/InternalTest.sol";
import "test/helpers/InternalTest.sol";

contract TestPositionsManager is InternalTest, PositionsManagerInternal {
function testValidatePermission(address owner, address manager) public {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.17;

import {Types} from "../../src/libraries/Types.sol";
import {MarketBalanceLib} from "../../src/libraries/MarketBalanceLib.sol";
import {Types} from "src/libraries/Types.sol";
import {MarketBalanceLib} from "src/libraries/MarketBalanceLib.sol";
import {ThreeHeapOrdering} from "@morpho-data-structures/ThreeHeapOrdering.sol";

import {Test} from "@forge-std/Test.sol";
Expand Down
10 changes: 3 additions & 7 deletions test/libraries/TestMarketLib.sol → test/unit/TestMarketLib.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.17;

import {Types} from "../../src/libraries/Types.sol";
import {MarketLib} from "../../src/libraries/MarketLib.sol";
import {Types} from "src/libraries/Types.sol";
import {MarketLib} from "src/libraries/MarketLib.sol";

import {Test} from "@forge-std/Test.sol";

Expand All @@ -14,11 +14,7 @@ contract TestMarketLib is Test {
function testIsCreated(Types.Market memory _market) public {
market = _market;

assertTrue(market.isCreated());

market.aToken = address(0);

assertFalse(market.isCreated());
assertEq(market.isCreated(), market.aToken != address(0));
}

function testGetSupplyIndexes(Types.Market memory _market) public {
Expand Down