-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import {AutomationCompatible} from "../AutomationCompatible.sol"; | ||
|
||
contract UpkeepMock is AutomationCompatible { | ||
bool public shouldRevertCheck; | ||
bool public canCheck; | ||
bool public canPerform; | ||
bytes public performData; | ||
uint256 public checkGasToBurn; | ||
uint256 public performGasToBurn; | ||
string public checkRevertReason; | ||
|
||
uint256 constant checkGasBuffer = 6000; // use all but this amount in gas burn loops | ||
uint256 constant performGasBuffer = 1000; // use all but this amount in gas burn loops | ||
|
||
event UpkeepPerformedWith(bytes upkeepData); | ||
|
||
function setShouldRevertCheck(bool value) public { | ||
shouldRevertCheck = value; | ||
} | ||
|
||
function setPerformData(bytes calldata data) public { | ||
performData = data; | ||
} | ||
|
||
function setCanCheck(bool value) public { | ||
canCheck = value; | ||
} | ||
|
||
function setCanPerform(bool value) public { | ||
canPerform = value; | ||
} | ||
|
||
function setCheckRevertReason(string calldata value) public { | ||
checkRevertReason = value; | ||
} | ||
|
||
function setCheckGasToBurn(uint256 value) public { | ||
require(value > checkGasBuffer || value == 0, "checkGasToBurn must be 0 (disabled) or greater than buffer"); | ||
if (value > 0) { | ||
checkGasToBurn = value - checkGasBuffer; | ||
} else { | ||
checkGasToBurn = 0; | ||
} | ||
} | ||
|
||
function setPerformGasToBurn(uint256 value) public { | ||
require(value > performGasBuffer || value == 0, "performGasToBurn must be 0 (disabled) or greater than buffer"); | ||
if (value > 0) { | ||
performGasToBurn = value - performGasBuffer; | ||
} else { | ||
performGasToBurn = 0; | ||
} | ||
} | ||
|
||
function checkUpkeep( | ||
bytes calldata | ||
) external override cannotExecute returns (bool callable, bytes memory executedata) { | ||
require(!shouldRevertCheck, checkRevertReason); | ||
uint256 startGas = gasleft(); | ||
bool couldCheck = canCheck; | ||
|
||
setCanCheck(false); // test that state modifications don't stick | ||
|
||
while (startGas - gasleft() < checkGasToBurn) {} // burn gas | ||
|
||
return (couldCheck, performData); | ||
} | ||
|
||
function performUpkeep(bytes calldata data) external override { | ||
uint256 startGas = gasleft(); | ||
|
||
require(canPerform, "Cannot perform"); | ||
|
||
emit UpkeepPerformedWith(data); | ||
|
||
while (startGas - gasleft() < performGasToBurn) {} // burn gas | ||
} | ||
} |