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

refactor(repo): refactor setup #56

Merged
merged 3 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
NETWORK=ethereum-mainnet
TX_NAME=test
TX_NAME_TRANSACTION_DATA=testTransactionData
ALCHEMY_KEY=
32 changes: 32 additions & 0 deletions .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Formatting

on:
push:
branches:
- main
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Install node
uses: actions/setup-node@v3
with:
node-version: 18
cache: yarn

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

- name: Run Linter
run: yarn lint
35 changes: 15 additions & 20 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
name: test
name: Foundry

on: push
on:
push:
branches:
- main
pull_request:
workflow_dispatch:

env:
FOUNDRY_PROFILE: ci
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true

jobs:
check:
strategy:
fail-fast: true

name: Foundry project
forge-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -19,16 +21,9 @@ jobs:

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

- name: Run Forge build
run: |
forge --version
forge build --sizes
id: build

- name: Run Forge tests
run: |
forge test --match-contract TestDAOSetup -vvv
id: test
run: forge test -vvv
env:
ALCHEMY_KEY: ${{ secrets.ALCHEMY_KEY }}
FOUNDRY_FUZZ_RUNS: 64
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/morpho-token"]
path = lib/morpho-token
url = https://github.com/morpho-org/morpho-token
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
[submodule "lib/morpho-token"]
path = lib/morpho-token
url = https://github.com/morpho-org/morpho-token
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Merlin Egalite
Copyright (c) 2023 Morpho Labs
Rubilmax marked this conversation as resolved.
Show resolved Hide resolved

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

## Overview

Morpho Seatbelt provides a framework for testing governance transactions to update Morpho Optimizers. Morpho utilizes the [Zodiac](https://github.com/gnosis/zodiac) collection of tools to enforce transaction delays and restrict certain functions to addresses with an appropriate role. Some key utilities included are reading gnosis safe transactions from a json, reading key internal state variables of contracts without external getters, and minimal interfaces to limit dependencies.
Morpho Seatbelt provides a framework for testing governance transactions to update any contract controlled (directly or indirectly) by the Morpho DAO. Morpho uses the [Zodiac](https://github.com/gnosis/zodiac) collection of tools to enforce transaction delays and restrict certain functions to addresses with an appropriate role. Some key utilities included are reading gnosis safe transactions from a json, reading key internal state variables of contracts without external getters, and minimal interfaces to limit dependencies.


---
Expand All @@ -19,21 +19,25 @@ Morpho Seatbelt provides a framework for testing governance transactions to upda
### Getting Started

- Install [Foundry](https://github.com/foundry-rs/foundry) or Run `foundryup` to initialize Foundry.
- Run `forge install` to initialize the repository by installing the required dependencies.
- If not testing on mainnet, add a config file in the [network config](./config/networks) using the mainnet config as a template, and create a `.env` file with a NETWORK field.
- If testing a safe transaction on the Morpho DAO, add the transaction information in the [transactions config](./config/transactions). You can use [this](./test/TestLog.sol) as a template. You can test two types of transactions with the Morpho DAO.
- Run `yarn` to initialize the repository by installing the required dependencies.
- Create a `.env` file with a `ALCHEMY_KEY` field populated with a personal alchemy RPC key.

The Raw Data transaction concerns the one's that you can execute directly with a simple script. The name of the json file has to be added in the `.env` in place of testRawData.
### Running tests

- Use `yarn test` to run tests on standard invariants regarding the Morpho DAO & the $MORPHO token setup.
- Use `yarn test:txs` to run tests on specific DAO transactions.

The other type of transaction that can be tested is the transaction that executed the function `executeTransactionFromModule` from the Morpho DAO. The arguments of the function `executeTransactionFromModule` need to be added to the json file. The name of the json file has to be added in the `.env` in place of testRawData.
### Testing a DAO transaction

#### Testing a transaction through the Delay Modifier

You can now test the SetUp of the Morpho DAO with the following command:
- Copy the parameters of the call from the DAO to the delay modifier's `execTransactionFromModule` to a [json file appropriately named](./test/transactions/data/).
- Create a test contract that inherits from `DelayModifierTxTest` (see examples: [ma3CbEthListingTxTest](./test/transactions/ma3CbEthListingTxTest.sol), [ma3REthListingTxTest](./test/transactions/ma3REthListingTxTest.sol), [ma3SDaiUsdtListingTxTest](./test/transactions/ma3SDaiUsdtListingTxTest.sol)).

```bash
forge test
```
#### Testing a transaction to the Morpho DAO

- Copy the transaction data to a [json file appropriately named](./test/transactions/data/).
- Create a test contract that inherits from `MorphoDaoTxTest` (see example: [swapStefanoGuillaumeDaoSignersTxTest](./test/transactions/swapStefanoGuillaumeDaoSignersTxTest.sol)).

## Questions & Feedback

Expand Down
22 changes: 5 additions & 17 deletions config/ConfigLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,14 @@ struct Config {
library ConfigLib {
using stdJson for string;

string internal constant OWNERS_PATH = "$.owners";
string internal constant CHAIN_ID_PATH = "$.chainId";
string internal constant RPC_ALIAS_PATH = "$.rpcAlias";
string internal constant FORK_BLOCK_NUMBER_PATH = "$.forkBlockNumber";

function getAddress(Config storage config, string memory key) internal returns (address) {
return config.json.readAddress(string.concat("$.", key));
}

function getUint(Config storage config, string memory key) internal returns (uint256) {
return config.json.readUint(string.concat("$.", key));
}

function getBytes(Config storage config, string memory key) internal returns (bytes memory) {
return config.json.readBytes(string.concat("$.", key));
}

function getBool(Config storage config, string memory key) internal returns (bool) {
return config.json.readBool(string.concat("$.", key));
}

function getAddressArray(Config storage config, string[] memory keys)
internal
returns (address[] memory addresses)
Expand All @@ -41,15 +29,15 @@ library ConfigLib {
}
}

function getChainId(Config storage config) internal returns (uint256) {
return config.json.readUint(CHAIN_ID_PATH);
}

function getRpcAlias(Config storage config) internal returns (string memory) {
return config.json.readString(RPC_ALIAS_PATH);
}

function getForkBlockNumber(Config storage config) internal returns (uint256) {
return config.json.readUint(FORK_BLOCK_NUMBER_PATH);
}

function getOwners(Config storage config) internal returns (address[] memory) {
return config.json.readAddressArray(OWNERS_PATH);
}
}
Loading