Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: book structure & CI #28

Merged
merged 2 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/install-mdbook/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,3 @@ runs:
- name: Install mdbook-i18n-helpers
run: cargo install mdbook-i18n-helpers --locked --version 0.1.0
shell: bash

- name: Install cairo programs verifier
run: cargo install --path mdbook-cairo --locked
shell: bash
22 changes: 9 additions & 13 deletions .github/workflows/verify-cairo-programs/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@ description: Verify if all Cairo programs extracted from markdown can be compile
runs:
using: composite
steps:
- name: Install scarb
run: |
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | bash -s -- -v 0.4.0

- name: Copy Cairo program verifier script
shell: bash
run: |
cp mdbook-cairo/scripts/cairo_programs_verifier.sh book/cairo/cairo-programs/

- name: Verify Cairo programs
uses: addnab/docker-run-action@v3
with:
image: starknet/cairo:1.1.0
options: -v ${{ github.workspace }}/book/cairo/cairo-programs:/cairo
run: |
sh /cairo/cairo_programs_verifier.sh false > /cairo/summary.md
mkdir -p book/listings && cp scripts/cairo_programs_verifier.sh book/listings && cp listings book/listings

- name: Generate job summary
shell: bash
run: cat book/cairo/cairo-programs/summary.md >> $GITHUB_STEP_SUMMARY
if: always()
- name: Run build script
run: |
chmod +x scripts/cairo_programs_verifier.sh
./scripts/cairo_programs_verifier.sh
26 changes: 26 additions & 0 deletions .github/workflows/verify_cairo_programs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Verify Cairo programs compilation

on:
pull_request:
branches:
- main

jobs:
compile_and_verify:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Rust cache
uses: ./.github/workflows/setup-rust-cache

- name: Install scarb
run: |
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | bash -s -- -v 0.4.0

- name: Run build script
run: |
chmod +x scripts/cairo_programs_verifier.sh
./scripts/cairo_programs_verifier.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
10 changes: 10 additions & 0 deletions listings/ch00-introduction/calling_other_contracts/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "calling_other_contracts"
version = "0.1.0"

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest

[dependencies]
starknet = "1.1.0"

[[target.starknet-contract]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod callee;
mod caller;
1 change: 1 addition & 0 deletions listings/ch00-introduction/errors/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
10 changes: 10 additions & 0 deletions listings/ch00-introduction/errors/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "errors"
version = "0.1.0"

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest

[dependencies]
starknet = "1.1.0"

[[target.starknet-contract]]
3 changes: 3 additions & 0 deletions listings/ch00-introduction/errors/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod simple_errors;
mod custom_errors;
mod vault_errors;
1 change: 1 addition & 0 deletions listings/ch00-introduction/storing_arrays/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
11 changes: 11 additions & 0 deletions listings/ch00-introduction/storing_arrays/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "storing_arrays"
version = "0.1.0"

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest

[dependencies]
starknet = "1.1.0"

[[target.starknet-contract]]
allowed-libfuncs-list.name = "experimental_v0.1.0"
1 change: 1 addition & 0 deletions listings/ch00-introduction/storing_arrays/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod storing_arrays;
1 change: 1 addition & 0 deletions listings/ch00-introduction/variables/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
10 changes: 10 additions & 0 deletions listings/ch00-introduction/variables/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "variables"
version = "0.1.0"

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest

[dependencies]
starknet = "1.1.0"

[[target.starknet-contract]]
3 changes: 3 additions & 0 deletions listings/ch00-introduction/variables/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod storage_variables;
mod local_variables;
mod global_variables;
1 change: 1 addition & 0 deletions listings/ch00-introduction/write_to_any_slot/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
11 changes: 11 additions & 0 deletions listings/ch00-introduction/write_to_any_slot/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "write_to_any_slot"
version = "0.1.0"

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest

[dependencies]
starknet = "1.1.0"

[[target.starknet-contract]]
allowed-libfuncs-list.name = "experimental_v0.1.0"
2 changes: 2 additions & 0 deletions listings/ch00-introduction/write_to_any_slot/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod test_write_any_slot;
mod write_any_slot;
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use write_to_any_slot::write_any_slot::WriteToAnySlot;

#[abi]
trait IWriteToAnySlot {
fn write_slot(value: u32);
fn read_slot() -> u32;
}

#[cfg(test)]
mod tests {
use super::WriteToAnySlot::{get_address_from_name};
use super::WriteToAnySlot;
use super::{IWriteToAnySlotDispatcher, IWriteToAnySlotDispatcherTrait};
use debug::PrintTrait;
use starknet::deploy_syscall;
use option::OptionTrait;
use array::ArrayTrait;
use traits::{Into, TryInto};
use starknet::class_hash::Felt252TryIntoClassHash;
use result::ResultTrait;

#[test]
#[available_gas(2000000000)]
fn test_read_write() {
// Set up.
let mut calldata: Array<felt252> = ArrayTrait::new();
let (address0, _) = deploy_syscall(
WriteToAnySlot::TEST_CLASS_HASH.try_into().unwrap(), 0, calldata.span(), false
)
.unwrap();
let mut contract = IWriteToAnySlotDispatcher { contract_address: address0 };

// Write to slot.
let value: u32 = 42;
contract.write_slot(value);

// Read from slot.
let read_value = contract.read_slot();
assert(read_value == value, 'wrong value read');
}
}

1 change: 1 addition & 0 deletions listings/ch01-applications/upgradeable_contract/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
10 changes: 10 additions & 0 deletions listings/ch01-applications/upgradeable_contract/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "upgradeable_contract"
version = "0.1.0"

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest

[dependencies]
starknet = "1.1.0"

[[target.starknet-contract]]
2 changes: 2 additions & 0 deletions listings/ch01-applications/upgradeable_contract/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod upgradeable_contract_v0;
mod upgradeable_contract_v1;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
mod UpgradeableContract_V0 {
use starknet::class_hash::ClassHash;
use zeroable::Zeroable;
use result::ResultTrait;
use starknet::SyscallResult;

struct Storage {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
mod UpgradeableContract_V1 {
use starknet::class_hash::ClassHash;
use zeroable::Zeroable;
use result::ResultTrait;
use starknet::SyscallResult;

struct Storage {}

Expand Down
1 change: 0 additions & 1 deletion mdbook-cairo/.gitignore

This file was deleted.

Loading