Skip to content

Commit 101e872

Browse files
authored
FM-363: Break up smoke-test Makefile.toml into reusable parts (#453)
* FM-363: Break up smoke-test Makefile.toml into reusable parts * FM-363: Reuse the infra scripts for testing * FM-363: Move cometbft related command to cometbft.toml
1 parent bc7de49 commit 101e872

15 files changed

Lines changed: 191 additions & 262 deletions

File tree

fendermint/testing/Makefile/ci.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CMT_WAIT_MILLIS = 20000
2+
# Help debug any issues with simplecoin by logging requests and responses.
3+
VERBOSITY = "--verbose"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extend = [
2+
{ path = "../../../infra/scripts/cometbft.toml" },
3+
]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
CMT_DOCKER_IMAGE="cometbft/cometbft:v0.37.x"
2+
FM_DOCKER_IMAGE="fendermint:latest"
3+
CMT_CONTAINER_NAME="${NETWORK_NAME}-cometbft"
4+
FM_CONTAINER_NAME="${NETWORK_NAME}-fendermint"
5+
ETHAPI_CONTAINER_NAME="${NETWORK_NAME}-ethapi"
6+
CMT_P2P_HOST_PORT=26656
7+
CMT_RPC_HOST_PORT=26657
8+
ETHAPI_HOST_PORT=8545
9+
FM_NETWORK=main
10+
FM_LOG_LEVEL=info
11+
ETHAPI_LOG_LEVEL=debug
12+
# If this wasn't present, any wait task is skipped.
13+
CARGO_MAKE_WAIT_MILLISECONDS=5000
14+
# This wait time seems to work locally.
15+
CMT_WAIT_MILLIS=10000
16+
# Keep example logs to a minimum.
17+
VERBOSITY=""
18+
TEST_SCRIPTS_DIR="${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/fendermint/testing/${TEST_DIR}/scripts"
19+
TEST_DATA_DIR="${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/fendermint/testing/${TEST_DIR}/test-data"
20+
NODE_NAME=node-0
21+
CMT_DIR=${TEST_DATA_DIR}/${NODE_NAME}/cometbft
22+
BASE_DIR=${TEST_DATA_DIR}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# smoke-test infrastructure:
2+
# cargo install cargo-make
3+
#
4+
# cd fendermint/testing/smoke-test
5+
# - then -
6+
# cargo make --profile ci
7+
# - or -
8+
# cargo make setup
9+
# cargo make test
10+
# docker logs smoke-ethapi
11+
# cargo make teardown
12+
13+
extend = [
14+
{ path = "./docker.toml" },
15+
{ path = "./cometbft.toml" },
16+
{ path = "./fendermint.toml" },
17+
{ path = "./ethapi.toml" },
18+
]
19+
20+
21+
# Define the following in test specific `Makefile.toml` files,
22+
# where `env.env` defines `NETWORK_NAME` and `TEST_DIR`, expected by `common.env`:
23+
# env_files = [
24+
# { path = "./env.env" },
25+
# { path = "../Makefile/common.env" },
26+
# { path = "../Makefile/ci.env", profile = "ci" },
27+
# ]
28+
29+
30+
[tasks.default]
31+
clear = true
32+
run_task = { name = [
33+
"setup",
34+
"test",
35+
], fork = true, cleanup_task = "teardown" }
36+
37+
# Waiting before starting the Eth API for the CometBFT websocket to start listening.
38+
[tasks.setup]
39+
dependencies = [
40+
"test-data-dir",
41+
"docker-network-create",
42+
"cometbft-init",
43+
"fendermint-init",
44+
"fendermint-start",
45+
"cometbft-start",
46+
"ethapi-start",
47+
"cometbft-wait",
48+
"fendermint-logs",
49+
"cometbft-logs",
50+
"ethapi-logs",
51+
]
52+
53+
[tasks.test]
54+
clear = true
55+
dependencies = []
56+
57+
[tasks.teardown]
58+
# `dependencies` doesn't seem to work with `cleanup_task`.
59+
run_task = { name = [
60+
"cometbft-stop",
61+
"cometbft-rm",
62+
"fendermint-stop",
63+
"fendermint-rm",
64+
"ethapi-stop",
65+
"ethapi-rm",
66+
"docker-network-rm",
67+
"test-data-dir-rm",
68+
] }
69+
70+
71+
[tasks.test-data-dir]
72+
script = """
73+
mkdir -p ${TEST_DATA_DIR}/keys;
74+
mkdir -p ${TEST_DATA_DIR}/${NODE_NAME}/fendermint/data/logs;
75+
mkdir -p ${TEST_DATA_DIR}/${NODE_NAME}/cometbft;
76+
cp -r ${TEST_SCRIPTS_DIR} ${TEST_DATA_DIR}/scripts
77+
"""
78+
79+
[tasks.test-data-dir-rm]
80+
script = """
81+
rm -rf ${TEST_DATA_DIR}
82+
"""
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extend = [
2+
{ path = "../../../infra/scripts/docker.toml" },
3+
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extend = [
2+
{ path = "../../../infra/scripts/ethapi.toml" },
3+
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extend = [
2+
{ path = "../../../infra/scripts/fendermint.toml" },
3+
]
4+
5+
[tasks.fendermint-init]
6+
extend = "fendermint-run"
7+
env = { "ENTRY" = "/data/scripts/init.sh", "FLAGS" = "-a STDOUT -a STDERR --rm" }
Lines changed: 10 additions & 220 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
[env]
2-
NETWORK_NAME = "smoke"
3-
CMT_CONTAINER_NAME = "smoke-cometbft"
4-
FM_CONTAINER_NAME = "smoke-fendermint"
5-
ETHAPI_CONTAINER_NAME = "smoke-ethapi"
6-
CMT_DOCKER_IMAGE = "cometbft/cometbft:v0.37.x"
7-
FM_DOCKER_IMAGE = "fendermint:latest"
8-
TEST_DATA_DIR = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/fendermint/testing/smoke-test/test-data"
9-
TEST_SCRIPTS_DIR = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/fendermint/testing/smoke-test/scripts"
10-
ACTORS_BUNDLE = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/../builtin-actors/output/bundle.car"
11-
CMT_HOST_PORT = 26657
12-
ETHAPI_HOST_PORT = 8545
13-
# If this wasn't present, any wait task is skipped.
14-
CARGO_MAKE_WAIT_MILLISECONDS = 5000
15-
# This wait time seems to work locally.
16-
CMT_WAIT_MILLIS = 10000
17-
# Keep example logs to a minimum.
18-
VERBOSITY = ""
19-
20-
[env.ci]
21-
CMT_WAIT_MILLIS = 20000
22-
# Help debug any issues with simplecoin by logging requests and responses.
23-
VERBOSITY = "--verbose"
24-
251
# smoke-test infrastructure:
262
# cargo install cargo-make
273
#
@@ -34,53 +10,27 @@ VERBOSITY = "--verbose"
3410
# docker logs smoke-ethapi
3511
# cargo make teardown
3612

37-
[tasks.default]
38-
clear = true
39-
run_task = { name = [
40-
"setup",
41-
"test",
42-
], fork = true, cleanup_task = "teardown" }
13+
extend = [
14+
{ path = "../Makefile/common.toml" },
15+
]
4316

44-
# Waiting before starting the Eth API for the CometBFT websocket to start listening.
45-
[tasks.setup]
46-
dependencies = [
47-
"test-data-dir",
48-
"network-create",
49-
"cometbft-init",
50-
"fendermint-init",
51-
"fendermint-start",
52-
"cometbft-start",
53-
"ethapi-start",
54-
"cometbft-wait",
55-
"fendermint-logs",
56-
"cometbft-logs",
57-
"ethapi-logs",
17+
env_files = [
18+
{ path = "./smoke.env" },
19+
{ path = "../Makefile/common.env" },
20+
{ path = "../Makefile/ci.env", profile = "ci" },
5821
]
5922

6023
[tasks.test]
6124
clear = true
6225
dependencies = ["simplecoin-example", "ethapi-example"]
6326

64-
[tasks.teardown]
65-
# `dependencies` doesn't seem to work with `cleanup_task`.
66-
run_task = { name = [
67-
"cometbft-stop",
68-
"cometbft-rm",
69-
"fendermint-stop",
70-
"fendermint-rm",
71-
"ethapi-stop",
72-
"ethapi-rm",
73-
"network-rm",
74-
"test-data-dir-rm",
75-
] }
76-
7727

7828
[tasks.simplecoin-example]
7929
# Using --release in the hope that it can reuse artifacts compiled earlier for the docker build.
8030
script = """
8131
cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}
8232
cargo run -p fendermint_rpc --release --example simplecoin -- \
83-
--secret-key fendermint/testing/smoke-test/test-data/fendermint/keys/alice.sk \
33+
--secret-key fendermint/testing/smoke-test/test-data/keys/alice.sk \
8434
${VERBOSITY}
8535
"""
8636

@@ -89,166 +39,6 @@ cargo run -p fendermint_rpc --release --example simplecoin -- \
8939
script = """
9040
cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}
9141
cargo run -p fendermint_eth_api --release --example ethers -- \
92-
--secret-key-from fendermint/testing/smoke-test/test-data/fendermint/keys/emily.sk \
93-
--secret-key-to fendermint/testing/smoke-test/test-data/fendermint/keys/eric.sk
94-
"""
95-
96-
97-
[tasks.test-data-dir]
98-
script = """
99-
mkdir -p ${TEST_DATA_DIR}/fendermint;
100-
mkdir -p ${TEST_DATA_DIR}/cometbft;
101-
"""
102-
103-
[tasks.test-data-dir-rm]
104-
script = """
105-
rm -rf ${TEST_DATA_DIR}
42+
--secret-key-from fendermint/testing/smoke-test/test-data/keys/emily.sk \
43+
--secret-key-to fendermint/testing/smoke-test/test-data/keys/eric.sk
10644
"""
107-
108-
109-
[tasks.cometbft-pull]
110-
command = "docker"
111-
args = ["pull", "${CMT_DOCKER_IMAGE}"]
112-
113-
[tasks.cometbft-init]
114-
extend = "cometbft-run"
115-
env = { "CMD" = "init", "FLAGS" = "-a STDOUT -a STDERR --rm" }
116-
117-
[tasks.cometbft-start]
118-
extend = "cometbft-run"
119-
env = { "CMD" = "start", "FLAGS" = "-d" }
120-
121-
[tasks.cometbft-wait]
122-
extend = "wait"
123-
env = { "CARGO_MAKE_WAIT_MILLISECONDS" = "${CMT_WAIT_MILLIS}" }
124-
125-
[tasks.cometbft-run]
126-
script = """
127-
docker run \
128-
${FLAGS} \
129-
--name ${CMT_CONTAINER_NAME} \
130-
--user $(id -u) \
131-
--network ${NETWORK_NAME} \
132-
--publish ${CMT_HOST_PORT}:26657 \
133-
--volume ${TEST_DATA_DIR}/cometbft:/cometbft \
134-
--env CMT_PROXY_APP=tcp://${FM_CONTAINER_NAME}:26658 \
135-
--env CMT_PEX=false \
136-
--env CMT_MAX_SUBSCRIPTION_CLIENTS=10 \
137-
--env CMT_MAX_SUBSCRIPTIONS_PER_CLIENT=1000 \
138-
${CMT_DOCKER_IMAGE} \
139-
${CMD}
140-
"""
141-
dependencies = ["cometbft-pull", "test-data-dir", "network-create"]
142-
143-
144-
[tasks.fendermint-init]
145-
extend = "fendermint-run"
146-
env = { "ENTRY" = "/scripts/init.sh", "FLAGS" = "-a STDOUT -a STDERR --rm" }
147-
148-
[tasks.fendermint-start]
149-
extend = "fendermint-run"
150-
env = { "ENTRY" = "fendermint", "CMD" = "run", "FLAGS" = "-d" }
151-
152-
[tasks.fendermint-run]
153-
script = """
154-
docker run \
155-
${FLAGS} \
156-
--name ${FM_CONTAINER_NAME} \
157-
--init \
158-
--user $(id -u) \
159-
--network ${NETWORK_NAME} \
160-
--volume ${TEST_DATA_DIR}:/data \
161-
--volume ${TEST_SCRIPTS_DIR}:/scripts \
162-
--env RUST_BACKTRACE=1 \
163-
--env FM_DATA_DIR=/data/fendermint/data \
164-
--env FM_CHAIN_NAME=${NETWORK_NAME} \
165-
--env TENDERMINT_RPC_URL=http://${CMT_CONTAINER_NAME}:26657 \
166-
--env LOG_LEVEL=info \
167-
--entrypoint ${ENTRY} \
168-
${FM_DOCKER_IMAGE} \
169-
${CMD}
170-
"""
171-
dependencies = ["test-data-dir", "network-create"]
172-
173-
[tasks.ethapi-start]
174-
extend = "ethapi-run"
175-
env = { "CMD" = "eth run", "FLAGS" = "-d" }
176-
177-
178-
[tasks.ethapi-run]
179-
script = """
180-
docker run \
181-
${FLAGS} \
182-
--name ${ETHAPI_CONTAINER_NAME} \
183-
--init \
184-
--user $(id -u) \
185-
--network ${NETWORK_NAME} \
186-
--publish ${ETHAPI_HOST_PORT}:8545 \
187-
--env TENDERMINT_WS_URL=ws://${CMT_CONTAINER_NAME}:26657/websocket \
188-
--env LOG_LEVEL=debug \
189-
--env RUST_BACKTRACE=1 \
190-
${FM_DOCKER_IMAGE} \
191-
${CMD}
192-
"""
193-
dependencies = ["network-create"]
194-
195-
[tasks.network-create]
196-
command = "docker"
197-
args = ["network", "create", "${NETWORK_NAME}"]
198-
ignore_errors = true
199-
200-
[tasks.network-rm]
201-
command = "docker"
202-
args = ["network", "rm", "${NETWORK_NAME}"]
203-
ignore_errors = true
204-
205-
[tasks.cometbft-rm]
206-
extend = "docker-rm"
207-
env = { "CONTAINER_NAME" = "${CMT_CONTAINER_NAME}" }
208-
209-
[tasks.cometbft-stop]
210-
extend = "docker-stop"
211-
env = { "CONTAINER_NAME" = "${CMT_CONTAINER_NAME}" }
212-
213-
[tasks.fendermint-rm]
214-
extend = "docker-rm"
215-
env = { "CONTAINER_NAME" = "${FM_CONTAINER_NAME}" }
216-
217-
[tasks.fendermint-stop]
218-
extend = "docker-stop"
219-
env = { "CONTAINER_NAME" = "${FM_CONTAINER_NAME}" }
220-
221-
[tasks.ethapi-rm]
222-
extend = "docker-rm"
223-
env = { "CONTAINER_NAME" = "${ETHAPI_CONTAINER_NAME}" }
224-
225-
[tasks.ethapi-stop]
226-
extend = "docker-stop"
227-
env = { "CONTAINER_NAME" = "${ETHAPI_CONTAINER_NAME}" }
228-
229-
[tasks.ethapi-logs]
230-
extend = "docker-logs"
231-
env = { "CONTAINER_NAME" = "${ETHAPI_CONTAINER_NAME}" }
232-
233-
[tasks.fendermint-logs]
234-
extend = "docker-logs"
235-
env = { "CONTAINER_NAME" = "${FM_CONTAINER_NAME}" }
236-
237-
[tasks.cometbft-logs]
238-
extend = "docker-logs"
239-
env = { "CONTAINER_NAME" = "${CMT_CONTAINER_NAME}" }
240-
241-
[tasks.docker-stop]
242-
command = "docker"
243-
args = ["stop", "${CONTAINER_NAME}"]
244-
ignore_errors = true
245-
246-
[tasks.docker-rm]
247-
command = "docker"
248-
args = ["rm", "--force", "${CONTAINER_NAME}"]
249-
ignore_errors = true
250-
251-
[tasks.docker-logs]
252-
command = "docker"
253-
args = ["logs", "${CONTAINER_NAME}"]
254-
ignore_errors = true

0 commit comments

Comments
 (0)