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

Feat: update v2.1.0 #65

Merged
merged 6 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
11 changes: 1 addition & 10 deletions .github/workflows/mdbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,10 @@ jobs:
- name: Install mdbook
uses: ./.github/workflows/install-mdbook

- name: Build in English
- name: Build book
run: |
mdbook build -d book

- name: Build all translations
run: |
for po_lang in $(cat ./LANGUAGES); do
echo "::group::Building $po_lang translation"
MDBOOK_BOOK__LANGUAGE=$po_lang \
mdbook build -d book/$po_lang
echo "::endgroup::"
done

- name: Verify Cairo programs
uses: ./.github/workflows/verify-cairo-programs

Expand Down
9 changes: 0 additions & 9 deletions .github/workflows/setup-rust-cache/action.yml

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/verify-cairo-programs/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ runs:
using: composite
steps:
- name: Install scarb
shell: bash
run: |
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | bash -s -- -v 0.5.1
uses: software-mansion/setup-scarb@v1
with:
scarb-version: "0.6.2"

- name: Run build script
shell: bash
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/verify_cairo_programs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ jobs:
- 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.5.1
uses: software-mansion/setup-scarb@v1
with:
scarb-version: "0.6.2"

- name: Run build script
run: |
Expand Down
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scarb 0.6.2
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ Starknet by Example is a collection of examples of how to use the [Cairo](https:

### Setup

1. Rust related packages:
1. Clone this repository.
2. Rust related packages:
- Install toolchain providing `cargo` using [rustup](https://rustup.rs/).
- Install [mdBook](https://rust-lang.github.io/mdBook/guide/installation.html)
2. Host machine packages:
- Install [mdBook](https://rust-lang.github.io/mdBook/guide/installation.html).
3. Install `scarb` using [asdf](https://asdf-vm.com/) with `asdf install`. Alternatively, you can install `scarb` manually by following the instructions [here](https://docs.swmansion.com/scarb/).

- Install [gettext](https://www.gnu.org/software/gettext/) for translations, usually available with regular package manager:
`sudo apt install gettext`.
### Local development

3. Clone this repository.

### Work locally
#### MdBook

All the Markdown files **MUST** be edited in english. To work locally in english:

Expand All @@ -29,7 +27,7 @@ All the Markdown files **MUST** be edited in english. To work locally in english

- Open a PR with your changes.

### Work locally (Cairo programs verification)
#### Cairo programs

The current book has script that verifies the compilation of all Cairo programs in the book.
Instead of directly writing Cairo programs in the markdown files, we use code blocks that import the Cairo programs from the `listing` directory.
Expand All @@ -39,3 +37,12 @@ To run the script locally, ensure that you are at the root of the repository (sa
and run:

`bash scripts/cairo_programs_verifier.sh`

This will check that all the Cairo programs in the book compile successfully using `scarb build`, that every tests passes using `scarb test`, and that the `scarb fmt -c` command does not identify any formatting issues.

You can also use `bash scripts/cairo_programs_format.sh` to format all the Cairo programs in the book using `scarb fmt` automatically.

If you want to add a new smart contract to the book, you can follow these steps:
1. Create a new directory in the `listing` directory.
2. Initialize a scarb project in the new directory with `scarb init`.
3. Add `[[target.starknet-contract]]` and the starknet dependency to the `Scarb.toml` file.
6 changes: 2 additions & 4 deletions listings/ch00-introduction/calling_other_contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
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 = ">=2.0.1"
starknet = ">=2.1.0"

[[target.starknet-contract]]
[[target.starknet-contract]]
4 changes: 1 addition & 3 deletions listings/ch00-introduction/constructor/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
name = "constructor"
version = "0.1.0"

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

[dependencies]
starknet = ">=2.0.1"
starknet = ">=2.1.0"

[[target.starknet-contract]]
2 changes: 1 addition & 1 deletion listings/ch00-introduction/counter/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ name = "counter"
version = "0.1.0"

[dependencies]
starknet = ">=2.0.1"
starknet = ">=2.1.0"

[[target.starknet-contract]]
2 changes: 1 addition & 1 deletion listings/ch00-introduction/counter/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mod counter;
mod counter;
4 changes: 1 addition & 3 deletions listings/ch00-introduction/custom_type_serde/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
name = "custom_type_serde"
version = "0.1.0"

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

[dependencies]
starknet = ">=2.0.1"
starknet = ">=2.1.0"

[[target.starknet-contract]]
4 changes: 1 addition & 3 deletions listings/ch00-introduction/errors/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
name = "errors"
version = "0.1.0"

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

[dependencies]
starknet = ">=2.0.1"
starknet = ">=2.1.0"

[[target.starknet-contract]]
2 changes: 1 addition & 1 deletion listings/ch00-introduction/errors/src/custom_errors.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod CustomErrorsExample {

#[generate_trait]
#[external(v0)]
impl CustomErrorsExample of ICustomErrorsExample{
impl CustomErrorsExample of ICustomErrorsExample {
fn test_assert(self: @ContractState, i: u256) {
assert(i > 0, Errors::NOT_POSITIVE);
}
Expand Down
2 changes: 1 addition & 1 deletion listings/ch00-introduction/events/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ name = "counter"
version = "0.1.0"

[dependencies]
starknet = ">=2.0.1"
starknet = ">=2.1.0"

[[target.starknet-contract]]
2 changes: 1 addition & 1 deletion listings/ch00-introduction/interfaces_traits/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ name = "interfaces_traits"
version = "0.1.0"

[dependencies]
starknet = ">=2.0.1"
starknet = ">=2.1.0"

[[target.starknet-contract]]
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ mod ImplicitInterfaceContract {
}
}
}
// ANCHOR_END: code
// ANCHOR_END: code


Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ mod implicit_internal_contract_tests {
let initial_value: u32 = 0;
assert(contract.get_value() == initial_value, 'wrong value');

let add_value: u32 = 10;
let add_value: u32 = 10;
contract.add(add_value);

assert(contract.get_value() == initial_value + add_value, 'wrong value after add');
}
}
}
2 changes: 1 addition & 1 deletion listings/ch00-introduction/interfaces_traits/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mod explicit;
mod implicit;
mod implicit_internal;
mod implicit_internal;
4 changes: 1 addition & 3 deletions listings/ch00-introduction/mappings/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
name = "maps"
version = "0.1.0"

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

[dependencies]
starknet = ">=2.0.1"
starknet = ">=2.1.0"

[[target.starknet-contract]]
4 changes: 1 addition & 3 deletions listings/ch00-introduction/storing_custom_types/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
name = "storing_custom_types"
version = "0.1.0"

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

[dependencies]
starknet = ">=2.0.1"
starknet = ">=2.1.0"

[[target.starknet-contract]]
4 changes: 2 additions & 2 deletions listings/ch00-introduction/storing_custom_types/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ mod StoringCustomType {
person: Person
}

// Deriving the storage_access::StorageAccess trait
// Deriving the starknet::Store trait
// allows us to store the `Person` struct in the contract's storage.
#[derive(Drop, storage_access::StorageAccess)]
#[derive(Drop, starknet::Store)]
struct Person {
age: u8,
name: felt252
Expand Down
2 changes: 1 addition & 1 deletion listings/ch00-introduction/testing/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ name = "tests"
version = "0.1.0"

[dependencies]
starknet = ">=2.0.1"
starknet = ">=2.1.0"

[[target.starknet-contract]]
3 changes: 2 additions & 1 deletion listings/ch00-introduction/testing/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ mod simple_contract_tests {
fn test_set_as_owner() {
// Fake the caller address to address 1
let owner = contract_address_const::<1>();
set_caller_address(owner);
set_contract_address(owner);

let contract = deploy(10);
assert(contract.get_owner() == owner, 'wrong owner');
Expand Down Expand Up @@ -132,3 +132,4 @@ mod simple_contract_tests {
}
// ANCHOR_END: test


4 changes: 1 addition & 3 deletions listings/ch00-introduction/variables/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
name = "variables"
version = "0.1.0"

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

[dependencies]
starknet = ">=2.0.1"
starknet = ">=2.1.0"

[[target.starknet-contract]]
4 changes: 1 addition & 3 deletions listings/ch00-introduction/visibility/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
name = "visibility"
version = "0.1.0"

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

[dependencies]
starknet = ">=2.0.1"
starknet = ">=2.1.0"

[[target.starknet-contract]]
4 changes: 1 addition & 3 deletions listings/ch01-advanced-concepts/storing_arrays/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
name = "storing_arrays"
version = "0.1.0"

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

[dependencies]
starknet = ">=2.0.1"
starknet = ">=2.1.0"

[[target.starknet-contract]]
Loading