Skip to content

Commit

Permalink
Fix "Sway Quickstart" (FuelLabs#3388)
Browse files Browse the repository at this point in the history
Changelog:

- [x] Fix name of "Sway Quickstart" document
- [x] Remove all references to tests in "Sway Quickstart"
- [x] Use underscore in "fuel_toolchain.md" file name

I have removed all references to the tests because as of the latest
version of `forc`, which v0.31.1 at the time of writing, the default
project that gets created with `forc new project_name` doesn't contain a
`tests` directory anymore.

Co-authored-by: Kaya Gökalp <[email protected]>
  • Loading branch information
PaulRBerg and kayagokalp authored Nov 21, 2022
1 parent 11795d9 commit 1d47c4f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 46 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions docs/src/introduction/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
To get started with Forc and Sway smart contract development, install the Fuel toolchain and Fuel full node and set up your first project.

- [Installation](./installation.md)
- [Getting Started](./overview.md)
- [The Fuel Toolchain](./fuel-toolchain.md)
- [Sway Quickstart](./sway_quickstart.md)
- [The Fuel Toolchain](./fuel_toolchain.md)
- [A Forc Project](./forc_project.md)
- [Standard Library](./standard_library.md)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Sway Quickstart

Follow this guide to write, test, and deploy a simple smart contract in Sway.
Follow this guide to write and deploy a simple smart contract in Sway.

Check out the [Developer Quickstart Guide](https://fuellabs.github.io/fuel-docs/master/developer-quickstart.html) for a step-by-step guide on building a fullstack dapp on Fuel. The guide will walk you through writing a smart contract, setting up a wallet, and building a frontend to interact with your contract.

Expand Down Expand Up @@ -48,12 +48,9 @@ Here is the project that Forc has initialized:
```console
$ cd counter_contract
$ tree .
├── Cargo.toml
├── Forc.toml
├── src
│   └── main.sw
└── tests
└── harness.rs
└── src
   └── main.sw
```

`Forc.toml` is the _manifest file_ (similar to `Cargo.toml` for Cargo or `package.json` for Node), and defines project metadata such as the project name and dependencies.
Expand Down Expand Up @@ -196,46 +193,11 @@ Logs:
TransactionId(HexFormatted(7cef24ea33513733ab78c5daa5328d622d4b38187d0f0d1857b272090d99f96a))
```

Note the contract IDyou will need it if you want to build out a frontend to interact with this contract.
Note the contract IDyou will need it if you want to build out a frontend to interact with this contract.

## Testing your Contract
## Testing Your Contract

In the directory `tests`, navigate to `harness.rs.` Here you'll see there is some boilerplate code to help you start interacting with and testing your contract.

At the bottom of the file, define the body of `can_get_contract_instance`. Here is what your code should look like to verify that the value of the counter did get incremented:

```sway
#[tokio::test]
async fn can_get_contract_instance() {
// Increment the counter
let _result = instance.increment().call().await.unwrap();
// Get the current value of the counter
let result = instance.counter().call().await.unwrap();
assert!(result.value > 0);
}
```

Run the following command in the terminal: `forc test`.

You'll see something like this as your output:

```console
Compiled library "core".
Compiled library "std".
Compiled contract "counter_contract".
Bytecode size is 224 bytes.
Compiling counter_contract v0.1.0 (<path/to/counter_contract>)
Finished test [unoptimized + debuginfo] target(s) in 4.55s
Running tests/harness.rs (target/debug/deps/integration_tests-7a2922c770587b45)

running 1 test
test can_get_contract_id ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.09s
```

Congratulations, you've just created and tested your first Sway smart contract 🎉.
We will cover how to test your contract later but, if you are eager to take a look, see [Unit Testing](../testing/unit-testing.md) and [Testing with Rust](../testing/testing-with-rust.md).

## Next Steps

Expand Down

0 comments on commit 1d47c4f

Please sign in to comment.