Skip to content

Commit 009acea

Browse files
committed
CI: add cli action
1 parent 92cc5f0 commit 009acea

File tree

3 files changed

+251
-1
lines changed

3 files changed

+251
-1
lines changed

.github/workflows/cli.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: CLI
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
10+
jobs:
11+
test-evm:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- run: docker build -f Dockerfile.cli --target cli-local-test . --progress=plain
16+
17+
test-solana:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v3
21+
- run: docker build -f Dockerfile.cli --target cli-local-test-solana . --progress=plain

Dockerfile.cli

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
FROM ubuntu:latest as base
1+
# NOTE: we use the backpackapp base image so we can use solana. You would think
2+
# that the solana installer script just works, but you would be wrong. It seems
3+
# to have been broken recently since the migration to the anza url.
4+
# The old installer url returns a 403. So we instead rely on solana binaries cached on docker hub. Everything is fine.
5+
FROM backpackapp/build:v0.29.0@sha256:9aee169b2d8b89b4a4243419ae35c176773136e78d751b3e439eff692c9c1293 as base
26

37
RUN apt update
48

@@ -49,3 +53,10 @@ FROM cli-local as cli-local-test
4953
COPY cli/test cli/test
5054
COPY evm evm
5155
RUN bash -ci "./cli/test/sepolia-bsc.sh"
56+
57+
FROM cli-local as cli-local-test-solana
58+
COPY cli/test cli/test
59+
# evm/script needed for the cli, at least for now
60+
COPY evm/script evm/script
61+
COPY solana solana
62+
RUN bash -ci "./cli/test/solana.sh --use-tmp-dir"

cli/test/solana.sh

