Skip to content

Commit

Permalink
refactor(repo): refactor setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed Sep 15, 2023
1 parent 398001c commit 365816b
Show file tree
Hide file tree
Showing 56 changed files with 1,569 additions and 1,771 deletions.
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=
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

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

0 comments on commit 365816b

Please sign in to comment.