@@ -31,14 +31,7 @@ abstract contract HelperAssert is HelperBase {
3131 if (a != b) {
3232 string memory aStr = FuzzLibString.toString (a);
3333 string memory bStr = FuzzLibString.toString (b);
34- bytes memory assertMsg = abi.encodePacked (
35- "Invalid: " ,
36- aStr,
37- "!= " ,
38- bStr,
39- ", reason: " ,
40- reason
41- );
34+ bytes memory assertMsg = createAssertFailMessage (aStr, bStr, "!= " , reason);
4235 emit AssertEqFail (string (assertMsg));
4336 platform.assertFail ();
4437 }
@@ -53,15 +46,8 @@ abstract contract HelperAssert is HelperBase {
5346 if (a != b) {
5447 string memory aStr = FuzzLibString.toString (a);
5548 string memory bStr = FuzzLibString.toString (b);
56- bytes memory assertMsg = abi.encodePacked (
57- "Invalid: " ,
58- aStr,
59- "!= " ,
60- bStr,
61- ", reason: " ,
62- reason
63- );
64- emit AssertEqFail (string (assertMsg));
49+ bytes memory assertMsg = createAssertFailMessage (aStr, bStr, "!= " , reason);
50+ emit AssertEqFail (string (assertMsg));
6551 platform.assertFail ();
6652 }
6753 }
@@ -75,14 +61,7 @@ abstract contract HelperAssert is HelperBase {
7561 if (a != b) {
7662 string memory aStr = a ? "true " : "false " ;
7763 string memory bStr = b ? "true " : "false " ;
78- bytes memory assertMsg = abi.encodePacked (
79- "Invalid: " ,
80- aStr,
81- "!= " ,
82- bStr,
83- ", reason: " ,
84- reason
85- );
64+ bytes memory assertMsg = createAssertFailMessage (aStr, bStr, "!= " , reason);
8665 emit AssertEqFail (string (assertMsg));
8766 platform.assertFail ();
8867 }
@@ -97,14 +76,7 @@ abstract contract HelperAssert is HelperBase {
9776 if (a != b) {
9877 string memory aStr = FuzzLibString.toString (a);
9978 string memory bStr = FuzzLibString.toString (b);
100- bytes memory assertMsg = abi.encodePacked (
101- "Invalid: " ,
102- aStr,
103- "!= " ,
104- bStr,
105- ", reason: " ,
106- reason
107- );
79+ bytes memory assertMsg = createAssertFailMessage (aStr, bStr, "!= " , reason);
10880 emit AssertEqFail (string (assertMsg));
10981 platform.assertFail ();
11082 }
@@ -121,14 +93,7 @@ abstract contract HelperAssert is HelperBase {
12193 bytes memory bBytes = abi.encodePacked (b);
12294 string memory aStr = FuzzLibString.toHexString (aBytes);
12395 string memory bStr = FuzzLibString.toHexString (bBytes);
124- bytes memory assertMsg = abi.encodePacked (
125- "Invalid: " ,
126- aStr,
127- "!= " ,
128- bStr,
129- ", reason: " ,
130- reason
131- );
96+ bytes memory assertMsg = createAssertFailMessage (aStr, bStr, "!= " , reason);
13297 emit AssertEqFail (string (assertMsg));
13398 platform.assertFail ();
13499 }
@@ -143,14 +108,7 @@ abstract contract HelperAssert is HelperBase {
143108 if (a == b) {
144109 string memory aStr = FuzzLibString.toString (a);
145110 string memory bStr = FuzzLibString.toString (b);
146- bytes memory assertMsg = abi.encodePacked (
147- "Invalid: " ,
148- aStr,
149- "== " ,
150- bStr,
151- ", reason: " ,
152- reason
153- );
111+ bytes memory assertMsg = createAssertFailMessage (aStr, bStr, "== " , reason);
154112 emit AssertNeqFail (string (assertMsg));
155113 platform.assertFail ();
156114 }
@@ -165,14 +123,7 @@ abstract contract HelperAssert is HelperBase {
165123 if (a == b) {
166124 string memory aStr = FuzzLibString.toString (a);
167125 string memory bStr = FuzzLibString.toString (b);
168- bytes memory assertMsg = abi.encodePacked (
169- "Invalid: " ,
170- aStr,
171- "== " ,
172- bStr,
173- ", reason: " ,
174- reason
175- );
126+ bytes memory assertMsg = createAssertFailMessage (aStr, bStr, "== " , reason);
176127 emit AssertNeqFail (string (assertMsg));
177128 platform.assertFail ();
178129 }
@@ -187,14 +138,7 @@ abstract contract HelperAssert is HelperBase {
187138 if (! (a >= b)) {
188139 string memory aStr = FuzzLibString.toString (a);
189140 string memory bStr = FuzzLibString.toString (b);
190- bytes memory assertMsg = abi.encodePacked (
191- "Invalid: " ,
192- aStr,
193- "< " ,
194- bStr,
195- " failed, reason: " ,
196- reason
197- );
141+ bytes memory assertMsg = createAssertFailMessage (aStr, bStr, "< " , reason);
198142 emit AssertGteFail (string (assertMsg));
199143 platform.assertFail ();
200144 }
@@ -209,14 +153,7 @@ abstract contract HelperAssert is HelperBase {
209153 if (! (a >= b)) {
210154 string memory aStr = FuzzLibString.toString (a);
211155 string memory bStr = FuzzLibString.toString (b);
212- bytes memory assertMsg = abi.encodePacked (
213- "Invalid: " ,
214- aStr,
215- "< " ,
216- bStr,
217- " failed, reason: " ,
218- reason
219- );
156+ bytes memory assertMsg = createAssertFailMessage (aStr, bStr, "< " , reason);
220157 emit AssertGteFail (string (assertMsg));
221158 platform.assertFail ();
222159 }
@@ -231,14 +168,7 @@ abstract contract HelperAssert is HelperBase {
231168 if (! (a > b)) {
232169 string memory aStr = FuzzLibString.toString (a);
233170 string memory bStr = FuzzLibString.toString (b);
234- bytes memory assertMsg = abi.encodePacked (
235- "Invalid: " ,
236- aStr,
237- "<= " ,
238- bStr,
239- " failed, reason: " ,
240- reason
241- );
171+ bytes memory assertMsg = createAssertFailMessage (aStr, bStr, "<= " , reason);
242172 emit AssertGtFail (string (assertMsg));
243173 platform.assertFail ();
244174 }
@@ -319,14 +249,7 @@ abstract contract HelperAssert is HelperBase {
319249 if (! (a < b)) {
320250 string memory aStr = FuzzLibString.toString (a);
321251 string memory bStr = FuzzLibString.toString (b);
322- bytes memory assertMsg = abi.encodePacked (
323- "Invalid: " ,
324- aStr,
325- ">= " ,
326- bStr,
327- " failed, reason: " ,
328- reason
329- );
252+ bytes memory assertMsg = createAssertFailMessage (aStr, bStr, ">= " , reason);
330253 emit AssertLtFail (string (assertMsg));
331254 platform.assertFail ();
332255 }
@@ -341,14 +264,7 @@ abstract contract HelperAssert is HelperBase {
341264 if (! (a < b)) {
342265 string memory aStr = FuzzLibString.toString (a);
343266 string memory bStr = FuzzLibString.toString (b);
344- bytes memory assertMsg = abi.encodePacked (
345- "Invalid: " ,
346- aStr,
347- ">= " ,
348- bStr,
349- " failed, reason: " ,
350- reason
351- );
267+ bytes memory assertMsg = createAssertFailMessage (aStr, bStr, ">= " , reason);
352268 emit AssertLtFail (string (assertMsg));
353269 platform.assertFail ();
354270 }
@@ -454,4 +370,9 @@ abstract contract HelperAssert is HelperBase {
454370 }
455371 t (allowed, messages[passIndex]);
456372 }
373+
374+ function createAssertFailMessage (string memory aStr , string memory bStr , string memory operator , string memory reason )internal pure returns (bytes memory ) {
375+ return bytes (abi.encodePacked ("Invalid: " , aStr, operator, bStr, ", reason: " , reason));
376+ }
377+
457378}
0 commit comments