Skip to content

Commit

Permalink
v0.4 test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Fletch153 committed Nov 18, 2024
1 parent 065ab8d commit 20b2e0d
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 682 deletions.
Empty file.
13 changes: 1 addition & 12 deletions contracts/src/v0.8/llo-feeds/v0.5.0/Verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions contracts/src/v0.8/llo-feeds/v0.5.0/interfaces/IVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -42,86 +42,25 @@ 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 {
Signer[] memory signers = _getSigners(MAX_ORACLES);
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 {
Signer[] memory signers = _getSigners(MAX_ORACLES);
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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.
Expand All @@ -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;

Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand Down
Loading

0 comments on commit 20b2e0d

Please sign in to comment.