Skip to content

Commit 24cbabc

Browse files
run format
1 parent fffd5c0 commit 24cbabc

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ When testing smart contracts in Solidity itself, it can be helpful to use cheat
1313
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.
1414

1515
## Cheat codes available in Echidna
16-
Echidna supports all cheat codes that are available in [hevm](https://github.com/ethereum/hevm). These are documented here: https://hevm.dev/controlling-the-unit-testing-environment.html#cheat-codes.
16+
17+
Echidna supports all cheat codes that are available in [hevm](https://github.com/ethereum/hevm). These are documented here: https://hevm.dev/controlling-the-unit-testing-environment.html#cheat-codes.
1718
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.
1819

1920
As an example, the `prank` cheat code is able to set the `msg.sender` address in the context of the next external call:
@@ -27,7 +28,7 @@ contract TestPrank {
2728
address constant HEVM_ADDRESS = 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D;
2829
IHevm hevm = IHevm(HEVM_ADDRESS);
2930
Contract c = ...
30-
31+
3132
function prankContract() public payable {
3233
hevm.prank(address(0x42424242);
3334
c.f(); // `c` will be called with `msg.sender = 0x42424242`
@@ -41,10 +42,10 @@ A specific example on the use of `sign` cheat code is available [here in our doc
4142

4243
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:
4344

44-
* It can break certain assumptions in Solidity. For example, the compiler assumes that `block.number` is constant during a transaction. There are [reports of the optimizer interfering with (re)computation of the `block.number` or `block.timestamp`](https://github.com/ethereum/solidity/issues/12963#issuecomment-1110162425), which can generate incorrect tests when using cheat codes.
45+
- It can break certain assumptions in Solidity. For example, the compiler assumes that `block.number` is constant during a transaction. There are [reports of the optimizer interfering with (re)computation of the `block.number` or `block.timestamp`](https://github.com/ethereum/solidity/issues/12963#issuecomment-1110162425), which can generate incorrect tests when using cheat codes.
4546

46-
* It can introduce false positives on the testing. For instance, using `prank` to simulate calls from a contract can allow transactions that are not possible in the blockchain.
47+
- It can introduce false positives on the testing. For instance, using `prank` to simulate calls from a contract can allow transactions that are not possible in the blockchain.
4748

48-
* Using too many cheat codes:
49-
* can be confusing or error-prone. Certain cheat code like `prank` allow to change caller in the next external call: It can be difficult to follow, in particular if it is used in internal functions or modifiers.
50-
* will create a dependency of your code with the particular tool or cheat code implementation: It can cause produce migrations to other tools or reusing the test code to be more difficult than expected.
49+
- Using too many cheat codes:
50+
- can be confusing or error-prone. Certain cheat code like `prank` allow to change caller in the next external call: It can be difficult to follow, in particular if it is used in internal functions or modifiers.
51+
- will create a dependency of your code with the particular tool or cheat code implementation: It can cause produce migrations to other tools or reusing the test code to be more difficult than expected.

0 commit comments

Comments
 (0)