Skip to content

Commit ef19db0

Browse files
authored
Merge pull request #325 from crytic/dev-expand-testing-modes
Expanded testing modes with missing information
2 parents b4fdd8c + 08aaac6 commit ef19db0

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

program-analysis/echidna/basic/testing-modes.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@ Echidna offers several ways to write properties, which often leaves developers a
44

55
**Table of Contents:**
66

7+
- [Introduction](#introduction)
78
- [Boolean Properties](#boolean-properties)
89
- [Assertions](#assertions)
910
- [Dapptest](#dapptest)
11+
- [Other testing modes](#other-testing-modes)
1012
- [Stateless vs. Stateful](#stateless-vs-stateful)
1113

14+
## Introduction
15+
16+
Echidna offer a variety of different testing modes. These can be selected using the `testingMode` config option or using the `--testing-mode` parameter. Each mode will be explained, highlighting the keyword needed for the configuration.
17+
1218
## Boolean Properties
1319

14-
By default, the "property" testing mode is used, which reports failures using special functions called properties:
20+
By default, the `property` testing mode is used, which reports failures using special functions called properties:
1521

1622
- Testing functions should be named with a specific prefix (e.g. `echidna_`).
1723
- Testing functions take no parameters and always return a boolean value.
@@ -57,7 +63,7 @@ This mode can be used when a property can be easily computed from the use of sta
5763

5864
## Assertions
5965

60-
Using the "assertion" testing mode, Echidna will report an assert violation if:
66+
Using the `assertion` testing mode, Echidna will report an assert violation if:
6167

6268
- The execution reverts during a call to `assert`. Technically speaking, Echidna will detect an assertion failure if it executes an `assert` call that fails in the first call frame of the target contract (so this excludes most internal transactions).
6369
- An `AssertionFailed` event (with any number of parameters) is emitted by any contract. This pseudo-code summarizes how assertions work:
@@ -119,7 +125,7 @@ function testStake(uint256 toStake) public {
119125

120126
## Dapptest
121127

122-
Using the "dapptest" testing mode, Echidna will report violations using certain functions following how dapptool and foundry work:
128+
Using the `dapptest` testing mode, Echidna will report violations using certain functions following how dapptool and foundry work:
123129

124130
- This mode uses any function name with one or more arguments, which will trigger a failure if they revert, except in one special case. Specifically, if the execution reverts with the special reason “FOUNDRY::ASSUME”, then the test will pass (this emulates how [the `assume` foundry cheat code works](https://github.com/gakonst/foundry/commit/7dcce93a38345f261d92297abf11fafd6a9e7a35#diff-47207bb2f6cf3c4ac054647e851a98a57286fb9bb37321200f91637262d3eabfR90-R96)). This pseudo-code summarizes how dapptests work:
125131

@@ -151,6 +157,14 @@ function checkDappTest(..) public { // One or more arguments are required
151157

152158
Use dapptest mode if you are testing stateless invariants and the code will never unexpectedly revert. Avoid using it for stateful testing, as it was not designed for that (although Echidna supports it).
153159

160+
## Other testing modes
161+
162+
Echidna allows other testing mode, which are less frecuently used:
163+
164+
- `overflow` mode: this mode is similar to `assertion` but it will only catch integer overflow (so no need to define any function with assertions). **It only works in solc 0.8.x or greater, for code outside `unchecked` blocks**.
165+
- `optimization` mode: this mode allows to maximize the value returned by a function. It is explained in detail in [its own tutorial](../advanced/optimization_mode.md).
166+
- `exploration` mode: this mode will not use any kind of invariants to check, allowing Echidna to collect coverage.
167+
154168
## Stateless vs. Stateful
155169

156170
Any of these testing modes can be used, in either stateful (by default) or stateless mode (using `--seqLen 1`). In stateful mode, Echidna will maintain the state between each function call and attempt to break the invariants. In stateless mode, Echidna will discard state changes during fuzzing. There are notable differences between these two modes.

0 commit comments

Comments
 (0)