Skip to content
Merged
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
2 changes: 1 addition & 1 deletion packages/horizon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"scripts": {
"lint:ts": "eslint '**/*.{js,ts}' --fix",
"lint:sol": "prettier --write contracts/**/*.sol && solhint --noPrompt --fix contracts/**/*.sol --config node_modules/solhint-graph-config/index.js",
"lint:sol": "prettier --write contracts/**/*.sol test/**/*.sol && solhint --noPrompt --fix contracts/**/*.sol --config node_modules/solhint-graph-config/index.js",
"lint": "yarn lint:ts && yarn lint:sol",
"clean": "rm -rf build dist cache cache_forge typechain-types",
"build": "forge build --skip test && BUILD_RUN=true hardhat compile",
Expand Down
7 changes: 6 additions & 1 deletion packages/horizon/test/GraphBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,12 @@ abstract contract GraphBaseTest is IHorizonStakingTypes, Utils, Constants {
subgraphDataServiceLegacyAddress
);

graphTallyCollector = new GraphTallyCollector("GraphTallyCollector", "1", address(controller), revokeSignerThawingPeriod);
graphTallyCollector = new GraphTallyCollector(
"GraphTallyCollector",
"1",
address(controller),
revokeSignerThawingPeriod
);

resetPrank(users.governor);
proxyAdmin.upgrade(stakingProxy, address(stakingBase));
Expand Down
19 changes: 6 additions & 13 deletions packages/horizon/test/data-service/DataService.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ contract DataServiceTest is HorizonStakingSharedTest {
assertEq(max, dataServiceOverride.PROVISION_TOKENS_MAX());
}

function test_ProvisionTokens_WhenCheckingAValidProvision_WithThawing(uint256 tokens, uint256 tokensThaw) external useIndexer {
function test_ProvisionTokens_WhenCheckingAValidProvision_WithThawing(
uint256 tokens,
uint256 tokensThaw
) external useIndexer {
dataService.setProvisionTokensRange(dataService.PROVISION_TOKENS_MIN(), dataService.PROVISION_TOKENS_MAX());
tokens = bound(tokens, dataService.PROVISION_TOKENS_MIN(), dataService.PROVISION_TOKENS_MAX());
tokensThaw = bound(tokensThaw, tokens - dataService.PROVISION_TOKENS_MIN() + 1, tokens);
Expand Down Expand Up @@ -313,12 +316,7 @@ contract DataServiceTest is HorizonStakingSharedTest {
dataService.VERIFIER_CUT_MIN(),
dataService.THAWING_PERIOD_MIN()
);
_setProvisionParameters(
users.indexer,
address(dataService),
dataService.VERIFIER_CUT_MIN(),
thawingPeriod
);
_setProvisionParameters(users.indexer, address(dataService), dataService.VERIFIER_CUT_MIN(), thawingPeriod);

// accept provision parameters
vm.expectRevert(
Expand Down Expand Up @@ -351,12 +349,7 @@ contract DataServiceTest is HorizonStakingSharedTest {
dataService.VERIFIER_CUT_MIN(),
dataService.THAWING_PERIOD_MIN()
);
_setProvisionParameters(
users.indexer,
address(dataService),
maxVerifierCut,
dataService.THAWING_PERIOD_MIN()
);
_setProvisionParameters(users.indexer, address(dataService), maxVerifierCut, dataService.THAWING_PERIOD_MIN());

// accept provision parameters
if (maxVerifierCut != dataService.VERIFIER_CUT_MIN()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ contract DataServiceFeesTest is HorizonStakingSharedTest {

// it should emit a an event
vm.expectEmit();
emit IDataServiceFees.StakeClaimLocked(serviceProvider, calcValues.predictedClaimId, calcValues.stakeToLock, calcValues.unlockTimestamp);
emit IDataServiceFees.StakeClaimLocked(
serviceProvider,
calcValues.predictedClaimId,
calcValues.stakeToLock,
calcValues.unlockTimestamp
);
dataService.lockStake(serviceProvider, tokens);

// after state
Expand Down Expand Up @@ -195,7 +200,9 @@ contract DataServiceFeesTest is HorizonStakingSharedTest {
tokensReleased: 0,
head: beforeHead
});
while (calcValues.head != bytes32(0) && (calcValues.claimsCount < numClaimsToRelease || numClaimsToRelease == 0)) {
while (
calcValues.head != bytes32(0) && (calcValues.claimsCount < numClaimsToRelease || numClaimsToRelease == 0)
) {
(uint256 claimTokens, , uint256 releasableAt, bytes32 nextClaim) = dataService.claims(calcValues.head);
if (releasableAt > block.timestamp) {
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ contract DataServiceBase is DataService {

function stopService(address serviceProvider, bytes calldata data) external {}

function collect(address serviceProvider, IGraphPayments.PaymentTypes feeType, bytes calldata data) external returns (uint256) {}
function collect(
address serviceProvider,
IGraphPayments.PaymentTypes feeType,
bytes calldata data
) external returns (uint256) {}

function slash(address serviceProvider, bytes calldata data) external {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ contract DataServiceBaseUpgradeable is DataService {

function stopService(address serviceProvider, bytes calldata data) external {}

function collect(address serviceProvider, IGraphPayments.PaymentTypes feeType, bytes calldata data) external returns (uint256) {}
function collect(
address serviceProvider,
IGraphPayments.PaymentTypes feeType,
bytes calldata data
) external returns (uint256) {}

function slash(address serviceProvider, bytes calldata data) external {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ contract DataServiceImpFees is DataServiceFees {

function stopService(address serviceProvider, bytes calldata data) external {}

function collect(address serviceProvider, IGraphPayments.PaymentTypes, bytes calldata data) external returns (uint256) {
function collect(
address serviceProvider,
IGraphPayments.PaymentTypes,
bytes calldata data
) external returns (uint256) {
uint256 amount = abi.decode(data, (uint256));
_releaseStake(serviceProvider, 0);
_lockStake(serviceProvider, amount * STAKE_TO_FEES_RATIO, block.timestamp + LOCK_DURATION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ contract DataServiceImpPausable is DataServicePausable {

function stopService(address serviceProvider, bytes calldata data) external {}

function collect(address serviceProvider, IGraphPayments.PaymentTypes feeType, bytes calldata data) external returns (uint256) {}
function collect(
address serviceProvider,
IGraphPayments.PaymentTypes feeType,
bytes calldata data
) external returns (uint256) {}

function slash(address serviceProvider, bytes calldata data) external {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ contract DataServiceImpPausableUpgradeable is DataServicePausableUpgradeable {

function stopService(address serviceProvider, bytes calldata data) external {}

function collect(address serviceProvider, IGraphPayments.PaymentTypes feeType, bytes calldata data) external returns (uint256) {}
function collect(
address serviceProvider,
IGraphPayments.PaymentTypes feeType,
bytes calldata data
) external returns (uint256) {}

function slash(address serviceProvider, bytes calldata data) external {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,19 @@ contract ProvisionTrackerTest is HorizonStakingSharedTest, ProvisionTrackerImple
assertEq(provisionTracker[users.indexer], delta);
}

function test_Release_RevertGiven_TheProvisionHasInsufficientLockedTokens(uint256 tokens) external useIndexer useProvisionDataService(address(this), tokens, 0, 0) {
function test_Release_RevertGiven_TheProvisionHasInsufficientLockedTokens(
uint256 tokens
) external useIndexer useProvisionDataService(address(this), tokens, 0, 0) {
// setup
provisionTracker.lock(staking, users.indexer, tokens, uint32(0));

uint256 tokensToRelease = tokens + 1;
vm.expectRevert(
abi.encodeWithSelector(ProvisionTracker.ProvisionTrackerInsufficientTokens.selector, tokens, tokensToRelease)
abi.encodeWithSelector(
ProvisionTracker.ProvisionTrackerInsufficientTokens.selector,
tokens,
tokensToRelease
)
);
provisionTracker.release(users.indexer, tokensToRelease);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ pragma solidity 0.8.27;
import { ProvisionTracker } from "../../../contracts/data-service/libraries/ProvisionTracker.sol";

contract ProvisionTrackerImplementation {
mapping(address => uint256) public provisionTracker;
mapping(address => uint256) public provisionTracker;
}
14 changes: 11 additions & 3 deletions packages/horizon/test/escrow/GraphEscrow.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ contract GraphEscrowTest is HorizonStakingSharedTest, PaymentsEscrowSharedTest {

function _cancelThawEscrow(address collector, address receiver) internal {
(, address msgSender, ) = vm.readCallers();
(, uint256 amountThawingBefore, uint256 thawEndTimestampBefore) = escrow.escrowAccounts(msgSender, collector, receiver);
(, uint256 amountThawingBefore, uint256 thawEndTimestampBefore) = escrow.escrowAccounts(
msgSender,
collector,
receiver
);

vm.expectEmit(address(escrow));
emit IPaymentsEscrow.CancelThaw(msgSender, collector, receiver, amountThawingBefore, thawEndTimestampBefore);
Expand All @@ -84,7 +88,11 @@ contract GraphEscrowTest is HorizonStakingSharedTest, PaymentsEscrowSharedTest {
emit IPaymentsEscrow.Withdraw(msgSender, collector, receiver, amountToWithdraw);
escrow.withdraw(collector, receiver);

(uint256 balanceAfter, uint256 tokensThawingAfter, uint256 thawEndTimestampAfter) = escrow.escrowAccounts(msgSender, collector, receiver);
(uint256 balanceAfter, uint256 tokensThawingAfter, uint256 thawEndTimestampAfter) = escrow.escrowAccounts(
msgSender,
collector,
receiver
);
uint256 tokenBalanceAfterSender = token.balanceOf(msgSender);
uint256 tokenBalanceAfterEscrow = token.balanceOf(address(escrow));

Expand All @@ -93,7 +101,7 @@ contract GraphEscrowTest is HorizonStakingSharedTest, PaymentsEscrowSharedTest {
assertEq(thawEndTimestampAfter, 0);

assertEq(tokenBalanceAfterSender, tokenBalanceBeforeSender + amountToWithdraw);
assertEq(tokenBalanceAfterEscrow, tokenBalanceBeforeEscrow - amountToWithdraw);
assertEq(tokenBalanceAfterEscrow, tokenBalanceBeforeEscrow - amountToWithdraw);
}

struct CollectPaymentData {
Expand Down
2 changes: 1 addition & 1 deletion packages/horizon/test/escrow/deposit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract GraphEscrowDepositTest is GraphEscrowTest {
_depositTokens(users.verifier, users.indexer, amount1);
_depositTokens(users.verifier, users.indexer, amount2);

(uint256 balance,,) = escrow.escrowAccounts(users.gateway, users.verifier, users.indexer);
(uint256 balance, , ) = escrow.escrowAccounts(users.gateway, users.verifier, users.indexer);
assertEq(balance, amount1 + amount2);
}
}
16 changes: 11 additions & 5 deletions packages/horizon/test/escrow/paused.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ import { IPaymentsEscrow } from "../../contracts/interfaces/IPaymentsEscrow.sol"
import { GraphEscrowTest } from "./GraphEscrow.t.sol";

contract GraphEscrowPausedTest is GraphEscrowTest {

/*
* MODIFIERS
*/

modifier usePaused(bool paused) {
address msgSender;
(, msgSender,) = vm.readCallers();
(, msgSender, ) = vm.readCallers();
resetPrank(users.governor);
controller.setPaused(paused);
resetPrank(msgSender);
Expand Down Expand Up @@ -46,7 +45,7 @@ contract GraphEscrowPausedTest is GraphEscrowTest {
}

function testPaused_RevertWhen_WithdrawTokens(
uint256 tokens,
uint256 tokens,
uint256 thawAmount
) public useGateway depositAndThawTokens(tokens, thawAmount) usePaused(true) {
// advance time
Expand All @@ -61,6 +60,13 @@ contract GraphEscrowPausedTest is GraphEscrowTest {
function testPaused_RevertWhen_CollectTokens(uint256 tokens, uint256 tokensDataService) public usePaused(true) {
resetPrank(users.verifier);
vm.expectRevert(abi.encodeWithSelector(IPaymentsEscrow.PaymentsEscrowIsPaused.selector));
escrow.collect(IGraphPayments.PaymentTypes.QueryFee, users.gateway, users.indexer, tokens, subgraphDataServiceAddress, tokensDataService);
escrow.collect(
IGraphPayments.PaymentTypes.QueryFee,
users.gateway,
users.indexer,
tokens,
subgraphDataServiceAddress,
tokensDataService
);
}
}
}
11 changes: 7 additions & 4 deletions packages/horizon/test/escrow/withdraw.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import { IGraphPayments } from "../../contracts/interfaces/IGraphPayments.sol";
import { GraphEscrowTest } from "./GraphEscrow.t.sol";

contract GraphEscrowWithdrawTest is GraphEscrowTest {

/*
* TESTS
*/

function testWithdraw_Tokens(
uint256 amount,
uint256 amount,
uint256 thawAmount
) public useGateway depositAndThawTokens(amount, thawAmount) {
// advance time
Expand All @@ -33,7 +32,11 @@ contract GraphEscrowWithdrawTest is GraphEscrowTest {
uint256 amount,
uint256 thawAmount
) public useGateway depositAndThawTokens(amount, thawAmount) {
bytes memory expectedError = abi.encodeWithSignature("PaymentsEscrowStillThawing(uint256,uint256)", block.timestamp, block.timestamp + withdrawEscrowThawingPeriod);
bytes memory expectedError = abi.encodeWithSignature(
"PaymentsEscrowStillThawing(uint256,uint256)",
block.timestamp,
block.timestamp + withdrawEscrowThawingPeriod
);
vm.expectRevert(expectedError);
escrow.withdraw(users.verifier, users.indexer);
}
Expand Down Expand Up @@ -68,4 +71,4 @@ contract GraphEscrowWithdrawTest is GraphEscrowTest {
resetPrank(users.gateway);
_withdrawEscrow(users.verifier, users.indexer);
}
}
}
17 changes: 11 additions & 6 deletions packages/horizon/test/libraries/LinkedList.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
pragma solidity 0.8.27;

import "forge-std/console.sol";
import {Test} from "forge-std/Test.sol";
import {LinkedList} from "../../contracts/libraries/LinkedList.sol";
import { Test } from "forge-std/Test.sol";
import { LinkedList } from "../../contracts/libraries/LinkedList.sol";

import {ListImplementation} from "./ListImplementation.sol";
import { ListImplementation } from "./ListImplementation.sol";

contract LinkedListTest is Test, ListImplementation {
using LinkedList for LinkedList.List;

function setUp() internal {
list = LinkedList.List({head: bytes32(0), tail: bytes32(0), nonce: 0, count: 0});
list = LinkedList.List({ head: bytes32(0), tail: bytes32(0), nonce: 0, count: 0 });
}

function test_Add_RevertGiven_TheItemIdIsZero() external {
Expand Down Expand Up @@ -161,8 +161,13 @@ contract LinkedListTest is Test, ListImplementation {
}
}

(uint256 processedCount, bytes memory acc) =
list.traverse(_getNextItem, _processItem, _deleteItem, _initAcc, _n);
(uint256 processedCount, bytes memory acc) = list.traverse(
_getNextItem,
_processItem,
_deleteItem,
_initAcc,
_n
);
uint256 afterNonce = list.nonce;
uint256 afterCount = list.count;
bytes32 afterTail = list.tail;
Expand Down
4 changes: 2 additions & 2 deletions packages/horizon/test/libraries/PPMMath.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ contract PPMMathTest is Test {
function test_mulPPM(uint256 a, uint256 b) public pure {
a = bound(a, 0, MAX_PPM);
b = bound(b, 0, type(uint256).max / MAX_PPM);

uint256 result = PPMMath.mulPPM(a, b);
assertEq(result, (a * b) / MAX_PPM);
}

function test_mulPPMRoundUp(uint256 a, uint256 b) public pure {
a = bound(a, 0, type(uint256).max / MAX_PPM);
b = bound(b, 0, MAX_PPM);

uint256 result = PPMMath.mulPPMRoundUp(a, b);
assertEq(result, a - PPMMath.mulPPM(a, MAX_PPM - b));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ contract GraphTallyTest is HorizonStakingSharedTest, PaymentsEscrowSharedTest {

function _getSignerProof(uint256 _proofDeadline, uint256 _signer) internal returns (bytes memory) {
(, address msgSender, ) = vm.readCallers();
bytes32 messageHash = keccak256(abi.encodePacked(block.chainid, address(graphTallyCollector), _proofDeadline, msgSender));
bytes32 messageHash = keccak256(
abi.encodePacked(block.chainid, address(graphTallyCollector), _proofDeadline, msgSender)
);
bytes32 proofToDigest = MessageHashUtils.toEthSignedMessageHash(messageHash);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(_signer, proofToDigest);
return abi.encodePacked(r, s, v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,11 @@ contract GraphTallyCollectTest is GraphTallyTest {

// Attempt to collect again
vm.expectRevert(
abi.encodeWithSelector(IGraphTallyCollector.GraphTallyCollectorInconsistentRAVTokens.selector, tokens, tokens)
abi.encodeWithSelector(
IGraphTallyCollector.GraphTallyCollectorInconsistentRAVTokens.selector,
tokens,
tokens
)
);
graphTallyCollector.collect(IGraphPayments.PaymentTypes.QueryFee, data);
}
Expand Down Expand Up @@ -466,7 +470,11 @@ contract GraphTallyCollectTest is GraphTallyTest {
// Try to collect again with the same allocation - should revert
bytes memory data = _getQueryFeeEncodedData(signerPrivateKey, collectTestParams[i]);
vm.expectRevert(
abi.encodeWithSelector(IGraphTallyCollector.GraphTallyCollectorInconsistentRAVTokens.selector, tokens, tokens)
abi.encodeWithSelector(
IGraphTallyCollector.GraphTallyCollectorInconsistentRAVTokens.selector,
tokens,
tokens
)
);
graphTallyCollector.collect(IGraphPayments.PaymentTypes.QueryFee, data);
}
Expand Down
Loading
Loading