Skip to content

Commit 730da30

Browse files
authored
feat: makefile targets for integration tests (#269)
New Makefile targets added that abstract Docker commands: ``` make test-sdk make test-cli make test-all ``` The existing `make test` command will revert to its original state (prior to the recent CI changes) of running unit-tests. Closes #268.
1 parent 29dfd04 commit 730da30

File tree

9 files changed

+131
-58
lines changed

9 files changed

+131
-58
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
- name: Build
5050
run: make build
5151

52-
- name: Run tests
52+
- name: Lint, tests, docs
5353
uses: dagger/dagger-for-github@8.0.0
5454
with:
5555
version: '0.18.2'
@@ -58,9 +58,3 @@ jobs:
5858
module: ci
5959
args: test --source ../ --localnet-image "$LOCALNET_IMAGE" --docker-username "$DOCKER_USERNAME" --docker-password env://DOCKER_PASSWORD 2>&1 | grep -vi -E "resolve|containerd|libnetwork|client|daemon|checkpoint|task|^$"
6060
dagger-flags: '--progress plain'
61-
62-
- name: Run linter
63-
run: make lint
64-
65-
- name: Generate documentation
66-
run: make doc

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1-
.PHONY: all build install test clean lint check-fmt check-clippy
1+
.PHONY: all build install test test-sdk test-cli test-all doc clean lint check-fmt check-clippy run-localnet stop-localnet
22

3-
all: lint build test doc
3+
# TODO: Use the latest localnet image once it can build with the latest IPC code
4+
RECALL_LOCALNET_IMAGE ?= "textile/recall-localnet:sha-dc4da8c-3e80bf0"
5+
6+
RECALL_NETWORK_CONFIG_FILE ?= /tmp/networks.toml
7+
8+
RECALL_NETWORK ?= localnet
9+
10+
RECALL_PRIVATE_KEY ?= 0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97
11+
12+
RECALL_CLI ?= ./target/release/recall
13+
14+
all: lint test-all doc
415

516
build:
617
cargo build --release
@@ -9,8 +20,30 @@ install:
920
cargo install --locked --path cli
1021

1122
test:
23+
cargo test --locked --workspace --exclude recall_sdk_tests
24+
25+
run-sdk-tests:
26+
cargo test --locked -p recall_sdk_tests
27+
28+
run-cli-tests:
29+
RECALL_NETWORK=${RECALL_NETWORK} \
30+
RECALL_NETWORK_CONFIG_FILE=${RECALL_NETWORK_CONFIG_FILE} \
31+
RECALL_CLI=${RECALL_CLI} \
32+
RECALL_PRIVATE_KEY=${RECALL_PRIVATE_KEY} \
33+
./scripts/run-cli-tests.sh
34+
35+
run-all-tests:
1236
cargo test --locked --workspace
1337

38+
test-sdk: run-localnet run-sdk-tests
39+
$(MAKE) stop-localnet
40+
41+
test-cli: build run-localnet run-cli-tests
42+
$(MAKE) stop-localnet
43+
44+
test-all: build run-localnet run-all-tests run-cli-tests
45+
$(MAKE) stop-localnet
46+
1447
doc:
1548
cargo doc --locked --no-deps --workspace --exclude recall_cli --open
1649

@@ -26,3 +59,16 @@ check-fmt:
2659

2760
check-clippy:
2861
cargo clippy --no-deps --tests -- -D clippy::all
62+
63+
run-localnet:
64+
$(MAKE) stop-localnet
65+
docker run --privileged --rm -d --name recall-localnet \
66+
-p 8545:8545 \
67+
-p 8645:8645 \
68+
-p 26657:26657 \
69+
${RECALL_LOCALNET_IMAGE}
70+
./scripts/check-localnet-container.sh
71+
docker cp recall-localnet:/workdir/localnet-data/networks.toml ${RECALL_NETWORK_CONFIG_FILE}
72+
73+
stop-localnet:
74+
docker rm -f recall-localnet || true

README.md

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -57,62 +57,44 @@ All the available commands include:
5757

5858
- Build all crates: `make build`
5959
- Install the CLI: `make install`
60-
- Run tests: `make test`
60+
- Run unit tests: `make test`
6161
- Run linter: `make lint`
6262
- Run formatter: `make check-fmt`
6363
- Run clippy: `make check-clippy`
6464
- Do all of the above: `make all`
6565
- Clean dependencies: `make clean`
6666

67-
## Testing
67+
## Integration Tests
6868

69-
Some of the tests require a Docker container to be running for `localnet`, and so will fail if you run `make test`
70-
without starting the container first. You can start this container using the following command:
69+
The integration tests require a Docker container to be running for `localnet`. You can use the following Make commands
70+
to spin up a `localnet` Docker container and execute tests against it:
7171

72+
SDK integration tests:
7273
```bash
73-
docker run --privileged --rm --name recall-localnet \
74-
-p 8545:8545 \
75-
-p 8645:8645 \
76-
-p 26657:26657 \
77-
textile/recall-localnet:latest
74+
make test-sdk
7875
```
7976

80-
If you'd like to test against a specific IPC commit, look for the corresponding `localnet` image in the
81-
[Docker Hub repository](https://hub.docker.com/r/textile/recall-localnet/tags) using the first 7 characters of the IPC
82-
commit hash. For example, for commit `dc4da8c14c541e1ef9e398a594e65660465c47f5`, the corresponding `localnet` image
83-
would be tagged `sha-dc4da8c-*` (in this case, `sha-dc4da8c-3e80bf0`). You can then run the following command:
84-
77+
CLI integration tests:
8578
```bash
86-
docker run --privileged --rm -d --name recall-localnet \
87-
-p 8545:8545 \
88-
-p 8645:8645 \
89-
-p 26657:26657 \
90-
textile/recall-localnet:sha-dc4da8c-3e80bf0
91-
```
92-
93-
Note that it can take several minutes for the `localnet` container to start up and be ready for testing. You can check
94-
the status of the container using the following command:
95-
96-
```text
97-
docker logs -f recall-localnet
79+
make test-cli
9880
```
9981

100-
The following logs should appear when the container is ready:
101-
82+
If you want to run all tests, including unit tests and SDK/CLI integration tests, you can use the following command:
10283
```bash
103-
All containers started. Waiting for termination signal...
84+
make test-all
10485
```
10586

106-
### Extracting Network Config
87+
If you'd like to test against a specific IPC commit, look for the corresponding `localnet` image in the
88+
[Docker Hub repository](https://hub.docker.com/r/textile/recall-localnet/tags) using the first 7 characters of the IPC
89+
commit hash. For example, for commit `dc4da8c14c541e1ef9e398a594e65660465c47f5`, the corresponding `localnet` image
90+
would be tagged `sha-dc4da8c-*` (in this case, `sha-dc4da8c-3e80bf0`).
10791

108-
To extract the network config from the `localnet` container, you can run the following command:
92+
You can then specify the image tag in the Make command. For example:
10993

11094
```bash
111-
docker exec -it recall-localnet bash -c "cat /workdir/localnet-data/networks.toml"
95+
RECALL_LOCALNET_IMAGE=textile/recall-localnet:sha-dc4da8c-3e80bf1 make test-sdk
11296
```
11397

114-
Add the `localnet` configuration to your `~/.config/recall/networks.toml` file.
115-
11698
### Adding New Integration Tests
11799

118100
All the tests in the repo are written as Rust unit tests, even the integration tests. New integration tests can be added

dagger/ci/main.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,11 @@ func (m *Ci) Test(
5858
}
5959
return codeContainer.
6060
WithServiceBinding("localnet", m.localnetService(localnetContainer)).
61-
WithExec([]string{
62-
"sh", "-c",
63-
"make test",
64-
}).
65-
WithExec([]string{
66-
"sh", "-c",
67-
"find tests/cli -type f | sort | xargs -I{} sh -c 'chmod +x {} && {}'",
68-
}).
61+
WithExec([]string{"sh", "-c", "make lint"}). // Lint
62+
WithExec([]string{"sh", "-c", "make test"}). // Unit tests
63+
WithExec([]string{"sh", "-c", "make run-sdk-tests"}). // SDK integration tests
64+
WithExec([]string{"sh", "-c", "make run-cli-tests"}). // CLI integration tests
65+
WithExec([]string{"sh", "-c", "make doc"}). // Docs
6966
Stdout(ctx)
7067
}
7168

@@ -148,7 +145,7 @@ func (m *Ci) codeContainer(
148145
}).
149146
WithDirectory("/src", source).
150147
WithWorkdir("/src").
151-
WithEnvVariable("TEST_TARGET_NETWORK_CONFIG", "/root/.config/recall/networks.toml").
148+
WithEnvVariable("RECALL_NETWORK_CONFIG_FILE", "/root/.config/recall/networks.toml").
152149
WithEnvVariable("RECALL_NETWORK", "localnet").
153150
WithEnvVariable("RECALL_PRIVATE_KEY", testAccountPrivateKey).
154151
WithExec([]string{
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
CONTAINER_NAME="recall-localnet"
4+
SEARCH_STRING="All containers started. Waiting for termination signal..."
5+
MAX_WAIT_TIME=300
6+
INTERVAL=5
7+
8+
start_time=$(date +%s)
9+
10+
while true; do
11+
if docker logs $CONTAINER_NAME 2>&1 | grep -q "$SEARCH_STRING"; then
12+
echo -e "\nLocalnet container ready!"
13+
exit 0
14+
fi
15+
16+
current_time=$(date +%s)
17+
elapsed_time=$((current_time - start_time))
18+
if [ $elapsed_time -ge $MAX_WAIT_TIME ]; then
19+
echo -e "\nLocalnet container startup failed!"
20+
exit 1
21+
fi
22+
23+
remaining=$((MAX_WAIT_TIME - elapsed_time))
24+
echo -ne "Waiting for Localnet container... ${elapsed_time}s elapsed, ${remaining}s remaining\r"
25+
26+
sleep $INTERVAL
27+
done

scripts/run-cli-tests.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
: "${RECALL_NETWORK:=localnet}"
4+
: "${RECALL_NETWORK_CONFIG_FILE:=/tmp/networks.toml}"
5+
: "${RECALL_CLI:=./target/release/recall}"
6+
: "${RECALL_PRIVATE_KEY:=0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97}"
7+
8+
export RECALL_NETWORK
9+
export RECALL_NETWORK_CONFIG_FILE
10+
export RECALL_CLI
11+
export RECALL_PRIVATE_KEY
12+
13+
for file in $(find tests/cli -type f | sort); do
14+
echo "Running test: $file"
15+
chmod +x "$file"
16+
17+
if ! "$file"; then
18+
echo "Test failed: $file"
19+
exit 1
20+
fi
21+
done
22+
23+
echo "All tests completed successfully!"

tests/sdk/README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Integration Tests
22

3-
This directory contains integration tests for the sdk. These run against the Recall network defined by the following env vars:
4-
- `RECALL_PRIVATE_KEY`, a private key for a wallet that has funds on the parent chain, RECALL, and credits
3+
This directory contains integration tests for the sdk.
54

6-
An example of running these tests against localnet Anvil default account 8 follows:
7-
`RECALL_PRIVATE_KEY=0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97 cargo test -- --nocapture`
5+
You can use the following Make command to run the tests. This command will spin up a Localnet Docker container and run
6+
the tests against it. The `RECALL_PRIVATE_KEY` environment variable can be set to any of the private keys listed in the
7+
section below.
8+
9+
```bash
10+
RECALL_PRIVATE_KEY=0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a make test-sdk
11+
```
812

913
## Anvil Test Accounts and Private Keys
1014

tests/sdk/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub mod test_utils {
5656
];
5757

5858
pub fn get_network_config() -> NetworkConfig {
59-
let network_config_path = env::var("TEST_TARGET_NETWORK_CONFIG")
59+
let network_config_path = env::var("RECALL_NETWORK_CONFIG_FILE")
6060
.unwrap_or_else(|_| DEFAULT_TEST_TARGET_NETWORK_CONFIG_PATH.to_string());
6161
let network_config_path = shellexpand::full(network_config_path.as_str()).unwrap();
6262
let network_config_path = Path::new(network_config_path.as_ref());

0 commit comments

Comments
 (0)