Skip to content

Commit

Permalink
Improved readability, adding E2E tests to use an existing token
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed Oct 29, 2024
1 parent c5e1259 commit ec49783
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 47 deletions.
4 changes: 2 additions & 2 deletions .env.dev.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
# The whale needs to hold at least 3000 tokens
TEST_TOKEN_WHALE="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)
# If you are testing with `make test-fork-factory-*`, you need to define the address of the
# existing factory to use. Otherwise, you should use `make test-fork-*`
FACTORY_ADDRESS="0x0000000000000000000000000000000000000000"
67 changes: 40 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
-include .env
-include .env.dev

# VARIABLE ASSIGNMENTS

# Set the RPC URL's for each target
test-fork-testnet: export RPC_URL = $(TESTNET_RPC_URL)
test-fork-prodnet: export RPC_URL = $(PRODNET_RPC_URL)
Expand All @@ -27,21 +29,29 @@ deploy-testnet: export VERIFIER_URL_PARAM = --verifier-url "https://sepolia.expl
deploy-prodnet: export ETHERSCAN_API_KEY_PARAM = --etherscan-api-key $(ETHERSCAN_API_KEY)

# Set production deployments' flag
test-fork-prod-testnet: export DEPLOY_AS_PRODUCTION = true
test-fork-prod-prodnet: export DEPLOY_AS_PRODUCTION = true
test-fork-prod-holesky: export DEPLOY_AS_PRODUCTION = true
test-fork-prod-sepolia: export DEPLOY_AS_PRODUCTION = true
deploy: export DEPLOY_AS_PRODUCTION = true

# 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
test-exfork-sepolia: export FORK_TEST_MODE = fork-existing
test-fork-factory-testnet: export FORK_TEST_MODE = fork-existing
test-fork-factory-prodnet: export FORK_TEST_MODE = fork-existing
test-fork-factory-holesky: export FORK_TEST_MODE = fork-existing
test-fork-factory-sepolia: export FORK_TEST_MODE = fork-existing

# CONSTANTS

