Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch committed Dec 19, 2024
1 parent b8c918f commit 62b26f4
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/build/guides/testing/differential-tests.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Assuming the contract has been deployed, and changes are being made to the local
3. Run the test to compare the baseline and local observable outcomes.

This test uses the same patterns used in [unit tests] and [integration tests]:

1. Create an environment, the `Env`.
2. Import the Wasm contract to compare with.
3. Register the local contract to be tested.
Expand Down
17 changes: 9 additions & 8 deletions docs/build/guides/testing/fuzzing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ The following steps can be used in any Stellar contract workspace. If experiment
$ cargo fuzz init
```

2. Open the contract's `Cargo.toml` file. Add `lib` as a `crate-type`.
3. Open the contract's `Cargo.toml` file. Add `lib` as a `crate-type`.

```diff
[lib]
-crate-type = ["cdylib"]
+crate-type = ["lib", "cdylib"]
```

2. Open the generated `fuzz/Cargo.toml` file. Add the `soroban-sdk` dependency.
4. Open the generated `fuzz/Cargo.toml` file. Add the `soroban-sdk` dependency.

```diff
[dependencies]
libfuzzer-sys = "0.4"
+soroban-sdk = { version = "*", features = ["testutils"] }
```

3. Open the generated `fuzz/src/fuzz_target_1.rs` file. It will look like the below.
5. Open the generated `fuzz/src/fuzz_target_1.rs` file. It will look like the below.

```rust
#![no_main]
Expand All @@ -52,7 +52,7 @@ The following steps can be used in any Stellar contract workspace. If experiment
});
```

4. Fill out the `fuzz_target!` call with test setup and assertions. For example, for the [increment example]:
6. Fill out the `fuzz_target!` call with test setup and assertions. For example, for the [increment example]:

```rust
#![no_main]
Expand Down Expand Up @@ -85,7 +85,7 @@ The following steps can be used in any Stellar contract workspace. If experiment
});
```

5. Execute the fuzz target.
7. Execute the fuzz target.

```
cargo +nightly fuzz run --sanitizer=thread fuzz_target_1
Expand All @@ -98,10 +98,11 @@ The following steps can be used in any Stellar contract workspace. If experiment
:::

This test uses the same patterns used in [unit tests] and [integration tests]:

1. Create an environment, the `Env`.
3. Register the contract to be tested.
4. Invoke functions using a client.
5. Assert expectations.
2. Register the contract to be tested.
3. Invoke functions using a client.
4. Assert expectations.

:::tip

Expand Down
1 change: 1 addition & 0 deletions docs/build/guides/testing/integration-tests.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fn test() {
```

Most tests, whether they're unit, mocks, or integration tests, will look very similar to the test above. The tests will do four things:

1. Create an environment, the `Env`.
2. Register the contract(s) to be tested.
3. Invoke functions using the generated client.
Expand Down
2 changes: 2 additions & 0 deletions docs/build/guides/testing/mocking.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fn test_notpaused() {
```

The following test checks that when the pause contract is paused, the increment contract function rejects attempts to increment.

```rust
#![cfg(test)]
use crate::{Error, IncrementContract, IncrementContractArgs, IncrementContractClient, Pause};
Expand Down Expand Up @@ -95,6 +96,7 @@ fn test_paused() {
```

Most tests, whether you're writing unit, mocks, or integration tests, will look very similar to these tests. They'll do four things:

1. Create an environment, the `Env`.
2. Register the contract(s) to be tested.
3. Invoke functions using the generated client.
Expand Down
1 change: 1 addition & 0 deletions docs/build/guides/testing/test-with-mainnet-data.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ fn test() {
```

Most tests, whether they're unit, mocks, or integration tests, will look very similar to the test above. The tests will do four things:

1. Create an environment, the `Env`.
2. Register the contract(s) to be tested.
3. Invoke functions using the generated client.
Expand Down
2 changes: 1 addition & 1 deletion docs/build/guides/testing/unit-tests.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Ref: https://github.com/stellar/soroban-examples/blob/main/increment/src/test.rs
In the test there's a full environment setup, used, and torn down in the test, and it happens fast. The Rust test harness runs all the tests for a contract in parallel and each will have its own isolated contract environment.

Most tests, even integration tests and fuzz tests, will look very similar to this unit test. They'll do four things:

1. Create an environment, the `Env`.

```rust
Expand All @@ -58,7 +59,6 @@ Most tests, even integration tests and fuzz tests, will look very similar to thi
assert_eq!(client.increment(), 1);
```


:::tip

Tests are written in Rust, alongside the contract. Same tools. Same APIs. Same SDK. No context switching! Use your favorite Rust tools and libraries that you'd use for any Rust test.
Expand Down

0 comments on commit 62b26f4

Please sign in to comment.