test: prove V1 accounting invariants

This commit is contained in:
golem
2026-08-17 17:19:02 -06:00
parent 2a21766237
commit 6dcbb03f3c
2 changed files with 122 additions and 0 deletions
+43
View File
@@ -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))
);
}
}