How Can an Invariant Be Checked during a Unit Test?
An invariant can be checked during a unit test by creating a special function within the test suite that asserts the invariant's condition is true at critical points of execution. After every state-changing function call (e.g. deposit, withdraw, transfer), the test suite calls the invariant check function.
If the invariant (e.g. total supply equals sum of balances) returns false at any point, the test immediately fails, signaling a bug. This ensures that the core financial rules are maintained throughout the test execution.