Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,419 changes: 0 additions & 1,419 deletions packages/contracts-test/tests/unit/rewards/rewards.test.ts

This file was deleted.

17 changes: 6 additions & 11 deletions packages/issuance/test/unit/rewards-manager/config.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ contract RewardsManagerConfigTest is RewardsManagerSharedTest {

address internal availabilityOracle = makeAddr("availabilityOracle");

function _setAvailabilityOracle() internal {
vm.prank(governor);
rm.setSubgraphAvailabilityOracle(availabilityOracle);
}

// -- initialize --

function test_Initialize_RevertWhen_CalledOnImplementation() public {
Expand Down Expand Up @@ -117,7 +112,7 @@ contract RewardsManagerConfigTest is RewardsManagerSharedTest {
}

function test_SubgraphAvailabilityService_SetOracle() public {
_setAvailabilityOracle();
_setAvailabilityOracle(availabilityOracle);
assertEq(rm.subgraphAvailabilityOracle(), availabilityOracle);
}

Expand All @@ -128,7 +123,7 @@ contract RewardsManagerConfigTest is RewardsManagerSharedTest {
}

function test_SubgraphAvailabilityService_Deny() public {
_setAvailabilityOracle();
_setAvailabilityOracle(availabilityOracle);

vm.expectEmit(address(rm));
emit RewardsDenylistUpdated(SUBGRAPH_DEPLOYMENT_ID_1, block.number);
Expand All @@ -138,7 +133,7 @@ contract RewardsManagerConfigTest is RewardsManagerSharedTest {
}

function test_SubgraphAvailabilityService_Undeny() public {
_setAvailabilityOracle();
_setAvailabilityOracle(availabilityOracle);

vm.prank(availabilityOracle);
rm.setDenied(SUBGRAPH_DEPLOYMENT_ID_1, true);
Expand All @@ -152,7 +147,7 @@ contract RewardsManagerConfigTest is RewardsManagerSharedTest {
}

function test_SubgraphAvailabilityService_DenyAlreadyDeniedIsNoOp() public {
_setAvailabilityOracle();
_setAvailabilityOracle(availabilityOracle);

vm.prank(availabilityOracle);
rm.setDenied(SUBGRAPH_DEPLOYMENT_ID_1, true);
Expand All @@ -169,7 +164,7 @@ contract RewardsManagerConfigTest is RewardsManagerSharedTest {
}

function test_SubgraphAvailabilityService_UndenyNotDeniedIsNoOp() public {
_setAvailabilityOracle();
_setAvailabilityOracle(availabilityOracle);

assertFalse(rm.isDenied(SUBGRAPH_DEPLOYMENT_ID_1));

Expand All @@ -189,7 +184,7 @@ contract RewardsManagerConfigTest is RewardsManagerSharedTest {
}

function test_SubgraphAvailabilityService_SetMinimumSubgraphSignalFromOracle() public {
_setAvailabilityOracle();
_setAvailabilityOracle(availabilityOracle);

uint256 newMinimumSignal = 2000 ether;
vm.expectEmit(address(rm));
Expand Down
63 changes: 23 additions & 40 deletions packages/issuance/test/unit/rewards-manager/eligibility.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,6 @@ contract RewardsManagerEligibilityTest is RewardsManagerSharedTest {

address internal allocationID1 = makeAddr("allocationID1");

/// Old `setupIndexerAllocation` followed by `mineEpoch`: the allocation earns `EPOCH_LENGTH` blocks.
function _allocateAndAccrue() internal returns (uint256 expectedRewards) {
_signalThenAllocate(SUBGRAPH_DEPLOYMENT_ID_1, allocationID1);
vm.roll(block.number + EPOCH_LENGTH);
return _expectedAllocationRewards(EPOCH_LENGTH, ALLOCATION, ALLOCATION);
}

function _setAvailabilityOracle() internal {
vm.prank(governor);
rm.setSubgraphAvailabilityOracle(governor);
}

function _setDenied(bool deny) internal {
vm.prank(governor);
rm.setDenied(SUBGRAPH_DEPLOYMENT_ID_1, deny);
}

function _findLog(Vm.Log[] memory logs, bytes32 topic) internal view returns (Vm.Log memory) {
for (uint256 i = 0; i < logs.length; ++i) {
if (logs[i].emitter == address(rm) && logs[i].topics[0] == topic) return logs[i];
Expand Down Expand Up @@ -99,7 +82,7 @@ contract RewardsManagerEligibilityTest is RewardsManagerSharedTest {

function test_RewardsEligibilityInTakeRewards_DeniesRewardsDueToEligibilityOracle() public {
_useEligibilityOracle(false);
uint256 expectedRewards = _allocateAndAccrue();
uint256 expectedRewards = _allocateAndAccrue(SUBGRAPH_DEPLOYMENT_ID_1, allocationID1);

vm.expectEmit(address(rm), 1);
emit RewardsDeniedDueToEligibility(indexer, allocationID1, expectedRewards);
Expand All @@ -108,7 +91,7 @@ contract RewardsManagerEligibilityTest is RewardsManagerSharedTest {

function test_RewardsEligibilityInTakeRewards_AllowsRewardsWhenOracleApproves() public {
_useEligibilityOracle(true);
uint256 expectedRewards = _allocateAndAccrue();
uint256 expectedRewards = _allocateAndAccrue(SUBGRAPH_DEPLOYMENT_ID_1, allocationID1);

vm.expectEmit(address(rm), 1);
emit HorizonRewardsAssigned(indexer, allocationID1, expectedRewards);
Expand All @@ -118,12 +101,12 @@ contract RewardsManagerEligibilityTest is RewardsManagerSharedTest {
// -- rewards eligibility oracle and denylist interaction --

function test_RewardsEligibilityOracleAndDenylistInteraction_PrioritizesDenylistOverOracleWhenBothDeny() public {
_setAvailabilityOracle();
_setDenied(true);
_setAvailabilityOracle(governor);
_setDenied(SUBGRAPH_DEPLOYMENT_ID_1, true);
_useEligibilityOracle(false);

// Created while denied: the accumulator is frozen, so the allocation has no rewards to deny
_allocateAndAccrue();
_allocateAndAccrue(SUBGRAPH_DEPLOYMENT_ID_1, allocationID1);

vm.recordLogs();
_close(allocationID1);
Expand All @@ -137,7 +120,7 @@ contract RewardsManagerEligibilityTest is RewardsManagerSharedTest {
public
{
_useEligibilityOracle(false);
uint256 expectedRewards = _allocateAndAccrue();
uint256 expectedRewards = _allocateAndAccrue(SUBGRAPH_DEPLOYMENT_ID_1, allocationID1);

vm.expectEmit(address(rm), 1);
emit RewardsDeniedDueToEligibility(indexer, allocationID1, expectedRewards);
Expand All @@ -146,7 +129,7 @@ contract RewardsManagerEligibilityTest is RewardsManagerSharedTest {

function test_RewardsEligibilityOracleAndDenylistInteraction_IndexerBecomesIneligibleMidAllocation() public {
_useEligibilityOracle(true);
uint256 expectedRewards = _allocateAndAccrue();
uint256 expectedRewards = _allocateAndAccrue(SUBGRAPH_DEPLOYMENT_ID_1, allocationID1);

// Eligibility is checked at close time, not at creation time
oracle.setIndexerEligible(indexer, false);
Expand All @@ -158,7 +141,7 @@ contract RewardsManagerEligibilityTest is RewardsManagerSharedTest {

function test_RewardsEligibilityOracleAndDenylistInteraction_IndexerBecomesEligibleMidAllocation() public {
_useEligibilityOracle(false);
uint256 expectedRewards = _allocateAndAccrue();
uint256 expectedRewards = _allocateAndAccrue(SUBGRAPH_DEPLOYMENT_ID_1, allocationID1);

oracle.setIndexerEligible(indexer, true);

Expand All @@ -168,10 +151,10 @@ contract RewardsManagerEligibilityTest is RewardsManagerSharedTest {
}

function test_RewardsEligibilityOracleAndDenylistInteraction_DenylistAddedMidAllocation() public {
_setAvailabilityOracle();
_allocateAndAccrue();
_setAvailabilityOracle(governor);
_allocateAndAccrue(SUBGRAPH_DEPLOYMENT_ID_1, allocationID1);

_setDenied(true);
_setDenied(SUBGRAPH_DEPLOYMENT_ID_1, true);
vm.roll(block.number + 1);

vm.expectEmit(address(rm));
Expand All @@ -180,14 +163,14 @@ contract RewardsManagerEligibilityTest is RewardsManagerSharedTest {
}

function test_RewardsEligibilityOracleAndDenylistInteraction_DenylistRemovedMidAllocation() public {
_setAvailabilityOracle();
_setDenied(true);
_setAvailabilityOracle(governor);
_setDenied(SUBGRAPH_DEPLOYMENT_ID_1, true);

// Created while denied: rewards accrued while denied are reclaimed at the subgraph level
_allocateAndAccrue();
_allocateAndAccrue(SUBGRAPH_DEPLOYMENT_ID_1, allocationID1);

// Undeny snapshots the accumulator, then only post-undeny rewards accrue
_setDenied(false);
_setDenied(SUBGRAPH_DEPLOYMENT_ID_1, false);
vm.roll(block.number + EPOCH_LENGTH);

vm.expectEmit(address(rm));
Expand All @@ -202,7 +185,7 @@ contract RewardsManagerEligibilityTest is RewardsManagerSharedTest {
function test_RewardsEligibilityOracleAndDenylistInteraction_AllowsRewardsWhenOracleIsZeroAddress() public {
assertEq(address(rm.getProviderEligibilityOracle()), address(0));

uint256 expectedRewards = _allocateAndAccrue();
uint256 expectedRewards = _allocateAndAccrue(SUBGRAPH_DEPLOYMENT_ID_1, allocationID1);

vm.expectEmit(address(rm), 1);
emit HorizonRewardsAssigned(indexer, allocationID1, expectedRewards);
Expand All @@ -214,7 +197,7 @@ contract RewardsManagerEligibilityTest is RewardsManagerSharedTest {
vm.prank(governor);
rm.setRevertOnIneligible(true);

_allocateAndAccrue();
_allocateAndAccrue(SUBGRAPH_DEPLOYMENT_ID_1, allocationID1);

vm.expectRevert(bytes("Indexer not eligible for rewards"));
issuer.close(allocationID1);
Expand All @@ -225,7 +208,7 @@ contract RewardsManagerEligibilityTest is RewardsManagerSharedTest {
vm.prank(governor);
rm.setRevertOnIneligible(true);

uint256 expectedRewards = _allocateAndAccrue();
uint256 expectedRewards = _allocateAndAccrue(SUBGRAPH_DEPLOYMENT_ID_1, allocationID1);

vm.expectEmit(address(rm));
emit HorizonRewardsAssigned(indexer, allocationID1, expectedRewards);
Expand All @@ -238,7 +221,7 @@ contract RewardsManagerEligibilityTest is RewardsManagerSharedTest {
_useEligibilityOracle(false);
assertFalse(rm.getRevertOnIneligible());

uint256 expectedRewards = _allocateAndAccrue();
uint256 expectedRewards = _allocateAndAccrue(SUBGRAPH_DEPLOYMENT_ID_1, allocationID1);

vm.expectEmit(address(rm), 1);
emit RewardsDeniedDueToEligibility(indexer, allocationID1, expectedRewards);
Expand All @@ -250,9 +233,9 @@ contract RewardsManagerEligibilityTest is RewardsManagerSharedTest {
uint256 snapshot = vm.snapshotState();

// Denylist denial: event WITHOUT amount. Deny after the allocation so there are rewards to deny.
_setAvailabilityOracle();
_allocateAndAccrue();
_setDenied(true);
_setAvailabilityOracle(governor);
_allocateAndAccrue(SUBGRAPH_DEPLOYMENT_ID_1, allocationID1);
_setDenied(SUBGRAPH_DEPLOYMENT_ID_1, true);
vm.roll(block.number + 1);

vm.recordLogs();
Expand All @@ -268,7 +251,7 @@ contract RewardsManagerEligibilityTest is RewardsManagerSharedTest {

// Eligibility denial: event WITH amount, what the indexer would have received
_useEligibilityOracle(false);
uint256 expectedRewards = _allocateAndAccrue();
uint256 expectedRewards = _allocateAndAccrue(SUBGRAPH_DEPLOYMENT_ID_1, allocationID1);

vm.recordLogs();
_close(allocationID1);
Expand Down
Loading
Loading