Skip to content

Commit b52fc1d

Browse files
committed
refactor: setup for standardizing benchmarks
1 parent 0f42a8b commit b52fc1d

15 files changed

+151
-130
lines changed

.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export ETH_RPC_URL=https://eth-mainnet.alchemyapi.io/v2/yourAlchemyApiKey
2+
export FORK_BLOCK=13724056
3+
export GAS_LIMIT=30000000
4+
5+
# skip type-checking to avoid its perfomance impact
6+
export TS_NODE_TRANSPILE_ONLY=1

Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
all :; dapp build
2-
clean :; dapp clean
3-
test :; dapp test --rpc-url ${ETH_RPC_URL}
4-
deploy :; dapp create Convex
1+
benchmark-all :; bash scripts/benchmark-all.sh
2+
benchmark-dapptools :; bash scripts/benchmark-dapptools.sh
3+
benchmark-foundry :; bash scripts/benchmark-foundry.sh
4+
benchmark-ganache :; bash scripts/benchmark-ganache.sh
5+
benchmark-hardhat :; bash scripts/benchmark-hardhat.sh

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ This repository benchmarks performance of various Ethereum development
44
frameworks by simulating a call to Convex's `systemShutdown` method. This method
55
uses about 16M gas and performs a number of token transfers
66

7-
To run tests, make sure you have an environment variable called `ETH_RPC_URL`.
8-
Then use the following test commands:
7+
## Usage
98

10-
- Hardhat: `yarn` then `yarn hardhat test --no-compile`
11-
- Dapptools: `dapp update` then `dapp test --rpc-url $ETH_RPC_URL`
12-
- Foundry: `forge test --rpc-url $ETH_RPC_URL`
13-
- Ganache v7 (@beta): `yarn` then `yarn benchmark:ganache`
9+
1. Run `cp .env.example .env`, and in the resulting `.env` file enter a URL to an Ethereum archive node in the `ETH_RPC_URL` environment variable. ([Alchemy](https://www.alchemy.com/) provides free archive node data)
1410

15-
Installation instructions for forge and dapptools can be found
16-
[here](https://github.com/gakonst/foundry/) and
17-
[here](https://github.com/dapphub/dapptools/) respectively.
11+
2. Run `yarn` to install dependencies for Ganache and Hardhat
12+
13+
3. Install Foundry's forge and Dapptools using the installation instructions[here](https://github.com/gakonst/foundry/) and [here](https://github.com/dapphub/dapptools/) respectively
14+
15+
4. Run `dapp update` to install dependencies for Dapptools and Foundry
16+
17+
5. Run any command in the `Makefile` to benchmark that tool. For example, use `make benchmark-hardhat` to run the simulation against Hardhat. Alternatively, run `make benchmark-all` to run all tools
18+
19+
## Tips
20+
21+
Dapptools seems to fail when run on macOS, as explained in [this](https://github.com/dapphub/dapptools/issues/876), so you may need to skip that script on macOS

hardhat.config.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

hardhat.config.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import '@nomiclabs/hardhat-waffle';
2+
import { HardhatUserConfig } from 'hardhat/config';
3+
4+
const config: HardhatUserConfig = {
5+
solidity: '0.8.10',
6+
defaultNetwork: 'hardhat',
7+
networks: {
8+
hardhat: {
9+
accounts: { mnemonic: 'test test test test test test test test test test test junk' },
10+
chainId: 31337,
11+
gas: Number(process.env.GAS_LIMIT), // set to block gas limit, which avoids calls to eth_estimateGas (results in same behavior as dapptools/foundry)
12+
forking: {
13+
url: process.env.ETH_RPC_URL,
14+
blockNumber: Number(process.env.FORK_BLOCK),
15+
},
16+
},
17+
},
18+
mocha: {
19+
timeout: 0,
20+
},
21+
};
22+
23+
export default config;

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
"repository": "https://github.com/mds1/convex-shutdown-simulation",
66
"author": "Matt Solomon <[email protected]>",
77
"license": "MIT",
8-
"scripts": {
9-
"benchmark:ganache": "ts-node ./benchmark-ganache.ts"
10-
},
118
"devDependencies": {
12-
"@nomiclabs/hardhat-ethers": "^2.0.2",
9+
"@nomiclabs/hardhat-ethers": "^2.0.3",
1310
"@nomiclabs/hardhat-waffle": "^2.0.1",
1411
"chai": "^4.3.4",
1512
"chalk": "^4",

scripts/benchmark-all.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
echo -e "\n--- BENCHMARKING DAPPTOOLS ---"
2+
# bash scripts/benchmark-dapptools.sh
3+
4+
echo -e "\n--- BENCHMARKING FOUNDRY ---"
5+
bash scripts/benchmark-foundry.sh
6+
7+
echo -e "\n--- BENCHMARKING GANACHE ---"
8+
bash scripts/benchmark-ganache.sh
9+
10+
echo -e "\n--- BENCHMARKING HARDHAT ---"
11+
bash scripts/benchmark-hardhat.sh

scripts/benchmark-dapptools.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
. ./.env
2+
3+
# dapptools has no option to set gas limit, but it's hardcoded by default
4+
# anyway so shouldn't be make a difference
5+
time dapp test --rpc-url $ETH_RPC_URL --rpc-block $FORK_BLOCK

scripts/benchmark-foundry.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
. ./.env
2+
3+
time forge test --rpc-url $ETH_RPC_URL --fork-block-number $FORK_BLOCK --gas-limit $GAS_LIMIT

scripts/benchmark-ganache.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
. ./.env
2+
3+
# Uses Ganache v6 (@beta)
4+
time yarn ts-node ./scripts/convex.ganache.ts

0 commit comments

Comments
 (0)