Skip to content

Commit

Permalink
add unit test, rebase and address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shileiwill committed Feb 7, 2024
1 parent d248f3d commit 0042b62
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
32 changes: 16 additions & 16 deletions contracts/src/v0.8/automation/dev/test/AutomationRegistry2_2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ contract AutomationRegistry2_2_LatestConfigDetails is AutomationRegistry2_2_SetU
}
}

contract AutomationRegistry2_2_CheckUpkeep is AutomationRegistry2_2_SetUp {
function testPreventExecutionOnCheckUpkeep() public {
IAutomationRegistryMaster registry = IAutomationRegistryMaster(
address(deployRegistry2_2(AutomationRegistryBase2_2.Mode(0)))
);

uint256 id = 1;
bytes memory triggerData = abi.encodePacked("trigger_data");

// The tx.origin is the DEFAULT_SENDER (0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38) of foundry
// Expecting a revert since the tx.origin is not address(0)
vm.expectRevert(abi.encodeWithSelector(IAutomationRegistryMaster.OnlySimulatedBackend.selector));
registry.checkUpkeep(id, triggerData);
}
}

contract AutomationRegistry2_2_SetConfig is AutomationRegistry2_2_SetUp {
event ConfigSet(
uint32 previousConfigBlockNumber,
Expand All @@ -88,22 +104,6 @@ contract AutomationRegistry2_2_SetConfig is AutomationRegistry2_2_SetUp {
bytes offchainConfig
);

function testPreventExecutionOnCheckUpkeep() public {
IAutomationRegistryMaster registry = IAutomationRegistryMaster(
address(deployRegistry2_2(AutomationRegistryBase2_2.Mode(0)))
);

uint256 id = 1;
bytes memory triggerData = abi.encodePacked("trigger_data");

(bool success, ) = address(registry).staticcall(
abi.encodeWithSelector(AutomationCompatibleInterface.checkUpkeep.selector, id, triggerData)
);

// Expect the call to revert with "OnlySimulatedBackend" error
require(!success, "Expected eth_call to revert for not allowed address");
}

function testSetConfigSuccess() public {
IAutomationRegistryMaster registry = IAutomationRegistryMaster(
address(deployRegistry2_2(AutomationRegistryBase2_2.Mode(0)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ contract AutomationRegistryLogicA2_2 is AutomationRegistryBase2_2, Chainable {
external
returns (bool upkeepNeeded, bytes memory performData, UpkeepFailureReason upkeepFailureReason, uint256 gasUsed)
{
_preventExecution();

bytes memory payload = abi.encodeWithSelector(CHECK_CALLBACK_SELECTOR, values, extraData);
return executeCallback(id, payload);
}
Expand Down
Loading

0 comments on commit 0042b62

Please sign in to comment.