Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
💄 reorder chapter 2
Browse files Browse the repository at this point in the history
  • Loading branch information
omarespejel committed Oct 26, 2023
1 parent f6d3412 commit c7feaec
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 57 deletions.
13 changes: 7 additions & 6 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@

- [Tooling](ch02-00-starknet-tooling.md)
- [Basic Installation](ch02-01-basic-installation.md)
- [Introduction to Starkli, Scarb and Katana](ch02-01-introduction-starkli-scarb-katana.md)
- [Introduction: Starkli, Scarb and Katana](ch02-02-starkli-scarb-katana.md)
- [Scarb: The Package Manager](ch02-03-scarb.md)
- [Starkli: A CLI interface 🚧](ch02-04-starkli.md)
- [Katana: A Local Node](ch02-05-katana.md)
- [Katana: A Local Node](ch02-04-katana.md)
- [Using the Testnet 🚧]()
- [Foundry Cast: Interacting with Starknet](ch02-05-foundry-cast.md)
- [Example - Deployment Script](ch02-05-01-deployment-script.md)
- [Starknet Devnet 🚧](ch02-06-starknet-devnet.md)
- [Starknet-js: Javascript SDK](ch02-07-starknet-js.md)
- [Examples](ch02-07-01-examples.md)
Expand All @@ -23,11 +25,10 @@
- [Starknet-React: React Integration](ch02-08-starknet-react.md)
- [Examples](ch02-08-01-examples.md)
- [Beginner - ERC-20 UI](ch02-08-01-01-erc20-ui.md)
- [Intermediate - Million Dollar Homepage](ch02-07-01-02-million-dollar-homepage.md)
- [Intermediate - Million Dollar Homepage](ch02-08-01-02-million-dollar-homepage.md)
- [Starknet-py: Python SDK 🚧](ch02-09-starknet-py.md)
- [Starknet-rs: Rust SDK 🚧](ch02-10-starknet-rs.md)
- [Foundry Cast: Interacting with Starknet](ch02-11-foundry-cast.md)
- [Example - Deployment Script](ch02-11-01-deployment-script.md)
- [Starkli: Querying the Blockchain 🚧](ch02-11-starkli.md)
- [Foundry Forge: Testing](ch02-12-foundry-forge.md)

## Architecture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ Having compiled the smart contract, it's time to declare it with Starkli and kat
source .env
```

Next, launch Katana. In a separate terminal, run:
Next, launch Katana. In a separate terminal, run (more details in the Katan subchapter):

```bash
katana
Expand Down
42 changes: 18 additions & 24 deletions src/ch02-05-katana.md → src/ch02-04-katana.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
# Katana: A Local Node

