Skip to content

Commit

Permalink
Merge pull request #51 from cartridge-gg/feat/5/5/scrap-dependencies
Browse files Browse the repository at this point in the history
Productionalization updates
  • Loading branch information
tarrencev committed Mar 18, 2024
2 parents f886075 + 16dfdbd commit 961655d
Show file tree
Hide file tree
Showing 71 changed files with 27,163 additions and 11,877 deletions.
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
scarb 2.4.3
starknet-foundry 0.14.0
scarb 2.5.4
starknet-foundry 0.18.0
python 3.9.18
dojo 0.4.4
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["crates/account_sdk"]
members = ["crates/account_sdk", "crates/webauthn/tests"]

[workspace.package]
edition = "2021"
Expand All @@ -10,10 +10,10 @@ version = "0.1.0"
anyhow = "1"
async-trait = "0.1"
base64 = "0.21"
cainome = { git = "https://github.com/cartridge-gg/cainome", tag = "v0.1.8", features = [
"abigen-rs",
cainome = { git = "https://github.com/piniom/cainome", tag="v0.2.4-expand", features = [
"abigen-rs", "expand-expr"
] }
cairo-lang-starknet = "2.4"
cairo-lang-starknet = "2.4.0"
futures = "0.3"
lazy_static = "1"
p256 = "0.13"
Expand All @@ -23,12 +23,12 @@ serde = "1"
serde_json = "1"
sha2 = "0.10"
starknet = "0.8"
starknet-crypto = "0.6"
starknet-crypto = "0.6.1"
thiserror = "1"
tokio = { version = "1", features = ["macros"] }
toml = "0.8"
u256-literal = "1"
url = "2"
wasm-bindgen = "0.2"
webauthn-authenticator-rs = { version = "0.4" }
webauthn-rs-proto = "0.4"
account-sdk = { path = "crates/account_sdk" }
tokio = { version = "1", features = ["macros", "time"] }
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ config := --account katana-0 \
# Build files helpers.
build := ./target/dev/cartridge_account_
sierra := .contract_class.json
artifacts := ./target/abi/
compiled := .compiled_contract_class.json
store := ./crates/account_sdk/compiled/

# Contract params for deploy.
test_pubkey = 0x1234
katana_0 = 0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973

generate_artifacts:
scarb --manifest-path ./crates/cartridge_account/Scarb.toml build
mkdir -p ${artifacts}
mkdir -p ${store}

jq .abi ${build}Account${sierra} > ${artifacts}account.abi.json
jq .abi ${build}ERC20${sierra} > ${artifacts}erc20.abi.json
jq . ${build}Account${sierra} > ${store}account${sierra}
jq . ${build}ERC20${sierra} > ${store}erc20${sierra}

cp ${build}Account${compiled} ${store}account${compiled}

deploy-katana:
@set -x; \
Expand Down
57 changes: 25 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ The project consists of several subfolders located in the ```crates``` directory

- **account_sdk** - a rust project to export and test functions for interacting with the custom account contract.
- **cartidge_account** - a cairo project with a custom account contract.
- **test_gen_scripts** - a python library to programatically generate cryptographic cairo tests.
- **webauthn** - cairo components to use in contracts.

The project has a global rust workspace.
Expand All @@ -17,14 +16,33 @@ The project has a global rust workspace.

This is a rust project, that will eventually be compiled to wasm. It's purpose is to export and test functions for interacting with the custom account contract. The testing framework implemented within uses [dojo/katana](https://github.com/dojoengine/dojo) underneath. Each test starts its own katana network, deploys a contract and performs operations on it. Naturally, you must have `katana` installed to run the tests. You can specify the path to the `katana` executable in the `account_sdk/KatanaConfig.toml` file. Note that if you have `dojo` installed and in `PATH` the path can remain simply as `katana`.

### Running the tests

To run the tests you first have to compile (to sierra and casm) the contract in the `cartidge_account` folder:
### Compiling the cairo code

To build rust you first have to compile cairo. Run

```bash
make
```

in the root directory.

### Commiting changes

The compiled account is stored in the git repository in the `crates/account_sdk/compiled/` folder. To make sure that the tests are run against the most reacent version of the code run `make` in the root repository. The `make` command should also be run before commiting any changes to ensure a valid state of the compiled code.

### Building for web assembly

After you've compiled the cairo code you can compile rust to wasm using

```bash
cargo build -p account-sdk --target wasm32-unknown-unknown --release
```

## Running the tests

Note, that to run the tests you first have to [compile](#compiling-the-cairo-code) (to sierra and casm) the contract in the `cartidge_account` folder.

StarkNet Foundry tests:

```bash
Expand All @@ -45,39 +63,14 @@ cargo test

The scarb builds the contract and saves the compiled code in the `cartridge_account/target` folder. The tests then fetch (at compile time) the comipled code and deploy it to the local network. Note that obviously the contract needs to be recompiled for any changes to be applied in the compiled code.

## src
## webauthn

This is a cairo project with backend methods that will allow for various authentication methods in the custom contact.
Written based on [this specification](https://www.w3.org/TR/webauthn/).

### Running the tests

Some of the tests are auto-generated using python scripts.
See the `test_gen_scripts` for details.
The tests in `src/tests/` which end in `_gen_test.cairo` are auto-generated and might be changed by the python script. You can write your tests manually, but make sure the name of the test file doesn't end in `_gen_test.cairo`, and you place the import "`use ...;`" below the auto-generated imports in `src/tests.cairo`.

To run the tests:

```shell
scarb test
```

To again generate the tests:

```shell
python test_gen_scripts/main.py
```

## test_gen_scripts

This is a python library to programatically generate cryptographic cairo tests.

### Python Enviroment

Use pyenv to have specific version of python easily.
We use python3.9

```sh
pip install -r requirements.txt
python test_gen_scripts/main.py
You can run scarb test to run a few hand-written tests inside each ```auth``` and ```session``` crates. The bulk of the tests are located in the ```tests``` directory. These tests are written in rust and use property based testing provided by the [proptest](https://docs.rs/proptest/latest/proptest/) crate and use [cairo args runner](https://github.com/neotheprogramist/cairo-args-runner) to interface with and call cairo functions. To run these tests ```cd``` to the ```crates/webauthn/tests``` directory and run:
```bash
cargo test
```
12 changes: 6 additions & 6 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ edition = "2023_10"
version = "0.1.0"

[workspace.dependencies]
alexandria_data_structures = { git = "https://github.com/keep-starknet-strange/alexandria", rev = "085f17c87cf6d168032ef5840c39b8e18012284f" }
alexandria_encoding = { git = "https://github.com/keep-starknet-strange/alexandria", rev = "085f17c87cf6d168032ef5840c39b8e18012284f" }
alexandria_merkle_tree = { git = "https://github.com/keep-starknet-strange/alexandria", rev = "085f17c87cf6d168032ef5840c39b8e18012284f" }
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts", tag = "v0.8.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.14.0" }
starknet = "2.4.3"
alexandria_data_structures = { git = "https://github.com/keep-starknet-strange/alexandria", tag="cairo-v2.5.4" }
alexandria_encoding = { git = "https://github.com/keep-starknet-strange/alexandria", tag="cairo-v2.5.4" }
alexandria_merkle_tree = { git = "https://github.com/keep-starknet-strange/alexandria", tag="cairo-v2.5.4" }
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts", tag = "v0.9.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.18.0" }
starknet = "2.5.3"
webauthn_auth = { path = "crates/webauthn/auth" }
webauthn_session = { path = "crates/webauthn/session" }
12 changes: 9 additions & 3 deletions crates/account_sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["cdylib"]
crate-type = ["lib"]

[dependencies]
anyhow.workspace = true
Expand All @@ -25,10 +25,16 @@ sha2.workspace = true
starknet.workspace = true
starknet-crypto.workspace = true
thiserror.workspace = true
tokio.workspace = true
toml.workspace = true
u256-literal.workspace = true
url.workspace = true
wasm-bindgen.workspace = true
webauthn-authenticator-rs.workspace = true
webauthn-rs-proto.workspace = true

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio.workspace = true

[target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys = "0.3.69"
web-sys = "0.3.69"
wasm-bindgen-futures = "0.4.42"

Large diffs are not rendered by default.

Loading

0 comments on commit 961655d

Please sign in to comment.