Skip to content

Commit

Permalink
Making the makefile pick the right values depending on the target
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed Oct 29, 2024
1 parent db1cfb7 commit 2376427
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 67 deletions.
14 changes: 7 additions & 7 deletions .env.dev.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# If deploying against a fork, pass the address of a large token holder who will be
# impersonated to distribute tokens to addresses inside test cases
# the whale should have >= 3000 tokens
TOKEN_TEST_WHALE="0x0000000000000000000000000000000000000000"
# If deploying against a fork, pass the address of a large token holder.
# This address will be impersonated to distribute tokens to addresses inside test cases.
# The whale needs to hold at least 3000 tokens
TEST_TOKEN_WHALE="0x0000000000000000000000000000000000000000"

# If the factory singleton is deployed, pass the address. "Fork existing" mode will use this previously
# deployed factory, and "fork deploy" will deploy a new factory instance
FACTORY="0x0000000000000000000000000000000000000000"
# If you are testing with FORK_TEST_MODE='fork-existing', define the address of the
# existing factory to use. Otherwise, you should use the default mode (fork-deploy)
FACTORY_ADDRESS="0x0000000000000000000000000000000000000000"
9 changes: 8 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# NETWORK AND DEPLOYMENT WALLET
DEPLOYMENT_PRIVATE_KEY="..."
NETWORK="sepolia"

# The name of the networks to use for test/production
TESTNET_NETWORK="holesky"
PRODNET_NETWORK="mainnet"

# The RPC of the networks to use for test/production
TESTNET_RPC_URL="https://holesky.drpc.org"
PRODNET_RPC_URL="https://eth.drpc.org"

# API Keys (optional)
# Note that having these active will slow down unit tests even when not needed
Expand Down
34 changes: 21 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,31 @@
-include .env.dev

# Set the RPC URL's for each target
test-fork-testnet: export RPC_URL = "https://sepolia.mode.network"
test-fork-prodnet: export RPC_URL = "https://mainnet.mode.network"
test-fork-testnet: export RPC_URL = $(TESTNET_RPC_URL)
test-fork-prodnet: export RPC_URL = $(PRODNET_RPC_URL)
test-fork-holesky: export RPC_URL = "https://holesky.drpc.org"
test-fork-sepolia: export RPC_URL = "https://sepolia.drpc.org"

pre-deploy-testnet: export RPC_URL = "https://sepolia.mode.network"
deploy-testnet: export RPC_URL = "https://sepolia.mode.network"
pre-deploy-prodnet: export RPC_URL = "https://mainnet.mode.network"
deploy-prodnet: export RPC_URL = "https://mainnet.mode.network"
pre-deploy-testnet: export RPC_URL = $(TESTNET_RPC_URL)
pre-deploy-prodnet: export RPC_URL = $(PRODNET_RPC_URL)
deploy-testnet: export RPC_URL = $(TESTNET_RPC_URL)
deploy-prodnet: export RPC_URL = $(PRODNET_RPC_URL)

# Override the verifier and block explorer parameters
# Set the network ID
pre-deploy-testnet: export NETWORK = $(TESTNET_NETWORK)
pre-deploy-prodnet: export NETWORK = $(PRODNET_NETWORK)
deploy-testnet: export NETWORK = $(TESTNET_NETWORK)
deploy-prodnet: export NETWORK = $(PRODNET_NETWORK)

# Override the verifier and block explorer parameters (network dependent)
deploy-testnet: export VERIFIER_TYPE_PARAM = --verifier blockscout
deploy-testnet: export VERIFIER_URL_PARAM = --verifier-url "https://sepolia.explorer.mode.network/api\?"
deploy-prodnet: export ETHERSCAN_API_KEY_PARAM = --etherscan-api-key $(ETHERSCAN_API_KEY)

# Set production deployments' flag
deploy: export DEPLOY_AS_PRODUCTION = true

# Override the fork mode
# Override the fork test mode (existing)
test-exfork-testnet: export FORK_TEST_MODE = fork-existing
test-exfork-prodnet: export FORK_TEST_MODE = fork-existing
test-exfork-holesky: export FORK_TEST_MODE = fork-existing
Expand Down Expand Up @@ -71,22 +77,24 @@ test-unit: ## Run unit tests, locally

#### Fork testing ####

