julien/lovepublic Fork 0
6b4a40d9d53d284f94b492aff5a8fc978f05781c
Commits
Clone
git clone https://git.rickub.com/julien/love.git
git clone ssh://git@rickub.com/julien/love.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

multichain-check.sh · 124 lines · 3.4 KBBash Blame HistoryRaw
Merge 2-multichain-check into main 7c6b16b rickub 10h ago1#!/usr/bin/env bash
2#
3# Deploys Love on two local anvil nodes with different chain ids and checks
Merge 3-peg-love-to-weth into main ce13509 rickub 9h ago4# that CREATE2 gives the token the same address on both. The address embeds the
5# wETH address, so this only holds for chains sharing one wETH deployment —
6# both nodes here are given the same WETH.
Merge 2-multichain-check into main 7c6b16b rickub 10h ago7#
8# Usage: ./script/multichain-check.sh
9#
Merge 3-peg-love-to-weth into main ce13509 rickub 9h ago10# Env overrides: PORT_A, PORT_B, CHAIN_ID_A, CHAIN_ID_B, SALT, WETH
Merge 2-multichain-check into main 7c6b16b rickub 10h ago11
12set -euo pipefail
13
14PORT_A=${PORT_A:-8545}
15PORT_B=${PORT_B:-8546}
16CHAIN_ID_A=${CHAIN_ID_A:-31337}
17CHAIN_ID_B=${CHAIN_ID_B:-31338}
18
19# First anvil dev account — local only, never use this key anywhere else.
20ANVIL_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
21CREATE2_FACTORY=0x4e59b44847b379578588920cA78FbF26c0B4956C
22
23ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
24RPC_A="http://127.0.0.1:$PORT_A"
25RPC_B="http://127.0.0.1:$PORT_B"
26TMP=$(mktemp -d)
27PIDS=()
28
29cleanup() {
30 for pid in ${PIDS[@]+"${PIDS[@]}"}; do
31 kill "$pid" 2>/dev/null || true
32 done
33 rm -rf "$TMP"
34 rm -rf "$ROOT/broadcast/Love.s.sol/$CHAIN_ID_A" "$ROOT/broadcast/Love.s.sol/$CHAIN_ID_B"
35 rmdir "$ROOT/broadcast/Love.s.sol" "$ROOT/broadcast" 2>/dev/null || true
36}
37trap cleanup EXIT
38
39start_node() {
40 local port=$1 chain_id=$2 rpc=$3
41 anvil --port "$port" --chain-id "$chain_id" --silent >"$TMP/anvil-$port.log" 2>&1 &
42 PIDS+=($!)
43
44 for _ in $(seq 1 50); do
45 if cast chain-id --rpc-url "$rpc" >/dev/null 2>&1; then
46 return 0
47 fi
48 sleep 0.2
49 done
50
51 echo "anvil on port $port never came up:" >&2
52 cat "$TMP/anvil-$port.log" >&2
53 exit 1
54}
55
56deploy() {
57 local rpc=$1 label=$2
58 forge script script/Love.s.sol:LoveScript \
59 --rpc-url "$rpc" \
60 --private-key "$ANVIL_KEY" \
61 --broadcast \
62 --skip-simulation >"$TMP/deploy-$label.log" 2>&1 ||
63 {
64 echo "deploy on $label failed:" >&2
65 cat "$TMP/deploy-$label.log" >&2
66 exit 1
67 }
68
69 grep -oE 'predicted +0x[0-9a-fA-F]{40}' "$TMP/deploy-$label.log" | tail -1 | grep -oE '0x[0-9a-fA-F]{40}'
70}
71
72report() {
73 local rpc=$1 addr=$2 label=$3
74 local code
75 code=$(cast code "$addr" --rpc-url "$rpc")
76
77 if [[ ${#code} -le 2 ]]; then
78 echo "$label: no code at $addr" >&2
79 exit 1
80 fi
81
Merge 3-peg-love-to-weth into main ce13509 rickub 9h ago82 printf '%s %s %s bytes %s / %s weth %s\n' \
Merge 2-multichain-check into main 7c6b16b rickub 10h ago83 "$label" "$addr" "$(((${#code} - 2) / 2))" \
84 "$(cast call "$addr" 'name()(string)' --rpc-url "$rpc")" \
Merge 3-peg-love-to-weth into main ce13509 rickub 9h ago85 "$(cast call "$addr" 'symbol()(string)' --rpc-url "$rpc")" \
86 "$(cast call "$addr" 'WETH()(address)' --rpc-url "$rpc")"
Merge 2-multichain-check into main 7c6b16b rickub 10h ago87}
88
89cd "$ROOT"
90
91for cmd in anvil cast forge; do
92 command -v "$cmd" >/dev/null || {
93 echo "$cmd not found — install foundry" >&2
94 exit 1
95 }
96done
97
98start_node "$PORT_A" "$CHAIN_ID_A" "$RPC_A"
99start_node "$PORT_B" "$CHAIN_ID_B" "$RPC_B"
100
101for pair in "A|$RPC_A" "B|$RPC_B"; do
102 IFS='|' read -r label rpc <<<"$pair"
103 if [[ $(cast code "$CREATE2_FACTORY" --rpc-url "$rpc") == "0x" ]]; then
104 echo "$label: deterministic deployer missing at $CREATE2_FACTORY" >&2
105 exit 1
106 fi
107done
108
109forge build >/dev/null
110
111ADDR_A=$(deploy "$RPC_A" A)
112ADDR_B=$(deploy "$RPC_B" B)
113
114echo "chain $CHAIN_ID_A"
115report "$RPC_A" "$ADDR_A" " A"
116echo "chain $CHAIN_ID_B"
117report "$RPC_B" "$ADDR_B" " B"
118
119if [[ "$ADDR_A" != "$ADDR_B" ]]; then
120 echo "FAIL: addresses differ" >&2
121 exit 1
122fi
123
124echo "OK: same address on both chains"