Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: approving collector for smaller allowance
Browse files Browse the repository at this point in the history
Maikol committed May 22, 2024
1 parent 1981324 commit b20cc18
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/horizon/contracts/payments/PaymentsEscrow.sol
Original file line number Diff line number Diff line change
@@ -82,8 +82,13 @@ contract PaymentsEscrow is Multicall, GraphDirectory, IPaymentsEscrow {

// approve a data service to collect funds
function approveCollector(address dataService, uint256 amount) external {
authorizedCollectors[msg.sender][dataService].authorized = true;
authorizedCollectors[msg.sender][dataService].amount = amount;
IGraphEscrow.Collector storage collector = authorizedCollectors[msg.sender][dataService];
if (collector.amount > amount) {
revert GraphEscrowCollectorInsufficientAmount(collector.amount, amount);
}

collector.authorized = true;
collector.amount = amount;
emit AuthorizedCollector(msg.sender, dataService);
}

10 changes: 10 additions & 0 deletions packages/horizon/test/escrow/collector.t.sol
Original file line number Diff line number Diff line change
@@ -15,6 +15,16 @@ contract GraphEscrowCollectorTest is GraphEscrowTest {
assertEq(thawEndTimestamp, 0);
}

function testCollector_RevertWhen_ApprovingForSmallerAllowance(
uint256 amount,
uint256 smallerAmount
) public useGateway useCollector(amount) {
vm.assume(smallerAmount < amount);
bytes memory expectedError = abi.encodeWithSignature("GraphEscrowCollectorInsufficientAmount(uint256,uint256)", amount, smallerAmount);
vm.expectRevert(expectedError);
escrow.approveCollector(users.verifier, smallerAmount);
}

// Collector thaw tests

function testCollector_Thaw(uint256 amount) public useGateway useCollector(amount) {

0 comments on commit b20cc18

Please sign in to comment.