From c7feaec38a044cda860cccdd235ad0e075441e11 Mon Sep 17 00:00:00 2001 From: "Omar U. Espejel" Date: Thu, 26 Oct 2023 17:08:38 +0700 Subject: [PATCH] :lipstick: reorder chapter 2 --- src/SUMMARY.md | 13 +++--- ...ana.md => ch02-02-starkli-scarb-katana.md} | 2 +- src/{ch02-05-katana.md => ch02-04-katana.md} | 42 ++++++++----------- ...ipt.md => ch02-05-01-deployment-script.md} | 0 ...oundry-cast.md => ch02-05-foundry-cast.md} | 9 ++++ ... ch02-08-01-02-million-dollar-homepage.md} | 0 ...{ch02-04-starkli.md => ch02-11-starkli.md} | 0 src/ch02-12-foundry-forge.md | 31 +++----------- 8 files changed, 40 insertions(+), 57 deletions(-) rename src/{ch02-01-introduction-starkli-scarb-katana.md => ch02-02-starkli-scarb-katana.md} (98%) rename src/{ch02-05-katana.md => ch02-04-katana.md} (78%) rename src/{ch02-11-01-deployment-script.md => ch02-05-01-deployment-script.md} (100%) rename src/{ch02-11-foundry-cast.md => ch02-05-foundry-cast.md} (95%) rename src/{ch02-07-01-02-million-dollar-homepage.md => ch02-08-01-02-million-dollar-homepage.md} (100%) rename src/{ch02-04-starkli.md => ch02-11-starkli.md} (100%) diff --git a/src/SUMMARY.md b/src/SUMMARY.md index b9db86f92..ca189a0be 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -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) @@ -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 diff --git a/src/ch02-01-introduction-starkli-scarb-katana.md b/src/ch02-02-starkli-scarb-katana.md similarity index 98% rename from src/ch02-01-introduction-starkli-scarb-katana.md rename to src/ch02-02-starkli-scarb-katana.md index b2fbdf022..33b5444b6 100644 --- a/src/ch02-01-introduction-starkli-scarb-katana.md +++ b/src/ch02-02-starkli-scarb-katana.md @@ -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 diff --git a/src/ch02-05-katana.md b/src/ch02-04-katana.md similarity index 78% rename from src/ch02-05-katana.md rename to src/ch02-04-katana.md index d3fb88f5a..d80edab14 100644 --- a/src/ch02-05-katana.md +++ b/src/ch02-04-katana.md @@ -1,6 +1,6 @@ # 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 @@ -8,14 +8,13 @@ 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 @@ -26,9 +25,7 @@ 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 @@ -36,29 +33,26 @@ 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 diff --git a/src/ch02-11-01-deployment-script.md b/src/ch02-05-01-deployment-script.md similarity index 100% rename from src/ch02-11-01-deployment-script.md rename to src/ch02-05-01-deployment-script.md diff --git a/src/ch02-11-foundry-cast.md b/src/ch02-05-foundry-cast.md similarity index 95% rename from src/ch02-11-foundry-cast.md rename to src/ch02-05-foundry-cast.md index 5be1fa3a8..dde2eb35c 100644 --- a/src/ch02-11-foundry-cast.md +++ b/src/ch02-05-foundry-cast.md @@ -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. diff --git a/src/ch02-07-01-02-million-dollar-homepage.md b/src/ch02-08-01-02-million-dollar-homepage.md similarity index 100% rename from src/ch02-07-01-02-million-dollar-homepage.md rename to src/ch02-08-01-02-million-dollar-homepage.md diff --git a/src/ch02-04-starkli.md b/src/ch02-11-starkli.md similarity index 100% rename from src/ch02-04-starkli.md rename to src/ch02-11-starkli.md diff --git a/src/ch02-12-foundry-forge.md b/src/ch02-12-foundry-forge.md index 10b42a607..9fe1b55b7 100644 --- a/src/ch02-12-foundry-forge.md +++ b/src/ch02-12-foundry-forge.md @@ -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. @@ -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. @@ -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.