-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
write happy path tests for automation23 registrar registerUpkeep() #12474
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import {IAutomationRegistryMaster2_3, AutomationRegistryBase2_3} from "../interf | |
import {AutomationRegistrar2_3} from "../v2_3/AutomationRegistrar2_3.sol"; | ||
import {ChainModuleBase} from "../../chains/ChainModuleBase.sol"; | ||
import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol"; | ||
import {MockUpkeep} from "../../mocks/MockUpkeep.sol"; | ||
|
||
/** | ||
* @title BaseTest provides basic test setup procedures and dependancies for use by other | ||
|
@@ -35,11 +36,15 @@ contract BaseTest is Test { | |
MockV3Aggregator internal NATIVE_USD_FEED; | ||
MockV3Aggregator internal USDTOKEN_USD_FEED; | ||
MockV3Aggregator internal FAST_GAS_FEED; | ||
MockUpkeep internal TARGET1; | ||
MockUpkeep internal TARGET2; | ||
|
||
// roles | ||
address internal constant OWNER = address(uint160(uint256(keccak256("OWNER")))); | ||
address internal constant UPKEEP_ADMIN = address(uint160(uint256(keccak256("UPKEEP_ADMIN")))); | ||
address internal constant FINANCE_ADMIN = address(uint160(uint256(keccak256("FINANCE_ADMIN")))); | ||
address internal constant STRANGER = address(uint160(uint256(keccak256("STRANGER")))); | ||
address internal constant BROKE_USER = address(uint160(uint256(keccak256("BROKE_USER")))); // do not mint to this address | ||
|
||
// nodes | ||
uint256 internal constant SIGNING_KEY0 = 0x7b2e97fe057e6de99d6872a2ef2abf52c9b4469bc848c2465ac3fcd8d336e81d; | ||
|
@@ -60,6 +65,9 @@ contract BaseTest is Test { | |
USDTOKEN_USD_FEED = new MockV3Aggregator(8, 100_000_000); // $1 | ||
FAST_GAS_FEED = new MockV3Aggregator(0, 1_000_000_000); // 1 gwei | ||
|
||
TARGET1 = new MockUpkeep(); | ||
TARGET2 = new MockUpkeep(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit, TARGET2 is not used anywhere. Code LGTM. let me know when you are ready, will stamp again. |
||
|
||
SIGNERS[0] = vm.addr(SIGNING_KEY0); //0xc110458BE52CaA6bB68E66969C3218A4D9Db0211 | ||
SIGNERS[1] = vm.addr(SIGNING_KEY1); //0xc110a19c08f1da7F5FfB281dc93630923F8E3719 | ||
SIGNERS[2] = vm.addr(SIGNING_KEY2); //0xc110fdF6e8fD679C7Cc11602d1cd829211A18e9b | ||
|
@@ -70,6 +78,17 @@ contract BaseTest is Test { | |
TRANSMITTERS[2] = address(uint160(uint256(keccak256("TRANSMITTER3")))); | ||
TRANSMITTERS[3] = address(uint160(uint256(keccak256("TRANSMITTER4")))); | ||
|
||
// mint funds | ||
vm.deal(UPKEEP_ADMIN, 10 ether); | ||
vm.deal(FINANCE_ADMIN, 10 ether); | ||
vm.deal(STRANGER, 10 ether); | ||
linkToken.mint(UPKEEP_ADMIN, 1000e18); | ||
linkToken.mint(FINANCE_ADMIN, 1000e18); | ||
linkToken.mint(STRANGER, 1000e18); | ||
mockERC20.mint(UPKEEP_ADMIN, 1000e18); | ||
mockERC20.mint(FINANCE_ADMIN, 1000e18); | ||
mockERC20.mint(STRANGER, 1000e18); | ||
|
||
vm.stopPrank(); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
contract MockUpkeep { | ||
bool public shouldCheckRevert; | ||
bool public shouldPerformRevert; | ||
bool public checkResult = true; | ||
bytes public performData; | ||
uint256 public checkGasToBurn; | ||
uint256 public performGasToBurn; | ||
|
||
event UpkeepPerformedWith(bytes upkeepData); | ||
error CheckRevert(); | ||
error PerformRevert(); | ||
|
||
function setShouldCheckRevert(bool value) public { | ||
shouldCheckRevert = value; | ||
} | ||
|
||
function setShouldPerformRevert(bool value) public { | ||
shouldPerformRevert = value; | ||
} | ||
|
||
function setCheckResult(bool value) public { | ||
checkResult = value; | ||
} | ||
|
||
function setPerformData(bytes calldata data) public { | ||
performData = data; | ||
} | ||
|
||
function setCheckGasToBurn(uint256 value) public { | ||
checkGasToBurn = value; | ||
} | ||
|
||
function setPerformGasToBurn(uint256 value) public { | ||
performGasToBurn = value; | ||
} | ||
|
||
function checkUpkeep(bytes calldata) external view returns (bool callable, bytes memory executedata) { | ||
if (shouldCheckRevert) revert CheckRevert(); | ||
uint256 startGas = gasleft(); | ||
while (startGas - gasleft() < checkGasToBurn) {} // burn gas | ||
return (checkResult, performData); | ||
} | ||
|
||
function performUpkeep(bytes calldata data) external { | ||
if (shouldPerformRevert) revert PerformRevert(); | ||
uint256 startGas = gasleft(); | ||
while (startGas - gasleft() < performGasToBurn) {} // burn gas | ||
emit UpkeepPerformedWith(data); | ||
} | ||
} |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch