Skip to content

Commit 3e051e9

Browse files
Csongor Kisskcsongor
Csongor Kiss
authored andcommitted
ethereum: Init foundry project and add installer for native solc
1 parent d3440f8 commit 3e051e9

File tree

9 files changed

+182
-30
lines changed

9 files changed

+182
-30
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ bigtable-writer.json
2626
/solana/artifacts-testnet/
2727
/solana/artifacts-devnet/
2828
/solana/artifacts-mainnet/
29+
/ethereum/out/
30+
/ethereum/cache/

Diff for: ethereum/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
ganache.log
2+
lib/*
3+
!lib/README.md

Diff for: ethereum/Makefile

+24-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,21 @@ node_modules: package-lock.json
88
touch -m node_modules
99
npm ci
1010

11-
dependencies: node_modules
11+
# Note: Forge really wants to manage dependencies via submodules, but that
12+
# workflow is a little awkward. There's currently no support for a more
13+
# traditional package manager workflow (with a package manifest file and
14+
# installation into a subdirectory that can be gitignored).
15+
# Instead, we just specify the dependencies here. make will then take care of
16+
# installing them if they are not yet present.
17+
# When adding a new dependency, make sure to specify the exact commit hash, and
18+
# the --no-git and --no-commit flags (see lib/forge-std below)
19+
.PHONY: forge_dependencies
20+
forge_dependencies: lib/forge-std
21+
22+
lib/forge-std:
23+
forge install foundry-rs/forge-std@2c7cbfc6fbede6d7c9e6b17afe997e3fdfe22fef --no-git --no-commit
24+
25+
dependencies: node_modules forge_dependencies
1226

1327
build: node_modules ${SOURCE_FILES}
1428
mkdir -p build
@@ -18,16 +32,23 @@ build: node_modules ${SOURCE_FILES}
1832
.env: .env.test
1933
cp $< $@
2034

21-
test: build .env dependencies
35+
test: test-forge test-ganache
36+
37+
.PHONY: test-ganache
38+
test-ganache: build .env dependencies
2239
@if pgrep ganache-cli; then echo "Error: ganache-cli already running. Stop it before running tests"; exit 1; fi
2340
npx ganache-cli -e 10000 --deterministic --time="1970-01-01T00:00:00+00:00" > ganache.log &
2441
sleep 5
2542
npm test || (pkill ganache-cli && exit 1)
2643
pkill ganache-cli || true
2744

2845
.PHONY: test-upgrade
29-
test-upgrade: build .env dependencies
46+
test-upgrade: build .env node_modules
3047
./simulate_upgrades
3148

49+
.PHONY:
50+
test-forge: dependencies
51+
forge test
52+
3253
clean:
3354
rm -rf ganache.log .env node_modules build

Diff for: ethereum/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,14 @@ chain address of the recipient, `target_chain` is the id of the chain to transfe
4646

4747
`lockETH(bytes32 recipient, uint8 target_chain)` is a convenience function to wrap the Ether sent with the function call
4848
and transfer it as described in `lockAssets`.
49+
50+
51+
### Forge
52+
53+
Some tests and scripts use [Foundry](https://getfoundry.sh/). It can be installed via the official installer, or by running
54+
55+
``` sh
56+
wormhole/ethereum $ ../scripts/install-foundry
57+
```
58+
59+
The installer script installs foundry and the appropriate solc version to build the contracts.

Diff for: ethereum/forge-test/Messages.t.sol

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// test/Messages.sol
2+
// SPDX-License-Identifier: Apache 2
3+
4+
pragma solidity ^0.8.0;
5+
6+
import "../contracts/Messages.sol";
7+
import "forge-std/Test.sol";
8+
9+
contract TestMessages is Messages, Test {
10+
function testQuorum() public {
11+
assertEq(quorum(0), 1);
12+
assertEq(quorum(1), 1);
13+
assertEq(quorum(2), 2);
14+
assertEq(quorum(3), 3);
15+
assertEq(quorum(4), 3);
16+
assertEq(quorum(5), 4);
17+
assertEq(quorum(6), 5);
18+
assertEq(quorum(7), 5);
19+
assertEq(quorum(8), 6);
20+
assertEq(quorum(9), 7);
21+
assertEq(quorum(10), 7);
22+
assertEq(quorum(11), 8);
23+
assertEq(quorum(12), 9);
24+
assertEq(quorum(19), 13);
25+
assertEq(quorum(20), 14);
26+
}
27+
}

Diff for: ethereum/foundry.toml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[default]
2+
solc_version = "0.8.4"
3+
optimizer = true
4+
optimizer_runs = 200
5+
src="contracts"
6+
# We put the tests into the forge-test directory (instead of test) so that
7+
# truffle doesn't try to build them
8+
test="forge-test"
9+
10+
out = 'out'
11+
libs = [
12+
'lib',
13+
'node_modules',
14+
]
15+
remappings = [
16+
'@openzeppelin/=node_modules/@openzeppelin/',
17+
'@solidity-parser/=node_modules/@solidity-parser/',
18+
'ds-test/=lib/forge-std/lib/ds-test/src/',
19+
'forge-std/=lib/forge-std/src/',
20+
'truffle/=node_modules/truffle/',
21+
]
22+
23+
# See more config options https://github.com/foundry-rs/foundry/tree/master/config

Diff for: ethereum/lib/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Forge installs the dependencies in this folder. They are .gitignored

Diff for: ethereum/test/wormhole.sol

-27
This file was deleted.

Diff for: scripts/install-foundry

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/bash
2+
3+
# This script install foundry and the solidity compiler required to build the
4+
# ethereum contracts. Foundry itself provides a mechanism to install solc, but
5+
# it doesn't work with certain firewall configurations.
6+
7+
set -euo pipefail
8+
9+
# check if foundry.toml exists
10+
if [ ! -f foundry.toml ]; then
11+
echo "foundry.toml not found. Please call from the ethereum directory." >& 2
12+
exit 1
13+
fi
14+
15+
# Read compiler version from foundry.toml
16+
SOLC_VERSION=$(grep solc_version foundry.toml | cut -d'=' -f2 | tr -d '" ') || true
17+
18+
if [ -z "$SOLC_VERSION" ]; then
19+
echo "solc_version not found in foundry.toml." >& 2
20+
exit 1
21+
fi
22+
23+
main() {
24+
OS=$(uname -s)
25+
case "$OS" in
26+
Darwin)
27+
install_mac
28+
;;
29+
Linux)
30+
install_linux
31+
;;
32+
*)
33+
echo "Unsupported OS: $OS"
34+
exit 1
35+
;;
36+
esac
37+
}
38+
39+
function install_mac() {
40+
if ! command -v brew > /dev/null; then
41+
echo "brew is unavailable. Please install: https://brew.sh"
42+
fi
43+
44+
if ! brew list libusb > /dev/null 2>&1; then
45+
echo "Installing libusb"
46+
brew install libusb
47+
fi
48+
49+
if ! command -v foundryup > /dev/null; then
50+
curl -L https://foundry.paradigm.xyz --silent | bash
51+
"$HOME/.foundry/bin/foundryup"
52+
fi
53+
54+
INSTALL_DIR="$HOME/.svm/$SOLC_VERSION"
55+
56+
mkdir -p "$INSTALL_DIR"
57+
58+
SOLC_PATH="$INSTALL_DIR/solc-$SOLC_VERSION"
59+
60+
if [ ! -f "$SOLC_PATH" ]; then
61+
echo "Installing solc-$SOLC_VERSION"
62+
curl -L --silent "https://github.com/ethereum/solidity/releases/download/v$SOLC_VERSION/solc-macos" > "$SOLC_PATH"
63+
chmod +x "$SOLC_PATH"
64+
echo "Installed $SOLC_PATH"
65+
else
66+
echo "Solidity compiler found: $SOLC_PATH"
67+
fi
68+
}
69+
70+
function install_linux() {
71+
if ! command -v foundryup > /dev/null; then
72+
curl -L https://foundry.paradigm.xyz --silent | bash
73+
"$HOME/.foundry/bin/foundryup"
74+
fi
75+
76+
INSTALL_DIR="$HOME/.svm/$SOLC_VERSION"
77+
78+
mkdir -p "$INSTALL_DIR"
79+
80+
SOLC_PATH="$INSTALL_DIR/solc-$SOLC_VERSION"
81+
82+
if [ ! -f "$SOLC_PATH" ]; then
83+
echo "Installing solc-$SOLC_VERSION"
84+
curl -L --silent "https://github.com/ethereum/solidity/releases/download/v$SOLC_VERSION/solc-static-linux" > "$SOLC_PATH"
85+
chmod +x "$SOLC_PATH"
86+
echo "Installed $SOLC_PATH"
87+
else
88+
echo "Solidity compiler found: $SOLC_PATH"
89+
fi
90+
}
91+
92+
main "$@"; exit

0 commit comments

Comments
 (0)