Skip to content

Commit

Permalink
Merge pull request #1440 from morpho-dao/test/add-ci-prod-tests
Browse files Browse the repository at this point in the history
Add production tests to CI
  • Loading branch information
Rubilmax authored Nov 30, 2022
2 parents b8038bd + 7ab351f commit 4d788cf
Show file tree
Hide file tree
Showing 24 changed files with 1,302 additions and 1,700 deletions.
52 changes: 52 additions & 0 deletions .github/actions/ci-foundry-upgrade/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Foundry upgrade tests
description: Runs full forge test suite given a protocol and a network

inputs:
protocol:
description: The protocol against which to run the forge test suite.
required: true
network:
description: The network against which to run the forge test suite.
required: true
alchemyKey:
description: The Alchemy key giving access to a private RPC.
required: true

runs:
using: composite
steps:
- uses: actions/setup-node@v3
with:
node-version: 16
cache: yarn

- name: Install dependencies
run: yarn install --frozen-lockfile
shell: bash

- name: Install Foundry
uses: onbjerg/foundry-toolchain@v1
with:
version: nightly

- name: Foundry fork cache
uses: actions/cache@v3
with:
path: ~/.foundry/cache
key: foundry-${{ hashFiles('Makefile', 'foundry.toml') }} # where fork block numbers & RPC are stored

- name: Foundry compilation cache
uses: actions/cache@v3
with:
path: |
cache
out
key: ${{ github.base_ref || github.ref_name }}-foundry-${{ inputs.protocol }}-${{ inputs.network }} # always keep compiled contracts from base branch

- name: Run upgrade tests
run: make ci-upgrade
shell: bash
env:
PROTOCOL: ${{ inputs.protocol }}
NETWORK: ${{ inputs.network }}
ALCHEMY_KEY: ${{ inputs.alchemyKey }}
37 changes: 37 additions & 0 deletions .github/workflows/ci-foundry-aave-v2-upgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Foundry upgrade tests (Morpho-Aave V2)

on:
push:
branches:
- main
pull_request:
# branches:
# - main # disabled for testing
paths:
- "lib/**"
- "config/**/aave-v2/**"
- "contracts/common/**"
- "contracts/aave-v2/**"
- "test-foundry/common/**"
- "test-foundry/aave-v2/**"
- "*.lock"
- "Makefile"
- "foundry.toml"
- "remappings.txt"
- ".github/actions/ci-foundry-upgrade/*"
- ".github/workflows/ci-foundry-aave-v2-upgrade.yml"

jobs:
morpho-aave-v2-eth-mainnet-upgrade:
name: eth-mainnet
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- uses: ./.github/actions/ci-foundry-upgrade
with:
protocol: aave-v2
network: eth-mainnet
alchemyKey: ${{ secrets.ALCHEMY_KEY }}
37 changes: 37 additions & 0 deletions .github/workflows/ci-foundry-compound-upgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Foundry upgrade tests (Morpho-Compound)

on:
push:
branches:
- main
pull_request:
# branches:
# - main # disabled for testing
paths:
- "lib/**"
- "config/**/compound/**"
- "contracts/common/**"
- "contracts/compound/**"
- "test-foundry/common/**"
- "test-foundry/compound/**"
- "*.lock"
- "Makefile"
- "foundry.toml"
- "remappings.txt"
- ".github/actions/ci-foundry-upgrade/*"
- ".github/workflows/ci-foundry-compound-upgrade.yml"

jobs:
morpho-compound-eth-mainnet-upgrade:
name: eth-mainnet
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- uses: ./.github/actions/ci-foundry-upgrade
with:
protocol: compound
network: eth-mainnet
alchemyKey: ${{ secrets.ALCHEMY_KEY }}
141 changes: 63 additions & 78 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,121 +1,106 @@
-include .env.local
.EXPORT_ALL_VARIABLES:
MAKEFLAGS += --no-print-directory

SMODE?=network
PROTOCOL?=compound
NETWORK?=eth-mainnet
PROTOCOL ?= compound
NETWORK ?= eth-mainnet

FOUNDRY_SRC=contracts/${PROTOCOL}/
FOUNDRY_TEST=test-foundry/${PROTOCOL}/
FOUNDRY_REMAPPINGS=@config/=config/${NETWORK}/${PROTOCOL}/
FOUNDRY_SRC ?= contracts/${PROTOCOL}/

FOUNDRY_PRIVATE_KEY?=${DEPLOYER_PRIVATE_KEY}
FOUNDRY_PROFILE ?= ${PROTOCOL}
FOUNDRY_REMAPPINGS ?= @config/=config/${NETWORK}/${PROTOCOL}/
FOUNDRY_PRIVATE_KEY ?= ${DEPLOYER_PRIVATE_KEY}