test-exfork-testnet: test-fork-testnet ## Fork test with an existing factory (testnet)
test-exfork-prodnet: test-fork-prodnet ## Fork test with an existing factory (production network)
test-exfork-holesky: test-fork-holesky ## Fork test with an existing factory (Holesky)
test-exfork-sepolia: test-fork-sepolia ## Fork test with an existing factory (Sepolia)

test-fork-testnet: test-fork ## Run a fork test (testnet)
test-fork-prodnet: test-fork ## Run a fork test (production network)
test-fork-holesky: test-fork ## Run a fork test (Holesky)
test-fork-sepolia: test-fork ## Run a fork test (Sepolia)

test-exfork-testnet: test-fork-testnet ## Fork test with an existing factory (testnet)
test-exfork-prodnet: test-fork-prodnet ## Fork test with an existing factory (production network)
test-exfork-holesky: test-fork-holesky ## Fork test with an existing factory (Holesky)
test-exfork-sepolia: test-fork-sepolia ## Fork test with an existing factory (Sepolia)

test-fork:
forge test --match-contract $(E2E_TEST_NAME) --rpc-url $(RPC_URL) $(VERBOSITY)

: ##

test-coverage: report/index.html ## Make an HTML coverage report under ./report
@which open > /dev/null && open report/index.html || echo -n
@which xdg-open > /dev/null && xdg-open report/index.html || echo -n

report/index.html: lcov.info.pruned
genhtml $^ -o report --branch-coverage
Expand Down
115 changes: 71 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,79 @@ Welcome to Aragon's veGovernance Plugin - a flexible, modular and secure system

## Setup

