Skip to content

Commit

Permalink
Variety of small fixes (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch authored Aug 1, 2022
1 parent 84511af commit 0941913
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 29 deletions.
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 prerequisites:

- 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

0 comments on commit 0941913

Please sign in to comment.