github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/test/periphery/drippie/dripchecks/CheckBalanceLow.t.sol (about) 1 // SPDX-License-Identifier: MIT 2 pragma solidity 0.8.15; 3 4 import { Test } from "forge-std/Test.sol"; 5 import { CheckBalanceLow } from "src/periphery/drippie/dripchecks/CheckBalanceLow.sol"; 6 7 /// @title CheckBalanceLowTest 8 /// @notice Tests the CheckBalanceLow contract via fuzzing both the success case 9 /// and the failure case. 10 contract CheckBalanceLowTest is Test { 11 /// @notice An instance of the CheckBalanceLow contract. 12 CheckBalanceLow c; 13 14 /// @notice Deploy the `CheckBalanceLow` contract. 15 function setUp() external { 16 c = new CheckBalanceLow(); 17 } 18 19 /// @notice Fuzz the `check` function and assert that it always returns true 20 /// when the target's balance is smaller than the threshold. 21 function testFuzz_check_succeeds(address _target, uint256 _threshold) external { 22 CheckBalanceLow.Params memory p = CheckBalanceLow.Params({ target: _target, threshold: _threshold }); 23 24 vm.assume(_target.balance < _threshold); 25 26 assertEq(c.check(abi.encode(p)), true); 27 } 28 29 /// @notice Fuzz the `check` function and assert that it always returns false 30 /// when the target's balance is larger than the threshold. 31 function testFuzz_check_highBalance_fails(address _target, uint256 _threshold) external { 32 CheckBalanceLow.Params memory p = CheckBalanceLow.Params({ target: _target, threshold: _threshold }); 33 34 // prevent overflows 35 vm.assume(_threshold != type(uint256).max); 36 vm.deal(_target, _threshold + 1); 37 38 assertEq(c.check(abi.encode(p)), false); 39 } 40 }