ifdef FOUNDRY_ETH_RPC_URL
FOUNDRY_TEST=test-foundry/prod/${PROTOCOL}/
FOUNDRY_FUZZ_RUNS=256
FOUNDRY_FUZZ_MAX_LOCAL_REJECTS=16384
FOUNDRY_FUZZ_MAX_GLOBAL_REJECTS=1048576
ifeq (${FOUNDRY_PROFILE}, production)
FOUNDRY_TEST = test-foundry/prod/${PROTOCOL}/
else
FOUNDRY_ETH_RPC_URL=https://${NETWORK}.g.alchemy.com/v2/${ALCHEMY_KEY}

ifeq (${NETWORK}, eth-mainnet)
FOUNDRY_CHAIN_ID=1
FOUNDRY_FORK_BLOCK_NUMBER?=15581371 # Block number when the Aave's V2 IRM was updated for the stETH.
endif

ifeq (${NETWORK}, eth-ropsten)
FOUNDRY_CHAIN_ID=3
endif

ifeq (${NETWORK}, eth-goerli)
FOUNDRY_CHAIN_ID=5
endif

ifeq (${NETWORK}, polygon-mainnet)
ifeq (${PROTOCOL}, aave-v3)
FOUNDRY_FORK_BLOCK_NUMBER?=29116728
FOUNDRY_CONTRACT_PATTERN_INVERSE=(Fees|IncentivesVault|Rewards)
endif

FOUNDRY_CHAIN_ID=137
FOUNDRY_FORK_BLOCK_NUMBER?=22116728
endif

ifeq (${NETWORK}, avalanche-mainnet)
ifeq (${PROTOCOL}, aave-v3)
FOUNDRY_FORK_BLOCK_NUMBER?=15675271
endif

FOUNDRY_CHAIN_ID=43114
FOUNDRY_ETH_RPC_URL=https://api.avax.network/ext/bc/C/rpc
FOUNDRY_FORK_BLOCK_NUMBER?=12675271
endif
FOUNDRY_TEST ?= test-foundry/${PROTOCOL}/
endif

ifeq (${SMODE}, local)
FOUNDRY_ETH_RPC_URL=http://localhost:8545
ifneq (${NETWORK}, avalanche-mainnet)
FOUNDRY_ETH_RPC_URL ?= https://${NETWORK}.g.alchemy.com/v2/${ALCHEMY_KEY}
endif


install:
@yarn
@foundryup
@git submodule update --init --recursive
yarn
foundryup
git submodule update --init --recursive

@chmod +x ./scripts/**/*.sh
chmod +x ./scripts/**/*.sh

deploy:
@echo Deploying Morpho-${PROTOCOL} on ${NETWORK}
@echo Deploying Morpho-${PROTOCOL}-${NETWORK}
./scripts/${PROTOCOL}/deploy.sh

initialize:
@echo Initializing Morpho-${PROTOCOL} on "${NETWORK}"
@echo Initializing Morpho-${PROTOCOL}-${NETWORK}
./scripts/${PROTOCOL}/initialize.sh

create-market:
@echo Creating market on Morpho-${PROTOCOL} on "${NETWORK}"
@echo Creating market on Morpho-${PROTOCOL}-${NETWORK}
./scripts/${PROTOCOL}/create-market.sh

anvil:
@echo Starting fork of "${NETWORK}" at block "${FOUNDRY_FORK_BLOCK_NUMBER}"
@echo Starting fork of ${NETWORK}
@anvil --fork-url ${FOUNDRY_ETH_RPC_URL} --fork-block-number "${FOUNDRY_FORK_BLOCK_NUMBER}"

script-%:
@echo Running script $* of Morpho-${PROTOCOL} on "${NETWORK}" with script mode: ${SMODE}
@echo Running script $* of Morpho-${PROTOCOL} on ${NETWORK} with script mode: ${SMODE}
@forge script scripts/${PROTOCOL}/$*.s.sol:$* --broadcast -vvvv

contracts:
FOUNDRY_TEST=/dev/null forge build --sizes --force

ci:
@forge test -vv
forge test -vvv

ci-upgrade:
@FOUNDRY_MATCH_CONTRACT=TestUpgrade FOUNDRY_FUZZ_RUNS=64 FOUNDRY_PROFILE=production make ci

test:
@echo Running all Morpho-${PROTOCOL} tests on "${NETWORK}" at block "${FOUNDRY_FORK_BLOCK_NUMBER}" with seed "${FOUNDRY_FUZZ_SEED}"
@forge test -vv | tee trace.ansi
@echo Running Morpho-${PROTOCOL}-${NETWORK} tests under \"${FOUNDRY_TEST}\"\
with profile \"${FOUNDRY_PROFILE}\", seed \"${FOUNDRY_FUZZ_SEED}\",\
match contract patterns \"\(${FOUNDRY_MATCH_CONTRACT}\)!${FOUNDRY_NO_MATCH_CONTRACT}\",\
match test patterns \"\(${FOUNDRY_MATCH_TEST}\)!${FOUNDRY_NO_MATCH_TEST}\"

coverage:
@echo Create lcov coverage report for Morpho-${PROTOCOL} tests on "${NETWORK}" at block "${FOUNDRY_FORK_BLOCK_NUMBER}" with seed "${FOUNDRY_FUZZ_SEED}"
@forge coverage --report lcov
@lcov --remove lcov.info -o lcov.info "test-foundry/*"
forge test -vvv | tee trace.ansi

