Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 623aad5

Browse files
authored
Run lints and tests in CI for starknet-rs-py (#224)
* Add `--all` flag to Makefile targets * Fix compile errors * Add test-py job to CI * Add make deps step to jobs * Move and rename .cargo/config.toml * Change python3.9 -> python3 * Add compile dep to clippy target
1 parent 4c2ebcb commit 623aad5

File tree

5 files changed

+41
-25
lines changed

5 files changed

+41
-25
lines changed

.cargo/config.toml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# needed for mac https://pyo3.rs/v0.14.2/building_and_distribution.html#macos
2+
[target.x86_64-apple-darwin]
3+
rustflags = ["-C", "link-arg=-undefined", "-C", "link-arg=dynamic_lookup"]
4+
5+
[target.aarch64-apple-darwin]
6+
rustflags = ["-C", "link-arg=-undefined", "-C", "link-arg=dynamic_lookup"]

.github/workflows/rust-tests.yml

+23-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ jobs:
2525
cache-on-failure: true
2626
- name: Checkout
2727
uses: actions/checkout@v3
28-
- name: Build
29-
run: make build
3028
- name: Deps
3129
run: make deps
30+
- name: Build
31+
run: make build
3232

3333
format:
3434
runs-on: ubuntu-20.04
@@ -44,6 +44,8 @@ jobs:
4444
cache-on-failure: true
4545
- name: Checkout
4646
uses: actions/checkout@v3
47+
- name: Deps
48+
run: make deps
4749
- name: Format
4850
run: cargo fmt --all -- --check
4951
- name: Run clippy
@@ -67,6 +69,25 @@ jobs:
6769
run: make deps
6870
- name: Run tests
6971
run: make test
72+
73+
test-py:
74+
runs-on: ubuntu-20.04
75+
steps:
76+
- name: Install Rust
77+
uses: actions-rs/toolchain@v1
78+
with:
79+
toolchain: ${{ env.RUST_TOOLCHAIN }}
80+
override: true
81+
components: rustfmt, clippy
82+
- uses: Swatinem/rust-cache@v2
83+
with:
84+
cache-on-failure: true
85+
- name: Checkout
86+
uses: actions/checkout@v3
87+
- name: Deps
88+
run: make deps
89+
- name: Run rs-py tests
90+
run: make test-py
7091

7192
coverage:
7293
runs-on: ubuntu-20.04

Makefile

+7-7
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ starknet_programs/%.json: starknet_programs/%.cairo
4343
# Normal rules.
4444
#
4545

46-
build:
47-
cargo build --release
46+
build: compile-cairo compile-starknet
47+
cargo build --release --all
4848

49-
check:
50-
cargo check
49+
check: compile-cairo compile-starknet
50+
cargo check --all
5151

5252
deps:
5353
cargo install cargo-tarpaulin --version 0.23.1
@@ -62,13 +62,13 @@ clean:
6262
-rm -f starknet_programs/*.json
6363
-rm -f tests/*.json
6464

65-
clippy:
66-
cargo clippy --all-targets -- -D warnings
65+
clippy: compile-cairo compile-starknet
66+
cargo clippy --all --all-targets -- -D warnings
6767

6868
test: compile-cairo compile-starknet
6969
cargo test
7070

71-
py-test: compile-cairo compile-starknet
71+
test-py: compile-cairo compile-starknet
7272
. starknet-venv/bin/activate
7373
cargo test -p starknet-rs-py --no-default-features --features embedded-python
7474

crates/starknet-rs-py/.cargo/config

-12
This file was deleted.

crates/starknet-rs-py/src/lib.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ use starknet_rs::{
1818
business_logic::state::cached_state::UNINITIALIZED_CLASS_HASH,
1919
definitions::constants::{
2020
DEFAULT_CONTRACT_STORAGE_COMMITMENT_TREE_HEIGHT, DEFAULT_GAS_PRICE,
21-
DEFAULT_SEQUENCER_ADDRESS, DEFAULT_VALIDATE_MAX_N_STEPS, N_STEPS_FEE_WEIGHT,
22-
TRANSACTION_VERSION,
21+
DEFAULT_SEQUENCER_ADDRESS, DEFAULT_VALIDATE_MAX_N_STEPS, TRANSACTION_VERSION,
2322
},
2423
services::api::contract_class::ContractClass,
2524
};
25+
use std::ops::Shl;
2626
use types::general_config::{PyStarknetChainId, PyStarknetGeneralConfig, PyStarknetOsConfig};
2727

2828
// TODO: remove once https://github.com/lambdaclass/cairo-rs/pull/917 is merged
@@ -224,13 +224,14 @@ pub fn starknet_rs_py(_py: Python, m: &PyModule) -> PyResult<()> {
224224

225225
m.add(
226226
"FAULTY_CLASS_HASH",
227-
felt_str!("0x1A7820094FEAF82D53F53F214B81292D717E7BB9A92BB2488092CD306F3993F").to_biguint(),
227+
felt_str!("748273551117330086452242911863358006088276559700222288674638023319407008063")
228+
.to_biguint(),
228229
)?;
229230

230231
m.add("UNINITIALIZED_CLASS_HASH", *UNINITIALIZED_CLASS_HASH)?;
231232

232233
// Indentation for transactions meant to query and not addressed to the OS.
233-
let query_version_base: Felt = Felt::from(1 << 128);
234+
let query_version_base = Felt::from(1).shl(128u32); // == 2 ** 128
234235
let query_version = query_version_base + Felt::from(TRANSACTION_VERSION);
235236
m.add("QUERY_VERSION", query_version.to_biguint())?;
236237

0 commit comments

Comments
 (0)