From 20b2e0ddabc5adb6cce5cf8953d593b0a3fdf4d0 Mon Sep 17 00:00:00 2001 From: Michael Fletcher Date: Mon, 18 Nov 2024 21:25:42 +0000 Subject: [PATCH] v0.4 test fixes --- .../src/v0.8/feeds/DualAggregatorOriginal.sol | 0 .../src/v0.8/llo-feeds/v0.5.0/Verifier.sol | 13 +- .../llo-feeds/v0.5.0/interfaces/IVerifier.sol | 7 - .../test/verifier/BaseVerifierTest.t.sol | 2 + .../verifier/VerifierInterfacesTest.t.sol | 4 +- .../test/verifier/VerifierSetConfigTest.t.sol | 73 +- .../verifier/VerifierTestBillingReport.t.sol | 16 +- .../test/verifier/VerifierTestRewards.t.sol | 26 +- ...erTestRewardsMultiVefifierFeeManager.t.sol | 71 +- .../verifier/VerifierVerifyBulkTest.t.sol | 4 +- .../test/verifier/VerifierVerifyTest.t.sol | 660 +++--------------- 11 files changed, 194 insertions(+), 682 deletions(-) create mode 100644 contracts/src/v0.8/feeds/DualAggregatorOriginal.sol diff --git a/contracts/src/v0.8/feeds/DualAggregatorOriginal.sol b/contracts/src/v0.8/feeds/DualAggregatorOriginal.sol new file mode 100644 index 00000000000..e69de29bb2d diff --git a/contracts/src/v0.8/llo-feeds/v0.5.0/Verifier.sol b/contracts/src/v0.8/llo-feeds/v0.5.0/Verifier.sol index 7f58959ac03..9ab936b0a33 100644 --- a/contracts/src/v0.8/llo-feeds/v0.5.0/Verifier.sol +++ b/contracts/src/v0.8/llo-feeds/v0.5.0/Verifier.sol @@ -132,16 +132,6 @@ contract Verifier is IVerifier, IVerifierProxyVerifier, ConfirmedOwner, TypeAndV revert ZeroAddress(); } - // Proxy should support TypeAndVersion as we need to identify which proxy is calling - if(!IERC165(verifierProxy).supportsInterface(type(TypeAndVersionInterface).interfaceId)) - revert VerifierProxyInvalid(); - - // If it's the v0.3 Proxy check it implements the V03 Interface - if (keccak256(bytes(TypeAndVersionInterface(verifierProxy).typeAndVersion())) == V03_PROXY_TYPE_AND_VERSION) { - if(!IERC165(verifierProxy).supportsInterface(type(IVerifierProxyV03).interfaceId)) - revert VerifierProxyInvalid(); - } - i_verifierProxy = verifierProxy; } @@ -376,8 +366,7 @@ contract Verifier is IVerifier, IVerifierProxyVerifier, ConfirmedOwner, TypeAndV return "Verifier 0.5.0"; } - // /// Utility function to get all configs off-chain - // TODO should we expose? + /// Utility function to get all configs off-chain function getAllConfigs( uint256 startIndex, uint256 endIndex diff --git a/contracts/src/v0.8/llo-feeds/v0.5.0/interfaces/IVerifier.sol b/contracts/src/v0.8/llo-feeds/v0.5.0/interfaces/IVerifier.sol index ed969a5b85c..83c15633ae1 100644 --- a/contracts/src/v0.8/llo-feeds/v0.5.0/interfaces/IVerifier.sol +++ b/contracts/src/v0.8/llo-feeds/v0.5.0/interfaces/IVerifier.sol @@ -37,11 +37,4 @@ interface IVerifier is IERC165 { * @param isActive The new config active status */ function setConfigActive(bytes32 configDigest, bool isActive) external; - - //TODO Nested config giving me trouble - // /** - // * @notice Returns all DON configurations - // * @return array of DON configurations - // */ - // function getAllConfigs() external view returns (CommonV5.Config[] memory); } diff --git a/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/BaseVerifierTest.t.sol b/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/BaseVerifierTest.t.sol index ee2967c2862..191487d398b 100644 --- a/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/BaseVerifierTest.t.sol +++ b/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/BaseVerifierTest.t.sol @@ -28,6 +28,8 @@ contract BaseTest is Test { uint8 internal constant FAULT_TOLERANCE = 10; + bytes32 internal DEFAULT_CONFIG_DIGEST = keccak256("DEFAULT_CONFIG_DIGEST"); + VerifierProxy internal s_verifierProxy; Verifier internal s_verifier; FeeManager internal feeManager; diff --git a/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierInterfacesTest.t.sol b/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierInterfacesTest.t.sol index b7ee8d7f43b..b1fc80a0dbe 100644 --- a/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierInterfacesTest.t.sol +++ b/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierInterfacesTest.t.sol @@ -76,7 +76,7 @@ contract VerifierInterfacesTest is VerifierWithFeeManager { function setUp() public virtual override { VerifierWithFeeManager.setUp(); - s_reportContext[0] = bytes32(uint256(1)); + s_reportContext[0] = DEFAULT_CONFIG_DIGEST; Signer[] memory signers = _getSigners(MAX_ORACLES); s_testReport = V3Report({ @@ -93,7 +93,7 @@ contract VerifierInterfacesTest is VerifierWithFeeManager { address[] memory signerAddrs = _getSignerAddresses(signers); Common.AddressAndWeight[] memory weights = new Common.AddressAndWeight[](1); weights[0] = Common.AddressAndWeight(DEFAULT_RECIPIENT_1, ONE_PERCENT * 100); - s_verifier.setConfig(bytes32(uint256(1)), signerAddrs, MINIMAL_FAULT_TOLERANCE, weights); + s_verifier.setConfig(DEFAULT_CONFIG_DIGEST, signerAddrs, MINIMAL_FAULT_TOLERANCE, weights); signedReport = _generateV3EncodedBlob(s_testReport, s_reportContext, signers); verifier = ITestVerifierProxy(address(s_verifierProxy)); diff --git a/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierSetConfigTest.t.sol b/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierSetConfigTest.t.sol index 7051b3fc013..ea7c91d69b8 100644 --- a/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierSetConfigTest.t.sol +++ b/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierSetConfigTest.t.sol @@ -15,7 +15,7 @@ contract VerifierSetConfigTest is BaseTest { Signer[] memory signers = _getSigners(MAX_ORACLES); changePrank(USER); s_verifier.setConfig( - bytes32(uint256(1)), + DEFAULT_CONFIG_DIGEST, _getSignerAddresses(signers), FAULT_TOLERANCE, new Common.AddressAndWeight[](0) @@ -25,13 +25,13 @@ contract VerifierSetConfigTest is BaseTest { function test_revertsIfSetWithTooManySigners() public { address[] memory signers = new address[](MAX_ORACLES + 1); vm.expectRevert(abi.encodeWithSelector(Verifier.ExcessSigners.selector, signers.length, MAX_ORACLES)); - s_verifier.setConfig(bytes32(uint256(1)), signers, FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); + s_verifier.setConfig(DEFAULT_CONFIG_DIGEST, signers, FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); } function test_revertsIfFaultToleranceIsZero() public { vm.expectRevert(abi.encodeWithSelector(Verifier.FaultToleranceMustBePositive.selector)); Signer[] memory signers = _getSigners(MAX_ORACLES); - s_verifier.setConfig(bytes32(uint256(1)), _getSignerAddresses(signers), 0, new Common.AddressAndWeight[](0)); + s_verifier.setConfig(DEFAULT_CONFIG_DIGEST, _getSignerAddresses(signers), 0, new Common.AddressAndWeight[](0)); } function test_revertsIfNotEnoughSigners() public { @@ -42,7 +42,7 @@ contract VerifierSetConfigTest is BaseTest { vm.expectRevert( abi.encodeWithSelector(Verifier.InsufficientSigners.selector, signers.length, FAULT_TOLERANCE * 3 + 1) ); - s_verifier.setConfig(bytes32(uint256(1)), signers, FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); + s_verifier.setConfig(DEFAULT_CONFIG_DIGEST, signers, FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); } function test_revertsIfDuplicateSigners() public { @@ -50,7 +50,7 @@ contract VerifierSetConfigTest is BaseTest { address[] memory signerAddrs = _getSignerAddresses(signers); signerAddrs[0] = signerAddrs[1]; vm.expectRevert(abi.encodeWithSelector(Verifier.NonUniqueSignatures.selector)); - s_verifier.setConfig(bytes32(uint256(1)), signerAddrs, FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); + s_verifier.setConfig(DEFAULT_CONFIG_DIGEST, signerAddrs, FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); } function test_revertsIfSignerContainsZeroAddress() public { @@ -58,70 +58,9 @@ contract VerifierSetConfigTest is BaseTest { address[] memory signerAddrs = _getSignerAddresses(signers); signerAddrs[0] = address(0); vm.expectRevert(abi.encodeWithSelector(Verifier.ZeroAddress.selector)); - s_verifier.setConfig(bytes32(uint256(1)), signerAddrs, FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); + s_verifier.setConfig(DEFAULT_CONFIG_DIGEST, signerAddrs, FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); } - //TODO Is this function still relevant? - // function test_donConfigIdIsSameForSignersInDifferentOrder() public { - // Signer[] memory signers = _getSigners(MAX_ORACLES); - // address[] memory signerAddrs = _getSignerAddresses(signers); - - // bytes24 expectedDonConfigId = _donConfigIdFromConfigData(signerAddrs, FAULT_TOLERANCE); - - // s_verifier.setConfig(bytes32(uint256(1)), signerAddrs, FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); - // vm.warp(block.timestamp + 1); - - // address temp = signerAddrs[0]; - // signerAddrs[0] = signerAddrs[1]; - // signerAddrs[1] = temp; - - // vm.expectRevert(abi.encodeWithSelector(Verifier.ConfigAlreadyExists.selector, expectedDonConfigId)); - - // s_verifier.setConfig(bytes32(uint256(1)), signerAddrs, FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); - // } - //TODO Function is not likely relevant anymore - // function test_NoConfigAlreadyExists() public { - // Signer[] memory signers = _getSigners(MAX_ORACLES); - // address[] memory signerAddrs = _getSignerAddresses(signers); - - // s_verifier.setConfig(bytes32(uint256(1)), signerAddrs, FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); - - // vm.warp(block.timestamp + 1); - - // // testing adding same set of Signers but different FAULT_TOLERENCE does not result in ConfigAlreadyExists revert - // s_verifier.setConfig(bytes32(uint256(2)), signerAddrs, FAULT_TOLERANCE - 1, new Common.AddressAndWeight[](0)); - - // vm.warp(block.timestamp + 1); - - // // testing adding a different set of Signers with same FAULT_TOLERENCE does not result in ConfigAlreadyExists revert - // address[] memory signerAddrsMinusOne = new address[](signerAddrs.length - 1); - // for (uint256 i = 0; i < signerAddrs.length - 1; i++) { - // signerAddrsMinusOne[i] = signerAddrs[i]; - // } - // s_verifier.setConfig( - // bytes32(uint256(1)), signerAddrsMinusOne, FAULT_TOLERANCE - 1, new Common.AddressAndWeight[](0) - // ); - // } - - //TODO Is this function still relevant? - // function test_addressesAndWeightsDoNotProduceSideEffectsInDonConfigIds() public { - // Signer[] memory signers = _getSigners(MAX_ORACLES); - // address[] memory signerAddrs = _getSignerAddresses(signers); - - // s_verifier.setConfig(bytes32(uint256(1)), signerAddrs, FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); - // vm.warp(block.timestamp + 1); - - // bytes24 expectedDonConfigId = _donConfigIdFromConfigData(signerAddrs, FAULT_TOLERANCE); - - // vm.expectRevert(abi.encodeWithSelector(Verifier.ConfigAlreadyExists.selector, expectedDonConfigId)); - - // // Same call to setConfig with different addressAndWeights do not entail a new DonConfigID - // // Resulting in a ConfigAlreadyExists error - // Common.AddressAndWeight[] memory weights = new Common.AddressAndWeight[](1); - // weights[0] = Common.AddressAndWeight(signers[0].signerAddress, 1); - // s_verifier.setConfig(bytes32(uint256(1)), signerAddrs, FAULT_TOLERANCE, weights); - // } - function test_setConfigActiveUnknownConfigId() public { vm.expectRevert(abi.encodeWithSelector(Verifier.ConfigDoesNotExist.selector)); s_verifier.setConfigActive(bytes32(uint256(3)), true); diff --git a/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierTestBillingReport.t.sol b/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierTestBillingReport.t.sol index 99cc78413d0..9aab6bdfa63 100644 --- a/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierTestBillingReport.t.sol +++ b/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierTestBillingReport.t.sol @@ -10,7 +10,7 @@ contract VerifierBillingTests is VerifierWithFeeManager { function setUp() public virtual override { VerifierWithFeeManager.setUp(); - s_reportContext[0] = bytes32(uint256(1)); + s_reportContext[0] = DEFAULT_CONFIG_DIGEST; s_testReportThree = V3Report({ feedId: FEED_ID_V3, observationsTimestamp: OBSERVATIONS_TIMESTAMP, @@ -28,9 +28,9 @@ contract VerifierBillingTests is VerifierWithFeeManager { Signer[] memory signers = _getSigners(MAX_ORACLES); address[] memory signerAddrs = _getSignerAddresses(signers); Common.AddressAndWeight[] memory weights = new Common.AddressAndWeight[](0); - s_verifier.setConfig(bytes32(uint256(1)), signerAddrs, FAULT_TOLERANCE, weights); + s_verifier.setConfig(DEFAULT_CONFIG_DIGEST, signerAddrs, FAULT_TOLERANCE, weights); bytes memory signedReport = _generateV3EncodedBlob(s_testReportThree, s_reportContext, signers); - bytes32 expectedDonConfigId = _donConfigIdFromConfigData(signerAddrs, FAULT_TOLERANCE); + bytes32 expectedDonConfigId = DEFAULT_CONFIG_DIGEST; _approveLink(address(rewardManager), DEFAULT_REPORT_LINK_FEE, USER); _verify(signedReport, address(link), 0, USER); @@ -48,7 +48,7 @@ contract VerifierBillingTests is VerifierWithFeeManager { Common.AddressAndWeight[] memory weights = new Common.AddressAndWeight[](1); weights[0] = Common.AddressAndWeight(signerAddrs[0], ONE_PERCENT * 100); - s_verifier.setConfig(bytes32(uint256(1)), signerAddrs, FAULT_TOLERANCE, weights); + s_verifier.setConfig(DEFAULT_CONFIG_DIGEST, signerAddrs, FAULT_TOLERANCE, weights); bytes memory signedReport = _generateV3EncodedBlob( s_testReportThree, s_reportContext, @@ -66,7 +66,7 @@ contract VerifierBillingTests is VerifierWithFeeManager { address[] memory signerAddrs = _getSignerAddresses(signers); Common.AddressAndWeight[] memory weights = new Common.AddressAndWeight[](0); - s_verifier.setConfig(bytes32(uint256(1)), signerAddrs, FAULT_TOLERANCE, weights); + s_verifier.setConfig(DEFAULT_CONFIG_DIGEST, signerAddrs, FAULT_TOLERANCE, weights); bytes memory signedReport = _generateV3EncodedBlob( s_testReportThree, s_reportContext, @@ -83,7 +83,7 @@ contract VerifierBillingTests is VerifierWithFeeManager { address[] memory signerAddrs = _getSignerAddresses(signers); Common.AddressAndWeight[] memory weights = new Common.AddressAndWeight[](0); - s_verifier.setConfig(bytes32(uint256(1)), signerAddrs, FAULT_TOLERANCE, weights); + s_verifier.setConfig(DEFAULT_CONFIG_DIGEST, signerAddrs, FAULT_TOLERANCE, weights); bytes memory signedReport = _generateV3EncodedBlob( s_testReportThree, s_reportContext, @@ -104,11 +104,11 @@ contract VerifierBulkVerifyBillingReport is VerifierWithFeeManager { function setUp() public virtual override { VerifierWithFeeManager.setUp(); // setting a DonConfig we can reuse in the rest of tests - s_reportContext[0] = bytes32(uint256(1)); + s_reportContext[0] = DEFAULT_CONFIG_DIGEST; Signer[] memory signers = _getSigners(MAX_ORACLES); address[] memory signerAddrs = _getSignerAddresses(signers); Common.AddressAndWeight[] memory weights = new Common.AddressAndWeight[](0); - s_verifier.setConfig(bytes32(uint256(1)), signerAddrs, FAULT_TOLERANCE, weights); + s_verifier.setConfig(DEFAULT_CONFIG_DIGEST, signerAddrs, FAULT_TOLERANCE, weights); } function test_verifyWithBulkLink() public { diff --git a/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierTestRewards.t.sol b/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierTestRewards.t.sol index 807302472dc..8c83f5b4e1b 100644 --- a/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierTestRewards.t.sol +++ b/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierTestRewards.t.sol @@ -31,7 +31,7 @@ contract VerifierBillingTests is VerifierWithFeeManager { function setUp() public virtual override { VerifierWithFeeManager.setUp(); - s_reportContext[0] = bytes32(uint256(1)); + s_reportContext[0] = DEFAULT_CONFIG_DIGEST; s_testReport = generateReportAtTimestamp(block.timestamp); } @@ -92,9 +92,9 @@ contract VerifierBillingTests is VerifierWithFeeManager { address[] memory signerAddrs = _getSignerAddresses(signers); Common.AddressAndWeight[] memory weights = new Common.AddressAndWeight[](1); weights[0] = Common.AddressAndWeight(DEFAULT_RECIPIENT_1, ONE_PERCENT * 100); - s_verifier.setConfig(bytes32(uint256(1)), signerAddrs, FAULT_TOLERANCE, weights); + s_verifier.setConfig(DEFAULT_CONFIG_DIGEST, signerAddrs, FAULT_TOLERANCE, weights); bytes memory signedReport = _generateV3EncodedBlob(s_testReport, s_reportContext, signers); - bytes32 expectedDonConfigId = _donConfigIdFromConfigData(signerAddrs, FAULT_TOLERANCE); + bytes32 expectedDonConfigId = DEFAULT_CONFIG_DIGEST; _approveLink(address(rewardManager), DEFAULT_REPORT_LINK_FEE, USER); _verify(signedReport, address(link), 0, USER); @@ -123,10 +123,10 @@ contract VerifierBillingTests is VerifierWithFeeManager { Signer[] memory signers = _getSigners(MAX_ORACLES); address[] memory signerAddrs = _getSignerAddresses(signers); (Common.AddressAndWeight[] memory weights, address[] memory recipients) = getRecipientAndWeightsGroup1(); - s_verifier.setConfig(bytes32(uint256(1)), signerAddrs, FAULT_TOLERANCE, weights); + s_verifier.setConfig(DEFAULT_CONFIG_DIGEST, signerAddrs, FAULT_TOLERANCE, weights); bytes memory signedReport = _generateV3EncodedBlob(s_testReport, s_reportContext, signers); - bytes32 expectedDonConfigId = _donConfigIdFromConfigData(signerAddrs, FAULT_TOLERANCE); + bytes32 expectedDonConfigId = DEFAULT_CONFIG_DIGEST; uint256 number_of_reports_verified = 10; @@ -149,7 +149,6 @@ contract VerifierBillingTests is VerifierWithFeeManager { assertEq(link.balanceOf(address(rewardManager)), 0); } - //TODO Is this function still relevant? function test_rewardsAreDistributedAccordingToWeightsUsingHistoricalConfigs() public { /* Verifies that reports verified with historical give rewards according to the verifying config AddressAndWeight. @@ -165,12 +164,12 @@ contract VerifierBillingTests is VerifierWithFeeManager { (Common.AddressAndWeight[] memory weights, address[] memory recipients) = getRecipientAndWeightsGroup1(); // Create ConfigA - s_verifier.setConfig(bytes32(uint256(1)), signerAddrs, MINIMAL_FAULT_TOLERANCE, weights); + s_verifier.setConfig(DEFAULT_CONFIG_DIGEST, signerAddrs, MINIMAL_FAULT_TOLERANCE, weights); vm.warp(block.timestamp + 100); V3Report memory testReportAtT1 = generateReportAtTimestamp(block.timestamp); bytes memory signedReportT1 = _generateV3EncodedBlob(testReportAtT1, s_reportContext, signers); - bytes32 expectedDonConfigIdA = _donConfigIdFromConfigData(signerAddrs, MINIMAL_FAULT_TOLERANCE); + bytes32 expectedDonConfigIdA = DEFAULT_CONFIG_DIGEST; uint256 number_of_reports_verified = 2; @@ -181,9 +180,10 @@ contract VerifierBillingTests is VerifierWithFeeManager { address[] memory signerAddrs2 = _getSignerAddresses(signers2); (Common.AddressAndWeight[] memory weights2, address[] memory recipients2) = getRecipientAndWeightsGroup2(); + bytes32 DUMMY_CONFIG_DIGEST = keccak256("DUMMY_CONFIG_DIGEST"); + // Create ConfigB - s_verifier.setConfig(bytes32(uint256(2)), signerAddrs2, MINIMAL_FAULT_TOLERANCE, weights2); - bytes32 expectedDonConfigIdB = _donConfigIdFromConfigData(signerAddrs2, MINIMAL_FAULT_TOLERANCE); + s_verifier.setConfig(DUMMY_CONFIG_DIGEST, signerAddrs2, MINIMAL_FAULT_TOLERANCE, weights2); V3Report memory testReportAtT2 = generateReportAtTimestamp(block.timestamp); @@ -193,6 +193,8 @@ contract VerifierBillingTests is VerifierWithFeeManager { _verify(signedReportT1, address(link), 0, USER); } + s_reportContext[0] = DUMMY_CONFIG_DIGEST; + // verifying using ConfigB (report with new timestamp) for (uint256 i = 0; i < number_of_reports_verified; i++) { _approveLink(address(rewardManager), DEFAULT_REPORT_LINK_FEE, USER); @@ -201,7 +203,7 @@ contract VerifierBillingTests is VerifierWithFeeManager { uint256 expected_pool_amount = DEFAULT_REPORT_LINK_FEE * number_of_reports_verified; assertEq(rewardManager.s_totalRewardRecipientFees(expectedDonConfigIdA), expected_pool_amount); - assertEq(rewardManager.s_totalRewardRecipientFees(expectedDonConfigIdB), expected_pool_amount); + assertEq(rewardManager.s_totalRewardRecipientFees(DUMMY_CONFIG_DIGEST), expected_pool_amount); // check the recipients are paid according to weights payRecipients(expectedDonConfigIdA, recipients, ADMIN); @@ -211,7 +213,7 @@ contract VerifierBillingTests is VerifierWithFeeManager { assertEq(link.balanceOf(recipients[i]), expected_pool_amount / 4); } - payRecipients(expectedDonConfigIdB, recipients2, ADMIN); + payRecipients(DUMMY_CONFIG_DIGEST, recipients2, ADMIN); for (uint256 i = 1; i < recipients2.length; i++) { // //each recipient should receive 1/4 of the pool diff --git a/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierTestRewardsMultiVefifierFeeManager.t.sol b/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierTestRewardsMultiVefifierFeeManager.t.sol index 6e10dc89715..413503db7a5 100644 --- a/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierTestRewardsMultiVefifierFeeManager.t.sol +++ b/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierTestRewardsMultiVefifierFeeManager.t.sol @@ -4,6 +4,7 @@ pragma solidity 0.8.19; import {Common} from "../../../libraries/Common.sol"; import {VerifierProxy} from "../../VerifierProxy.sol"; import {MultipleVerifierWithMultipleFeeManagers} from "./BaseVerifierTest.t.sol"; +import {RewardManager} from "../../RewardManager.sol"; contract MultiVerifierBillingTests is MultipleVerifierWithMultipleFeeManagers { uint8 MINIMAL_FAULT_TOLERANCE = 2; @@ -20,7 +21,7 @@ contract MultiVerifierBillingTests is MultipleVerifierWithMultipleFeeManagers { function setUp() public virtual override { MultipleVerifierWithMultipleFeeManagers.setUp(); - s_reportContext[0] = bytes32(uint256(1)); + s_reportContext[0] = DEFAULT_CONFIG_DIGEST; s_testReport = generateReportAtTimestamp(block.timestamp); } @@ -93,38 +94,42 @@ contract MultiVerifierBillingTests is MultipleVerifierWithMultipleFeeManagers { Common.AddressAndWeight[] memory weights3 = new Common.AddressAndWeight[](1); weights3[0] = Common.AddressAndWeight(DEFAULT_RECIPIENT_3, ONE_PERCENT * 100); - //TODO Not sure if these should have different config digests - s_verifier.setConfig(bytes32(uint256(1)), signerAddrs, FAULT_TOLERANCE, weights); - s_verifier2.setConfig(bytes32(uint256(1)), signerAddrs, MINIMAL_FAULT_TOLERANCE, weights2); - s_verifier3.setConfig(bytes32(uint256(1)), signerAddrs, MINIMAL_FAULT_TOLERANCE + 1, weights3); + bytes32 DUMMY_CONFIG_DIGEST_1 = keccak256("DUMMY_CONFIG_DIGEST_1"); + bytes32 DUMMY_CONFIG_DIGEST_2 = keccak256("DUMMY_CONFIG_DIGEST_2"); + + s_verifier.setConfig(DEFAULT_CONFIG_DIGEST, signerAddrs, FAULT_TOLERANCE, weights); + s_verifier2.setConfig(DUMMY_CONFIG_DIGEST_1, signerAddrs, MINIMAL_FAULT_TOLERANCE, weights2); + s_verifier3.setConfig(DUMMY_CONFIG_DIGEST_2, signerAddrs, MINIMAL_FAULT_TOLERANCE + 1, weights3); + bytes memory signedReport = _generateV3EncodedBlob(s_testReport, s_reportContext, signers); - bytes32 expectedDonConfigID = _donConfigIdFromConfigData(signerAddrs, FAULT_TOLERANCE); - bytes32 expectedDonConfigID2 = _donConfigIdFromConfigData(signerAddrs, MINIMAL_FAULT_TOLERANCE); - bytes32 expectedDonConfigID3 = _donConfigIdFromConfigData(signerAddrs, MINIMAL_FAULT_TOLERANCE + 1); + s_reportContext[0] = DUMMY_CONFIG_DIGEST_1; + bytes memory signedReport2 = _generateV3EncodedBlob(s_testReport, s_reportContext, signers); + s_reportContext[0] = DUMMY_CONFIG_DIGEST_2; + bytes memory signedReport3 = _generateV3EncodedBlob(s_testReport, s_reportContext, signers); _approveLink(address(rewardManager), DEFAULT_REPORT_LINK_FEE, USER); _verify(s_verifierProxy, signedReport, address(link), 0, USER); assertEq(link.balanceOf(USER), DEFAULT_LINK_MINT_QUANTITY - DEFAULT_REPORT_LINK_FEE); // internal state checks - assertEq(feeManager.s_linkDeficit(expectedDonConfigID), 0); - assertEq(rewardManager.s_totalRewardRecipientFees(expectedDonConfigID), DEFAULT_REPORT_LINK_FEE); + assertEq(feeManager.s_linkDeficit(DEFAULT_CONFIG_DIGEST), 0); + assertEq(rewardManager.s_totalRewardRecipientFees(DEFAULT_CONFIG_DIGEST), DEFAULT_REPORT_LINK_FEE); assertEq(link.balanceOf(address(rewardManager)), DEFAULT_REPORT_LINK_FEE); // check the recipients are paid according to weights // These rewards happened through verifier1 and feeManager1 address[] memory recipients = new address[](1); recipients[0] = DEFAULT_RECIPIENT_1; - payRecipients(expectedDonConfigID, recipients, ADMIN); + payRecipients(DEFAULT_CONFIG_DIGEST, recipients, ADMIN); assertEq(link.balanceOf(recipients[0]), DEFAULT_REPORT_LINK_FEE); assertEq(link.balanceOf(address(rewardManager)), 0); - // these rewards happaned through verifier2 and feeManager1 + // these rewards happened through verifier2 and feeManager1 address[] memory recipients2 = new address[](1); recipients2[0] = DEFAULT_RECIPIENT_2; _approveLink(address(rewardManager), DEFAULT_REPORT_LINK_FEE, USER); - _verify(s_verifierProxy2, signedReport, address(link), 0, USER); - payRecipients(expectedDonConfigID2, recipients2, ADMIN); + _verify(s_verifierProxy2, signedReport2, address(link), 0, USER); + payRecipients(DUMMY_CONFIG_DIGEST_1, recipients2, ADMIN); assertEq(link.balanceOf(recipients2[0]), DEFAULT_REPORT_LINK_FEE); assertEq(link.balanceOf(address(rewardManager)), 0); @@ -132,9 +137,43 @@ contract MultiVerifierBillingTests is MultipleVerifierWithMultipleFeeManagers { address[] memory recipients3 = new address[](1); recipients3[0] = DEFAULT_RECIPIENT_3; _approveLink(address(rewardManager), DEFAULT_REPORT_LINK_FEE, USER); - _verify(s_verifierProxy3, signedReport, address(link), 0, USER); - payRecipients(expectedDonConfigID3, recipients3, ADMIN); + _verify(s_verifierProxy3, signedReport3, address(link), 0, USER); + payRecipients(DUMMY_CONFIG_DIGEST_2, recipients3, ADMIN); assertEq(link.balanceOf(recipients3[0]), DEFAULT_REPORT_LINK_FEE); assertEq(link.balanceOf(address(rewardManager)), 0); } + + function test_multipleFeeManagersAndVerifiersWithSameAddress() public { + /* + In this test we got: + - three verifiers (verifier, verifier2, verifier3). + - two fee managers (feeManager, feeManager2) + - one reward manager + + we glue: + - feeManager is used by verifier1 and verifier2 + - feeManager is used by verifier3 + - Rewardmanager is used by feeManager and feeManager2 + + In this test we do verificatons via verifier1, verifier2 and verifier3 and check that rewards are set accordingly + + */ + Signer[] memory signers = _getSigners(MAX_ORACLES); + address[] memory signerAddrs = _getSignerAddresses(signers); + Common.AddressAndWeight[] memory weights = new Common.AddressAndWeight[](1); + weights[0] = Common.AddressAndWeight(DEFAULT_RECIPIENT_1, ONE_PERCENT * 100); + + Common.AddressAndWeight[] memory weights2 = new Common.AddressAndWeight[](1); + weights2[0] = Common.AddressAndWeight(DEFAULT_RECIPIENT_2, ONE_PERCENT * 100); + + Common.AddressAndWeight[] memory weights3 = new Common.AddressAndWeight[](1); + weights3[0] = Common.AddressAndWeight(DEFAULT_RECIPIENT_3, ONE_PERCENT * 100); + + s_verifier.setConfig(DEFAULT_CONFIG_DIGEST, signerAddrs, FAULT_TOLERANCE, weights); + + // should fail with InvalidPoolId + vm.expectRevert(abi.encodeWithSelector(RewardManager.InvalidPoolId.selector)); + + s_verifier2.setConfig(DEFAULT_CONFIG_DIGEST, signerAddrs, FAULT_TOLERANCE, weights2); + } } diff --git a/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierVerifyBulkTest.t.sol b/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierVerifyBulkTest.t.sol index c312e3457a3..0aa60a7986c 100644 --- a/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierVerifyBulkTest.t.sol +++ b/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierVerifyBulkTest.t.sol @@ -12,7 +12,7 @@ contract VerifierVerifyBulkTest is BaseTest { function setUp() public virtual override { BaseTest.setUp(); - s_reportContext[0] = bytes32(uint256(1)); + s_reportContext[0] = DEFAULT_CONFIG_DIGEST; s_testReportThree = V3Report({ feedId: FEED_ID_V3, @@ -63,7 +63,7 @@ contract VerifierVerifyBulkTest is BaseTest { address[] memory signersAddrSubset1 = _getSignerAddresses(signersSubset1); // Config1 s_verifier.setConfig( - bytes32(uint256(1)), + DEFAULT_CONFIG_DIGEST, signersAddrSubset1, MINIMAL_FAULT_TOLERANCE, new Common.AddressAndWeight[](0) diff --git a/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierVerifyTest.t.sol b/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierVerifyTest.t.sol index 86773103391..468bc56472c 100644 --- a/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierVerifyTest.t.sol +++ b/contracts/src/v0.8/llo-feeds/v0.5.0/test/verifier/VerifierVerifyTest.t.sol @@ -30,9 +30,9 @@ contract VerifierVerifyTest is BaseTest { // Simple use case just setting a config and verifying a report Signer[] memory signers = _getSigners(MAX_ORACLES); address[] memory signerAddrs = _getSignerAddresses(signers); - s_reportContext[0] = bytes32(uint256(1)); + s_reportContext[0] = DEFAULT_CONFIG_DIGEST; - s_verifier.setConfig(bytes32(uint256(1)), signerAddrs, FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); + s_verifier.setConfig(DEFAULT_CONFIG_DIGEST, signerAddrs, FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); bytes memory signedReport = _generateV3EncodedBlob(s_testReportThree, s_reportContext, signers); @@ -40,24 +40,63 @@ contract VerifierVerifyTest is BaseTest { assertReportsEqual(verifierResponse, s_testReportThree); } + + function test_verifyReportWithMultipleConfigs() public { + // Simple use case just setting a config and verifying a report + Signer[] memory signers = _getSigners(MAX_ORACLES); + Signer[] memory signers2 = _getSigners(MAX_ORACLES); + Signer[] memory signers3 = _getSigners(MAX_ORACLES); + + address[] memory signerAddrs = _getSignerAddresses(signers); + address[] memory signerAddrs2 = _getSignerAddresses(signers2); + address[] memory signerAddrs3 = _getSignerAddresses(signers3); + + s_reportContext[0] = DEFAULT_CONFIG_DIGEST; + + bytes32 DUMMY_CONFIG_1 = keccak256("DUMMY_CONFIG_1"); + bytes32 DUMMY_CONFIG_2 = keccak256("DUMMY_CONFIG_2"); + + s_verifier.setConfig(DEFAULT_CONFIG_DIGEST, signerAddrs, FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); + s_verifier.setConfig(DUMMY_CONFIG_1, signerAddrs2, FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); + s_verifier.setConfig(DUMMY_CONFIG_2, signerAddrs3, FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); + + //verify + bytes memory signedReport = _generateV3EncodedBlob(s_testReportThree, s_reportContext, signers); + s_verifierProxy.verify(signedReport, abi.encode(native)); + + s_reportContext[0] = DUMMY_CONFIG_1; + bytes memory signedReport2 = _generateV3EncodedBlob(s_testReportThree, s_reportContext, signers2); + s_verifierProxy.verify(signedReport2, abi.encode(native)); + + s_reportContext[0] = DUMMY_CONFIG_2; + bytes memory signedReport3 = _generateV3EncodedBlob(s_testReportThree, s_reportContext, signers3); + s_verifierProxy.verify(signedReport3, abi.encode(native)); + + + vm.expectRevert(abi.encodeWithSelector(Verifier.BadVerification.selector)); + s_reportContext[0] = keccak256("UNKNOWN_CONFIG"); + bytes memory signedReport4 = _generateV3EncodedBlob(s_testReportThree, s_reportContext, signers); + s_verifierProxy.verify(signedReport4, abi.encode(native)); + } + function test_verifyTogglingActiveFlagsDonConfigs() public { // sets config Signer[] memory signers = _getSigners(MAX_ORACLES); address[] memory signerAddrs = _getSignerAddresses(signers); - s_reportContext[0] = bytes32(abi.encode(uint256(1))); + s_reportContext[0] = DEFAULT_CONFIG_DIGEST; bytes memory signedReport = _generateV3EncodedBlob(s_testReportThree, s_reportContext, signers); - s_verifier.setConfig(bytes32(uint256(1)), signerAddrs, FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); + s_verifier.setConfig(DEFAULT_CONFIG_DIGEST, signerAddrs, FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); // verifies report bytes memory verifierResponse = s_verifierProxy.verify(signedReport, abi.encode(native)); assertReportsEqual(verifierResponse, s_testReportThree); // test verifying via a config that is deactivated - s_verifier.setConfigActive(bytes32(uint256(1)), false); + s_verifier.setConfigActive(DEFAULT_CONFIG_DIGEST, false); vm.expectRevert(abi.encodeWithSelector(Verifier.BadVerification.selector)); verifierResponse = s_verifierProxy.verify(signedReport, abi.encode(native)); // test verifying via a reactivated config - s_verifier.setConfigActive(bytes32(uint256(1)), true); + s_verifier.setConfigActive(DEFAULT_CONFIG_DIGEST, true); verifierResponse = s_verifierProxy.verify(signedReport, abi.encode(native)); assertReportsEqual(verifierResponse, s_testReportThree); } @@ -76,7 +115,7 @@ contract VerifierVerifyTest is BaseTest { signersSubset1[6] = signers[6]; address[] memory signersAddrSubset1 = _getSignerAddresses(signersSubset1); s_verifier.setConfig( - bytes32(uint256(1)), + DEFAULT_CONFIG_DIGEST, signersAddrSubset1, MINIMAL_FAULT_TOLERANCE, new Common.AddressAndWeight[](0) @@ -105,7 +144,7 @@ contract VerifierVerifyTest is BaseTest { signersSubset1[6] = signers[6]; address[] memory signersAddrSubset1 = _getSignerAddresses(signersSubset1); s_verifier.setConfig( - bytes32(uint256(1)), + DEFAULT_CONFIG_DIGEST, signersAddrSubset1, MINIMAL_FAULT_TOLERANCE, new Common.AddressAndWeight[](0) @@ -133,7 +172,7 @@ contract VerifierVerifyTest is BaseTest { signersSubset1[6] = signers[6]; address[] memory signersAddrSubset1 = _getSignerAddresses(signersSubset1); s_verifier.setConfig( - bytes32(uint256(1)), + DEFAULT_CONFIG_DIGEST, signersAddrSubset1, MINIMAL_FAULT_TOLERANCE, new Common.AddressAndWeight[](0) @@ -166,7 +205,7 @@ contract VerifierVerifyTest is BaseTest { signersSubset1[6] = signers[6]; address[] memory signersAddrSubset1 = _getSignerAddresses(signersSubset1); s_verifier.setConfig( - bytes32(uint256(1)), + DEFAULT_CONFIG_DIGEST, signersAddrSubset1, MINIMAL_FAULT_TOLERANCE, new Common.AddressAndWeight[](0) @@ -186,550 +225,59 @@ contract VerifierVerifyTest is BaseTest { vm.expectRevert(abi.encodeWithSelector(Verifier.BadVerification.selector)); s_verifierProxy.verify(signedReport, abi.encode(native)); } - //TODO is this test still relevant? You can't have a newer config now. - // function test_canVerifyOlderV3ReportsWithOlderConfigs() public { - // /* - // This test is checking we can use historical Configs to verify reports: - // - DonConfigA has signers {A, B, C, E} is set at time T1 - // - DonConfigB has signers {A, B, C, D} is set at time T2 - // - checks we can verify a report with {B, C, D} signers (via DonConfigB) - // - checks we can verify a report with {B, C, E} signers and timestamp below T2 (via DonConfigA historical config) - // - checks we can't verify a report with {B, C, E} signers and timestamp above T2 (it gets verivied via DonConfigB) - // - sets DonConfigA as deactivated - // - checks we can't verify a report with {B, C, E} signers and timestamp below T2 (via DonConfigA) - // */ - // Signer[] memory signers = _getSigners(MAX_ORACLES); - - // uint8 MINIMAL_FAULT_TOLERANCE = 2; - // BaseTest.Signer[] memory signersSubset1 = new BaseTest.Signer[](7); - // signersSubset1[0] = signers[0]; - // signersSubset1[1] = signers[1]; - // signersSubset1[2] = signers[2]; - // signersSubset1[3] = signers[3]; - // signersSubset1[4] = signers[4]; - // signersSubset1[5] = signers[5]; - // signersSubset1[6] = signers[6]; - - // address[] memory signersAddrSubset1 = _getSignerAddresses(signersSubset1); - // // Config1 - // s_verifier.setConfig(bytes32(uint256(1)), signersAddrSubset1, MINIMAL_FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); - - // BaseTest.Signer[] memory signersSubset2 = new BaseTest.Signer[](7); - // signersSubset2[0] = signers[0]; - // signersSubset2[1] = signers[1]; - // signersSubset2[2] = signers[2]; - // signersSubset2[3] = signers[3]; - // signersSubset2[4] = signers[4]; - // signersSubset2[5] = signers[5]; - // signersSubset2[6] = signers[29]; - // address[] memory signersAddrSubset2 = _getSignerAddresses(signersSubset2); - - // V3Report memory reportAtSetConfig1Timestmap = V3Report({ - // feedId: FEED_ID_V3, - // observationsTimestamp: OBSERVATIONS_TIMESTAMP, - // validFromTimestamp: uint32(block.timestamp), - // nativeFee: uint192(DEFAULT_REPORT_NATIVE_FEE), - // linkFee: uint192(DEFAULT_REPORT_LINK_FEE), - // expiresAt: uint32(block.timestamp), - // benchmarkPrice: MEDIAN, - // bid: BID, - // ask: ASK - // }); - - // vm.warp(block.timestamp + 100); - - // // Config2 - // s_verifier.setConfig(bytes32(uint256(1)), signersAddrSubset2, MINIMAL_FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); - - // V3Report memory reportAtSetConfig2Timestmap = V3Report({ - // feedId: FEED_ID_V3, - // observationsTimestamp: OBSERVATIONS_TIMESTAMP, - // validFromTimestamp: uint32(block.timestamp), - // nativeFee: uint192(DEFAULT_REPORT_NATIVE_FEE), - // linkFee: uint192(DEFAULT_REPORT_LINK_FEE), - // expiresAt: uint32(block.timestamp), - // benchmarkPrice: MEDIAN, - // bid: BID, - // ask: ASK - // }); - - // BaseTest.Signer[] memory reportSigners = new BaseTest.Signer[](5); - // reportSigners[0] = signers[0]; - // reportSigners[1] = signers[1]; - // reportSigners[2] = signers[2]; - // reportSigners[3] = signers[3]; - // reportSigners[4] = signers[29]; - - // bytes memory signedReport = _generateV3EncodedBlob(reportAtSetConfig2Timestmap, s_reportContext, reportSigners); - - // // this report is verified via Config2 - // bytes memory verifierResponse = s_verifierProxy.verify(signedReport, abi.encode(native)); - // assertReportsEqual(verifierResponse, reportAtSetConfig2Timestmap); - - // BaseTest.Signer[] memory reportSigners2 = new BaseTest.Signer[](5); - // reportSigners2[0] = signers[0]; - // reportSigners2[1] = signers[1]; - // reportSigners2[2] = signers[2]; - // reportSigners2[3] = signers[3]; - // reportSigners2[4] = signers[6]; - - // bytes memory signedReport2 = _generateV3EncodedBlob(reportAtSetConfig1Timestmap, s_reportContext, reportSigners2); - - // // this report is verified via Config1 (using a historical config) - // bytes memory verifierResponse2 = s_verifierProxy.verify(signedReport2, abi.encode(native)); - // assertReportsEqual(verifierResponse2, reportAtSetConfig1Timestmap); - - // // same report with same signers but with a higher timestamp gets verified via Config2 - // // which means verification fails - // bytes memory signedReport3 = _generateV3EncodedBlob(reportAtSetConfig2Timestmap, s_reportContext, reportSigners2); - // vm.expectRevert(abi.encodeWithSelector(Verifier.BadVerification.selector)); - // s_verifierProxy.verify(signedReport3, abi.encode(native)); - - // // deactivating Config1 and trying a reverifications ends in failure - // s_verifier.setConfigActive(bytes32(uint256(1)), false); - // vm.expectRevert(abi.encodeWithSelector(Verifier.BadVerification.selector)); - // s_verifierProxy.verify(signedReport2, abi.encode(native)); - // } - - // function test_revertsVerifyIfNoAccess() public { - // vm.mockCall( - // ACCESS_CONTROLLER_ADDRESS, - // abi.encodeWithSelector(AccessControllerInterface.hasAccess.selector, USER), - // abi.encode(false) - // ); - // bytes memory signedReport = _generateV3EncodedBlob( - // s_testReportThree, - // s_reportContext, - // _getSigners(FAULT_TOLERANCE + 1) - // ); - - // vm.expectRevert(abi.encodeWithSelector(Verifier.AccessForbidden.selector)); - - // changePrank(USER); - // s_verifier.verify(signedReport, abi.encode(native), msg.sender); - // } - - // //TODO is this test still relevant? You can't have a newer config now. - // function test_canVerifyNewerReportsWithNewerConfigs() public { - // /* - // This test is checking that we use prefer verifiying via newer configs instead of old ones. - // - DonConfigA has signers {A, B, C, E} is set at time T1 - // - DonConfigB has signers {F, G, H, I} is set at time T2 - // - DonConfigC has signers {J, K, L, M } is set at time T3 - // - checks we can verify a report with {K, L, M} signers (via DonConfigC) - // */ - // Signer[] memory signers = _getSigners(MAX_ORACLES); - - // uint8 MINIMAL_FAULT_TOLERANCE = 2; - // BaseTest.Signer[] memory signersSubset1 = new BaseTest.Signer[](7); - // signersSubset1[0] = signers[0]; - // signersSubset1[1] = signers[1]; - // signersSubset1[2] = signers[2]; - // signersSubset1[3] = signers[3]; - // signersSubset1[4] = signers[4]; - // signersSubset1[5] = signers[5]; - // signersSubset1[6] = signers[6]; - - // address[] memory signersAddrSubset1 = _getSignerAddresses(signersSubset1); - // // Config1 - // s_verifier.setConfig(signersAddrSubset1, MINIMAL_FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); - // vm.warp(block.timestamp + 1); - - // BaseTest.Signer[] memory signersSubset2 = new BaseTest.Signer[](7); - // signersSubset2[0] = signers[7]; - // signersSubset2[1] = signers[8]; - // signersSubset2[2] = signers[9]; - // signersSubset2[3] = signers[10]; - // signersSubset2[4] = signers[11]; - // signersSubset2[5] = signers[12]; - // signersSubset2[6] = signers[13]; - - // address[] memory signersAddrSubset2 = _getSignerAddresses(signersSubset2); - // // Config2 - // s_verifier.setConfig(signersAddrSubset2, MINIMAL_FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); - // vm.warp(block.timestamp + 1); - - // BaseTest.Signer[] memory signersSubset3 = new BaseTest.Signer[](7); - // signersSubset3[0] = signers[30]; - // signersSubset3[1] = signers[29]; - // signersSubset3[2] = signers[28]; - // signersSubset3[3] = signers[27]; - // signersSubset3[4] = signers[26]; - // signersSubset3[5] = signers[25]; - // signersSubset3[6] = signers[24]; - - // address[] memory signersAddrSubset3 = _getSignerAddresses(signersSubset3); - // // Config3 - // s_verifier.setConfig(signersAddrSubset3, MINIMAL_FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); - // vm.warp(block.timestamp + 1); - - // V3Report memory report = V3Report({ - // feedId: FEED_ID_V3, - // observationsTimestamp: OBSERVATIONS_TIMESTAMP, - // validFromTimestamp: uint32(block.timestamp), - // nativeFee: uint192(DEFAULT_REPORT_NATIVE_FEE), - // linkFee: uint192(DEFAULT_REPORT_LINK_FEE), - // expiresAt: uint32(block.timestamp), - // benchmarkPrice: MEDIAN, - // bid: BID, - // ask: ASK - // }); - - // BaseTest.Signer[] memory reportSigners = new BaseTest.Signer[](3); - // reportSigners[0] = signers[30]; - // reportSigners[1] = signers[29]; - // reportSigners[2] = signers[28]; - - // bytes memory signedReport = _generateV3EncodedBlob(report, s_reportContext, reportSigners); - - // s_verifierProxy.verify(signedReport, abi.encode(native)); - // } - - // //TODO is this test still relevant? You can't have a newer config now. - // function test_rollingOutConfiguration() public { - // /* - // This test is checking that we can roll out to a new DON without downtime using a transition configuration - // - DonConfigA has signers {A, B, C} is set at time T1 - // - DonConfigB (transition config) has signers {A, B, C, D, E, F} is set at time T2 - // - DonConfigC has signers {D, E, F} is set at time T3 - - // - checks we can verify a report with {A, B, C} signers (via DonConfigA) at time between T1 and T2 - // - checks we can verify a report with {A, B, C} signers (via DonConfigB) at time between T2 and T3 - // - checks we can verify a report with {D, E, F} signers (via DonConfigB) at time between T2 and T3 - // - checks we can verify a report with {D, E, F} signers (via DonConfigC) at time > T3 - // - checks we can't verify a report with {A, B, C} signers (via DonConfigC) and timestamp >T3 at time > T3 - // - checks we can verify a report with {A, B, C} signers (via DonConfigC) and timestamp between T2 and T3 at time > T3 (historical check) - - // */ - - // Signer[] memory signers = _getSigners(MAX_ORACLES); - - // uint8 MINIMAL_FAULT_TOLERANCE = 2; - // BaseTest.Signer[] memory signersSubset1 = new BaseTest.Signer[](7); - // signersSubset1[0] = signers[0]; - // signersSubset1[1] = signers[1]; - // signersSubset1[2] = signers[2]; - // signersSubset1[3] = signers[3]; - // signersSubset1[4] = signers[4]; - // signersSubset1[5] = signers[5]; - // signersSubset1[6] = signers[6]; - - // // ConfigA - // address[] memory signersAddrSubset1 = _getSignerAddresses(signersSubset1); - // s_verifier.setConfig(signersAddrSubset1, MINIMAL_FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); - - // V3Report memory reportT1 = V3Report({ - // feedId: FEED_ID_V3, - // observationsTimestamp: OBSERVATIONS_TIMESTAMP, - // validFromTimestamp: uint32(block.timestamp), - // nativeFee: uint192(DEFAULT_REPORT_NATIVE_FEE), - // linkFee: uint192(DEFAULT_REPORT_LINK_FEE), - // expiresAt: uint32(block.timestamp), - // benchmarkPrice: MEDIAN, - // bid: BID, - // ask: ASK - // }); - - // BaseTest.Signer[] memory reportSignersConfigA = new BaseTest.Signer[](3); - // reportSignersConfigA[0] = signers[0]; - // reportSignersConfigA[1] = signers[1]; - // reportSignersConfigA[2] = signers[2]; - - // // just testing ConfigA - // bytes memory signedReport = _generateV3EncodedBlob(reportT1, s_reportContext, reportSignersConfigA); - // s_verifierProxy.verify(signedReport, abi.encode(native)); - - // vm.warp(block.timestamp + 100); - - // BaseTest.Signer[] memory signersSuperset = new BaseTest.Signer[](14); - // // signers in ConfigA - // signersSuperset[0] = signers[0]; - // signersSuperset[1] = signers[1]; - // signersSuperset[2] = signers[2]; - // signersSuperset[3] = signers[3]; - // signersSuperset[4] = signers[4]; - // signersSuperset[5] = signers[5]; - // signersSuperset[6] = signers[6]; - // // new signers - // signersSuperset[7] = signers[7]; - // signersSuperset[8] = signers[8]; - // signersSuperset[9] = signers[9]; - // signersSuperset[10] = signers[10]; - // signersSuperset[11] = signers[11]; - // signersSuperset[12] = signers[12]; - // signersSuperset[13] = signers[13]; - - // BaseTest.Signer[] memory reportSignersConfigC = new BaseTest.Signer[](3); - // reportSignersConfigC[0] = signers[7]; - // reportSignersConfigC[1] = signers[8]; - // reportSignersConfigC[2] = signers[9]; - - // // ConfigB (transition Config) - // address[] memory signersAddrsSuperset = _getSignerAddresses(signersSuperset); - // s_verifier.setConfig(signersAddrsSuperset, MINIMAL_FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); - - // V3Report memory reportT2 = V3Report({ - // feedId: FEED_ID_V3, - // observationsTimestamp: OBSERVATIONS_TIMESTAMP, - // validFromTimestamp: uint32(block.timestamp), - // nativeFee: uint192(DEFAULT_REPORT_NATIVE_FEE), - // linkFee: uint192(DEFAULT_REPORT_LINK_FEE), - // expiresAt: uint32(block.timestamp), - // benchmarkPrice: MEDIAN, - // bid: BID, - // ask: ASK - // }); - - // // testing we can verify a fresh (block timestamp) report with ConfigA signers. This should use ConfigB - // signedReport = _generateV3EncodedBlob(reportT2, s_reportContext, reportSignersConfigA); - // s_verifierProxy.verify(signedReport, abi.encode(native)); - - // // testing we can verify an old ( non fresh block timestamp) report with ConfigA signers. This should use ConfigA - // signedReport = _generateV3EncodedBlob(reportT1, s_reportContext, reportSignersConfigA); - // s_verifierProxy.verify(signedReport, abi.encode(native)); - // // deactivating to make sure we are really verifiying via ConfigA - // s_verifier.setConfigActive(0, false); - // vm.expectRevert(abi.encodeWithSelector(Verifier.BadVerification.selector)); - // s_verifierProxy.verify(signedReport, abi.encode(native)); - // s_verifier.setConfigActive(0, true); - - // // testing we can verify a fresh (block timestamp) report with the new signers. This should use ConfigB - // signedReport = _generateV3EncodedBlob(reportT2, s_reportContext, reportSignersConfigC); - // s_verifierProxy.verify(signedReport, abi.encode(native)); - - // vm.warp(block.timestamp + 100); - - // // Adding ConfigC - // BaseTest.Signer[] memory signersSubset2 = new BaseTest.Signer[](7); - // signersSubset2[0] = signers[7]; - // signersSubset2[1] = signers[8]; - // signersSubset2[2] = signers[9]; - // signersSubset2[3] = signers[10]; - // signersSubset2[4] = signers[11]; - // signersSubset2[5] = signers[12]; - // signersSubset2[6] = signers[13]; - // address[] memory signersAddrsSubset2 = _getSignerAddresses(signersSubset2); - // s_verifier.setConfig(signersAddrsSubset2, MINIMAL_FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); - - // V3Report memory reportT3 = V3Report({ - // feedId: FEED_ID_V3, - // observationsTimestamp: OBSERVATIONS_TIMESTAMP, - // validFromTimestamp: uint32(block.timestamp), - // nativeFee: uint192(DEFAULT_REPORT_NATIVE_FEE), - // linkFee: uint192(DEFAULT_REPORT_LINK_FEE), - // expiresAt: uint32(block.timestamp), - // benchmarkPrice: MEDIAN, - // bid: BID, - // ask: ASK - // }); - - // // testing we can verify reports with ConfigC signers - // signedReport = _generateV3EncodedBlob(reportT3, s_reportContext, reportSignersConfigC); - // s_verifierProxy.verify(signedReport, abi.encode(native)); - - // // testing an old report (block timestamp) with ConfigC signers should verify via ConfigB - // signedReport = _generateV3EncodedBlob(reportT2, s_reportContext, reportSignersConfigC); - // s_verifierProxy.verify(signedReport, abi.encode(native)); - // // deactivating to make sure we are really verifiying via ConfigB - // s_verifier.setConfigActive(1, false); - // vm.expectRevert(abi.encodeWithSelector(Verifier.BadVerification.selector)); - // s_verifierProxy.verify(signedReport, abi.encode(native)); - // s_verifier.setConfigActive(1, true); - - // // testing a recent report with ConfigA signers should not verify - // signedReport = _generateV3EncodedBlob(reportT3, s_reportContext, reportSignersConfigA); - // vm.expectRevert(abi.encodeWithSelector(Verifier.BadVerification.selector)); - // s_verifierProxy.verify(signedReport, abi.encode(native)); - - // // testing an old report (block timestamp) with ConfigA signers should verify via ConfigB - // signedReport = _generateV3EncodedBlob(reportT2, s_reportContext, reportSignersConfigA); - // s_verifierProxy.verify(signedReport, abi.encode(native)); - // // deactivating to make sure we are really verifiying via ConfigB - // s_verifier.setConfigActive(1, false); - // vm.expectRevert(abi.encodeWithSelector(Verifier.BadVerification.selector)); - // s_verifierProxy.verify(signedReport, abi.encode(native)); - // s_verifier.setConfigActive(1, true); - - // // testing an old report (block timestamp) with ConfigA signers should verify via ConfigA - // signedReport = _generateV3EncodedBlob(reportT1, s_reportContext, reportSignersConfigA); - // s_verifierProxy.verify(signedReport, abi.encode(native)); - // // deactivating to make sure we are really verifiying via ConfigB - // s_verifier.setConfigActive(0, false); - // vm.expectRevert(abi.encodeWithSelector(Verifier.BadVerification.selector)); - // s_verifierProxy.verify(signedReport, abi.encode(native)); - // s_verifier.setConfigActive(0, true); - // } - - // function test_verifyFailsWhenReportIsOlderThanConfig() public { - // /* - // - SetConfig A at time T0 - // - SetConfig B at time T1 - // - tries verifing report issued at blocktimestmap < T0 - - // this test is failing: ToDo Ask Michael - // */ - // Signer[] memory signers = _getSigners(MAX_ORACLES); - // address[] memory signerAddrs = _getSignerAddresses(signers); - // s_reportContext[0] = bytes32(abi.encode(uint32(5), uint8(1))); - - // vm.warp(block.timestamp + 100); - - // V3Report memory reportAtTMinus100 = V3Report({ - // feedId: FEED_ID_V3, - // observationsTimestamp: OBSERVATIONS_TIMESTAMP, - // validFromTimestamp: uint32(block.timestamp - 100), - // nativeFee: uint192(DEFAULT_REPORT_NATIVE_FEE), - // linkFee: uint192(DEFAULT_REPORT_LINK_FEE), - // expiresAt: uint32(block.timestamp), - // benchmarkPrice: MEDIAN, - // bid: BID, - // ask: ASK - // }); - - // s_verifier.setConfig(signerAddrs, FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); - // vm.warp(block.timestamp + 100); - // s_verifier.setConfig(signerAddrs, FAULT_TOLERANCE - 1, new Common.AddressAndWeight[](0)); - - // bytes memory signedReport = _generateV3EncodedBlob(reportAtTMinus100, s_reportContext, signers); - - // vm.expectRevert(abi.encodeWithSelector(Verifier.BadVerification.selector)); - // s_verifierProxy.verify(signedReport, abi.encode(native)); - // } - - // function test_scenarioRollingNewChainWithHistoricConfigs() public { - // /* - // This test is checking that we can roll out in a new network and set historic configurations : - // - Stars with a chain at blocktimestamp 1000 - // - SetConfigA with teimstamp 100 - // - SetConfigB with timesmtap 200 - // - SetConfigC with timestamp current - // - tries verifying reports for all the configs - // */ - - // vm.warp(block.timestamp + 1000); - - // Signer[] memory signers = _getSigners(MAX_ORACLES); - - // uint8 MINIMAL_FAULT_TOLERANCE = 2; - // BaseTest.Signer[] memory signersA = new BaseTest.Signer[](7); - // signersA[0] = signers[0]; - // signersA[1] = signers[1]; - // signersA[2] = signers[2]; - // signersA[3] = signers[3]; - // signersA[4] = signers[4]; - // signersA[5] = signers[5]; - // signersA[6] = signers[6]; - - // // ConfigA (historical config) - // uint32 configATimestmap = 100; - // address[] memory signersAddrA = _getSignerAddresses(signersA); - // s_verifier.setConfigWithActivationTime( - // signersAddrA, - // MINIMAL_FAULT_TOLERANCE, - // new Common.AddressAndWeight[](0), - // configATimestmap - // ); - - // // ConfigB (historical config) - // uint32 configBTimestmap = 200; - // // Config B - // BaseTest.Signer[] memory signersB = new BaseTest.Signer[](7); - // // signers in ConfigA - // signersB[0] = signers[8]; - // signersB[1] = signers[9]; - // signersB[2] = signers[10]; - // signersB[3] = signers[11]; - // signersB[4] = signers[12]; - // signersB[5] = signers[13]; - // signersB[6] = signers[14]; - // address[] memory signersAddrsB = _getSignerAddresses(signersB); - // s_verifier.setConfigWithActivationTime( - // signersAddrsB, - // MINIMAL_FAULT_TOLERANCE, - // new Common.AddressAndWeight[](0), - // configBTimestmap - // ); - - // // ConfigC (config at current timestamp) - // // BaseTest.Signer[] memory signersC = new BaseTest.Signer[](7); - // // signers in ConfigA - // signersB[6] = signers[15]; - // address[] memory signersAddrsC = _getSignerAddresses(signersB); - // s_verifier.setConfig(bytes32(uint256(1)), signersAddrsC, MINIMAL_FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); - - // vm.warp(block.timestamp + 10); - - // // historical report - // V3Report memory s_testReportA = V3Report({ - // feedId: FEED_ID_V3, - // observationsTimestamp: OBSERVATIONS_TIMESTAMP, - // validFromTimestamp: uint32(101), - // nativeFee: uint192(DEFAULT_REPORT_NATIVE_FEE), - // linkFee: uint192(DEFAULT_REPORT_LINK_FEE), - // expiresAt: uint32(block.timestamp + 1000), - // benchmarkPrice: MEDIAN, - // bid: BID, - // ask: ASK - // }); - - // // historical report - // V3Report memory s_testReportB = V3Report({ - // feedId: FEED_ID_V3, - // observationsTimestamp: OBSERVATIONS_TIMESTAMP, - // validFromTimestamp: uint32(201), - // nativeFee: uint192(DEFAULT_REPORT_NATIVE_FEE), - // linkFee: uint192(DEFAULT_REPORT_LINK_FEE), - // expiresAt: uint32(block.timestamp + 1000), - // benchmarkPrice: MEDIAN, - // bid: BID, - // ask: ASK - // }); - - // // report at recent timestamp - // V3Report memory s_testReportC = V3Report({ - // feedId: FEED_ID_V3, - // observationsTimestamp: OBSERVATIONS_TIMESTAMP, - // validFromTimestamp: uint32(block.timestamp), - // nativeFee: uint192(DEFAULT_REPORT_NATIVE_FEE), - // linkFee: uint192(DEFAULT_REPORT_LINK_FEE), - // expiresAt: uint32(block.timestamp + 1000), - // benchmarkPrice: MEDIAN, - // bid: BID, - // ask: ASK - // }); - - // BaseTest.Signer[] memory reportSignersA = new BaseTest.Signer[](3); - // reportSignersA[0] = signers[0]; - // reportSignersA[1] = signers[1]; - // reportSignersA[2] = signers[2]; - - // BaseTest.Signer[] memory reportSignersB = new BaseTest.Signer[](3); - // reportSignersB[0] = signers[8]; - // reportSignersB[1] = signers[9]; - // reportSignersB[2] = signers[14]; - - // BaseTest.Signer[] memory reportSignersC = new BaseTest.Signer[](3); - // reportSignersC[0] = signers[15]; - // reportSignersC[1] = signers[13]; - // reportSignersC[2] = signers[12]; - - // bytes memory signedReportA = _generateV3EncodedBlob(s_testReportA, s_reportContext, reportSignersA); - // bytes memory signedReportB = _generateV3EncodedBlob(s_testReportB, s_reportContext, reportSignersB); - // bytes memory signedReportC = _generateV3EncodedBlob(s_testReportC, s_reportContext, reportSignersC); - - // // verifying historical reports - // s_verifierProxy.verify(signedReportA, abi.encode(native)); - // s_verifierProxy.verify(signedReportB, abi.encode(native)); - // // verifiying a current report - // s_verifierProxy.verify(signedReportC, abi.encode(native)); - - // // current report verified by historical report fails - // bytes memory signedNewReportWithOldSignatures = _generateV3EncodedBlob( - // s_testReportC, - // s_reportContext, - // reportSignersA - // ); - // vm.expectRevert(abi.encodeWithSelector(Verifier.BadVerification.selector)); - // s_verifierProxy.verify(signedNewReportWithOldSignatures, abi.encode(native)); - // } + + function test_revertsVerifyIfNoAccess() public { + vm.mockCall( + ACCESS_CONTROLLER_ADDRESS, + abi.encodeWithSelector(AccessControllerInterface.hasAccess.selector, USER), + abi.encode(false) + ); + bytes memory signedReport = _generateV3EncodedBlob( + s_testReportThree, + s_reportContext, + _getSigners(FAULT_TOLERANCE + 1) + ); + + vm.expectRevert(abi.encodeWithSelector(Verifier.AccessForbidden.selector)); + + changePrank(USER); + s_verifier.verify(signedReport, abi.encode(native), msg.sender); + } + + function test_verifyFailsWhenReportIsOlderThanConfig() public { + /* + - SetConfig A at time T0 + - SetConfig B at time T1 + - tries verifing report issued at blocktimestmap < T0 + */ + Signer[] memory signers = _getSigners(MAX_ORACLES); + address[] memory signerAddrs = _getSignerAddresses(signers); + s_reportContext[0] = bytes32(abi.encode(uint32(5), uint8(1))); + + vm.warp(block.timestamp + 100); + + V3Report memory reportAtTMinus100 = V3Report({ + feedId: FEED_ID_V3, + observationsTimestamp: OBSERVATIONS_TIMESTAMP, + validFromTimestamp: uint32(block.timestamp - 100), + nativeFee: uint192(DEFAULT_REPORT_NATIVE_FEE), + linkFee: uint192(DEFAULT_REPORT_LINK_FEE), + expiresAt: uint32(block.timestamp), + benchmarkPrice: MEDIAN, + bid: BID, + ask: ASK + }); + + + s_verifier.setConfig(DEFAULT_CONFIG_DIGEST, signerAddrs, FAULT_TOLERANCE, new Common.AddressAndWeight[](0)); + vm.warp(block.timestamp + 100); + + bytes32 DUMMY_CONFIG_1 = keccak256("DUMMY_CONFIG_1"); + s_verifier.setConfig(DUMMY_CONFIG_1, signerAddrs, FAULT_TOLERANCE - 1, new Common.AddressAndWeight[](0)); + + bytes memory signedReport = _generateV3EncodedBlob(reportAtTMinus100, s_reportContext, signers); + + vm.expectRevert(abi.encodeWithSelector(Verifier.BadVerification.selector)); + s_verifierProxy.verify(signedReport, abi.encode(native)); + } }