+218
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
#!/usr/bin/env bash
2+
3+
# This script deploys the NTT program to a local Solana test validator and
4+
# upgrades it.
5+
#
6+
# TODO: this script should be separated into
7+
# 1) a general purpose validator startup script
8+
# 2) the actual test script that sets up the NTT program and runs the tests
9+
#
10+
# We could then write multiple tests easily. For now, this will do.
11+
# TODO: add better test coverage (registrations, pausing, etc)
12+
13+
set -euo pipefail
14+
15+
# Default values
16+
PORT=6000
17+
FAUCET_PORT=6100
18+
NETWORK="http://127.0.0.1:$PORT"
19+
KEYS_DIR="keys"
20+
OVERRIDES_FILE="overrides.json"
21+
DEPLOYMENT_FILE="deployment.json"
22+
KEEP_ALIVE=false
23+
USE_TMP_DIR=false
24+
25+
# Function to display usage information
26+
usage() {
27+
cat << EOF
28+
Usage: $0 [options]
29+
30+
Options:
31+
-h, --help Show this help message
32+
-p, --port PORT Set the RPC port (default: 6000)
33+
-f, --faucet-port PORT Set the faucet port (default: 6100)
34+
-k, --keys-dir DIR Set the keys directory (default: keys)
35+
-o, --overrides FILE Set the overrides file (default: overrides.json)
36+
-d, --deployment FILE Set the deployment file (default: deployment.json)
37+
--keep-alive Keep the validator running after the script finishes
38+
--use-tmp-dir Use a temporary directory for deployment (useful for testing)
39+
EOF
40+
exit 1
41+
}
42+
43+
# Parse command-line options
44+
while [[ $# -gt 0 ]]; do
45+
case $1 in
46+
-h|--help)
47+
usage
48+
;;
49+
-p|--port)
50+
PORT="$2"
51+
shift 2
52+
;;
53+
-f|--faucet-port)
54+
FAUCET_PORT="$2"
55+
shift 2
56+
;;
57+
-k|--keys-dir)
58+
KEYS_DIR="$2"
59+
shift 2
60+
;;
61+
-o|--overrides)
62+
OVERRIDES_FILE="$2"
63+
shift 2
64+
;;
65+
-d|--deployment)
66+
DEPLOYMENT_FILE="$2"
67+
shift 2
68+
;;
69+
--keep-alive)
70+
KEEP_ALIVE=true
71+
shift
72+
;;
73+
--use-tmp-dir)
74+
USE_TMP_DIR=true
75+
shift
76+
;;
77+
*)
78+
echo "Unknown option: $1"
79+
usage
80+
;;
81+
esac
82+
done
83+
84+
# Update NETWORK variable based on potentially changed PORT
85+
NETWORK="http://127.0.0.1:$PORT"
86+
87+
validator_dir=$(mktemp -d)
88+
89+
if [ "$USE_TMP_DIR" = true ]; then
90+
tmp_dir=$(mktemp -d)
91+
cd "$tmp_dir" || exit
92+
ntt new test-ntt
93+
cd test-ntt || exit
94+
fi
95+
96+
# Function to clean up resources
97+
cleanup() {
98+
echo "Cleaning up..."
99+
kill "$pid" 2>/dev/null || true
100+
rm -rf "$validator_dir"
101+
if [ "$USE_TMP_DIR" = true ]; then
102+
rm -rf "$tmp_dir"
103+
fi
104+
if [ -f "${OVERRIDES_FILE}.bak" ]; then
105+
mv "${OVERRIDES_FILE}.bak" "$OVERRIDES_FILE"
106+
else
107+
rm -f "$OVERRIDES_FILE"
108+
fi
109+
solana config set --keypair "$old_default_keypair" > /dev/null
110+
}
111+
112+
# Set up trap for cleanup
113+
trap cleanup EXIT
114+
115+
# Prepare directories and files
116+
rm -rf "$KEYS_DIR"
117+
mkdir -p "$KEYS_DIR"
118+
119+
# Backup and create overrides file
120+
cp "$OVERRIDES_FILE" "${OVERRIDES_FILE}.bak" 2>/dev/null || true
121+
cat << EOF > "$OVERRIDES_FILE"
122+
{
123+
"chains": {
124+
"Solana": {
125+
"rpc": "$NETWORK"
126+
}
127+
}
128+
}
129+
EOF
130+
131+
# Start Solana test validator
132+
pushd "$validator_dir" || exit
133+
# TODO: the deployment doesn't fully work, because we need to load in the wormhole program and its associated
134+
# accounts. This is a bit tedious, but would be great to do.
135+
# NOTE: this will not run in an emulated x86 docker environment (on an arm mac
136+
# host), because the binary needs AVX instructions which the emulator doesn't
137+
# support.
138+
solana-test-validator --rpc-port "$PORT" --faucet-port "$FAUCET_PORT" > /dev/null 2>&1 &
139+
pid=$!
140+
popd || exit
141+
142+
old_default_keypair=$(solana config get keypair | awk '{print $3}')
143+
144+
# Wait for validator to start
145+
echo "Waiting for Solana test validator to start..."
146+
for _ in {1..30}; do
147+
if solana cluster-version -u "$NETWORK" &>/dev/null; then
148+
echo "Solana test validator started successfully."
149+
break
150+
fi
151+
sleep 1
152+
done
153+
154+
# Check if validator started successfully
155+
if ! kill -0 "$pid" 2>/dev/null; then
156+
echo "Failed to start solana-test-validator"
157+
exit 1
158+
fi
159+
160+
# Initialize NTT
161+
rm -rf "$DEPLOYMENT_FILE"
162+
ntt init Mainnet
163+
164+
# Generate and configure keypairs
165+
pushd "$KEYS_DIR" || exit
166+
keypair=$(solana-keygen grind --starts-with w:1 --ignore-case | grep 'Wrote keypair' | awk '{print $4}')
167+
keypair=$(realpath "$keypair")
168+
solana config set --keypair "$keypair"
169+
170+
# Airdrop SOL
171+
solana airdrop 50 -u "$NETWORK" --keypair "$keypair"
172+
# This steps is a bit voodoo -- we airdrop to this special address, which is
173+
# needed for querying the program version. For more info, grep for these pubkeys in the ntt repo.
174+
solana airdrop 1 Hk3SdYTJFpawrvRz4qRztuEt2SqoCG7BGj2yJfDJSFbJ -u "$NETWORK" --keypair "$keypair" > /dev/null
175+
solana airdrop 1 98evdAiWr7ey9MAQzoQQMwFQkTsSR6KkWQuFqKrgwNwb -u "$NETWORK" --keypair "$keypair" > /dev/null
176+
177+
# Create and configure token
178+
token=$(spl-token create-token --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb -u "$NETWORK" | grep "Address:" | awk '{print $2}')
179+
echo "Token: $token"
180+
181+
ntt_keypair=$(solana-keygen grind --starts-with ntt:1 --ignore-case | grep 'Wrote keypair' | awk '{print $4}')
182+
ntt_keypair_without_json=${ntt_keypair%.json}
183+
ntt_keypair=$(realpath "$ntt_keypair")
184+
popd || exit
185+
186+
# Set token authority
187+
authority=$(ntt solana token-authority "$ntt_keypair_without_json")
188+
echo "Authority: $authority"
189+
spl-token authorize "$token" mint "$authority" -u "$NETWORK"
190+
191+
# Add chain and upgrade
192+
ntt add-chain Solana --ver 1.0.0 --mode burning --token "$token" --payer "$keypair" --program-key "$ntt_keypair"
193+
194+
echo "Getting status"
195+
ntt status || true
196+
197+
solana program extend "$ntt_keypair_without_json" 100000 -u "$NETWORK"
198+
ntt upgrade Solana --ver 2.0.0 --payer "$keypair" --program-key "$ntt_keypair" --yes
199+
ntt status || true
200+
201+
ntt push --payer "$keypair" --yes
202+
203+
cat "$DEPLOYMENT_FILE"
204+
205+
if [ "$KEEP_ALIVE" = true ]; then
206+
# wait for C-c to kill the validator
207+
# print information about the running validator
208+
echo "==============================="
209+
echo "Validator is running on port $PORT"
210+
echo "Faucet is running on port $FAUCET_PORT"
211+
echo "Keys are stored in $KEYS_DIR"
212+
echo "Overrides are stored in $OVERRIDES_FILE"
213+
214+
echo "Press Ctrl-C to stop the validator..."
215+
while true; do
216+
sleep 1
217+
done
218+
fi

0 commit comments

Comments
 (0)