pragma solidity 0.8.20; import {Test} from "forge-std/Test.sol"; import {Gatekeeper} from "../../src/Gatekeeper.sol"; import {IStorageHistory} from "../../src/interfaces/IStorageHistory.sol"; contract GatekeeperStorageHistoryTest is Test { address constant ALICE = 0x0000000000000000000000000000000000000001; address constant BOB = 0x0000000000000000000000000000000000000002; uint256 constant INIT_AMOUNT = 69 * 1e18; uint256 constant INIT_GHOSTED = type(uint104).max / 2; uint256 constant EXISTENTIAL = 0; Gatekeeper gatekeeper; function setUp() public { vm.prank(ALICE); gatekeeper = new Gatekeeper(EXISTENTIAL, address(0)); } function test_correctStorageHistoryInitialization() public view { address storageHistory = gatekeeper.storageHistory(); IStorageHistory.DeploymentSnapshot memory snapshot = IStorageHistory(storageHistory).deploymentSnapshot(); assertEq(snapshot.deployedAt, 0); assertEq(snapshot.amountIn, 0); assertEq(snapshot.amountOut, 0); assertEq(gatekeeper.ghostedSupply(), 0); } function test_historicalAmountsOnlyIncrease(uint256 ghostAmount) public { vm.assume(ghostAmount > 0 && ghostAmount < INIT_GHOSTED / 2); bytes32 receiver = bytes32(abi.encodePacked(ALICE)); address storageHistory = gatekeeper.storageHistory(); IStorageHistory.DeploymentSnapshot memory snapshot = IStorageHistory(storageHistory).deploymentSnapshot(); uint104 amountIn = snapshot.amountIn; uint104 amountOut = snapshot.amountOut; if (ghostAmount % 2 == 0) { vm.prank(ALICE); gatekeeper.ghost(receiver, ghostAmount); // forge-lint: disable-next-line(unsafe-typecast) amountIn += uint104(ghostAmount); } else { if (IStorageHistory(storageHistory).bridgeImbalance() >= ghostAmount) { vm.prank(ALICE); gatekeeper.materialize(0, ghostAmount, 0, BOB); // forge-lint: disable-next-line(unsafe-typecast) amountOut += uint104(ghostAmount); } } IStorageHistory.DeploymentSnapshot memory newSnapshot = IStorageHistory(storageHistory).deploymentSnapshot(); assertEq(newSnapshot.amountIn, amountIn); assertEq(newSnapshot.amountOut, amountOut); assertEq(gatekeeper.ghostedSupply(), amountIn - amountOut); } }