Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
Add an example of fuzzing soroban contracts.
Why
This example supports the fuzzing features added to the SDK in stellar/rs-soroban-sdk#957.
Once landed it will be supported by this tutorial for soroban-docs: stellar-deprecated/soroban-docs#486
It is probably best to review both patches simultaneously in case any changes are needed to the example to support changes requested in the docs.
This example demonstrates how to write fuzz tests and fuzz with cargo-fuzz, and how to convert fuzz tests to proptests.
The contract added here under
fuzzing
is a duplicate of the timelock example, with some changes to illustrate fuzzing features required by the accompanying soroban-docs patch. That patch, linked above, explains this example comprehensively, so it may help reviewing. Differences from the timelock example include: an extra check that the balance is nonzero, the ability to make multiple withdrawals.The duplication of the timelock contract is perhaps unfortunate, but I think useful - the contract is not the point of this example, and readers will potentially already be familiar with it by the time they read the fuzzing tutorial. It is ok for the fuzzing version of the timelock contract to drift from the main timelock contract during maintenance; they do not need to be exactly the same.
A few lines of the contract are commented out purposely so that the fuzzers will fail. The tutorial illustrates this and expects the reader to fix it.
Known limitations
It duplicates the timelock example.
The makefile runs
cargo check
on the fuzz tests to ensure that they build for CI, but it does not actually run the fuzzer because that would require ensuringcargo-fuzz
is installed.