@@ -14,9 +14,11 @@ import {IToll} from "src/toll/IToll.sol";
14
14
* @notice IToll's `chaincheck` Integration Test
15
15
*
16
16
* @dev Config Definition:
17
+ *
17
18
* ```json
18
19
* {
19
20
* "IToll": {
21
+ * "disabled": bool,
20
22
* "legacy": bool,
21
23
* "tolled": [
22
24
* "<Ethereum address>",
@@ -32,23 +34,23 @@ contract ITollChaincheck is Chaincheck {
32
34
Vm internal constant vm =
33
35
Vm (address (uint160 (uint (keccak256 ("hevm cheat code " )))));
34
36
35
- IToll private toll ;
36
- string private config;
37
+ IToll self ;
38
+ string config;
37
39
38
- string [] private _logs ;
40
+ string [] logs ;
39
41
40
42
modifier notLegacy () {
41
43
if (! config.readBool (".IToll.legacy " )) {
42
44
_;
43
45
}
44
46
}
45
47
46
- function setUp (address self , string memory config_ )
48
+ function setUp (address self_ , string memory config_ )
47
49
external
48
50
override (Chaincheck)
49
51
returns (Chaincheck)
50
52
{
51
- toll = IToll (self );
53
+ self = IToll (self_ );
52
54
config = config_;
53
55
54
56
return Chaincheck (address (this ));
@@ -59,13 +61,18 @@ contract ITollChaincheck is Chaincheck {
59
61
override (Chaincheck)
60
62
returns (bool , string [] memory )
61
63
{
64
+ // Don't run if disabled.
65
+ if (config.readBool (".IToll.disabled " )) {
66
+ return (logs.length == 0 , logs);
67
+ }
68
+
62
69
check_tolled_containsAllExpectedAddresses ();
63
70
check_tolled_onlyExpectedAddressesAreTolled ();
64
71
check_tolled_zeroAddressNotTolled ();
65
72
check_tolled_ownAddressNotTolled ();
66
73
67
74
// Fail run if non-zero number of logs.
68
- return (_logs .length == 0 , _logs );
75
+ return (logs .length == 0 , logs );
69
76
}
70
77
71
78
/// @dev Checks that each address expected to be tolled is actually tolled.
@@ -75,8 +82,8 @@ contract ITollChaincheck is Chaincheck {
75
82
// Check that each expected address is tolled.
76
83
for (uint i; i < expected.length ; i++ ) {
77
84
// Using `bud(address)(uint)` to support legacy instances.
78
- if (toll .bud (expected[i]) != 1 ) {
79
- _logs .push (
85
+ if (self .bud (expected[i]) != 1 ) {
86
+ logs .push (
80
87
string .concat (
81
88
StdStyle.red ("Expected address not tolled: " ),
82
89
vm.toString (expected[i])
@@ -91,40 +98,43 @@ contract ITollChaincheck is Chaincheck {
91
98
/// @dev Only non-legacy versions supported.
92
99
function check_tolled_onlyExpectedAddressesAreTolled () internal notLegacy {
93
100
address [] memory expected = config.readAddressArray (".IToll.tolled " );
94
- address [] memory actual = toll .tolled ();
101
+ address [] memory actual = self .tolled ();
95
102
96
103
for (uint i; i < actual.length ; i++ ) {
104
+ bool found = false ;
105
+
97
106
for (uint j; j < expected.length ; j++ ) {
98
107
if (actual[i] == expected[j]) {
108
+ found = true ;
99
109
break ; // Found address. Continue with outer loop.
100
110
}
111
+ }
101
112
102
- // Log if unknown address tolled.
103
- if (j == expected.length - 1 ) {
104
- _logs.push (
105
- string .concat (
106
- StdStyle.red ("Unknown address tolled: " ),
107
- vm.toString (actual[i])
108
- )
109
- );
110
- }
113
+ // Log if unknown address tolled.
114
+ if (! found) {
115
+ logs.push (
116
+ string .concat (
117
+ StdStyle.red ("Unknown address tolled: " ),
118
+ vm.toString (actual[i])
119
+ )
120
+ );
111
121
}
112
122
}
113
123
}
114
124
115
125
/// @dev Checks that the zero address is not tolled.
116
126
function check_tolled_zeroAddressNotTolled () internal {
117
127
// Using `bud(address)(uint)` to support legacy instances.
118
- if (toll .bud (address (0 )) != 0 ) {
119
- _logs .push (StdStyle.red ("Zero address tolled " ));
128
+ if (self .bud (address (0 )) != 0 ) {
129
+ logs .push (StdStyle.red ("Zero address tolled " ));
120
130
}
121
131
}
122
132
123
133
/// @dev Checks that own address is not tolled.
124
134
function check_tolled_ownAddressNotTolled () internal {
125
135
// Using `bud(address)(uint)` to support legacy instances.
126
- if (toll .bud (address (toll )) != 0 ) {
127
- _logs .push (StdStyle.red ("Own address tolled " ));
136
+ if (self .bud (address (self )) != 0 ) {
137
+ logs .push (StdStyle.red ("Own address tolled " ));
128
138
}
129
139
}
130
140
}
0 commit comments