80 lines
2.2 KiB
Solidity
80 lines
2.2 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
pragma solidity 0.8.35;
|
|
|
|
import {Test} from "forge-std/Test.sol";
|
|
|
|
import {BankV1} from "../../src/BankV1.sol";
|
|
import {MockUSDC} from "../../src/MockUSDC.sol";
|
|
|
|
contract BankHandler is Test {
|
|
MockUSDC internal immutable token;
|
|
BankV1 internal immutable bank;
|
|
|
|
address internal immutable actor0;
|
|
address internal immutable actor1;
|
|
address internal immutable actor2;
|
|
address internal immutable actor3;
|
|
|
|
uint256 public ghostDeposited;
|
|
uint256 public ghostWithdrawn;
|
|
uint256 public ghostDonated;
|
|
|
|
constructor(MockUSDC token_, BankV1 bank_) {
|
|
token = token_;
|
|
bank = bank_;
|
|
actor0 = address(0x1001);
|
|
actor1 = address(0x1002);
|
|
actor2 = address(0x1003);
|
|
actor3 = address(0x1004);
|
|
}
|
|
|
|
function deposit(uint256 actorSeed, uint256 amount) external {
|
|
address actor = actorAt(actorSeed % actorCount());
|
|
amount = bound(amount, 1, 10_000e6);
|
|
token.mint(actor, amount);
|
|
|
|
vm.startPrank(actor);
|
|
token.approve(address(bank), amount);
|
|
bank.deposit(amount);
|
|
vm.stopPrank();
|
|
|
|
ghostDeposited += amount;
|
|
}
|
|
|
|
function withdraw(uint256 actorSeed, uint256 amount) external {
|
|
address actor = actorAt(actorSeed % actorCount());
|
|
uint256 balance = bank.balanceOf(actor);
|
|
if (balance == 0) return;
|
|
|
|
amount = bound(amount, 1, balance);
|
|
vm.startPrank(actor);
|
|
bank.withdraw(amount);
|
|
vm.stopPrank();
|
|
|
|
ghostWithdrawn += amount;
|
|
}
|
|
|
|
function donate(uint256 actorSeed, uint256 amount) external {
|
|
address actor = actorAt(actorSeed % actorCount());
|
|
amount = bound(amount, 1, 1_000e6);
|
|
token.mint(actor, amount);
|
|
|
|
vm.startPrank(actor);
|
|
token.transfer(address(bank), amount);
|
|
vm.stopPrank();
|
|
|
|
ghostDonated += amount;
|
|
}
|
|
|
|
function actorCount() public pure returns (uint256) {
|
|
return 4;
|
|
}
|
|
|
|
function actorAt(uint256 index) public view returns (address) {
|
|
if (index == 0) return actor0;
|
|
if (index == 1) return actor1;
|
|
if (index == 2) return actor2;
|
|
return actor3;
|
|
}
|
|
}
|