From de75fd7d206e1df1bd2cbaec7ffe14ba7f152dbe Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 30 Aug 2022 11:26:23 -0700 Subject: [PATCH] Update the tutorial for creating a project (#89) --- docs/tutorials/create-a-project.mdx | 44 +++++++++++++---------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/docs/tutorials/create-a-project.mdx b/docs/tutorials/create-a-project.mdx index af1ee70e..27e2eb88 100644 --- a/docs/tutorials/create-a-project.mdx +++ b/docs/tutorials/create-a-project.mdx @@ -47,25 +47,23 @@ The `soroban-sdk` is in early development. Report issues soroban-sdk = "0.0.4" [dev_dependencies] -project-name = { path = ".", features = ["testutils"] } +soroban-sdk = { version = "0.0.4", features = ["testutils"] } [features] -default = ["export"] -export = [] testutils = ["soroban-sdk/testutils"] ``` -The `features` list and `dev_dependencies` configure three variations that the -contract can be built with: -- By `default`, with `export` enabled, contract functions will be exported and -available to be invoked when the contract is deployed. -- Optionally without `export` enabled, contract functions will not be exported. -Types will be still exposed, which is useful when developing multiple contracts -together and this contract is to be imported into another but its functions are -not intended to be invoked. -- And `testutils` which will cause additional test utilities to be generated for -calling the contract in tests. The library itself is added as a `dev_dependencies` -so that whenever its tests are running the `testutils` feature is enabled. +The `features` list includes a `testutils` feature, which will cause additional +test utilities to be generated for calling the contract in tests. + +:::info +The `testutils` test utilities are automatically enabled inside [Rust unit +tests] inside the same crate as your contract. If you write [Rust integration +tests], or write tests from another crate, you'll need to add `#[cfg(feature = +"testutils")]` to those tests and enable the `testutils` feature when running +your tests with `cargo test --features testutils` to be able to use those test +utilities. +::: ## Configure the `release` Profile @@ -92,24 +90,17 @@ lto = true The steps below should produce a `Cargo.toml` that looks like so. ```toml title="Cargo.toml" -[package] -name = "project-name" -version = "0.1.0" -edition = "2021" - [lib] crate-type = ["cdylib", "rlib"] +[features] +testutils = ["soroban-sdk/testutils"] + [dependencies] soroban-sdk = "0.0.4" [dev_dependencies] -project-name = { path = ".", features = ["testutils"] } - -[features] -default = ["export"] -export = [] -testutils = ["soroban-sdk/testutils"] +soroban-sdk = { version = "0.0.4", features = ["testutils"] } [profile.release] opt-level = "z" @@ -121,3 +112,6 @@ panic = "abort" codegen-units = 1 lto = true ``` + +[Rust unit tests]: https://doc.rust-lang.org/rust-by-example/testing/unit_testing.html +[Rust integration tests]: https://doc.rust-lang.org/rust-by-example/testing/integration_testing.html