Skip to content

Commit

Permalink
Refactoring the Makefile, optimizing env vars and making the E2E test…
Browse files Browse the repository at this point in the history
… use AragonTest
  • Loading branch information
brickpop committed Oct 29, 2024
1 parent 5ff4451 commit db1cfb7
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 246 deletions.
8 changes: 8 additions & 0 deletions .env.dev.example
Original file line number Diff line number Diff line change
@@ -0,0 +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 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"
20 changes: 1 addition & 19 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
# Fork Test mode:
# "fork-deploy" will run against the live network fork, deploying new contracts via a new instance of the factory
# "fork-existing" will run against the live network fork, using the existing factory & therefore the existing contracts
FORK_TEST_MODE="fork-deploy"

# With false, the script will deploy mock tokens with open mint functions
DEPLOY_AS_PRODUCTION=false

# 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="0x"

# 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"

# NETWORK AND DEPLOYMENT WALLET
DEPLOYMENT_PRIVATE_KEY="..."
NETWORK="sepolia"
Expand All @@ -25,11 +8,10 @@ NETWORK="sepolia"
# ETHERSCAN_API_KEY="..."
# ALCHEMY_API_KEY="..."


# MULTISIG PARAMETERS
# define a list of multisig members - said multisig will be assigned administrator roles of the ve contracts
MULTISIG_MEMBERS_JSON_FILE_NAME="/script/multisig-members.json"
MIN_APPROVALS="1" # How many multisig approvals are required
MIN_APPROVALS="1" # How many multisig approvals are required
MULTISIG_PROPOSAL_EXPIRATION_PERIOD="864000" # How long until a pending proposal expires (10 days)

# GAUGE VOTER PARAMETERS
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
^.env.example
^.env.dev.example
.env*

# Foundry
Expand Down
121 changes: 71 additions & 50 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,67 +1,92 @@
.DEFAULT_TARGET: help

# include .env file and export its env vars
# (-include to ignore error if it does not exist)
# Import the .env files and export their values (ignore any error if missing)
-include .env
-include .env.dev

test-fork-testnet: export RPC_URL = https://sepolia.mode.network
test-fork-prodnet: export RPC_URL = https://mainnet.mode.network
test-fork-holesky: export RPC_URL = https://holesky.drpc.org
test-fork-sepolia: export RPC_URL = https://sepolia.drpc.org
# 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-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 = "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"

deploy-testnet: export VERIFIER_URL = https://sepolia.explorer.mode.network/api\?
deploy-testnet: export VERIFIER_PARAM = --verifier blockscout
# Override the verifier and block explorer parameters
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
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_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
VERBOSITY=-vvv

.PHONY: help
help:
@echo "Available targets:"
@echo
@grep -E '^[a-zA-Z0-9_-]*:.*?## .*$$' Makefile \
| sed -n 's/^\(.*\): \(.*\)##\(.*\)/- \1 \3/p'
| sed -n 's/^\(.*\): \(.*\)##\(.*\)/- make \1 \3/p' \
| sed 's/^- make $$//g'

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