To get started, ensure that [Foundry](https://getfoundry.sh/) is installed on your computer, then copy `.env.example` into `.env` and define the parameters
To get started, ensure that [Foundry](https://getfoundry.sh/) is installed on your computer.

### Understanding `.env.example`
<details>
<summary>Also make sure to install [GNU Make](https://www.gnu.org/software/make/).</summary>

```sh
# debian
sudo apt install build-essential

The env.example file contains descriptions for all the initial settings. You don't need all of these right away but should review prior to fork tests and deployments
# arch
sudo pacman -S base-devel

## Using the Makefile
# nix
nix-env -iA nixpkgs.gnumake

The `Makefile` functions as a script runner for common tasks. It's recommended to start there. Ensure you have the required tools installed to run the `make` command on your system:
# macOS
brew install make
```

```sh
# debian
sudo apt install build-essential
</details>

# arch
sudo pacman -S base-devel
### Using the Makefile

# nix
nix-env -iA nixpkgs.gnumake
The `Makefile` as the command launcher of the project. It's the recommended way to work with it. It manages the env variables of common tasks and executes only the steps that require being run.

# macOS
brew install make
```
$ make
Available targets:
Then run the commands as needed
- make init Check the required tools and dependencies
- make clean Clean the artifacts
```sh
# Setup the repo
make install
- make test-unit Run unit tests, locally
# run unit tests
make unit-test
- make test-fork-testnet Run a fork test (testnet)
- make test-fork-prodnet Run a fork test (production network)
- make test-fork-holesky Run a fork test (Holesky)
- make test-fork-sepolia Run a fork test (Sepolia)
- make test-exfork-testnet Fork test with an existing factory (testnet)
- make test-exfork-prodnet Fork test with an existing factory (production network)
- make test-exfork-holesky Fork test with an existing factory (Holesky)
- make test-exfork-sepolia Fork test with an existing factory (Sepolia)
# generate coverage report in the `report` directory
# requires lcov and genhtml
# serve the report/index.html in browser to view
make coverage
- make test-coverage Make an HTML coverage report under ./report
# the .env.example is set to work with sepolia
make ft-sepolia-fork
- make pre-deploy-testnet Simulate a deployment to the defined testnet
- make pre-deploy-prodnet Simulate a deployment to the defined production network
- make deploy-testnet Deploy to the defined testnet network and verify
- make deploy-prodnet Deploy to the production network and verify
```

Run `make init`:
- It ensures that Foundry is installed
- It runs a first compilation of the project
- It copies `.env.example` into `.env` and `.env.dev.example` into `.env.dev`

Next, customize the values of `.env` and optionally `.env.dev`.

### Understanding `.env.example`

The env.example file contains descriptions for all the initial settings. You don't need all of these right away but should review prior to fork tests and deployments

## Running fork tests

Fork testing has 2 modes:

1. "fork-deploy" will run against the live network fork, deploying new contracts via a new instance of the factory
1. "fork-deploy" will run against the live network fork, deploying new contracts via a new instance of the factory. See `make test-fork-testnet`, `make test-fork-prodnet` and simmilar

2. "fork-existing" will run against the live network fork, using the existing factory & therefore the existing contracts
2. "fork-existing" will run against the live network fork, using the existing factory & therefore the existing contracts. See `make test-exfork-testnet`, `make test-exfork-prodnet` and simmilar

In both cases, you will need to find the correct Aragon OSx contracts for the chain you wish to fork against. These can be found in the [OSx commons repo](https://github.com/aragon/osx-commons/tree/main/configs/src/deployments/json)

> If running frequent fork tests it's recommended you pass a block number to enable caching
> If running frequent fork tests it's recommended to pass a block number to enable caching
## Deployment

Expand All @@ -65,25 +85,32 @@ Deployments are done using the deployment factory. This is a singleton contract
- Deploy all contracts
- Set permissions
- Transfer ownership to a freshly deployed multisig
- Store the addresses of the deployment in a single, queriable place.
- Store the addresses of the deployment in a single source of truth that can be queried at any time.

Check the `Makefile` for examples of deployments on different networks.
Check the available make targets to simulate and deploy the smart contracts:

```
- make pre-deploy-testnet Simulate a deployment to the defined testnet
- make pre-deploy-prodnet Simulate a deployment to the defined production network
- make deploy-testnet Deploy to the defined testnet network and verify
- make deploy-prodnet Deploy to the production network and verify
```

### Deployment Checklist

- [] I have reviewed the parameters for the veDAO I want to deploy
- [] I have reviewed the multisig file for the correct addresses
- [] I have ensured all multisig members have undergone a proper security review and are aware of the security implications of being on said multisig
- [] I have updated the `.env` with these parameters
- [] I have updated the `CurveConstantLib` and `Clock` with any new constants.
- [] All my unit tests pass
- [] I have run a fork test in `fork-deploy` mode against the OSx contracts on my target testnet
- [] I have deployed my contracts successfully to a target testnet
- [] I have confirmed my tests still work in `fork-existing` mode with the live tokens and the factory.
- [] I have run the same workflow against the mainnet I wish to deploy on
- [] I have previewed my deploy
- [] My deployer address is a fresh wallet or setup for repeat production deploys in a safe manner.
- [] My wallet has sufficient native token for gas
- [ ] I have reviewed the parameters for the veDAO I want to deploy
- [ ] I have reviewed the multisig file for the correct addresses
- [ ] I have ensured all multisig members have undergone a proper security review and are aware of the security implications of being on said multisig
- [ ] I have updated the `.env` with these parameters
- [ ] I have updated the `CurveConstantLib` and `Clock` with any new constants.
- [ ] All my unit tests pass
- [ ] I have run a fork test in `fork-deploy` mode against the OSx contracts on my target testnet
- [ ] I have deployed my contracts successfully to a target testnet
- [ ] I have confirmed my tests still work in `fork-existing` mode with the live tokens and the factory.
- [ ] I have run the same workflow against the mainnet I wish to deploy on
- [ ] I have previewed my deploy
- [ ] My deployer address is a fresh wallet or setup for repeat production deploys in a safe manner.
- [ ] My wallet has sufficient native token for gas

### Manual from the command line

Expand Down
4 changes: 2 additions & 2 deletions test/fork/e2eV2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ contract TestE2EV2 is AragonTest, IWithdrawalQueueErrors, IGaugeVote, IEscrowCur
}
// connect to the existing factory to fetch the contract addresses
else if (_getTestMode() == TestMode.ForkExisting) {
address factoryAddress = vm.envAddress("FACTORY");
address factoryAddress = vm.envOr("FACTORY_ADDRESS", address(0));
if (factoryAddress == address(0)) {
revert("Factory address not set");
}
Expand Down Expand Up @@ -1384,7 +1384,7 @@ contract TestE2EV2 is AragonTest, IWithdrawalQueueErrors, IGaugeVote, IEscrowCur
} catch {}

// next we just try a good old fashioned find a whale and rug them in the test
address whale = vm.envOr("TOKEN_TEST_WHALE", address(0));
address whale = vm.envOr("TEST_TOKEN_WHALE", address(0));
if (whale == address(0)) {
return false;
}
Expand Down

0 comments on commit 2376427

Please sign in to comment.