Skip to content

Commit a180645

Browse files
authored
Merge pull request #65 from nisedo/dev-rename-util-files-to-match-contracts
Fix #43: Rename util files to match contract names
2 parents ea832b9 + 831af2e commit a180645

File tree

12 files changed

+110
-63
lines changed

12 files changed

+110
-63
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ Run the test suite using `echidna . --contract CryticABDKMath64x64Harness --seq-
491491

492492
# Helper functions
493493

494-
The repository provides a collection of functions and events meant to simplify the debugging and testing of assertions in Echidna. Commonly used functions, such as integer clamping or logging for different types are available in [contracts/util/PropertiesHelper.sol](contracts/util/PropertiesHelper.sol).
494+
The repository provides a collection of functions and events meant to simplify the debugging and testing of assertions in Echidna. Commonly used functions, such as integer clamping or logging for different types are available in [contracts/util/PropertiesAsserts.sol](contracts/util/PropertiesAsserts.sol).
495495

496496
Available helpers:
497497

@@ -508,7 +508,7 @@ Log a value for debugging. When the assertion is violated, the value of `someVal
508508
```solidity
509509
pragma solidity ^0.8.0;
510510
511-
import "@crytic/properties/contracts/util/PropertiesHelper.sol";
511+
import "@crytic/properties/contracts/util/PropertiesAsserts.sol";
512512
513513
contract TestProperties is PropertiesAsserts {
514514
// ...
@@ -536,7 +536,7 @@ Assert equality, and log violations:
536536
```solidity
537537
pragma solidity ^0.8.0;
538538
539-
import "@crytic/properties/contracts/util/PropertiesHelper.sol";
539+
import "@crytic/properties/contracts/util/PropertiesAsserts.sol";
540540
541541
contract TestProperties is PropertiesAsserts {
542542
// ...
@@ -564,7 +564,7 @@ Assure that a function's fuzzed parameter is in a certain range:
564564
```solidity
565565
pragma solidity ^0.8.0;
566566
567-
import "@crytic/properties/contracts/util/PropertiesHelper.sol";
567+
import "@crytic/properties/contracts/util/PropertiesAsserts.sol";
568568
569569
contract TestProperties is PropertiesAsserts {
570570
int256 constant MAX_VALUE = 2 ** 160;
@@ -584,7 +584,7 @@ contract TestProperties is PropertiesAsserts {
584584

585585
# HEVM cheat codes support
586586

587-
Since version 2.0.5, Echidna supports [HEVM cheat codes](https://hevm.dev/std-test-tutorial.html#supported-cheat-codes). This repository contains a [`Hevm.sol`](contracts/util/Hevm.sol) contract that exposes cheat codes for easy integration into contracts under test.
587+
Since version 2.0.5, Echidna supports [HEVM cheat codes](https://hevm.dev/std-test-tutorial.html#supported-cheat-codes). This repository contains a [`IHevm.sol`](contracts/util/IHevm.sol) contract that exposes cheat codes for easy integration into contracts under test.
588588

589589
Cheat codes should be used with care, since they can alter the execution environment in ways that are not expected, and may introduce false positives or false negatives.
590590

@@ -595,7 +595,7 @@ Use `prank` to simulate a call from a different `msg.sender`:
595595
```solidity
596596
pragma solidity ^0.8.0;
597597
598-
import "@crytic/properties/contracts/util/Hevm.sol";
598+
import "@crytic/properties/contracts/util/IHevm.sol";
599599
600600
contract TestProperties {
601601
// ...

contracts/ERC20/external/properties/ERC20ExternalPausableProperties.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity ^0.8.0;
33

44
import "../util/ERC20ExternalTestBase.sol";
5-
import "../../../util/Hevm.sol";
5+
import "../../../util/IHevm.sol";
66

77
abstract contract CryticERC20ExternalPausableProperties is
88
CryticERC20ExternalTestBase

contracts/ERC20/external/util/ERC20ExternalTestBase.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: AGPL-3.0-or-later
22
pragma solidity ^0.8.0;
33

4-
import "../../../util/PropertiesHelper.sol";
4+
import "../../../util/PropertiesAsserts.sol";
55
import "./ITokenMock.sol";
66
import "../../../util/PropertiesConstants.sol";
77

contracts/ERC20/internal/util/ERC20TestBase.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pragma solidity ^0.8.0;
33

44
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
55
import "../../../util/PropertiesConstants.sol";
6-
import "../../../util/PropertiesHelper.sol";
6+
import "../../../util/PropertiesAsserts.sol";
77

88
abstract contract CryticERC20Base is
99
ERC20,

contracts/ERC4626/util/Actor.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pragma solidity ^0.8.0;
33

44
import {IERC4626} from "../../util/IERC4626.sol";
55
import {TestERC20Token} from "../util/TestERC20Token.sol";
6-
import {PropertiesAsserts} from "../../util/PropertiesHelper.sol";
6+
import {PropertiesAsserts} from "../../util/PropertiesAsserts.sol";
77

88
/// @notice This contract has two purposes:
99
/// 1. Act as a proxy for performing vault deposits/withdraws (since we don't have vm.prank)

contracts/ERC4626/util/ERC4626PropertyTestBase.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {IERC20} from "../../util/IERC20.sol";
55
import {IERC4626} from "../../util/IERC4626.sol";
66
import {TestERC20Token} from "./TestERC20Token.sol";
77
import {Actor} from "../util/Actor.sol";
8-
import {PropertiesAsserts} from "../../util/PropertiesHelper.sol";
8+
import {PropertiesAsserts} from "../../util/PropertiesAsserts.sol";
99
import {RedemptionProxy} from "./RedemptionProxy.sol";
1010

1111
/// @notice This contract is used as a base contract for all 4626 property tests.

contracts/ERC721/external/properties/ERC721ExternalBasicProperties.sol

Lines changed: 75 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,49 @@
22
pragma solidity ^0.8.13;
33

44
import "../util/ERC721ExternalTestBase.sol";
5-
import "../../../util/Hevm.sol";
5+
import "../../../util/IHevm.sol";
66

7-
abstract contract CryticERC721ExternalBasicProperties is CryticERC721ExternalTestBase {
7+
abstract contract CryticERC721ExternalBasicProperties is
8+
CryticERC721ExternalTestBase
9+
{
810
using Address for address;
911

1012
////////////////////////////////////////
1113
// Properties
1214

1315
// Querying the balance of address(0) should throw
14-
function test_ERC721_external_balanceOfZeroAddressMustRevert() public virtual {
16+
function test_ERC721_external_balanceOfZeroAddressMustRevert()
17+
public
18+
virtual
19+
{
1520
token.balanceOf(address(0));
1621
assertWithMsg(false, "address(0) balance query should have reverted");
1722
}
1823

1924
// Querying the owner of an invalid token should throw
20-
function test_ERC721_external_ownerOfInvalidTokenMustRevert() public virtual {
25+
function test_ERC721_external_ownerOfInvalidTokenMustRevert()
26+
public
27+
virtual
28+
{
2129
token.ownerOf(type(uint256).max);
2230
assertWithMsg(false, "Invalid token owner query should have reverted");
2331
}
2432

2533
// Approving an invalid token should throw
26-
function test_ERC721_external_approvingInvalidTokenMustRevert() public virtual {
34+
function test_ERC721_external_approvingInvalidTokenMustRevert()
35+
public
36+
virtual
37+
{
2738
token.approve(address(0), type(uint256).max);
2839
assertWithMsg(false, "Approving an invalid token should have reverted");
2940
}
3041

3142
// transferFrom a token that the caller is not approved for should revert
32-
function test_ERC721_external_transferFromNotApproved(address target) public virtual {
43+
function test_ERC721_external_transferFromNotApproved(
44+
address target
45+
) public virtual {
3346
uint256 selfBalance = token.balanceOf(msg.sender);
34-
require(selfBalance > 0);
47+
require(selfBalance > 0);
3548
require(target != address(this));
3649
require(target != msg.sender);
3750
uint tokenId = token.tokenOfOwnerByIndex(msg.sender, 0);
@@ -44,9 +57,11 @@ abstract contract CryticERC721ExternalBasicProperties is CryticERC721ExternalTes
4457
}
4558

4659
// transferFrom should reset approval for that token
47-
function test_ERC721_external_transferFromResetApproval(address target) public virtual {
60+
function test_ERC721_external_transferFromResetApproval(
61+
address target
62+
) public virtual {
4863
uint256 selfBalance = token.balanceOf(msg.sender);
49-
require(selfBalance > 0);
64+
require(selfBalance > 0);
5065
require(target != address(this));
5166
require(target != msg.sender);
5267
require(target != address(0));
@@ -56,39 +71,50 @@ abstract contract CryticERC721ExternalBasicProperties is CryticERC721ExternalTes
5671
hevm.prank(msg.sender);
5772
token.approve(address(this), tokenId);
5873
token.transferFrom(msg.sender, target, tokenId);
59-
74+
6075
address approved = token.getApproved(tokenId);
6176
assertWithMsg(approved == address(0), "Approval was not reset");
6277
}
6378

6479
// transferFrom correctly updates owner
65-
function test_ERC721_external_transferFromUpdatesOwner(address target) public virtual {
80+
function test_ERC721_external_transferFromUpdatesOwner(
81+
address target
82+
) public virtual {
6683
uint256 selfBalance = token.balanceOf(msg.sender);
67-
require(selfBalance > 0);
84+
require(selfBalance > 0);
6885
require(target != address(this));
6986
require(target != msg.sender);
7087
require(target != address(0));
7188
uint tokenId = token.tokenOfOwnerByIndex(msg.sender, 0);
7289

7390
hevm.prank(msg.sender);
7491
try token.transferFrom(msg.sender, target, tokenId) {
75-
assertWithMsg(token.ownerOf(tokenId) == target, "Token owner not updated");
92+
assertWithMsg(
93+
token.ownerOf(tokenId) == target,
94+
"Token owner not updated"
95+
);
7696
} catch {
7797
assertWithMsg(false, "transferFrom unexpectedly reverted");
7898
}
7999
}
80100

81101
// transfer from zero address should revert
82-
function test_ERC721_external_transferFromZeroAddress(address target, uint256 tokenId) public virtual {
102+
function test_ERC721_external_transferFromZeroAddress(
103+
address target,
104+
uint256 tokenId
105+
) public virtual {
83106
token.transferFrom(address(0), target, tokenId);
84107

85-
assertWithMsg(false, "transferFrom does not revert when `from` is the zero-address");
108+
assertWithMsg(
109+
false,
110+
"transferFrom does not revert when `from` is the zero-address"
111+
);
86112
}
87113

88114
// Transfers to the zero address should revert
89115
function test_ERC721_external_transferToZeroAddress() public virtual {
90116
uint256 selfBalance = token.balanceOf(msg.sender);
91-
require(selfBalance > 0);
117+
require(selfBalance > 0);
92118
uint tokenId = token.tokenOfOwnerByIndex(msg.sender, 0);
93119

94120
hevm.prank(msg.sender);
@@ -100,42 +126,63 @@ abstract contract CryticERC721ExternalBasicProperties is CryticERC721ExternalTes
100126
// Transfers to self should not break accounting
101127
function test_ERC721_external_transferFromSelf() public virtual {
102128
uint256 selfBalance = token.balanceOf(msg.sender);
103-
require(selfBalance > 0);
129+
require(selfBalance > 0);
104130
uint tokenId = token.tokenOfOwnerByIndex(msg.sender, 0);
105131
hevm.prank(msg.sender);
106132

107133
try token.transferFrom(msg.sender, msg.sender, tokenId) {
108-
assertWithMsg(token.ownerOf(tokenId) == msg.sender, "Self transfer changes owner");
109-
assertEq(token.balanceOf(msg.sender), selfBalance, "Self transfer breaks accounting");
134+
assertWithMsg(
135+
token.ownerOf(tokenId) == msg.sender,
136+
"Self transfer changes owner"
137+
);
138+
assertEq(
139+
token.balanceOf(msg.sender),
140+
selfBalance,
141+
"Self transfer breaks accounting"
142+
);
110143
} catch {
111144
assertWithMsg(false, "transferFrom unexpectedly reverted");
112145
}
113-
114146
}
115147

116148
// Transfer to self reset approval
117-
function test_ERC721_external_transferFromSelfResetsApproval() public virtual {
149+
function test_ERC721_external_transferFromSelfResetsApproval()
150+
public
151+
virtual
152+
{
118153
uint256 selfBalance = token.balanceOf(msg.sender);
119-
require(selfBalance > 0);
154+
require(selfBalance > 0);
120155
uint tokenId = token.tokenOfOwnerByIndex(msg.sender, 0);
121156
require(token.ownerOf(tokenId) == msg.sender);
122157

123158
hevm.prank(msg.sender);
124159
token.approve(address(this), tokenId);
125160

126161
token.transferFrom(msg.sender, msg.sender, tokenId);
127-
assertWithMsg(token.getApproved(tokenId) == address(0), "Self transfer does not reset approvals");
162+
assertWithMsg(
163+
token.getApproved(tokenId) == address(0),
164+
"Self transfer does not reset approvals"
165+
);
128166
}
129167

130168
// safeTransferFrom reverts if receiver does not implement the callback
131-
function test_ERC721_external_safeTransferFromRevertsOnNoncontractReceiver() public virtual {
169+
function test_ERC721_external_safeTransferFromRevertsOnNoncontractReceiver()
170+
public
171+
virtual
172+
{
132173
uint256 selfBalance = token.balanceOf(msg.sender);
133-
require(selfBalance > 0);
174+
require(selfBalance > 0);
134175
uint tokenId = token.tokenOfOwnerByIndex(msg.sender, 0);
135176
hevm.prank(msg.sender);
136177

137-
token.safeTransferFrom(msg.sender, address(mockUnsafeReceiver), tokenId);
138-
assertWithMsg(false, "safeTransferFrom does not revert if receiver does not implement ERC721.onERC721Received");
178+
token.safeTransferFrom(
179+
msg.sender,
180+
address(mockUnsafeReceiver),
181+
tokenId
182+
);
183+
assertWithMsg(
184+
false,
185+
"safeTransferFrom does not revert if receiver does not implement ERC721.onERC721Received"
186+
);
139187
}
140-
141188
}

contracts/ERC721/external/properties/ERC721ExternalBurnableProperties.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity ^0.8.13;
33

44
import "../util/ERC721ExternalTestBase.sol";
5-
import "../../../util/Hevm.sol";
5+
import "../../../util/IHevm.sol";
66

77
abstract contract CryticERC721ExternalBurnableProperties is
88
CryticERC721ExternalTestBase
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
// SPDX-License-Identifier: AGPL-3.0-or-later
22
pragma solidity ^0.8.0;
33

4-
import "../../../util/PropertiesHelper.sol";
4+
import "../../../util/PropertiesAsserts.sol";
55
import "../../util/IERC721Internal.sol";
66
import "../../../util/PropertiesConstants.sol";
77
import "@openzeppelin/contracts/utils/Address.sol";
88
import {MockReceiver} from "./MockReceiver.sol";
99

10-
11-
abstract contract CryticERC721ExternalTestBase is PropertiesAsserts, PropertiesConstants {
12-
10+
abstract contract CryticERC721ExternalTestBase is
11+
PropertiesAsserts,
12+
PropertiesConstants
13+
{
1314
IERC721Internal public token;
1415
MockReceiver public mockSafeReceiver;
1516
MockReceiver public mockUnsafeReceiver;
1617

17-
constructor() {
18-
}
19-
18+
constructor() {}
2019
}

contracts/ERC721/internal/util/ERC721TestBase.sol

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,34 @@ pragma solidity ^0.8.0;
44
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
55
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
66
import "../../../util/PropertiesConstants.sol";
7-
import "../../../util/PropertiesHelper.sol";
7+
import "../../../util/PropertiesAsserts.sol";
88
import {MockReceiver} from "./MockReceiver.sol";
9-
import "../../../util/Hevm.sol";
10-
11-
abstract contract CryticERC721TestBase is ERC721, ERC721Enumerable, PropertiesAsserts, PropertiesConstants {
9+
import "../../../util/IHevm.sol";
1210

11+
abstract contract CryticERC721TestBase is
12+
ERC721,
13+
ERC721Enumerable,
14+
PropertiesAsserts,
15+
PropertiesConstants
16+
{
1317
// Is the contract allowed to change its total supply?
1418
bool isMintableOrBurnable;
1519
MockReceiver safeReceiver;
1620
MockReceiver unsafeReceiver;
1721

1822
// The following functions are overrides required by Solidity.
19-
function _beforeTokenTransfer(address from, address to, uint256 tokenId, uint256 batchSize)
20-
internal
21-
virtual
22-
override(ERC721, ERC721Enumerable)
23-
{
23+
function _beforeTokenTransfer(
24+
address from,
25+
address to,
26+
uint256 tokenId,
27+
uint256 batchSize
28+
) internal virtual override(ERC721, ERC721Enumerable) {
2429
super._beforeTokenTransfer(from, to, tokenId, batchSize);
2530
}
2631

27-
function supportsInterface(bytes4 interfaceId)
28-
public
29-
view
30-
virtual
31-
override(ERC721, ERC721Enumerable)
32-
returns (bool)
33-
{
32+
function supportsInterface(
33+
bytes4 interfaceId
34+
) public view virtual override(ERC721, ERC721Enumerable) returns (bool) {
3435
return super.supportsInterface(interfaceId);
3536
}
3637
}

0 commit comments

Comments
 (0)