lcov-html:
@echo Transforming the lcov coverage report into html
@genhtml lcov.info -o coverage
test-prod:
@FOUNDRY_NO_MATCH_CONTRACT=TestUpgrade FOUNDRY_PROFILE=production make test

gas-report:
@echo Creating gas report for Morpho-${PROTOCOL} on "${NETWORK}" at block "${FOUNDRY_FORK_BLOCK_NUMBER}" with seed "${FOUNDRY_FUZZ_SEED}"
@forge test --gas-report | tee trace.ansi
test-upgrade:
@FOUNDRY_MATCH_CONTRACT=TestUpgrade FOUNDRY_PROFILE=production make test

test-common:
@echo Running all common tests on "${NETWORK}"
@FOUNDRY_TEST=test-foundry/common forge test -vvv | tee trace.ansi
@FOUNDRY_TEST=test-foundry/common/ FOUNDRY_PROFILE=common make test

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

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

test-%:
@FOUNDRY_MATCH_TEST=$* make test

contract-% c-%:
@echo Running tests for contract $* of Morpho-${PROTOCOL} on "${NETWORK}" at block "${FOUNDRY_FORK_BLOCK_NUMBER}"
@forge test -vvv --match-contract $* | tee trace.ansi
@FOUNDRY_MATCH_CONTRACT=$* make test

coverage:
@echo Create lcov coverage report for Morpho-${PROTOCOL}-${NETWORK} tests
forge coverage --report lcov
lcov --remove lcov.info -o lcov.info "test-foundry/*"

lcov-html:
@echo Transforming the lcov coverage report into html
genhtml lcov.info -o coverage

gas-report:
@echo Create gas report from Morpho-${PROTOCOL}-${NETWORK} tests under \"${FOUNDRY_TEST}\"\
with profile \"${FOUNDRY_PROFILE}\", seed \"${FOUNDRY_FUZZ_SEED}\",

single-% s-%:
@echo Running single test $* of Morpho-${PROTOCOL} on "${NETWORK}" at block "${FOUNDRY_FORK_BLOCK_NUMBER}"
@forge test -vvvv --match-test $* | tee trace.ansi
forge test --gas-report | tee trace.ansi

storage-layout-generate:
@./scripts/storage-layout.sh generate snapshots/.storage-layout-${PROTOCOL} Morpho RewardsManager Lens
Expand All @@ -133,4 +118,4 @@ config:
@forge config


.PHONY: test config test-common foundry coverage
.PHONY: test config test-common foundry coverage contracts
4 changes: 4 additions & 0 deletions config/eth-mainnet/aave-v2/Config.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {ILendingPool} from "@contracts/aave-v2/interfaces/aave/ILendingPool.sol"
import {IPriceOracleGetter} from "@contracts/aave-v2/interfaces/aave/IPriceOracleGetter.sol";
import {IAaveIncentivesController} from "@contracts/aave-v2/interfaces/aave/IAaveIncentivesController.sol";
import {ILendingPoolAddressesProvider} from "@contracts/aave-v2/interfaces/aave/ILendingPoolAddressesProvider.sol";
import {IRewardsManager} from "@contracts/aave-v2/interfaces/IRewardsManager.sol";
import {IIncentivesVault} from "@contracts/aave-v2/interfaces/IIncentivesVault.sol";
import {IEntryPositionsManager} from "@contracts/aave-v2/interfaces/IEntryPositionsManager.sol";
import {IExitPositionsManager} from "@contracts/aave-v2/interfaces/IExitPositionsManager.sol";
Expand Down Expand Up @@ -53,12 +54,15 @@ contract Config is BaseConfig {
TransparentUpgradeableProxy(payable(0x507fA343d0A90786d86C7cd885f5C49263A91FF4));
TransparentUpgradeableProxy public morphoProxy =
TransparentUpgradeableProxy(payable(0x777777c9898D384F785Ee44Acfe945efDFf5f3E0));
TransparentUpgradeableProxy public rewardsManagerProxy;

Lens public lensImplV1;
Morpho public morphoImplV1;
IRewardsManager public rewardsManagerImplV1;

Lens public lens;
Morpho public morpho;
IRewardsManager public rewardsManager;
IIncentivesVault public incentivesVault;
IEntryPositionsManager public entryPositionsManager;
IExitPositionsManager public exitPositionsManager;
Expand Down
18 changes: 17 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,21 @@ revert_strings = "default"
names = true
sizes = true

[fuzz]
[profile.default.fuzz]
runs = 1024

[profile.production.fuzz]
runs = 256

[profile.common]
test = "test-foundry/common"

[profile.compound]
fork_block_number = 15_581_371

[profile.aave-v2]
fork_block_number = 15_581_371 # Block number when the Aave's V2 IRM was updated for the stETH.

[profile.aave-v3]
eth_rpc_url = "https://api.avax.network/ext/bc/C/rpc"
fork_block_number = 15_675_271
Loading

0 comments on commit 4d788cf

Please sign in to comment.