TEST_SRC_FILES=$(wildcard test/*.sol test/**/*.sol script/*.sol script/**/*.sol src/escrow/increasing/delegation/*.sol src/libs/ProxyLib.sol)
FORK_TEST_WILDCARD="test/fork/**/*.sol"
E2E_TEST_NAME=TestE2EV2
DEPLOY_SCRIPT=script/Deploy.s.sol:Deploy
DEPLOY_SCRIPT=script/DeployGauges.s.sol:DeployGauges
VERBOSITY=-vvv
DEPLOYMENT_LOG_FILE=$(shell echo "./deployment-$(shell date +"%y-%m-%d-%H-%M").log")

# TARGETS

.PHONY: help
help:
@echo "Available targets:"
Expand All @@ -52,9 +62,9 @@ help:

.PHONY: init
init: .env .env.dev ## Check the required tools and dependencies
@which forge || curl -L https://foundry.paradigm.xyz | bash
@which forge > /dev/null || curl -L https://foundry.paradigm.xyz | bash
@forge build
@which lcov || echo "Note: lcov can be installed by running 'sudo apt install lcov'"
@which lcov > /dev/null || echo "Note: lcov can be installed by running 'sudo apt install lcov'"

.PHONY: clean
clean: ## Clean the artifacts
Expand All @@ -74,25 +84,6 @@ clean: ## Clean the artifacts
test-unit: ## Run unit tests, locally
forge test --no-match-path $(FORK_TEST_WILDCARD)

: ##

#### Fork testing ####

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
Expand All @@ -101,13 +92,35 @@ report/index.html: lcov.info.pruned
genhtml $^ -o report --branch-coverage

lcov.info.pruned: lcov.info
lcov --remove ./$< -o ./$<.pruned $^
lcov --remove ./$< -o ./$@ $^

lcov.info: $(TEST_SRC_FILES)
forge coverage --no-match-path $(FORK_TEST_WILDCARD) --report lcov

: ##

#### Fork testing ####

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

test-fork-prod-testnet: test-fork-testnet ## Fork test using the .env token params (testnet)
test-fork-prod-prodnet: test-fork-prodnet ## Fork test using the .env token params (production network)
test-fork-prod-holesky: test-fork-holesky ## Fork test using the .env token params (Holesky)
test-fork-prod-sepolia: test-fork-sepolia ## Fork test using the .env token params (Sepolia)

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

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

: ##

#### Deployment targets ####

pre-deploy-testnet: pre-deploy ## Simulate a deployment to the defined testnet
Expand Down
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ To get started, ensure that [Foundry](https://getfoundry.sh/) is installed on yo

### Using the Makefile

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.
The `Makefile` as the target 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.

```
$ make
Expand All @@ -37,18 +37,21 @@ Available targets:
- make clean Clean the artifacts
- make test-unit Run unit tests, locally
- 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)
- make test-coverage Make an HTML coverage report under ./report
- make test-fork-testnet Run a clean fork test (testnet)
- make test-fork-prodnet Run a clean fork test (production network)
- make test-fork-holesky Run a clean fork test (Holesky)
- make test-fork-sepolia Run a clean fork test (Sepolia)
- make test-fork-prod-testnet Fork test using the .env token params (testnet)
- make test-fork-prod-prodnet Fork test using the .env token params (production network)
- make test-fork-prod-holesky Fork test using the .env token params (Holesky)
- make test-fork-prod-sepolia Fork test using the .env token params (Sepolia)
- make test-fork-factory-testnet Fork test on an existing factory (testnet)
- make test-fork-factory-prodnet Fork test on an existing factory (production network)
- make test-fork-factory-holesky Fork test on an existing factory (Holesky)
- make test-fork-factory-sepolia Fork test on an existing factory (Sepolia)
- 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
Expand Down Expand Up @@ -135,22 +138,22 @@ RPC_URL="https://eth-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
# Run the deployment script

# If using Etherscan
forge script --chain "$NETWORK" script/Deploy.s.sol:Deploy --rpc-url "$RPC_URL" --broadcast --verify
forge script --chain "$NETWORK" script/DeployGauges.s.sol:Deploy --rpc-url "$RPC_URL" --broadcast --verify

# If using BlockScout
forge script --chain "$NETWORK" script/Deploy.s.sol:Deploy --rpc-url "$RPC_URL" --broadcast --verify --verifier blockscout --verifier-url "https://sepolia.explorer.mode.network/api\?"
forge script --chain "$NETWORK" script/DeployGauges.s.sol:Deploy --rpc-url "$RPC_URL" --broadcast --verify --verifier blockscout --verifier-url "https://sepolia.explorer.mode.network/api\?"
```

If you get the error Failed to get EIP-1559 fees, add `--legacy` to the command:

```sh
forge script --chain "$NETWORK" script/Deploy.s.sol:Deploy --rpc-url "$RPC_URL" --broadcast --verify --legacy
forge script --chain "$NETWORK" script/DeployGauges.s.sol:Deploy --rpc-url "$RPC_URL" --broadcast --verify --legacy
```

If some contracts fail to verify on Etherscan, retry with this command:

```sh
forge script --chain "$NETWORK" script/Deploy.s.sol:Deploy --rpc-url "$RPC_URL" --verify --legacy --private-key "$DEPLOYMENT_PRIVATE_KEY" --resume
forge script --chain "$NETWORK" script/DeployGauges.s.sol:Deploy --rpc-url "$RPC_URL" --verify --legacy --private-key "$DEPLOYMENT_PRIVATE_KEY" --resume
```

## Contracts Overview
Expand Down
2 changes: 1 addition & 1 deletion script/Deploy.s.sol → script/DeployGauges.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {PluginSetupProcessor} from "@aragon/osx/framework/plugin/setup/PluginSet
import {MockERC20} from "@mocks/MockERC20.sol";
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";

contract Deploy is Script {
contract DeployGauges is Script {
using SafeCast for uint256;

SimpleGaugeVoterSetup simpleGaugeVoterSetup;
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 @@ -18,7 +18,7 @@ import {IGaugeVote} from "src/voting/ISimpleGaugeVoter.sol";
import {VotingEscrow, Lock, QuadraticIncreasingEscrow, ExitQueue, SimpleGaugeVoter, SimpleGaugeVoterSetup, ISimpleGaugeVoterSetupParams} from "src/voting/SimpleGaugeVoterSetup.sol";

import {GaugesDaoFactory, GaugePluginSet, Deployment} from "src/factory/GaugesDaoFactory.sol";
import {Deploy, DeploymentParameters} from "script/Deploy.s.sol";
import {DeployGauges, DeploymentParameters} from "script/DeployGauges.s.sol";

interface IERC20Mint is IERC20 {
function mint(address _to, uint256 _amount) external;
Expand Down Expand Up @@ -105,7 +105,7 @@ contract TestE2EV2 is AragonTest, IWithdrawalQueueErrors, IGaugeVote, IEscrowCur
/// 3. Fork Mode: Existing (Supported): we don't deploy via the factory, we use the existing contract for everything
function setUp() public {
// deploy the deploy script
Deploy deploy = new Deploy();
DeployGauges deploy = new DeployGauges();

// fetch the deployment parameters
DeploymentParameters memory deploymentParameters = deploy.getDeploymentParameters(
Expand Down

0 comments on commit ec49783

Please sign in to comment.