-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from CoinFabrik/122-write-assert-violation-do…
…cumentation 122 write assert violation documentation
- Loading branch information
Showing
4 changed files
with
44 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Assert violation | ||
|
||
### What it does | ||
|
||
Checks for `assert!` macro usage. | ||
|
||
### Why is this bad? | ||
|
||
The `assert!` macro can cause the contract to panic. | ||
|
||
### Example | ||
|
||
```rust | ||
pub fn assert_if_greater_than_10(_env: Env, value: u128) -> bool { | ||
assert!(value <= 10, "value should be less than 10"); | ||
true | ||
} | ||
|
||
``` | ||
Use instead: | ||
|
||
```rust | ||
pub fn assert_if_greater_than_10(_env: Env, value: u128) -> Result<bool, AVError> { | ||
if value <= 10 { | ||
Ok(true) | ||
} else { | ||
Err(AVError::GreaterThan10) | ||
} | ||
} | ||
``` | ||
### Implementation | ||
|
||
The detector's implementation can be found at [this link](https://github.com/CoinFabrik/scout-soroban/tree/main/detectors/assert-violation). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters