Skip to content

Commit

Permalink
fix: failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Maikol committed May 27, 2024
1 parent ed3fa1e commit b05d064
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 43 deletions.
2 changes: 1 addition & 1 deletion packages/horizon/contracts/staking/HorizonStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
}

function setMaxThawingPeriod(uint64 maxThawingPeriod) external override onlyGovernor {
maxThawingPeriod = _maxThawingPeriod;
_maxThawingPeriod = maxThawingPeriod;
emit MaxThawingPeriodSet(_maxThawingPeriod);
}

Expand Down
4 changes: 1 addition & 3 deletions packages/horizon/test/escrow/GraphEscrow.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,19 @@ contract GraphEscrowTest is HorizonStakingSharedTest {
}

modifier approveEscrow(uint256 tokens) {
changePrank(users.gateway);
_approveEscrow(tokens);
_;
}

modifier useDeposit(uint256 tokens) {
changePrank(users.gateway);
vm.assume(tokens > 0);
vm.assume(tokens <= 10_000_000_000 ether);
_depositTokens(tokens);
_;
}

modifier useCollector(uint256 tokens) {
changePrank(users.gateway);
vm.assume(tokens > 0);
escrow.approveCollector(users.verifier, tokens);
_;
}
Expand Down
14 changes: 9 additions & 5 deletions packages/horizon/test/escrow/collect.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract GraphEscrowCollectTest is GraphEscrowTest {
function testCollect_RevertWhen_CollectorNotAuthorized(uint256 amount) public {
vm.startPrank(users.verifier);
uint256 dataServiceCut = 30000; // 3%
bytes memory expectedError = abi.encodeWithSignature("GraphEscrowCollectorNotAuthorized(address,address)", users.gateway, users.verifier);
bytes memory expectedError = abi.encodeWithSignature("PaymentsEscrowCollectorNotAuthorized(address,address)", users.gateway, users.verifier);
vm.expectRevert(expectedError);
escrow.collect(IGraphPayments.PaymentTypes.QueryFee, users.gateway, users.indexer, amount, subgraphDataServiceAddress, dataServiceCut);
vm.stopPrank();
Expand All @@ -45,8 +45,12 @@ contract GraphEscrowCollectTest is GraphEscrowTest {
) public useGateway useCollector(insufficientAmount) useDeposit(amount) {
vm.assume(insufficientAmount < amount);

changePrank(users.verifier);
bytes memory expectedError = abi.encodeWithSignature("GraphEscrowInsufficientAllowance(uint256,uint256)", insufficientAmount, amount);
vm.startPrank(users.verifier);
bytes memory expectedError = abi.encodeWithSignature(
"PaymentsEscrowInsufficientAllowance(uint256,uint256)",
insufficientAmount,
amount
);
vm.expectRevert(expectedError);
escrow.collect(IGraphPayments.PaymentTypes.QueryFee, users.gateway, users.indexer, amount, subgraphDataServiceAddress, 0);
}
Expand All @@ -57,8 +61,8 @@ contract GraphEscrowCollectTest is GraphEscrowTest {
) public useGateway useCollector(amount) useDeposit(insufficientAmount) {
vm.assume(insufficientAmount < amount);

changePrank(users.verifier);
bytes memory expectedError = abi.encodeWithSignature("GraphEscrowInsufficientBalance(uint256,uint256)", insufficientAmount, amount);
vm.startPrank(users.verifier);
bytes memory expectedError = abi.encodeWithSignature("PaymentsEscrowInsufficientBalance(uint256,uint256)", insufficientAmount, amount);
vm.expectRevert(expectedError);
escrow.collect(IGraphPayments.PaymentTypes.QueryFee, users.gateway, users.indexer, amount, subgraphDataServiceAddress, 0);
vm.stopPrank();
Expand Down
8 changes: 4 additions & 4 deletions packages/horizon/test/escrow/collector.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract GraphEscrowCollectorTest is GraphEscrowTest {
uint256 smallerAmount
) public useGateway useCollector(amount) {
vm.assume(smallerAmount < amount);
bytes memory expectedError = abi.encodeWithSignature("GraphEscrowInsufficientAllowance(uint256,uint256)", amount, smallerAmount);
bytes memory expectedError = abi.encodeWithSignature("PaymentsEscrowInconsistentAllowance(uint256,uint256)", amount, smallerAmount);
vm.expectRevert(expectedError);
escrow.approveCollector(users.verifier, smallerAmount);
}
Expand Down Expand Up @@ -52,7 +52,7 @@ contract GraphEscrowCollectorTest is GraphEscrowTest {
}

function testCollector_RevertWhen_CancelThawIsNotThawing(uint256 amount) public useGateway useCollector(amount) {
bytes memory expectedError = abi.encodeWithSignature("GraphEscrowNotThawing()");
bytes memory expectedError = abi.encodeWithSignature("PaymentsEscrowNotThawing()");
vm.expectRevert(expectedError);
escrow.cancelThawCollector(users.verifier);
vm.stopPrank();
Expand All @@ -70,14 +70,14 @@ contract GraphEscrowCollectorTest is GraphEscrowTest {
}

function testCollector_RevertWhen_RevokeIsNotThawing(uint256 amount) public useGateway useCollector(amount) {
bytes memory expectedError = abi.encodeWithSignature("GraphEscrowNotThawing()");
bytes memory expectedError = abi.encodeWithSignature("PaymentsEscrowNotThawing()");
vm.expectRevert(expectedError);
escrow.revokeCollector(users.verifier);
}

function testCollector_RevertWhen_RevokeIsStillThawing(uint256 amount) public useGateway useCollector(amount) {
escrow.thawCollector(users.verifier);
bytes memory expectedError = abi.encodeWithSignature("GraphEscrowStillThawing(uint256,uint256)", block.timestamp, block.timestamp + revokeCollectorThawingPeriod);
bytes memory expectedError = abi.encodeWithSignature("PaymentsEscrowStillThawing(uint256,uint256)", block.timestamp, block.timestamp + revokeCollectorThawingPeriod);
vm.expectRevert(expectedError);
escrow.revokeCollector(users.verifier);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/horizon/test/escrow/thaw.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract GraphEscrowThawTest is GraphEscrowTest {
function testThaw_RevertWhen_InsufficientThawAmount(
uint256 amount
) public useGateway useDeposit(amount) {
bytes memory expectedError = abi.encodeWithSignature("GraphEscrowInsufficientTokensThawing()");
bytes memory expectedError = abi.encodeWithSignature("PaymentsEscrowInsufficientTokensThawing()");
vm.expectRevert(expectedError);
escrow.thaw(users.indexer, 0);
}
Expand All @@ -27,7 +27,7 @@ contract GraphEscrowThawTest is GraphEscrowTest {
uint256 amount
) public useGateway useDeposit(amount) {
uint256 overAmount = amount + 1;
bytes memory expectedError = abi.encodeWithSignature("GraphEscrowInsufficientBalance(uint256,uint256)", amount, overAmount);
bytes memory expectedError = abi.encodeWithSignature("PaymentsEscrowInsufficientBalance(uint256,uint256)", amount, overAmount);
vm.expectRevert(expectedError);
escrow.thaw(users.indexer, overAmount);
}
Expand Down
6 changes: 2 additions & 4 deletions packages/horizon/test/escrow/withdraw.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,17 @@ contract GraphEscrowWithdrawTest is GraphEscrowTest {
}

function testWithdraw_RevertWhen_NotThawing(uint256 amount) public useGateway useDeposit(amount) {
bytes memory expectedError = abi.encodeWithSignature("GraphEscrowNotThawing()");
bytes memory expectedError = abi.encodeWithSignature("PaymentsEscrowNotThawing()");
vm.expectRevert(expectedError);
escrow.withdraw(users.indexer);
vm.stopPrank();
}

function testWithdraw_RevertWhen_StillThawing(
uint256 amount,
uint256 thawAmount
) public useGateway depositAndThawTokens(amount, thawAmount) {
bytes memory expectedError = abi.encodeWithSignature("GraphEscrowStillThawing(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.indexer);
vm.stopPrank();
}
}
16 changes: 10 additions & 6 deletions packages/horizon/test/staking/delegation/undelegate.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract HorizonStakingUndelegateTest is HorizonStakingTest {
// TODO: maybe create a changePrank
vm.stopPrank();
vm.startPrank(users.delegator);
bytes memory expectedError = abi.encodeWithSignature("HorizonStakingInvalidZeroTokens()");
bytes memory expectedError = abi.encodeWithSignature("HorizonStakingInvalidZeroShares()");
vm.expectRevert(expectedError);
_undelegate(0);
}
Expand All @@ -47,9 +47,9 @@ contract HorizonStakingUndelegateTest is HorizonStakingTest {
vm.assume(overDelegationShares > delegation.shares);

bytes memory expectedError = abi.encodeWithSignature(
"HorizonStakingInsufficientTokens(uint256,uint256)",
overDelegationShares,
delegation.shares
"HorizonStakingInvalidSharesAmount(uint256,uint256)",
delegation.shares,
overDelegationShares
);
vm.expectRevert(expectedError);
_undelegate(overDelegationShares);
Expand All @@ -69,8 +69,12 @@ contract HorizonStakingUndelegateTest is HorizonStakingTest {
vm.startPrank(users.delegator);
uint256 minShares = delegationAmount - MIN_DELEGATION + 1;
withdrawShares = bound(withdrawShares, minShares, delegationAmount - 1);

vm.expectRevert("!minimum-delegation");
bytes memory expectedError = abi.encodeWithSignature(
"HorizonStakingInsufficientTokens(uint256,uint256)",
delegationAmount - withdrawShares,
MIN_DELEGATION
);
vm.expectRevert(expectedError);
_undelegate(withdrawShares);
}
}
2 changes: 1 addition & 1 deletion packages/horizon/test/staking/delegation/withdraw.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ contract HorizonStakingWithdrawDelegationTest is HorizonStakingTest {
useProvision(10_000_000 ether, 0, MAX_THAWING_PERIOD)
useDelegation(delegationAmount)
{
bytes memory expectedError = abi.encodeWithSignature("HorizonStakingNotEnoughThawedTokens()");
bytes memory expectedError = abi.encodeWithSignature("HorizonStakingNothingThawing()");
vm.expectRevert(expectedError);
_withdrawDelegated();
}
Expand Down
7 changes: 3 additions & 4 deletions packages/horizon/test/staking/provision/deprovision.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ contract HorizonStakingDeprovisionTest is HorizonStakingTest {
uint32 maxVerifierCut,
uint64 thawingPeriod
) public useIndexer useProvision(amount, maxVerifierCut, thawingPeriod) {
bytes memory expectedError = abi.encodeWithSignature("HorizonStakingNotEnoughThawedTokens()");
bytes memory expectedError = abi.encodeWithSignature("HorizonStakingCannotFulfillThawRequest()");
vm.expectRevert(expectedError);
_deprovision(amount);
}
Expand All @@ -74,8 +74,7 @@ contract HorizonStakingDeprovisionTest is HorizonStakingTest {
) public useIndexer useProvision(amount, maxVerifierCut, thawingPeriod) useThawRequest(amount) {
vm.assume(thawingPeriod > 0);
bytes memory expectedError = abi.encodeWithSignature(
"HorizonStakingStillThawing(uint256,uint256)",
block.timestamp,
"HorizonStakingStillThawing(uint256)",
block.timestamp + thawingPeriod
);
vm.expectRevert(expectedError);
Expand All @@ -91,7 +90,7 @@ contract HorizonStakingDeprovisionTest is HorizonStakingTest {
vm.assume(deprovisionAmount > amount);
skip(thawingPeriod + 1);

bytes memory expectedError = abi.encodeWithSignature("HorizonStakingNotEnoughThawedTokens()");
bytes memory expectedError = abi.encodeWithSignature("HorizonStakingCannotFulfillThawRequest()");
vm.expectRevert(expectedError);
_deprovision(deprovisionAmount);
}
Expand Down
20 changes: 16 additions & 4 deletions packages/horizon/test/staking/provision/provision.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ contract HorizonStakingProvisionTest is HorizonStakingTest {
}

function testProvision_RevertWhen_InsufficientTokens(uint256 amount) public useIndexer useStake(1000 ether) {
vm.assume(amount < MIN_PROVISION_SIZE);
bytes memory expectedError = abi.encodeWithSignature("HorizonStakingInsufficientTokens(uint256,uint256)", MIN_PROVISION_SIZE, amount);
amount = bound(amount, 0, MIN_PROVISION_SIZE - 1);
bytes memory expectedError = abi.encodeWithSignature(
"HorizonStakingInvalidTokens(uint256,uint256)",
amount,
MIN_PROVISION_SIZE
);
vm.expectRevert(expectedError);
staking.provision(users.indexer, subgraphDataServiceAddress, amount, 0, 0);
}
Expand All @@ -29,7 +33,11 @@ contract HorizonStakingProvisionTest is HorizonStakingTest {
) public useIndexer useStake(amount) {
vm.assume(amount > MIN_PROVISION_SIZE);
vm.assume(maxVerifierCut > MAX_MAX_VERIFIER_CUT);
bytes memory expectedError = abi.encodeWithSignature("HorizonStakingMaxVerifierCutExceeded(uint32,uint32)", MAX_MAX_VERIFIER_CUT, maxVerifierCut);
bytes memory expectedError = abi.encodeWithSignature(
"HorizonStakingInvalidMaxVerifierCut(uint32,uint32)",
maxVerifierCut,
MAX_MAX_VERIFIER_CUT
);
vm.expectRevert(expectedError);
staking.provision(users.indexer, subgraphDataServiceAddress, amount, maxVerifierCut, 0);
}
Expand All @@ -40,7 +48,11 @@ contract HorizonStakingProvisionTest is HorizonStakingTest {
) public useIndexer useStake(amount) {
vm.assume(amount > MIN_PROVISION_SIZE);
vm.assume(thawingPeriod > MAX_THAWING_PERIOD);
bytes memory expectedError = abi.encodeWithSignature("HorizonStakingMaxThawingPeriodExceeded(uint64,uint64)", MAX_THAWING_PERIOD, thawingPeriod);
bytes memory expectedError = abi.encodeWithSignature(
"HorizonStakingInvalidThawingPeriod(uint64,uint64)",
thawingPeriod,
MAX_THAWING_PERIOD
);
vm.expectRevert(expectedError);
staking.provision(users.indexer, subgraphDataServiceAddress, amount, 0, thawingPeriod);
}
Expand Down
7 changes: 3 additions & 4 deletions packages/horizon/test/staking/provision/reprovision.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ contract HorizonStakingReprovisionTest is HorizonStakingTest {
function testReprovision_RevertWhen_NoThawingTokens(
uint256 amount
) public useIndexer useProvision(amount, 0, 0) {
bytes memory expectedError = abi.encodeWithSignature("HorizonStakingNotEnoughThawedTokens()");
bytes memory expectedError = abi.encodeWithSignature("HorizonStakingCannotFulfillThawRequest()");
vm.expectRevert(expectedError);
_reprovision(amount);
}
Expand All @@ -102,8 +102,7 @@ contract HorizonStakingReprovisionTest is HorizonStakingTest {
{
vm.assume(thawingPeriod > 0);
bytes memory expectedError = abi.encodeWithSignature(
"HorizonStakingStillThawing(uint256,uint256)",
block.timestamp,
"HorizonStakingStillThawing(uint256)",
block.timestamp + thawingPeriod
);
vm.expectRevert(expectedError);
Expand All @@ -124,7 +123,7 @@ contract HorizonStakingReprovisionTest is HorizonStakingTest {
skip(thawingPeriod + 1);

_createProvision(newDataService, newProvisionAmount, 0, thawingPeriod);
bytes memory expectedError = abi.encodeWithSignature("HorizonStakingNotEnoughThawedTokens()");
bytes memory expectedError = abi.encodeWithSignature("HorizonStakingCannotFulfillThawRequest()");
vm.expectRevert(expectedError);
_reprovision(newProvisionAmount);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/horizon/test/staking/slash/slash.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ contract HorizonStakingSlashTest is HorizonStakingTest {
slashAmount = bound(slashAmount, MIN_PROVISION_SIZE, amount);
bytes memory expectedError = abi.encodeWithSignature(
"HorizonStakingInsufficientTokens(uint256,uint256)",
slashAmount,
0 ether
0 ether,
slashAmount
);
vm.expectRevert(expectedError);
vm.startPrank(subgraphDataServiceAddress);
Expand Down
6 changes: 3 additions & 3 deletions packages/horizon/test/staking/thaw/thaw.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ contract HorizonStakingThawTest is HorizonStakingTest {
) public useIndexer useProvision(amount, 0, thawingPeriod) {
vm.assume(thawAmount > amount);
bytes memory expectedError = abi.encodeWithSignature(
"HorizonStakingInsufficientTokens(uint256,uint256)",
thawAmount,
amount
"HorizonStakingInsufficientTokensAvailable(uint256,uint256)",
amount,
thawAmount
);
vm.expectRevert(expectedError);
_createThawRequest(thawAmount);
Expand Down

0 comments on commit b05d064

Please sign in to comment.