Skip to content

Commit

Permalink
Refactoring the makefile to make targets generic
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed Oct 29, 2024
1 parent d1db1e9 commit 5ff4451
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ MIN_LOCK_DURATION="3600" # 1 hour
VOTING_PAUSED=true

# Initial minimum amount needed (in wei) to create a lock
MIN_DEPOSIT="1000000000000000000" # 1 ether
MIN_DEPOSIT="1000000000000000000" # 1 ether (in token terms)

# PLUGIN REPO PARAMETERS (per-network)
# SEPOLIA
Expand Down
126 changes: 81 additions & 45 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,68 +1,104 @@
.DEFAULT_TARGET: help

# include .env file and export its env vars
# (-include to ignore error if it does not exist)
-include .env

# linux: allow shell scripts to be executed
allow-scripts:; chmod +x ./coverage.sh
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

# init the repo
install :; make allow-scripts && forge build
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

# create an HTML coverage report in ./report (requires lcov & genhtml)
coverage:; ./coverage.sh
#
# run unit tests
test-unit :; forge test --no-match-path "test/fork/**/*.sol"
deploy-testnet: export VERIFIER_URL = https://sepolia.explorer.mode.network/api\?
deploy-testnet: export VERIFIER_PARAM = --verifier blockscout

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

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

.PHONY: init
init: ## 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"

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

: ##

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

: ##

#### Fork testing ####

# Fork testing - mode sepolia
ft-mode-sepolia-fork :; forge test --match-contract TestE2EV2 \
--rpc-url https://sepolia.mode.network \
-vv
test-fork-testnet: ## Run a fork test on the defined testnet
forge test --match-contract $(E2E_TEST_NAME) --rpc-url $(RPC_URL) -vvv

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

# Fork testing - mode mainnet
ft-mode-fork :; forge test --match-contract TestE2EV2 \
--rpc-url https://mainnet.mode.network/ \
-vvvvv
: ##

# Fork testing - holesky
ft-holesky-fork :; forge test --match-contract TestE2EV2 \
--rpc-url https://holesky.drpc.org \
-vvvvv
test-coverage: report/index.html ## Make an HTML coverage report under ./report

# Fork testing - sepolia
ft-sepolia-fork :; forge test --match-contract TestE2EV2 \
--rpc-url https://sepolia.drpc.org \
-vvvvv
report/index.html: lcov.info.pruned
genhtml $^ -o report --branch-coverage

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

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

: ##

#### Deployments ####

deploy-preview-mode-sepolia :; forge script script/Deploy.s.sol:Deploy \
--rpc-url https://sepolia.mode.network \
--private-key $(DEPLOYMENT_PRIVATE_KEY) \
-vvvvv
pre-deploy-testnet: ## Simulate a deployment to the defined testnet
forge script $(DEPLOY_SCRIPT) \
--rpc-url $(RPC_URL) \
-vvv

deploy-mode-sepolia :; forge script script/Deploy.s.sol:Deploy \
--rpc-url https://sepolia.mode.network \
--private-key $(DEPLOYMENT_PRIVATE_KEY) \
deploy-testnet: ## Deploy to the defined testnet network and verify
forge script $(DEPLOY_SCRIPT) \
--rpc-url $(RPC_URL) \
--broadcast \
--verify \
--verifier blockscout \
--verifier-url https://sepolia.explorer.mode.network/api\? \
-vvvvv

deploy-preview-mode :; forge script script/Deploy.s.sol:Deploy \
--rpc-url https://mainnet.mode.network \
--private-key $(DEPLOYMENT_PRIVATE_KEY) \
-vvvvv

deploy-mode :; forge script script/Deploy.s.sol:Deploy \
--rpc-url https://mainnet.mode.network \
--private-key $(DEPLOYMENT_PRIVATE_KEY) \
$(VERIFIER_PARAM) \
--verifier-url $(VERIFIER_URL) \
-vvv

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

deploy-prodnet: ## Deploy to the production network and verify
forge script $(DEPLOY_SCRIPT) \
--rpc-url $(RPC_URL) \
--broadcast \
--verify \
--etherscan-api-key $(ETHERSCAN_API_KEY) \
-vvv

Binary file removed bun.lockb
Binary file not shown.
9 changes: 0 additions & 9 deletions coverage.sh

This file was deleted.

4 changes: 4 additions & 0 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ contract Deploy is Script {
string memory membersFilePath = vm.envString("MULTISIG_MEMBERS_JSON_FILE_NAME");
string memory path = string.concat(vm.projectRoot(), membersFilePath);
string memory strJson = vm.readFile(path);

bool exists = vm.keyExistsJson(strJson, "$.members");
if (!exists) revert EmptyMultisig();

result = vm.parseJsonAddressArray(strJson, "$.members");

if (result.length == 0) revert EmptyMultisig();
Expand Down
9 changes: 4 additions & 5 deletions test/fork/e2eV2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,8 @@ contract TestE2EV2 is Test, IWithdrawalQueueErrors, IGaugeVote, IEscrowCurveToke
// setup OSx mocks
// write the addresses
}

// deploy the contracts via the factory
if (_getTestMode() == TestMode.ForkDeploy) {
else if (_getTestMode() == TestMode.ForkDeploy) {
// random ens domain
deploymentParameters.voterEnsSubdomain = _hToS(
keccak256(abi.encodePacked("gauges", block.timestamp))
Expand Down Expand Up @@ -1310,15 +1309,15 @@ contract TestE2EV2 is Test, IWithdrawalQueueErrors, IGaugeVote, IEscrowCurveToke
//////////////////////////////////////////////////////////////*/

function _getTestMode() internal view returns (TestMode) {
string memory mode = vm.envString("FORK_TEST_MODE");
string memory mode = vm.envOr("FORK_TEST_MODE", string("fork-deploy"));
if (keccak256(abi.encodePacked(mode)) == keccak256(abi.encodePacked("fork-deploy"))) {
return TestMode.ForkDeploy;
} else if (
keccak256(abi.encodePacked(mode)) == keccak256(abi.encodePacked("fork-existing"))
) {
return TestMode.ForkExisting;
} else if (keccak256(abi.encodePacked(mode)) == keccak256(abi.encodePacked("local"))) {
revert("Local mode not yet supported");
return TestMode.Local;
} else {
revert("Invalid test mode - valid options are fork-deploy, fork-existing, local");
}
Expand Down Expand Up @@ -1395,7 +1394,7 @@ contract TestE2EV2 is Test, IWithdrawalQueueErrors, IGaugeVote, IEscrowCurveToke
} catch {}

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

0 comments on commit 5ff4451

Please sign in to comment.