Skip to content

Commit ff20c0e

Browse files
Update on-using-cheat-codes.md
1 parent f00289f commit ff20c0e

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

program-analysis/echidna/advanced/on-using-cheat-codes.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@
55
- [How and when to use cheat codes](#how-and-when-to-use-cheat-codes)
66
- [Introduction](#introduction)
77
- [Cheat codes available in Echidna](#cheat-codes-available-in-echidna)
8-
- [Advise on using cheat codes](#advise-on-using-cheat-codes)
8+
- [Advice on using cheat codes](#advice-on-using-cheat-codes)
99

1010
## Introduction
1111

12-
When solidity smart contract testing is performed from Solidity itself, usually requires some "help" in order to tackle some EVM/Solidity limitations.
13-
Cheat code are special functions that allow to change the state of the EVM in ways that are not posible in production. These were introduced by Dapptools in
14-
hevm and adopted (and expanded) in other projects such as Foundry.
12+
When testing smart contracts in Solidity itself, it can be helpful to use cheat codes in order to overcome some of the limitations of the EVM/Solidity.
13+
Cheat codes are special functions that allow to change the state of the EVM in ways that are not posible in production. These were introduced by Dapptools in hevm and adopted (and expanded) in other projects such as Foundry.
1514

1615
## Cheat codes available in Echidna
1716

1817
Since Echidna uses [hevm](https://github.com/ethereum/hevm), all the supported list of cheat code is documented here: https://hevm.dev/controlling-the-unit-testing-environment.html#cheat-codes.
1918
If a new cheat code is added in the future, Echidna only needs to update the hevm version and everything should work out of the box.
2019

21-
As an example, this is code "simulates" the use of another sender for the external call using "prank":
20+
As an example, the `prank` cheat code is able to set the `msg.sender` address in the context of the next external call:
2221

2322
```solidity
2423
interface IHevm {
@@ -32,16 +31,16 @@ contract TestPrank {
3231
3332
function prankContract() public payable {
3433
hevm.prank(address(0x42424242);
35-
c.f();
34+
c.f(); // `c` will be called with `msg.sender = 0x42424242`
3635
}
3736
}
3837
```
3938

4039
A specific example on the use of `sign` cheat code is available [here in our documentation](hevm-cheats-to-test-permit.md).
4140

42-
## Advise on how and when using cheat codes
41+
## Advice on how and when using cheat codes
4342

44-
While we provide support for the use of cheat codes, these should be used responsabily. We offer the following advise on the use of cheat codes:
43+
While we provide support for the use of cheat codes, these should be used responsibly. We offer the following advice on the use of cheat codes:
4544

4645
* It should be used only if Echidna will not perform the same action with a native feature. For instance, Echidna automatically increases the timestamp and block number. There are [some reports of the optimizer interfering with (re)computation of the block.number or timestamp](https://github.com/ethereum/solidity/issues/12963#issuecomment-1110162425), which could generate incorrect tests when using cheat codes.
4746
Using the corresponding built-in Echidna features should never intefer with the optimization level or any other compiler feature (if this happens, then it is a bug).

0 commit comments

Comments
 (0)