Skip to content

Commit 277dbb6

Browse files
committed
tests: add integration testing for cli
1 parent 4d5cf86 commit 277dbb6

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

.github/workflows/test.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,15 @@ jobs:
3434
- uses: ApeWorX/github-action@v3
3535
- run: pip install .
3636
- run: ape test -s --gas tests/functional
37+
38+
integration:
39+
name: Integration Tests
40+
runs-on: ubuntu-latest
41+
needs: compilation
42+
43+
steps:
44+
- uses: actions/checkout@v5
45+
- uses: ApeWorX/github-action@v3
46+
- run: pip install .
47+
- uses: foundry-rs/foundry-toolchain@v1
48+
- run: ape test -s --gas tests/integration

tests/integration/conftest.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import subprocess
2+
3+
import pytest
4+
from click.testing import CliRunner
5+
from ape.utils.os import create_tempdir
6+
7+
8+
@pytest.fixture(scope="session")
9+
def DEFAULT_ARGS():
10+
# NOTE: Must be done w/ Foundry, otherwise doesn't support `CreateX.inject()`
11+
return ["--network", "::foundry", "--account", "TEST::0"]
12+
13+
14+
@pytest.fixture(scope="session")
15+
def cli():
16+
from caravan.__main__ import cli
17+
18+
yield cli
19+
20+
21+
@pytest.fixture()
22+
def runner(monkeypatch):
23+
with (
24+
create_tempdir() as XDG_CONFIG_HOME,
25+
create_tempdir() as XDG_CACHE_HOME,
26+
):
27+
monkeypatch.setattr("caravan.settings.USER_CONFIG_DIR", XDG_CONFIG_HOME)
28+
monkeypatch.setattr("caravan.settings.USER_CACHE_DIR", XDG_CACHE_HOME)
29+
30+
runner = CliRunner(
31+
env={
32+
"XDG_CONFIG_HOME": str(XDG_CONFIG_HOME),
33+
"XDG_CACHE_HOME": str(XDG_CACHE_HOME),
34+
}
35+
)
36+
37+
with runner.isolated_filesystem():
38+
p = subprocess.Popen(
39+
["ape", "networks", "run", "--network", "::foundry"], shell=True
40+
)
41+
yield runner
42+
p.terminate()

tests/integration/test_sudo.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import pytest
2+
3+
from caravan.settings import FACTORY_DETERMINISTIC_ADDRESS as FACTORY
4+
from caravan.settings import SINGLETON_DETERMINISTIC_ADDRESSES as SINGLETONS
5+
6+
7+
def test_deploy_factory(DEFAULT_ARGS, runner, cli):
8+
cmd = ["sudo", "deploy", "factory", *DEFAULT_ARGS]
9+
assert (result := runner.invoke(cli, cmd)).exit_code == 0
10+
assert f"CaravanFactory deployed to {FACTORY}" in result.output, result.output
11+
12+
13+
@pytest.mark.parametrize("version", SINGLETONS)
14+
def test_deploy_singleton(DEFAULT_ARGS, runner, cli, version):
15+
cmd = ["sudo", "deploy", "singleton", "--version", version, *DEFAULT_ARGS]
16+
assert (result := runner.invoke(cli, cmd)).exit_code == 0
17+
assert f"Caravan v{version} deployed to {SINGLETONS[version]}" in result.output, (
18+
result.output
19+
)

0 commit comments

Comments
 (0)