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

Variety of small fixes #65

Merged
merged 5 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 8 additions & 8 deletions docs/examples/hello-world.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ pub struct HelloContract;

Contract functions look much like regular Rust functions. They mave have any
number of arguments, but arguments must support being transmitted to and from
the Host environment that the contract runs in. The Soroban SDK provides some
types like `Symbol`, `Vec`, `Map`, `Binary`, `FixedBinary`, etc that can be
used. Primitive values like `u64`, `i64`, `u32`, `i32`, and `bool` can also be
used. Floats are not supported.
the Soroban environment that the contract runs in. The Soroban SDK provides some
types like `Vec`, `Map`, `BigInt`, `Symbol`, `Binary`, `FixedBinary`, etc that
can be used. Primitive values like `u64`, `i64`, `u32`, `i32`, and `bool` can
also be used. Floats are not supported.

Contract inputs must not be references.

If the first argument of a contract function is of the `soroban_sdk::Env` type,
an `Env` will be provided that provides access to Host functionality. Most
functionality within the SDK requires an Env, so it is recommended to have it in
the argument list for most functions.
an `Env` will be provided that provides access to additional functionality. Most
functionality within the SDK requires an `Env`, so it is recommended to have it
in the argument list for most functions.

```rust
#[contractimpl]
Expand Down Expand Up @@ -115,7 +115,7 @@ fn test() {
```

In any test the first thing that is always required is an `Env`, which is the
Host environment that the contract will run it.
Soroban environment that the contract will run it.

```rust
let env = Env::default();
Expand Down
8 changes: 4 additions & 4 deletions docs/getting-started/quick-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ test test::test ... ok

Try changing the values in the test to see how it works.

## Build WASM
## Build the Contract

To build the contract into a `.wasm` file, use the `cargo build` command.

Expand All @@ -142,10 +142,10 @@ A `.wasm` file should be outputted in the `target` directory:
target/wasm32-unknown-unknown/release/first-project.wasm
```

## Run the WASM
## Run the Contract

If you have [`soroban-cli`] installed, you can invoke contract functions in the
WASM using it.
contract.

```sh
soroban-cli invoke \
Expand All @@ -155,7 +155,7 @@ soroban-cli invoke \
--arg friend
```

The following output should occur using the code above.
You should see the following output:

```json
["Hello","friend"]
Expand Down
8 changes: 3 additions & 5 deletions docs/getting-started/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ title: Setup

Soroban contracts are small programs written in the [Rust] programming language.

To build and develop contracts you need only a couple pre-requisites: To setup
your development environment to develop contracts, you need only a couple
pre-requisites:
To build and develop contracts you need only a couple pre-requisites:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're doing some clean-ups, I think prerequisites is actually a single word without hyphen.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, bundled a fix into 0f6fa9e.


- A [Rust] toolchain
- An editor that supports Rust
Expand Down Expand Up @@ -40,8 +38,8 @@ https://www.rust-lang.org/tools

## Install the Soroban CLI

The Soroban CLI can execute WASM contracts in the same environment the contract
will execute on network, however in a local sandbox.
The Soroban CLI can execute Soroban contracts in the same environment the
contract will execute on network, however in a local sandbox.

Install the Soroban CLI using `cargo install`.

Expand Down
12 changes: 7 additions & 5 deletions docs/tutorials/build-and-run.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,28 @@ title: Build and Run

## Build a Contract

To build a Soroban contract into a `.wasm` file, use the `cargo build` command.
To build a Soroban contract to deploy or run with the [`soroban-cli`], use the
`cargo build` command.

```sh
cargo build --target wasm32-unknown-unknown --release
```

A `.wasm` file should be outputted in the `target` directory:
A `.wasm` file will be outputted in the `target` directory. The `.wasm` file is
the built contract.

```
target/wasm32-unknown-unknown/release/[project-name].wasm
```

## Run a Contract

If you have [`soroban-cli`] installed, you can invoke contract functions in a
WASM file.
If you have the [`soroban-cli`] installed, you can invoke contract functions
that have been built.

Using the code we wrote in [Write a Contract] and the resulting `.wasm` file
we built in [Build and Run] run the following command to invoke the `hello`
function with a single argument `"friend"`.
function with a single argument `friend`.

```sh
soroban-cli invoke \
Expand Down
3 changes: 2 additions & 1 deletion docs/tutorials/build-optimized.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ It is highly recommended to use the release profile outlined in [Configure the
Release Profile], otherwise the contract will be too large to deploy or run.
:::

[Create a Project]: create-a-project#configure-the-release-profile
[Configure the Release Profile]: create-a-project#configure-the-release-profile

## Install Rust `nightly`

To install the nightly Rust toolchain use `rustup`.

```sh
rustup install nightly
rustup target add --toolchain nightly wasm32-unknown-unknown
```

## Install `wasm-opt`
Expand Down
24 changes: 17 additions & 7 deletions docs/tutorials/testing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ sidebar_position: 5
title: Testing
---

Writing tests for Soroban contracts involves writing Rust code using the Rust
test facilities and toolchain that you'd use for testing any Rust code.
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

Writing tests for Soroban contracts involves writing Rust code using the test
facilities and toolchain that you'd use for testing any Rust code.

Given a simple contract like the contract demonstrated in [Write a
Contract](write-a-contract.mdx).
Contract](write-a-contract.mdx), a simple test will look like this.

<Tabs>
<TabItem value="lib.rs" label="src/lib.rs">

```rust title="src/lib.rs"
```rust
#![no_std]
use soroban_sdk::{contractimpl, vec, Env, Symbol, Vec};

Expand All @@ -24,9 +30,10 @@ impl Contract {
}
```

A simple test will look like this.
</TabItem>
<TabItem value="test.rs" label="src/test.rs" default>

```rust title="src/test.rs"
```rust
#![cfg(test)]

use super::{Contract, hello};
Expand All @@ -46,8 +53,11 @@ fn test() {
}
```

</TabItem>
</Tabs>

In any test the first thing that is always required is an `Env`, which is the
Host environment that the contract will run it.
Soroban environment that the contract will run inside of.

```rust
let env = Env::default();
Expand Down
15 changes: 8 additions & 7 deletions docs/tutorials/write-a-contract.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ how to setup a project.

Many of the types available in typical Rust programs, such as `std::vec::Vec`,
are not available, as there is no allocator and no heap memory in Soroban
contracts. The `soroban-sdk` provides a variety of types like `Vec`, `Map`, and
`BigInt`, `Binary`, `FixedBinary`, that all utilize the Host environment's memory
and native capabilities.
contracts. The `soroban-sdk` provides a variety of types like `Vec`, `Map`,
`BigInt`, `Binary`, `FixedBinary`, that all utilize the Soroban environment's
memory and native capabilities.

```rust
pub struct Contract;
Expand All @@ -40,10 +40,11 @@ impl Contract {
}
```

Contract functions live inside a `impl` for a struct. The `impl` block is
annotated with `#[contractimpl]`, and the functions that are intended to be
called are assigned `pub` visibility and have an `Env` argument as their first
argument.
Contract functions live inside an `impl` for a struct. The `impl` block is
annotated with `#[contractimpl]`. Functions that are intended to be called
externally are should be marked with `pub` visibility. The first argument can be
an `Env` argument to get a copy of the Soroban environment, which is necessary
for most things.

Implementations annotated can be configured to export the contract functions
only if a feature is enabled, with `export_if = "[feature-name]"`.
Expand Down