test: prove V1 accounting invariants
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity 0.8.35;
|
||||
|
||||
import {BankTestBase} from "./helpers/BankTestBase.sol";
|
||||
import {BankHandler} from "./helpers/BankHandler.sol";
|
||||
|
||||
contract BankInvariantTest is BankTestBase {
|
||||
BankHandler internal handler;
|
||||
|
||||
function setUp() public override {
|
||||
super.setUp();
|
||||
|
||||
handler = new BankHandler(token, bank);
|
||||
vm.prank(owner);
|
||||
token.transferOwnership(address(handler));
|
||||
|
||||
targetContract(address(handler));
|
||||
bytes4[] memory selectors = new bytes4[](3);
|
||||
selectors[0] = handler.deposit.selector;
|
||||
selectors[1] = handler.withdraw.selector;
|
||||
selectors[2] = handler.donate.selector;
|
||||
targetSelector(FuzzSelector({addr: address(handler), selectors: selectors}));
|
||||
}
|
||||
|
||||
function invariant_liabilitiesEqualTrackedBalances() public view {
|
||||
uint256 sum;
|
||||
for (uint256 i; i < handler.actorCount(); ++i) {
|
||||
sum += bank.balanceOf(handler.actorAt(i));
|
||||
}
|
||||
assertEq(sum, bank.totalLiabilities());
|
||||
}
|
||||
|
||||
function invariant_reservesCoverLiabilities() public view {
|
||||
assertGe(token.balanceOf(address(bank)), bank.totalLiabilities());
|
||||
}
|
||||
|
||||
function invariant_ghostAccountingMatchesChain() public view {
|
||||
assertEq(handler.ghostDeposited() - handler.ghostWithdrawn(), bank.totalLiabilities());
|
||||
assertEq(
|
||||
handler.ghostDeposited() + handler.ghostDonated() - handler.ghostWithdrawn(), token.balanceOf(address(bank))
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user