Skip to content

Commit b5a46ad

Browse files
authored
Use pre-compiled devnet binary from release assets (#1345)
1 parent 25aab73 commit b5a46ad

File tree

5 files changed

+117
-59
lines changed

5 files changed

+117
-59
lines changed

.github/workflows/checks.yml

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name: Checks
22

33
env:
4-
DEVNET_SHA: "c6ffb99"
54
CAIRO_LANG_VERSION: "0.13.1"
5+
DEVNET_VERSION: "0.0.5"
66

77
on:
88
push:
@@ -23,7 +23,7 @@ jobs:
2323
runs-on: ubuntu-latest
2424
steps:
2525

26-
- uses: actions/checkout@v3
26+
- uses: actions/checkout@v4
2727

2828
- name: Install poetry
2929
run: |
@@ -71,7 +71,7 @@ jobs:
7171

7272
# ====================== SETUP ====================== #
7373

74-
- uses: actions/checkout@v3
74+
- uses: actions/checkout@v4
7575
- uses: asdf-vm/actions/setup@v3
7676
- uses: actions/setup-python@v4
7777
with:
@@ -160,9 +160,7 @@ jobs:
160160
matrix:
161161
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
162162
steps:
163-
- uses: actions/checkout@v3
164-
- uses: actions-rust-lang/setup-rust-toolchain@v1
165-
- uses: Swatinem/rust-cache@v2
163+
- uses: actions/checkout@v4
166164

167165
- name: Download contracts
168166
uses: actions/download-artifact@v3
@@ -196,10 +194,7 @@ jobs:
196194
# ====================== SETUP DEVNET ====================== #
197195

198196
- name: Install devnet
199-
run: |
200-
cargo install --locked \
201-
--git https://github.com/0xSpaceShard/starknet-devnet-rs.git \
202-
--rev ${{ env.DEVNET_SHA }}
197+
run: ./starknet_py/tests/install_devnet.sh
203198

204199
# ====================== RUN TESTS ====================== #
205200

@@ -237,7 +232,7 @@ jobs:
237232
SEPOLIA_INTEGRATION_ACCOUNT_PRIVATE_KEY: ${{ secrets.SEPOLIA_INTEGRATION_ACCOUNT_PRIVATE_KEY }}
238233
SEPOLIA_INTEGRATION_ACCOUNT_ADDRESS: ${{ secrets.SEPOLIA_INTEGRATION_ACCOUNT_ADDRESS }}
239234
steps:
240-
- uses: actions/checkout@v3
235+
- uses: actions/checkout@v4
241236

242237
- name: Download contracts
243238
uses: actions/download-artifact@v3
@@ -299,9 +294,10 @@ jobs:
299294
matrix:
300295
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
301296
steps:
302-
- uses: actions/checkout@v3
303-
- uses: actions-rust-lang/setup-rust-toolchain@v1
304-
- uses: Swatinem/rust-cache@v2
297+
- uses: actions/checkout@v4
298+
- uses: dtolnay/rust-toolchain@dc6353516c68da0f06325f42ad880f76a5e77ec9
299+
with:
300+
toolchain: stable
305301

306302
- name: Download contracts
307303
uses: actions/download-artifact@v3
@@ -317,7 +313,9 @@ jobs:
317313
# ====================== SETUP DEVNET ====================== #
318314

319315
- name: Install devnet
320-
run: cargo install --locked --git https://github.com/0xSpaceShard/starknet-devnet-rs.git --rev ${{ env.DEVNET_SHA }}
316+
run: |
317+
$DEVNET_INSTALL_DIR = "$(git rev-parse --show-toplevel)/starknet_py/tests/e2e/devnet"
318+
cargo install starknet-devnet --version ${{ env.DEVNET_VERSION }} --root $DEVNET_INSTALL_DIR
321319
322320
# ====================== SETUP PYTHON ====================== #
323321

@@ -368,9 +366,7 @@ jobs:
368366
matrix:
369367
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
370368
steps:
371-
- uses: actions/checkout@v3
372-
- uses: actions-rust-lang/setup-rust-toolchain@v1
373-
- uses: Swatinem/rust-cache@v2
369+
- uses: actions/checkout@v4
374370

375371
- name: Download contracts
376372
uses: actions/download-artifact@v3
@@ -404,10 +400,7 @@ jobs:
404400
# ====================== SETUP DEVNET ====================== #
405401

406402
- name: Install devnet
407-
run: |
408-
cargo install --locked \
409-
--git https://github.com/0xSpaceShard/starknet-devnet-rs.git \
410-
--rev ${{ env.DEVNET_SHA }}
403+
run: ./starknet_py/tests/install_devnet.sh
411404

412405
# ====================== RUN TESTS ====================== #
413406

@@ -437,9 +430,10 @@ jobs:
437430
matrix:
438431
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
439432
steps:
440-
- uses: actions/checkout@v3
441-
- uses: actions-rust-lang/setup-rust-toolchain@v1
442-
- uses: Swatinem/rust-cache@v2
433+
- uses: actions/checkout@v4
434+
- uses: dtolnay/rust-toolchain@dc6353516c68da0f06325f42ad880f76a5e77ec9
435+
with:
436+
toolchain: stable
443437

444438
- name: Download contracts
445439
uses: actions/download-artifact@v3
@@ -473,7 +467,9 @@ jobs:
473467
# ====================== SETUP DEVNET ====================== #
474468

475469
- name: Install devnet
476-
run: cargo install --locked --git https://github.com/0xSpaceShard/starknet-devnet-rs.git --rev ${{ env.DEVNET_SHA }}
470+
run: |
471+
$DEVNET_INSTALL_DIR = "$(git rev-parse --show-toplevel)/starknet_py/tests/e2e/devnet"
472+
cargo install starknet-devnet --version ${{ env.DEVNET_VERSION }} --root $DEVNET_INSTALL_DIR
477473
478474
# ====================== RUN TESTS ====================== #
479475

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,6 @@ cython_debug/
153153

154154
# Test variables
155155
/starknet_py/tests/e2e/test-variables.env
156+
157+
# Devnet binary
158+
/starknet_py/tests/e2e/devnet

docs/development.rst

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,13 @@ Development dependencies
1515
Setup
1616
-----
1717

18-
In order to run tests on devnet, you need to install `starknet-devnet-rs <https://github.com/0xSpaceShard/starknet-devnet-rs>`_.
19-
The correct version of devnet to use corresponds to the Starknet and RPC specification that are currently supported by Starknet.py.
20-
Information about the supported version for the latest release can be found in the :doc:`migration guide<migration_guide>`.
18+
Starknet devnet
19+
^^^^^^^^^^^^^^^
2120

22-
To avoid version discrepancies or other related issues, we recommend installing this dependency using the ``cargo install`` command, and specifying a certain commit along with the correct Starknet and RPC versions.
21+
To install `starknet-devnet-rs <https://github.com/0xSpaceShard/starknet-devnet-rs>`_ run the script ``./starknet_py/tests/install_devnet.sh``.
2322

24-
Below is the command you can use to do this, designed for compatibility with the current version of Starknet.py:
25-
26-
.. code-block:: bash
27-
28-
cargo install \
29-
--locked \
30-
--git https://github.com/0xSpaceShard/starknet-devnet-rs.git \
31-
--rev c6ffb99
32-
33-
If you choose to install `starknet-devnet-rs <https://github.com/0xSpaceShard/starknet-devnet-rs>`_ using a different method, please make sure to add the executable ``starknet-devnet`` to your ``PATH`` environment variable.
23+
Environment variables
24+
^^^^^^^^^^^^^^^^^^^^^
3425

3526
In order to be able to run tests on testnet and integration networks (``starknet_py/tests/e2e/tests_on_networks/``), you must set some environmental variables:
3627

@@ -44,17 +35,19 @@ In order to be able to run tests on testnet and integration networks (``starknet
4435
The best way to set environment variables is to create ``test-variables.env`` file in ``starknet_py/tests/e2e/`` directory, so they can be loaded by the ``python-dotenv`` library.
4536
You can find an example file ``test-variables.env.template`` in the same directory with the format of how it should look like.
4637

38+
Dependencies
39+
^^^^^^^^^^^^
40+
4741
.. code-block:: bash
4842
49-
# Install dependencies
5043
poetry install
5144
52-
# Compile contracts
53-
poe compile_contracts
45+
Contracts
46+
^^^^^^^^^
5447

55-
# Make sure everything was installed properly
56-
poe test
48+
.. code-block:: bash
5749
50+
poe compile_contracts
5851
5952
Git hooks
6053
---------
@@ -90,25 +83,18 @@ Tests
9083
# Run whole suite
9184
poe test
9285
86+
# Run only tests on networks
87+
poe test_ci_on_networks
88+
89+
# Run unit tests and tests on devnet
90+
poe test_ci
91+
9392
# Generate test report in terminal
9493
poe test_report
9594
9695
# Generate HTML report and open it in the browser
9796
poe test_html
9897
99-
# Run only unit tests
100-
poe test_unit
101-
102-
# Run only e2e tests
103-
poe test_e2e
104-
105-
Running e2e tests in PyCharm
106-
----------------------------
107-
1. Run ``starkware-devnet`` script before running e2e tests in PyCharm.
108-
2. Use ``E2E tests`` configuration to run or debug.
109-
110-
⚠️ **Warning**: Make sure to fill your interpreter in the configuration, to match your project's poetry venv.
111-
11298
Code style guide
11399
----------------
114100

starknet_py/tests/e2e/fixtures/devnet.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import subprocess
33
import time
44
from contextlib import closing
5+
from pathlib import Path
56
from typing import Generator, List
67

78
import pytest
@@ -25,8 +26,9 @@ def start_devnet():
2526

2627

2728
def get_start_devnet_command(devnet_port: int) -> List[str]:
29+
devnet_path = Path(__file__).parent.parent / "devnet" / "bin" / "starknet-devnet"
2830
return [
29-
"starknet-devnet",
31+
str(devnet_path),
3032
"--port",
3133
str(devnet_port),
3234
"--accounts", # deploys specified number of accounts
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
set -e
3+
4+
DEVNET_INSTALL_DIR="$(git rev-parse --show-toplevel)/starknet_py/tests/e2e/devnet/bin"
5+
DEVNET_REPO="https://github.com/0xSpaceShard/starknet-devnet-rs"
6+
DEVNET_VERSION="v0.0.5"
7+
8+
require_cmd() {
9+
if ! command -v "$1" >/dev/null 2>&1; then
10+
echo "$1 is not available"
11+
echo "Please install $1 and run the script again"
12+
exit 1
13+
fi
14+
}
15+
16+
get_architecture() {
17+
local _ostype _cputype _arch _clibtype
18+
_ostype="$(uname -s)"
19+
_cputype="$(uname -m)"
20+
_clibtype="gnu"
21+
22+
if [ "$_ostype" = Linux ] && ldd --_requested_version 2>&1 | grep -q 'musl'; then
23+
_clibtype="musl"
24+
fi
25+
26+
if [ "$_ostype" = Darwin ] && [ "$_cputype" = i386 ] && sysctl hw.optional.x86_64 | grep -q ': 1'; then
27+
_cputype=x86_64
28+
fi
29+
30+
case "$_ostype" in
31+
Linux)
32+
_ostype=unknown-linux-$_clibtype
33+
;;
34+
35+
Darwin)
36+
_ostype=apple-darwin
37+
;;
38+
*)
39+
err "unsupported OS type: $_ostype"
40+
;;
41+
esac
42+
43+
case "$_cputype" in
44+
aarch64 | arm64)
45+
_cputype=aarch64
46+
;;
47+
48+
x86_64 | x86-64 | x64 | amd64)
49+
_cputype=x86_64
50+
;;
51+
*)
52+
err "unknown CPU type: $_cputype"
53+
;;
54+
esac
55+
56+
_arch="${_cputype}-${_ostype}"
57+
58+
RETVAL="$_arch"
59+
}
60+
61+
require_cmd curl
62+
require_cmd tar
63+
64+
get_architecture
65+
SYSTEM_TRIPLET="$RETVAL"
66+
67+
mkdir -p "${DEVNET_INSTALL_DIR}"
68+
curl -L "${DEVNET_REPO}/releases/download/${DEVNET_VERSION}/starknet-devnet-${SYSTEM_TRIPLET}.tar.gz" | tar -xz -C "${DEVNET_INSTALL_DIR}" || exit 1
69+
70+
echo "All done!"
71+
exit 0

0 commit comments

Comments
 (0)