.PHONY: clean
clean: ## Clean the artifacts
clean: ## Clean the artifacts
rm -Rf ./out/* lcov.info* ./report/*

# Copy the .env files if not present
.env:
cp .env.example .env
@echo "NOTE: Edit the correct values of .env before you continue"

.env.dev:
cp .env.dev.example .env.dev
@echo "NOTE: Edit the correct values of .env.dev before you continue"

: ##

test-unit: ## Run unit tests, locally
test-unit: ## Run unit tests, locally
forge test --no-match-path $(FORK_TEST_WILDCARD)

: ##

#### Fork testing ####

test-fork-testnet: ## Run a fork test on the defined testnet
forge test --match-contract $(E2E_TEST_NAME) --rpc-url $(RPC_URL) -vvv
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-prodnet: ## Run a fork test on the defined production network
forge test --match-contract $(E2E_TEST_NAME) --rpc-url $(RPC_URL) -vvv
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-fork-holesky: ## Run a fork test on Holesky
forge test --match-contract $(E2E_TEST_NAME) --rpc-url $(RPC_URL) -vvv

test-fork-sepolia: ## Run a fork test on Sepolia
forge test --match-contract $(E2E_TEST_NAME) --rpc-url $(RPC_URL) -vvv
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
test-coverage: report/index.html ## Make an HTML coverage report under ./report

report/index.html: lcov.info.pruned
genhtml $^ -o report --branch-coverage
Expand All @@ -74,31 +99,27 @@ lcov.info: $(TEST_SRC_FILES)

: ##

#### Deployments ####
#### Deployment targets ####

pre-deploy-testnet: ## Simulate a deployment to the defined testnet
forge script $(DEPLOY_SCRIPT) \
--rpc-url $(RPC_URL) \
-vvv
pre-deploy-testnet: pre-deploy ## Simulate a deployment to the defined testnet
pre-deploy-prodnet: pre-deploy ## Simulate a deployment to the defined production network

deploy-testnet: ## Deploy to the defined testnet network and verify
forge script $(DEPLOY_SCRIPT) \
--rpc-url $(RPC_URL) \
--broadcast \
--verify \
$(VERIFIER_PARAM) \
--verifier-url $(VERIFIER_URL) \
-vvv

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

pre-deploy:
forge script $(DEPLOY_SCRIPT) \
--rpc-url $(RPC_URL) \
-vvv
--chain $(NETWORK) \
--rpc-url $(RPC_URL) \
$(VERBOSITY)

deploy-prodnet: ## Deploy to the production network and verify
deploy:
forge script $(DEPLOY_SCRIPT) \
--rpc-url $(RPC_URL) \
--broadcast \
--verify \
--etherscan-api-key $(ETHERSCAN_API_KEY) \
-vvv
--chain $(NETWORK) \
--rpc-url $(RPC_URL) \
--broadcast \
--verify \
$(VERIFIER_TYPE_PARAM) \
$(VERIFIER_URL_PARAM) \
$(ETHERSCAN_API_KEY_PARAM) \
$(VERBOSITY)
2 changes: 1 addition & 1 deletion script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract Deploy is Script {
/// @notice Runs the deployment flow, records the given parameters and artifacts, and it becomes read only
function run() public broadcast {
// Prepare all parameters
bool isProduction = vm.envBool("DEPLOY_AS_PRODUCTION");
bool isProduction = vm.envOr("DEPLOY_AS_PRODUCTION", false);
DeploymentParameters memory parameters = getDeploymentParameters(isProduction);

// Create the DAO
Expand Down
39 changes: 39 additions & 0 deletions test/base/AragonTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;

import {IPluginSetup, PluginSetup} from "@aragon/osx/framework/plugin/setup/PluginSetup.sol";
import {DAO} from "@aragon/osx/core/dao/DAO.sol";
import {RATIO_BASE} from "@aragon/osx/plugins/utils/Ratio.sol";
import {ALICE_ADDRESS, BOB_ADDRESS, CAROL_ADDRESS, DAVID_ADDRESS, TAIKO_BRIDGE_ADDRESS} from "../constants.sol";
import {Test} from "forge-std/Test.sol";

contract AragonTest is Test {
address immutable alice = ALICE_ADDRESS;
address immutable bob = BOB_ADDRESS;
address immutable carol = CAROL_ADDRESS;
address immutable david = DAVID_ADDRESS;
address immutable taikoBridge = TAIKO_BRIDGE_ADDRESS;
address immutable randomWallet = vm.addr(1234567890);

address immutable DAO_BASE = address(new DAO());

bytes internal constant EMPTY_BYTES = "";

constructor() {
vm.label(alice, "Alice");
vm.label(bob, "Bob");
vm.label(carol, "Carol");
vm.label(david, "David");
vm.label(randomWallet, "Random wallet");
}

/// @notice Returns the address and private key associated to the given name.
/// @param name The name to get the address and private key for.
/// @return addr The address associated with the name.
/// @return pk The private key associated with the name.
function getWallet(string memory name) internal returns (address addr, uint256 pk) {
pk = uint256(keccak256(abi.encodePacked(name)));
addr = vm.addr(pk);
vm.label(addr, name);
}
}
13 changes: 13 additions & 0 deletions test/constants.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;

uint64 constant MAX_UINT64 = uint64(2 ** 64 - 1);
address constant ADDRESS_ZERO = address(0x0);
address constant NO_CONDITION = ADDRESS_ZERO;

// Actors
address constant ALICE_ADDRESS = address(0xa11ce);
address constant BOB_ADDRESS = address(0xB0B);
address constant CAROL_ADDRESS = address(0xc4601);
address constant DAVID_ADDRESS = address(0xd471d);
address constant TAIKO_BRIDGE_ADDRESS = address(0xb61d6e);
Loading

0 comments on commit db1cfb7

Please sign in to comment.