diff --git a/contracts/.solcover.js b/contracts/.solcover.js index 83704830704..f82f0fef0cf 100644 --- a/contracts/.solcover.js +++ b/contracts/.solcover.js @@ -3,11 +3,18 @@ module.exports = { 'v0.8/mocks', 'v0.8/interfaces', 'v0.8/vendor', + 'v0.8/tests', 'v0.8/dev/interfaces', 'v0.8/dev/vendor', 'v0.8/dev/Keeper2_0/interfaces', 'v0.8/dev/transmission', 'v0.8/tests', + 'v0.8/automation/testhelpers', + 'v0.8/shared', + 'v0.8/vrf/testhelpers', + 'v0.8/vrf/mocks', + 'v0.8/llo-feeds/test', + 'v0.8/functions/tests', ], istanbulReporter: ['text', 'text-summary', 'json'], mocha: { diff --git a/contracts/src/v0.8/automation/testhelpers/UpkeepAutoFunder.sol b/contracts/src/v0.8/automation/testhelpers/UpkeepAutoFunder.sol new file mode 100644 index 00000000000..263aad5492f --- /dev/null +++ b/contracts/src/v0.8/automation/testhelpers/UpkeepAutoFunder.sol @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import {AutomationCompatible} from "../AutomationCompatible.sol"; +import {LinkTokenInterface} from "../../shared/interfaces/LinkTokenInterface.sol"; +import {ConfirmedOwner} from "../../shared/access/ConfirmedOwner.sol"; +import {AutomationRegistryBaseInterface} from "../interfaces/v2_0/AutomationRegistryInterface2_0.sol"; + +contract UpkeepAutoFunder is AutomationCompatible, ConfirmedOwner { + bool public s_isEligible; + bool public s_shouldCancel; + uint256 public s_upkeepId; + uint96 public s_autoFundLink; + LinkTokenInterface public immutable LINK; + AutomationRegistryBaseInterface public immutable s_keeperRegistry; + + constructor(address linkAddress, address registryAddress) ConfirmedOwner(msg.sender) { + LINK = LinkTokenInterface(linkAddress); + s_keeperRegistry = AutomationRegistryBaseInterface(registryAddress); + + s_isEligible = false; + s_shouldCancel = false; + s_upkeepId = 0; + s_autoFundLink = 0; + } + + function setShouldCancel(bool value) external onlyOwner { + s_shouldCancel = value; + } + + function setIsEligible(bool value) external onlyOwner { + s_isEligible = value; + } + + function setAutoFundLink(uint96 value) external onlyOwner { + s_autoFundLink = value; + } + + function setUpkeepId(uint256 value) external onlyOwner { + s_upkeepId = value; + } + + function checkUpkeep( + bytes calldata data + ) external override cannotExecute returns (bool callable, bytes calldata executedata) { + return (s_isEligible, data); + } + + function performUpkeep(bytes calldata data) external override { + require(s_isEligible, "Upkeep should be eligible"); + s_isEligible = false; // Allow upkeep only once until it is set again + + // Topup upkeep so it can be called again + LINK.transferAndCall(address(s_keeperRegistry), s_autoFundLink, abi.encode(s_upkeepId)); + + if (s_shouldCancel) { + s_keeperRegistry.cancelUpkeep(s_upkeepId); + } + } +} diff --git a/contracts/src/v0.8/automation/testhelpers/UpkeepReverter.sol b/contracts/src/v0.8/automation/testhelpers/UpkeepReverter.sol new file mode 100644 index 00000000000..1d140ccf6d0 --- /dev/null +++ b/contracts/src/v0.8/automation/testhelpers/UpkeepReverter.sol @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import {AutomationCompatible} from "../AutomationCompatible.sol"; + +contract UpkeepReverter is AutomationCompatible { + function checkUpkeep( + bytes calldata data + ) public view override cannotExecute returns (bool callable, bytes calldata executedata) { + require(false, "!working"); + return (true, data); + } + + function performUpkeep(bytes calldata) external pure override { + require(false, "!working"); + } +}