Skip to content

Commit

Permalink
fix UpkeepMock ref
Browse files Browse the repository at this point in the history
  • Loading branch information
RensR committed Mar 25, 2024
1 parent 795a309 commit 9162338
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions contracts/src/v0.8/automation/testhelpers/UpkeepMock.sol
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
}
}

0 comments on commit 9162338

Please sign in to comment.