-
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
add reorgProtectionEnabled feature flag in registry 2.2 #11862
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5de68e5
add skipReorgProtection feature flag in registry 2.2
FelixFan1992 33b2b98
update tests
FelixFan1992 838637c
fix lint error
FelixFan1992 048da4b
fix tests and add docs
FelixFan1992 6a2f90f
remove unused param
FelixFan1992 0ee7d75
prettier
FelixFan1992 33656d4
update
FelixFan1992 52849d1
prettier
FelixFan1992 35aaba5
put the boolean in hot vars
FelixFan1992 0872942
run prettier
FelixFan1992 e8f88a4
Merge branch 'develop' into AUTO-8798
FelixFan1992 3072cb8
rename
FelixFan1992 652acfc
rebase
FelixFan1992 9176888
gen wrappers
FelixFan1992 3b00b43
add foundry test for 2.2
FelixFan1992 64e3ab1
fix tests
FelixFan1992 700ee3e
remove only
FelixFan1992 9514873
remove unnecessary change
FelixFan1992 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
contracts/src/v0.8/automation/dev/interfaces/v2_2/IAutomationRegistryMaster.sol
Large diffs are not rendered by default.
Oops, something went wrong.
189 changes: 189 additions & 0 deletions
189
contracts/src/v0.8/automation/dev/test/AutomationRegistry2_2.t.sol
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,189 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity 0.8.16; | ||
|
||
import {AutomationForwarderLogic} from "../../AutomationForwarderLogic.sol"; | ||
import {BaseTest} from "./BaseTest.t.sol"; | ||
import {AutomationRegistry2_2} from "../v2_2/AutomationRegistry2_2.sol"; | ||
import {AutomationRegistryBase2_2} from "../v2_2/AutomationRegistryBase2_2.sol"; | ||
import {AutomationRegistryLogicA2_2} from "../v2_2/AutomationRegistryLogicA2_2.sol"; | ||
import {AutomationRegistryLogicB2_2} from "../v2_2/AutomationRegistryLogicB2_2.sol"; | ||
import {IAutomationRegistryMaster} from "../interfaces/v2_2/IAutomationRegistryMaster.sol"; | ||
|
||
contract AutomationRegistry2_2_SetUp is BaseTest { | ||
address internal constant LINK_ETH_FEED = 0x1111111111111111111111111111111111111110; | ||
address internal constant FAST_GAS_FEED = 0x1111111111111111111111111111111111111112; | ||
address internal constant LINK_TOKEN = 0x1111111111111111111111111111111111111113; | ||
|
||
// Signer private keys used for these test | ||
uint256 internal constant PRIVATE0 = 0x7b2e97fe057e6de99d6872a2ef2abf52c9b4469bc848c2465ac3fcd8d336e81d; | ||
uint256 internal constant PRIVATE1 = 0xab56160806b05ef1796789248e1d7f34a6465c5280899159d645218cd216cee6; | ||
uint256 internal constant PRIVATE2 = 0x6ec7caa8406a49b76736602810e0a2871959fbbb675e23a8590839e4717f1f7f; | ||
uint256 internal constant PRIVATE3 = 0x80f14b11da94ae7f29d9a7713ea13dc838e31960a5c0f2baf45ed458947b730a; | ||
|
||
uint64 internal constant OFFCHAIN_CONFIG_VERSION = 30; // 2 for OCR2 | ||
uint8 internal constant F = 1; | ||
|
||
address[] internal s_valid_signers; | ||
address[] internal s_valid_transmitters; | ||
address[] internal s_registrars; | ||
|
||
function setUp() public override { | ||
s_valid_transmitters = new address[](4); | ||
for (uint160 i = 0; i < 4; ++i) { | ||
s_valid_transmitters[i] = address(4 + i); | ||
} | ||
|
||
s_valid_signers = new address[](4); | ||
s_valid_signers[0] = vm.addr(PRIVATE0); //0xc110458BE52CaA6bB68E66969C3218A4D9Db0211 | ||
s_valid_signers[1] = vm.addr(PRIVATE1); //0xc110a19c08f1da7F5FfB281dc93630923F8E3719 | ||
s_valid_signers[2] = vm.addr(PRIVATE2); //0xc110fdF6e8fD679C7Cc11602d1cd829211A18e9b | ||
s_valid_signers[3] = vm.addr(PRIVATE3); //0xc11028017c9b445B6bF8aE7da951B5cC28B326C0 | ||
|
||
s_registrars = new address[](1); | ||
s_registrars[0] = 0x3a0eDE26aa188BFE00b9A0C9A431A1a0CA5f7966; | ||
} | ||
|
||
function deployRegistry2_2(AutomationRegistryBase2_2.Mode mode) public returns (IAutomationRegistryMaster) { | ||
AutomationForwarderLogic forwarderLogic = new AutomationForwarderLogic(); | ||
AutomationRegistryLogicB2_2 logicB2_2 = new AutomationRegistryLogicB2_2( | ||
mode, | ||
LINK_TOKEN, | ||
LINK_ETH_FEED, | ||
FAST_GAS_FEED, | ||
address(forwarderLogic) | ||
); | ||
AutomationRegistryLogicA2_2 logicA2_2 = new AutomationRegistryLogicA2_2(logicB2_2); | ||
IAutomationRegistryMaster registry2_2 = IAutomationRegistryMaster( | ||
address(new AutomationRegistry2_2(AutomationRegistryLogicB2_2(address(logicA2_2)))) | ||
); | ||
return registry2_2; | ||
} | ||
} | ||
|
||
contract AutomationRegistry2_2_LatestConfigDetails is AutomationRegistry2_2_SetUp { | ||
function testGet() public { | ||
IAutomationRegistryMaster registry = IAutomationRegistryMaster( | ||
address(deployRegistry2_2(AutomationRegistryBase2_2.Mode(0))) | ||
); | ||
(uint32 configCount, uint32 blockNumber, bytes32 configDigest) = registry.latestConfigDetails(); | ||
assertEq(configCount, 0); | ||
assertEq(blockNumber, 0); | ||
assertEq(configDigest, ""); | ||
} | ||
} | ||
|
||
contract AutomationRegistry2_2_SetConfig is AutomationRegistry2_2_SetUp { | ||
event ConfigSet( | ||
uint32 previousConfigBlockNumber, | ||
bytes32 configDigest, | ||
uint64 configCount, | ||
address[] signers, | ||
address[] transmitters, | ||
uint8 f, | ||
bytes onchainConfig, | ||
uint64 offchainConfigVersion, | ||
bytes offchainConfig | ||
); | ||
|
||
function testSetConfigSuccess() public { | ||
IAutomationRegistryMaster registry = IAutomationRegistryMaster( | ||
address(deployRegistry2_2(AutomationRegistryBase2_2.Mode(0))) | ||
); | ||
(uint32 configCount, , ) = registry.latestConfigDetails(); | ||
assertEq(configCount, 0); | ||
|
||
AutomationRegistryBase2_2.OnchainConfig memory cfg = AutomationRegistryBase2_2.OnchainConfig({ | ||
paymentPremiumPPB: 10_000, | ||
flatFeeMicroLink: 40_000, | ||
checkGasLimit: 5_000_000, | ||
stalenessSeconds: 90_000, | ||
gasCeilingMultiplier: 0, | ||
minUpkeepSpend: 0, | ||
maxPerformGas: 10_000_000, | ||
maxCheckDataSize: 5_000, | ||
maxPerformDataSize: 5_000, | ||
maxRevertDataSize: 5_000, | ||
fallbackGasPrice: 20_000_000_000, | ||
fallbackLinkPrice: 200_000_000_000, | ||
transcoder: 0xB1e66855FD67f6e85F0f0fA38cd6fBABdf00923c, | ||
registrars: s_registrars, | ||
upkeepPrivilegeManager: 0xD9c855F08A7e460691F41bBDDe6eC310bc0593D8, | ||
reorgProtectionEnabled: true | ||
}); | ||
bytes memory onchainConfigBytes = abi.encode(cfg); | ||
|
||
uint256 a = 1234; | ||
address b = address(0); | ||
bytes memory offchainConfigBytes = abi.encode(a, b); | ||
bytes32 configDigest = _configDigestFromConfigData( | ||
block.chainid, | ||
address(registry), | ||
++configCount, | ||
s_valid_signers, | ||
s_valid_transmitters, | ||
F, | ||
onchainConfigBytes, | ||
OFFCHAIN_CONFIG_VERSION, | ||
offchainConfigBytes | ||
); | ||
|
||
vm.expectEmit(); | ||
emit ConfigSet( | ||
0, | ||
configDigest, | ||
configCount, | ||
s_valid_signers, | ||
s_valid_transmitters, | ||
F, | ||
onchainConfigBytes, | ||
OFFCHAIN_CONFIG_VERSION, | ||
offchainConfigBytes | ||
); | ||
|
||
registry.setConfig( | ||
s_valid_signers, | ||
s_valid_transmitters, | ||
F, | ||
onchainConfigBytes, | ||
OFFCHAIN_CONFIG_VERSION, | ||
offchainConfigBytes | ||
); | ||
|
||
(, , address[] memory signers, address[] memory transmitters, uint8 f) = registry.getState(); | ||
|
||
assertEq(signers, s_valid_signers); | ||
assertEq(transmitters, s_valid_transmitters); | ||
assertEq(f, F); | ||
} | ||
|
||
function _configDigestFromConfigData( | ||
uint256 chainId, | ||
address contractAddress, | ||
uint64 configCount, | ||
address[] memory signers, | ||
address[] memory transmitters, | ||
uint8 f, | ||
bytes memory onchainConfig, | ||
uint64 offchainConfigVersion, | ||
bytes memory offchainConfig | ||
) internal pure returns (bytes32) { | ||
uint256 h = uint256( | ||
keccak256( | ||
abi.encode( | ||
chainId, | ||
contractAddress, | ||
configCount, | ||
signers, | ||
transmitters, | ||
f, | ||
onchainConfig, | ||
offchainConfigVersion, | ||
offchainConfig | ||
) | ||
) | ||
); | ||
uint256 prefixMask = type(uint256).max << (256 - 16); // 0xFFFF00..00 | ||
uint256 prefix = 0x0001 << (256 - 16); // 0x000100..00 | ||
return bytes32((prefix & prefixMask) | (h & ~prefixMask)); | ||
} | ||
} |
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,13 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.16; | ||
|
||
import "forge-std/Test.sol"; | ||
|
||
contract BaseTest is Test { | ||
address internal OWNER = 0x00007e64E1fB0C487F25dd6D3601ff6aF8d32e4e; | ||
|
||
function setUp() public virtual { | ||
vm.startPrank(OWNER); | ||
deal(OWNER, 1e20); | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think we can keep all of the tests in a single
AutomationRegistry2_2_Test
contract, yeah? I don't see the need to separate tests into their own contractsThere 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.
according to CCIP's foundry tests, each function to be tested will have a separate contract like this.
i am thinking we can follow their style guide.