`Katana` is an indispensable tool designed to aid in local development.
`Katana` is designed to aid in local development.
This creation by the [Dojo
team](https://github.com/dojoengine/dojo/blob/main/crates/katana/README.md)
enables you to perform all Starknet-related activities in a local
environment, thus serving as an efficient platform for development and
testing.

We suggest employing either `katana` or `starknet-devnet` for testing
your contracts, with the latter discussed in detail in the following
your contracts, with the latter discussed in another
subchapter. The `starknet-devnet` is a public testnet, maintained by the
[Shard Labs team](https://github.com/Shard-Labs/starknet-devnet). Both
[Shard Labs team](https://github.com/0xSpaceShard/starknet-devnet-rs). Both
these tools offer an effective environment for development and testing.

For an example of how to use `katana` to deploy and interact with a
contract, see [Chapter 2’s Voting contract
example](https://book.starknet.io/chapter_2/deploy_call_invoke.html).
contract, see the introduction subchapter of this Chapter or a voting contract example in [The Cairo Book](https://book.cairo-lang.org/ch99-01-04-01-voting-contract.html).

## Understanding RPC in Starknet

Expand All @@ -26,39 +25,34 @@ receiving these calls.

RPC can be obtained from various sources: . To support the
decentralization of the Network, you can use your own local Starknet
node. Consult [Chapter 4](https://book.starknet.io/chapter_4/node.html)
for guidelines on setting up your node. . For ease of access, consider
using a provider such as
node. For ease of access, consider using a provider such as
[Infura](https://docs.infura.io/networks/starknet/how-to) or
[Alchemy](https://www.alchemy.com/starknet) to get an RPC client. . For
development and testing, a temporary local node such as `katana` can be
used.

## Getting Started with Katana

To install `katana` from its source code, run the following commands:

mkdir ~/.dojo && cd ~/.dojo
git clone https://github.com/dojoengine/dojo
cd dojo
cargo install --path ./crates/katana --locked --force

Once installed, confirm it with the version command:
To install Katana, use the `dojoup` installer from the command line:

katana --version
```bash
curl -L https://install.dojoengine.org | bash
dojoup
```

Updating `katana` to its latest version involves going back to the
`dojo` directory and running the following commands:
After restarting your terminal, verify the installation with:

cd ~/.dojo/dojo
git pull
```bash
katana --version
```

# If you are using a local Starknet node, ensure to stop it first.
cargo install --path ./crates/katana --locked --force
To upgrade Katana, rerun the installation command.

To initialize a local Starknet node, execute the following command:

katana --accounts 3 --seed 0 --gas-price 250
```bash
katana --accounts 3 --seed 0 --gas-price 250
```

The `--accounts` flag determines the number of accounts to be created,
while the `--seed` flag sets the seed for the private keys of these
Expand Down
File renamed without changes.
9 changes: 9 additions & 0 deletions src/ch02-11-foundry-cast.md → src/ch02-05-foundry-cast.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Foundry Cast: Starknet CLI Interaction

[Starknet Foundry](https://github.com/foundry-rs/starknet-foundry) is a tool designed for testing and developing Starknet contracts. It is an adaptation of the Ethereum Foundry for Starknet, aiming to expedite the development process.

The project consists of two primary components:

- **Forge**: A testing tool specifically for Cairo contracts. This tool acts as a test runner and boasts features designed to enhance your testing process. Tests are written directly in Cairo, eliminating the need for other programming languages. Additionally, the Forge implementation uses Rust, mirroring Ethereum Foundry's choice of language.
- **Cast**: This serves as a DevOps tool for Starknet, initially supporting a series of commands to interface with Starknet. In the future, Cast aims to offer deployment scripts for contracts and other DevOps functions.

## Cast

Cast provides the Command Line Interface (CLI) for starknet, while Forge addresses testing. Written in Rust, Cast utilizes starknet Rust and integrates with Scarb. This integration allows for argument specification in `Scarb.toml`, streamlining the process.

`sncast` simplifies interaction with smart contracts, reducing the number of necessary commands compared to using `starkli` alone.
Expand Down
File renamed without changes.
31 changes: 5 additions & 26 deletions src/ch02-12-foundry-forge.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
# Foundry Forge: Testing

[Starknet Foundry](https://github.com/foundry-rs/starknet-foundry) is a tool designed for testing and developing Starknet contracts. It is an adaptation of the Ethereum Foundry for Starknet, aiming to expedite the development process.

The project consists of two primary components:

- **Forge**: A testing tool specifically for Cairo contracts. This tool acts as a test runner and boasts features designed to enhance your testing process. Tests are written directly in Cairo, eliminating the need for other programming languages. Additionally, the Forge implementation uses Rust, mirroring Ethereum Foundry's choice of language.
- **Cast**: This serves as a DevOps tool for StarkNet, initially supporting a series of commands to interface with StarkNet. In the future, Cast aims to offer deployment scripts for contracts and other DevOps functions.

## Forge

Merely deploying contracts is not the end game. Many tools have offered this capability in the past. Forge sets itself apart by hosting a Cairo VM instance, enabling the sequential execution of tests. It employs Scarb for contract compilation.

To utilize Forge, define test functions and label them with test attributes. Users can either test standalone Cairo functions or integrate contracts, dispatchers, and test contract interactions on-chain.
Expand Down Expand Up @@ -315,7 +306,7 @@ Collected 1 test from erc20_contract package
#### Utilizing Foundry Cheat Codes
When testing smart contracts, simulating different conditions is essential. `Foundry Cheat Codes` from the `snforge_std` library offer these simulation capabilities for StarkNet smart contracts.
When testing smart contracts, simulating different conditions is essential. `Foundry Cheat Codes` from the `snforge_std` library offer these simulation capabilities for Starknet smart contracts.
These cheat codes consist of helper functions that adjust the smart contract's environment. They allow developers to modify parameters or conditions to examine contract behavior in specific scenarios.
Expand Down Expand Up @@ -539,22 +530,10 @@ If a test fails, the output will resemble:
tests::test_erc20::tests::test_balance_of
```

## Key Takeaways:

- Starknet Foundry is a tool designed for testing and developing Starknet contracts.

- Forge allows you to write and run tests directly in Cairo.

- To set up a new project with Starknet Foundry, you can use the snforge command-line tool with the --init option.

- You can integrate snforge with existing Scarb projects by adding the snforge_std dependency.

- The example demonstrates how to test a Starknet contract using snforge and the expected output format.

- Fuzz testing is used to identify vulnerabilities by introducing random inputs to the code. You can configure the number of runs and the seed for the test.
### Conclusion

- You can filter tests using the snforge command, allowing you to execute specific tests based on their names or other criteria.
Starknet Foundry offers a notable step forward in Starknet contract development and testing. This toolset sharpens the process of creating, deploying, and testing Cairo contracts. Its main components, Forge and Cast, provide developers with robust tools for Cairo contract work.

- The --exit-first flag can be used to stop the test suite upon the first test failure, providing detailed information about the failure.
Forge shines with its dual functionality: deploying and thoroughly testing Cairo contracts. It directly supports test writing in Cairo, removing the need for other languages and simplifying the task. Moreover, Forge seamlessly integrates with Scarb, emphasizing its adaptability, especially with existing Scarb projects.

Overall, Starknet Foundry simplifies the testing and development process for Starknet contracts by providing tools and features for effective contract testing and debugging.
The `snforge` command-line tool makes initializing, setting up, and testing Starknet contracts straightforward.

0 comments on commit c7feaec

Please sign in to comment.