/ lib / truffle / src / AssertGeneral.sol
AssertGeneral.sol
 1  //SPDX-License-Identifier: MIT
 2  pragma solidity >= 0.4.15 < 0.9.0;
 3  
 4  library AssertGeneral {
 5  
 6      /*
 7          Event: TestEvent
 8  
 9          Fired when an assertion is made.
10  
11          Params:
12              result (bool) - Whether or not the assertion holds.
13              message (string) - A message to display if the assertion does not hold.
14      */
15      event TestEvent(bool indexed result, string message);
16      
17      // ************************************** general **************************************
18  
19      /*
20          Function: fail()
21  
22          Mark the test as failed.
23  
24          Params:
25              message (string) - A message associated with the failure.
26  
27          Returns:
28              result (bool) - false.
29      */
30      function fail(string memory message) public returns (bool result) {
31          _report(false, message);
32          return false;
33      }
34      
35      /******************************** internal ********************************/
36  
37          /*
38              Function: _report
39  
40              Internal function for triggering <TestEvent>.
41  
42              Params:
43                  result (bool) - The test result (true or false).
44                  message (string) - The message that is sent if the assertion fails.
45          */
46      function _report(bool result, string memory message) internal {
47          if(result)
48              emit TestEvent(true, "");
49          else
50              emit TestEvent(false, message);
51      }
52  }